Description Details Active bindings Methods Author(s) Examples
Number Legnth
Number Legnth
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.
vSets or gets the number value
dvSets or gets the number derivative value
new()Initialise the reference object of class 'number'
.number$new(name = NULL)
namenumber name
finalize()Awares of a reference object associated
to an existing number is removed
.number$finalize()
name()Returns the name of the number.
.number$name()
Returns the name of the number
id()Returns the id of the number
(i.e. its position index in the NUMBERS_ array).
.number$id()
Returns the id of the number
pop()Pop (removes) the number from the
NUMBERS_ array.
.number$pop()
Returns invisible self
\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()
}
is.linked()Checks that the reference object is linked to
a number
.number$is.linked()
Retursn TRUE if is linked, FALSE otherwise
\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()
}
rank()Returns the rank of the number.
.number$rank()
Returns the rank of the number
\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
x$rank() # 2
modello.close()
}
has.dx()Returns TRUE if the number has derivative,
FALSE otherwise
.number$has.dx()
TRUE/FALSE
\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()
}
collect()Returns a list representation of the number
.number$collect()
save()Saves the number in RDS format
.number$save(file = NULL, ...)
filefilename, if null the number name is used
...additional arguments for the function saveRDS
length()Returns the size of the number
.number$length()
Returns the size of the number
\donttest{
modello.init(10, 10, 10, 10)
x = number(c(1, 2, 3))
x$length() # 3
modello.close()
}
dim()Returns the shape of the number
.number$dim()
Returns the number shape
\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9, 3, 3)))
x$dim() # c(3, 3)
modello.close()
}
set.v()Sets the value of the number
.number$set.v(x)
xnumber value
Returns invisible self
modello.init(10, 10, 10, 10) x = number(1) x$set.v(2) x$get.v() modello.close()
get.v()Returns the value of a number
.number$get.v()
Returns the number value
\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$set.v(2)
x$get.v()
modello.close()
}
set.dv()Sets the derivative value of the number
.number$set.dv(x)
xnumber derivative value
Returns invisible self
\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()
}
set.slice()Sets the values of a slice in a number
.number$set.slice(v, ..., dx = FALSE)
vvalue to be set
...indexes along the number dimensions defining the slice
dxif TRUE the slice is taken from the gradient
Returns invisible self
\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()
}
set.flat_slice()Sets the values of a slice in a number
considering the number flat
.number$set.flat_slice(v, s, dx = FALSE)
vvalue to be set
sindexes defining the slice
dxif TRUE the slice is taken from the gradient
Returns invisible self
\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()
}
get.dv()Returns the derivative value of a number
.number$get.dv()
Returns the number value
\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()
}
slice()Create a slice of the number
.number$slice(...)
...slice indexes
nameoutout number name
Returns a reference object of class 'number' with the slice
\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()
}
flat_slice()Create a flat slice of the number
.number$flat_slice(s)
sflat slice indexes
nameoutout number name
Returns a reference object of class 'number' with the flat slice
\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()
}
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.
.number$contiguous.slice(s1, s2 = NULL)
s1intial index of the contiguous slice
s2final index of the contiguous slice
nameoutout number name
Returns a reference object of class 'number' with the contiguous slice
\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()
}
reshape()Reshape the number according the the given shape vector.
The number is not copied but reshaped through pointers.
.number$reshape(shp, name = NULL)
shpshape vector
nameoutput number name
Returns a reference object of class 'number' with the reshape
\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()
}
drop.dim()Reshape the number by dropping the collapsed dimensions.
The number is not copied but reshaped through pointers.
.number$drop.dim()
nameoutput number name
\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()
}
bind()Binds the number to another along the given dimension
.number$bind(x, k)
xnumber to bind
kdimension index
namename of the output number
Returns areference object of class 'number'
\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()
}
op()Runs the node operator that generated the number
.number$op()
Returns invisible self
\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()
}
bw.zero()Resest the derivative values for the number node
accoriding to the backward differentiation schema.
.number$bw.zero()
Returns invisible self
\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()
}
bw()Applies bakward differentiation to the number node
.number$bw()
Returns invisible self
\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()
}
print()Prints a representation of the number
.number$print()
clone()The objects of this class are cloneable with this method.
.number$clone(deep = FALSE)
deepWhether to make a deep clone.
Filippo Monari
Filippo Monari
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | ## ------------------------------------------------
## Method `.number$pop`
## ------------------------------------------------
modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()
## ------------------------------------------------
## Method `.number$is.linked`
## ------------------------------------------------
modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()
## ------------------------------------------------
## Method `.number$rank`
## ------------------------------------------------
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
x$rank() # 2
modello.close()
## ------------------------------------------------
## Method `.number$has.dx`
## ------------------------------------------------
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 `.number$length`
## ------------------------------------------------
modello.init(10, 10, 10, 10)
x = number(c(1, 2, 3))
x$length() # 3
modello.close()
## ------------------------------------------------
## Method `.number$dim`
## ------------------------------------------------
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9, 3, 3)))
x$dim() # c(3, 3)
modello.close()
## ------------------------------------------------
## 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`
## ------------------------------------------------
modello.init(10, 10, 10, 10)
x = number(1)
x$set.v(2)
x$get.v()
modello.close()
## ------------------------------------------------
## Method `.number$set.dv`
## ------------------------------------------------
modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()
## ------------------------------------------------
## Method `.number$set.slice`
## ------------------------------------------------
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 `.number$set.flat_slice`
## ------------------------------------------------
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 `.number$get.dv`
## ------------------------------------------------
modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()
## ------------------------------------------------
## Method `.number$slice`
## ------------------------------------------------
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 `.number$flat_slice`
## ------------------------------------------------
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 `.number$contiguous.slice`
## ------------------------------------------------
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 `.number$reshape`
## ------------------------------------------------
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 `.number$drop.dim`
## ------------------------------------------------
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 `.number$bind`
## ------------------------------------------------
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 `.number$op`
## ------------------------------------------------
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 `.number$bw.zero`
## ------------------------------------------------
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 `.number$bw`
## ------------------------------------------------
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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.