tensorA (version 0.36.1)

add.tensor: Element-wise arithmetic operations +,-,*,/ with tensors

Description

Adds/subs/multiplies/devides tensors element by element . The luxury difference to a simple + is that we do not need to consider the correct permutation of indices or rules on implicit replication, since all of this is handled automatically.

Usage

add.tensor(X,Y,op="+",only=NULL)
## Methods for class tensor
# x + y
# x - y
# x * y
# x - y

Arguments

X

a tensor

Y

a tensor

op

a binary function used to perform the "addition"

only

a list of dimnames that may be considered as equal. This parameter is here to allow parallelization of tensors with only partially known structure.

Value

A tensor giving the element-wise operation X,Y. If some of the indices are missing in one of the tensors they are added by repetition.

Details

The tensors are properly reordered such that dimensions of the same name are identified. If dimensions are missing in one of the tensors it is correspondingly repeated.

See Also

to.tensor

Examples

Run this code
# NOT RUN {
A <- to.tensor(1:20,c(U=2,V=2,W=5))
add.tensor(A,A)/2 -A
(A+A)/2
A/A
A * 1/A
norm.tensor(reorder.tensor(A,c(2,3,1)) - A)
# }

Run the code above in your browser using DataLab