-
Notifications
You must be signed in to change notification settings - Fork 71
Element wise unary operations
The following element-wise unary mathematical operators are available all as free functions
Unary addition operation
Tensor<double,2,3,4> a;
Tensor<double,2,3,4> b = +a;
assert(all_of(b==a));
Unary subtraction operation
Tensor<double,2,3,4> a;
Tensor<double,2,3,4> b = -a;
assert(all_of(b==-a));
Compute element-wise absolute value of a tensor
Tensor<double,2,3,4> a;
Tensor<double,2,3,4> b = abs(a);
Compute element-wise square root of a tensor
Tensor<double,2,3,4> a;
Tensor<double,2,3,4> b = sqrt(a);
Compute element-wise cubic root of a tensor
Tensor<double,2,3,4> a;
Tensor<double,2,3,4> b = cbrt(a);
Compute element-wise natural logarithm of a tensor
Tensor<double,2,3,4> a;
Tensor<double,2,3,4> b = log(a);
Compute element-wise base 10 logarithm of a tensor
Tensor<double,2,3,4> a;
Tensor<double,2,3,4> b = log10(a);
Compute element-wise base 2 logarithm of a tensor
Tensor<double,2,3,4> a;
Tensor<double,2,3,4> b = log2(a);
Compute element-wise natural logarithm of a tensor plus one
Tensor<double,2,3,4> a;
Tensor<double,2,3,4> b = log1p(a);
Compute element-wise Euler exponential of a tensor
Tensor<double,2,3,4> a;
auto b = exp(a);
Compute element-wise 2-based exponential of a tensor
Tensor<double,2,3,4> a;
auto b = exp2(a);
Compute element-wise Euler exponential of a tensor minus one
Tensor<double,2,3,4> a;
auto b = expm1(a);
Compute element-wise sin
of a tensor
Tensor<double,2,3,4> a;
auto b = sin(a);
Compute element-wise cos
of a tensor
Tensor<double,2,3,4> a;
auto b = cos(a);
Compute element-wise tan
of a tensor
Tensor<double,2,3,4> a;
auto b = tan(a);
Compute element-wise asin
of a tensor
Tensor<double,2,3,4> a;
auto b = asin(a);
Compute element-wise acos
of a tensor
Tensor<double,2,3,4> a;
auto b = acos(a);
Compute element-wise atan
of a tensor
Tensor<double,2,3,4> a;
auto b = atan(a);
Compute element-wise sinh
of a tensor
Tensor<double,2,3,4> a;
auto b = sinh(a);
Compute element-wise cosh
of a tensor
Tensor<double,2,3,4> a;
auto b = cosh(a);
Compute element-wise tanh
of a tensor
Tensor<double,2,3,4> a;
auto b = tanh(a);
Compute element-wise asinh
of a tensor
Tensor<double,2,3,4> a;
auto b = asinh(a);
Compute element-wise acosh
of a tensor
Tensor<double,2,3,4> a;
auto b = acosh(a);
Compute element-wise atanh
of a tensor
Tensor<double,2,3,4> a;
auto b = atanh(a);
Round a tensor element-wise
Tensor<double,2,3,4> a;
auto b = round(a);
Ceil a tensor element-wise
Tensor<double,2,3,4> a;
auto b = ceil(a);
Floor a tensor element-wise
Tensor<double,2,3,4> a;
auto b = floor(a);
Truncate a tensor element-wise
Tensor<double,2,3,4> a;
auto b = trunc(a);
Compute element-wise error function erf
of a tensor
Tensor<double,2,3,4> a;
auto b = erf(a);
Compute element-wise gamma function tgamma
of a tensor
Tensor<double,2,3,4> a;
auto b = tgamma(a);
Compute element-wise logarithmic gamma function lgamma
of a tensor
Tensor<double,2,3,4> a;
auto b = lgamma(a);
Compute element-wise conjugate of a complex valued tensor
Tensor<std::complex<double>,2,3,4> a;
auto b = conj(a);
Compute element-wise argument (or phase angle) of a complex valued tensor
Tensor<std::complex<double>,2,3,4> a;
auto b = arg(a);
Note that this operators do not immediately evaluate work so the result is not a tensor unless you explicitly assign them to a tensor. You can chain these operations for instance
sqrt(a+1);
sin(sqrt(a+1));
exp(sin(sqrt(a+1)));
exp(sin(sqrt(a+1))) + log(a*10);
// and so on
// or on TensorMap
TensorMap<double,2,3,4> b(a);
sqrt(b); // same as sqrt(a)
The following element-wise unary boolean operators are available all as free functions
Compute the element-wise not
of a tensor expression
Tensor<double,2,3,4> a;
Tensor<bool,2,3,4> b = !a;
Check if the elements in the tensor expression are inf
Tensor<double,2,3,4> a;
Tensor<bool,2,3,4> b = isinf(a);
assert(all_of(b==false));
Check if the elements in the tensor expression are nan
Tensor<double,2,3,4> a;
Tensor<bool,2,3,4> b = isnan(a);
Check if the elements in the tensor expression are finite
Tensor<double,2,3,4> a;
Tensor<bool,2,3,4> b = isfinite(a);