-
Notifications
You must be signed in to change notification settings - Fork 76
Element wise binary operations
The following element-wise binary arithmetic operators are available all as free functions (note a Fastor expression can be a tensor, a complex expression or a number).
Element-wise addition of two tensors
Tensor<double,2,3> a,b,c;
c = a+b;
Element-wise subtraction of two tensors
Tensor<double,2,3> a,b,c;
c = a-b;
Element-wise multiplication of two tensors
Tensor<double,2,3> a,b,c;
c = a*b;
Element-wise division of two tensors
Tensor<double,2,3> a,b,c;
c = a/b;
Compute element-wise minimum of two tensors
Tensor<double,2,3> a,b,c;
c = min(a,b);
Compute element-wise maximum of two tensors
Tensor<double,2,3> a,b,c;
c = max(a,b);
Raise a tensor to the power given by another tensor element-wise. If both operands are tensors or tensor expressions then they should have the same size and dimension
Tensor<double,2,3> a,b,c;
c = pow(a,b);
Compute arc tangent element-wise given two tensors. If both operands are tensors or tensor expressions then they should have the same size and dimension
Tensor<double,2,3> a,b,c;
c = atan2(a,b);
Compute square root of the sum of the squares of two tensors. If both operands are tensors or tensor expressions then they should have the same size and dimension
Tensor<double,2,3> a,b,c;
c = hypot(a,b);
The following element-wise binary boolean operators are available all as free functions
Check for element-wise equality between two tensors
Tensor<double,2,3> a,b;
Tensor<bool,2,3> c = a==b;
Check for element-wise inequality between two tensors
Tensor<double,2,3> a,b;
Tensor<bool,2,3> c = a!=b;
Element-wise greater than of two tensors
Tensor<double,2,3> a,b;
Tensor<bool,2,3> c = a>b;
Element-wise less than of two tensors
Tensor<double,2,3> a,b;
Tensor<bool,2,3> c = a<b;
Element-wise greater than or equal of two tensors
Tensor<double,2,3> a,b;
Tensor<bool,2,3> c = a>=b;
Element-wise less than or equal of two tensors
Tensor<double,2,3> a,b;
Tensor<bool,2,3> c = a<=b;
Element-wise and
of two tensors
Tensor<double,2,3> a,b;
Tensor<bool,2,3> c = a && b;
Element-wise or
of two tensors
Tensor<double,2,3> a,b;
Tensor<bool,2,3> c = a || b;
A Fastor::Expression
can also include numbers/scalars, for example
Tensor<int,2,2> a = {{1,2},{3,4}};
Tensor<bool,2,2> b = a > 2;
will give you
[0, 0]
[1, 1]
You can have complex boolean expressions on both sides of the comparisons
Tensor<int,2,2> a = {{1,2},{3,4}};
Tensor<bool,2,2> b = a+1 > a-1;
will give you
[1, 1]
[1, 1]
Note that, the result of the comparison is an expression and not another tensor so you will have to manually assign the result to a boolean tensor of the same dimensions.