Learn R Programming

rTensor (version 1.4.8)

Ops-methods: 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 Tensor,Tensor
Ops(e1, e2)

Arguments

e1

left-hand object

e2

right-hand object

Examples

Run this code
# NOT RUN {
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])
}
}
}
# }

Run the code above in your browser using DataLab