Ops-methods {rTensor} | R Documentation |
Conformable elementwise operators for Tensor
Description
Overloads elementwise operators for tensors, arrays, and vectors that are conformable (have the same modes).
Usage
## S4 method for signature 'Tensor,Tensor'
Ops(e1, e2)
Arguments
e1 |
left-hand object |
e2 |
right-hand object |
Examples
tnsr <- rand_tensor(c(3,4,5))
tnsr2 <- rand_tensor(c(3,4,5))
tnsrsum <- tnsr + tnsr2
tnsrdiff <- tnsr - tnsr2
tnsrelemprod <- tnsr * tnsr2
tnsrelemquot <- tnsr / tnsr2
for (i in 1:3L){
for (j in 1:4L){
for (k in 1:5L){
stopifnot(tnsrsum@data[i,j,k]==tnsr@data[i,j,k]+tnsr2@data[i,j,k])
stopifnot(tnsrdiff@data[i,j,k]==(tnsr@data[i,j,k]-tnsr2@data[i,j,k]))
stopifnot(tnsrelemprod@data[i,j,k]==tnsr@data[i,j,k]*tnsr2@data[i,j,k])
stopifnot(tnsrelemquot@data[i,j,k]==tnsr@data[i,j,k]/tnsr2@data[i,j,k])
}
}
}
[Package rTensor version 1.4.8 Index]