Learn R Programming

modello (version 0.1.1)

.number: Number Legnth

Description

Number Legnth

Number Legnth

Arguments

Active bindings

v

Sets or gets the number value

dv

Sets or gets the number derivative value

Methods

Public methods

Method new()

Initialise the reference object of class 'number'

Usage

.number$new(name = NULL)

Arguments

name

number name

Method finalize()

Awares of a reference object associated to an existing number is removed

Usage

.number$finalize()

Method name()

Returns the name of the number.

Usage

.number$name()

Returns

Returns the name of the number

Method id()

Returns the id of the number (i.e. its position index in the NUMBERS_ array).

Usage

.number$id()

Returns

Returns the id of the number

Method pop()

Pop (removes) the number from the NUMBERS_ array.

Usage

.number$pop()

Returns

Returns invisible self

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()
}

Method is.linked()

Checks that the reference object is linked to a number

Usage

.number$is.linked()

Returns

Retursn TRUE if is linked, FALSE otherwise

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()
}

Method rank()

Returns the rank of the number.

Usage

.number$rank()

Returns

Returns the rank of the number

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
x$rank() # 2
modello.close()
}

Method has.dx()

Returns TRUE if the number has derivative, FALSE otherwise

Usage

.number$has.dx()

Returns

TRUE/FALSE

Examples

\donttest{
modello.init(10, 10, 10, 10)
x1 = number(1)
x1$has.dx() # TRUE
x2 = number(1, dx=FALSE)
x2$has.dx() # FALSE
modello.close()
}

Method collect()

Returns a list representation of the number

Usage

.number$collect()

Method save()

Saves the number in RDS format

Usage

.number$save(file = NULL, ...)

Arguments

file

filename, if null the number name is used

...

additional arguments for the function saveRDS

Method length()

Returns the size of the number

Usage

.number$length()

Returns

Returns the size of the number

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(c(1, 2, 3))
x$length() # 3
modello.close()
}

Method dim()

Returns the shape of the number

Usage

.number$dim()

Returns

Returns the number shape

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9, 3, 3)))
x$dim() # c(3, 3)
modello.close()
}

Method set.v()

Sets the value of the number

Usage

.number$set.v(x)

Arguments

x

number value

Returns

Returns invisible self

Examples

modello.init(10, 10, 10, 10)
x = number(1)
x$set.v(2)
x$get.v()
modello.close()

Method get.v()

Returns the value of a number

Usage

.number$get.v()

Returns

Returns the number value

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$set.v(2)
x$get.v()
modello.close()
}

Method set.dv()

Sets the derivative value of the number

Usage

.number$set.dv(x)

Arguments

x

number derivative value

Returns

Returns invisible self

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()
}

Method set.slice()

Sets the values of a slice in a number

Usage

.number$set.slice(v, ..., dx = FALSE)

Arguments

v

value to be set

...

indexes along the number dimensions defining the slice

dx

if TRUE the slice is taken from the gradient

Returns

Returns invisible self

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(0, 3, 3))
print(x$v)
print(x$dv)
x$set.slice(1, 1:3, 1:3)
x$set.slice(2, 1:3, 1:3, dx=TRUE)
print(x$v)
print(x$dv)
modello.close()
}

Method set.flat_slice()

Sets the values of a slice in a number considering the number flat

Usage

.number$set.flat_slice(v, s, dx = FALSE)

Arguments

v

value to be set

s

indexes defining the slice

dx

if TRUE the slice is taken from the gradient

Returns

Returns invisible self

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(0, 3, 3))
print(x$v)
print(x$dv)
x$set.flat_slice(1, 1:9)
x$set.flat_slice(2, 1:9, dx=TRUE)
print(x$v)
print(x$dv)
modello.close()
}

Method get.dv()

Returns the derivative value of a number

Usage

.number$get.dv()

Returns

Returns the number value

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()
}

Method slice()

Create a slice of the number

Usage

.number$slice(...)

Arguments

...

slice indexes

name

outout number name

Returns

Returns a reference object of class 'number' with the slice

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$slice(1:2, 1:3)
print(y$v)
modello.close()
}

Method flat_slice()

Create a flat slice of the number

Usage

.number$flat_slice(s)

Arguments

s

flat slice indexes

name

outout number name

Returns

Returns a reference object of class 'number' with the flat slice

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$flat_slice(1:6)
print(y$v)
modello.close()
}

Method contiguous.slice()

Create a contiguous slice of the number. Slice along the leading order (columns).

The number values are not copied but only referred through pointers.

Usage

.number$contiguous.slice(s1, s2 = NULL)

Arguments

s1

intial index of the contiguous slice

s2

final index of the contiguous slice

name

outout number name

Returns

Returns a reference object of class 'number' with the contiguous slice

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$slice(1, 2)
print(y$v)
modello.close()
}

Method reshape()

Reshape the number according the the given shape vector.

The number is not copied but reshaped through pointers.

Usage

.number$reshape(shp, name = NULL)

Arguments

shp

shape vector

name

output number name

Returns

Returns a reference object of class 'number' with the reshape

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(c(1, 2, 3, 4, 5, 6))
y = x$reshape(c(3, 2))
print(x)
print(x$v)
print(y)
print(y$v)
modello.close()
}

Method drop.dim()

Reshape the number by dropping the collapsed dimensions.

The number is not copied but reshaped through pointers.

Usage

.number$drop.dim()

Arguments

name

output number name

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(as.matrix(c(1, 2, 3)))
print(x)
print(x$v)
y = x$drop.dim()
print(y)
print(y$v)
modello.close()
}

Method bind()

Binds the number to another along the given dimension

Usage

.number$bind(x, k)

Arguments

x

number to bind

k

dimension index

name

name of the output number

Returns

Returns areference object of class 'number'

Examples

\donttest{
modello.init(10, 10, 10, 10)
x = number(as.matrix(c(1, 2, 3)))
y = number(as.matrix(c(4, 5, 6)))
z = x$bind(y, 2)
print(z)
print(z$v)
modello.close()
}

Method op()

Runs the node operator that generated the number

Usage

.number$op()

Returns

Returns invisible self

Examples

\donttest{
modello.init(10, 10, 10, 10)
g = graph.open()
x1 = number(1)
x2 = number(2)
x3 = x1 + x2
graph.close()
print(x3$v)
x1$v = 2
x3$op()
print(x3$v)
modello.close()
}

Method bw.zero()

Resest the derivative values for the number node accoriding to the backward differentiation schema.

Usage

.number$bw.zero()

Returns

Returns invisible self

Examples

\donttest{
modello.init(10, 10, 10, 10)
g = graph.open()
x1 = number(4)
x2 = number(2)
x3 = x1 ** x2
g = graph.close()
print(x1$dv)
print(x2$dv)
x3$dv = 1
x3$bw()
print(x1$dv)
print(x2$dv)
x3$bw.zero()
print(x1$dv)
print(x2$dv)
modello.close()
}

Method bw()

Applies bakward differentiation to the number node

Usage

.number$bw()

Returns

Returns invisible self

Examples

\donttest{
modello.init(10, 10, 10, 10)
x1 = number(4)
x2 = number(2)
g = graph.open()
x3 = x1 ** x2
graph.close()
print(x1$dv)
print(x2$dv)
x3$dv = 1
x3$bw()
print(x1$dv)
print(x2$dv)
x3$bw.zero()
print(x1$dv)
print(x2$dv)
modello.close()
}

Method print()

Prints a representation of the number

Usage

.number$print()

Method clone()

The objects of this class are cloneable with this method.

Usage

.number$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

R6 class representing a number

Object of this class are created by the '.modello' session object that linkes them with the corresponding numbers in the FORTRAN environment.

Examples

Run this code
# NOT RUN {
## ------------------------------------------------
## Method `.number$pop`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$is.linked`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$rank`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
x$rank() # 2
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$has.dx`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x1 = number(1)
x1$has.dx() # TRUE
x2 = number(1, dx=FALSE)
x2$has.dx() # FALSE
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$length`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(c(1, 2, 3))
x$length() # 3
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$dim`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9, 3, 3)))
x$dim() # c(3, 3)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$set.v`
## ------------------------------------------------

modello.init(10, 10, 10, 10)
x = number(1)
x$set.v(2)
x$get.v()
modello.close()

## ------------------------------------------------
## Method `.number$get.v`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(1)
x$set.v(2)
x$get.v()
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$set.dv`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$set.slice`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(matrix(0, 3, 3))
print(x$v)
print(x$dv)
x$set.slice(1, 1:3, 1:3)
x$set.slice(2, 1:3, 1:3, dx=TRUE)
print(x$v)
print(x$dv)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$set.flat_slice`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(matrix(0, 3, 3))
print(x$v)
print(x$dv)
x$set.flat_slice(1, 1:9)
x$set.flat_slice(2, 1:9, dx=TRUE)
print(x$v)
print(x$dv)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$get.dv`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$slice`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$slice(1:2, 1:3)
print(y$v)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$flat_slice`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$flat_slice(1:6)
print(y$v)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$contiguous.slice`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$slice(1, 2)
print(y$v)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$reshape`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(c(1, 2, 3, 4, 5, 6))
y = x$reshape(c(3, 2))
print(x)
print(x$v)
print(y)
print(y$v)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$drop.dim`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(as.matrix(c(1, 2, 3)))
print(x)
print(x$v)
y = x$drop.dim()
print(y)
print(y$v)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$bind`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x = number(as.matrix(c(1, 2, 3)))
y = number(as.matrix(c(4, 5, 6)))
z = x$bind(y, 2)
print(z)
print(z$v)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$op`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
g = graph.open()
x1 = number(1)
x2 = number(2)
x3 = x1 + x2
graph.close()
print(x3$v)
x1$v = 2
x3$op()
print(x3$v)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$bw.zero`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
g = graph.open()
x1 = number(4)
x2 = number(2)
x3 = x1 ** x2
g = graph.close()
print(x1$dv)
print(x2$dv)
x3$dv = 1
x3$bw()
print(x1$dv)
print(x2$dv)
x3$bw.zero()
print(x1$dv)
print(x2$dv)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.number$bw`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x1 = number(4)
x2 = number(2)
g = graph.open()
x3 = x1 ** x2
graph.close()
print(x1$dv)
print(x2$dv)
x3$dv = 1
x3$bw()
print(x1$dv)
print(x2$dv)
x3$bw.zero()
print(x1$dv)
print(x2$dv)
modello.close()
# }

Run the code above in your browser using DataLab