Skip to content

Element wise unary operations

Roman edited this page Jun 11, 2020 · 3 revisions

Element-wise unary operations

Element-wise unary math operations

The following element-wise unary mathematical operators are available all as free functions

+(Fastor::Expression)

Unary addition operation

Tensor<double,2,3,4> a; 
Tensor<double,2,3,4> b = +a;
assert(all_of(b==a)); 

-(Fastor::Expression)

Unary subtraction operation

Tensor<double,2,3,4> a; 
Tensor<double,2,3,4> b = -a;
assert(all_of(b==-a)); 

abs(Fastor::Expression)

Compute element-wise absolute value of a tensor

Tensor<double,2,3,4> a; 
Tensor<double,2,3,4> b = abs(a);

sqrt(Fastor::Expression)

Compute element-wise square root of a tensor

Tensor<double,2,3,4> a; 
Tensor<double,2,3,4> b = sqrt(a);

cbrt(Fastor::Expression)

Compute element-wise cubic root of a tensor

Tensor<double,2,3,4> a; 
Tensor<double,2,3,4> b = cbrt(a);

log(Fastor::Expression)

Compute element-wise natural logarithm of a tensor

Tensor<double,2,3,4> a; 
Tensor<double,2,3,4> b = log(a);

log10(Fastor::Expression)

Compute element-wise base 10 logarithm of a tensor

Tensor<double,2,3,4> a; 
Tensor<double,2,3,4> b = log10(a);

log2(Fastor::Expression)

Compute element-wise base 2 logarithm of a tensor

Tensor<double,2,3,4> a; 
Tensor<double,2,3,4> b = log2(a);

log1p(Fastor::Expression)

Compute element-wise natural logarithm of a tensor plus one

Tensor<double,2,3,4> a; 
Tensor<double,2,3,4> b = log1p(a);

exp(Fastor::Expression)

Compute element-wise Euler exponential of a tensor

Tensor<double,2,3,4> a; 
auto b = exp(a);

exp2(Fastor::Expression)

Compute element-wise 2-based exponential of a tensor

Tensor<double,2,3,4> a; 
auto b = exp2(a);

expm1(Fastor::Expression)

Compute element-wise Euler exponential of a tensor minus one

Tensor<double,2,3,4> a; 
auto b = expm1(a);

sin(Fastor::Expression)

Compute element-wise sin of a tensor

Tensor<double,2,3,4> a; 
auto b = sin(a);

cos(Fastor::Expression)

Compute element-wise cos of a tensor

Tensor<double,2,3,4> a; 
auto b = cos(a);

tan(Fastor::Expression)

Compute element-wise tan of a tensor

Tensor<double,2,3,4> a; 
auto b = tan(a);

asin(Fastor::Expression)

Compute element-wise asin of a tensor

Tensor<double,2,3,4> a; 
auto b = asin(a);

acos(Fastor::Expression)

Compute element-wise acos of a tensor

Tensor<double,2,3,4> a; 
auto b = acos(a);

atan(Fastor::Expression)

Compute element-wise atan of a tensor

Tensor<double,2,3,4> a; 
auto b = atan(a);

sinh(Fastor::Expression)

Compute element-wise sinh of a tensor

Tensor<double,2,3,4> a; 
auto b = sinh(a);

cosh(Fastor::Expression)

Compute element-wise cosh of a tensor

Tensor<double,2,3,4> a; 
auto b = cosh(a);

tanh(Fastor::Expression)

Compute element-wise tanh of a tensor

Tensor<double,2,3,4> a; 
auto b = tanh(a);

asinh(Fastor::Expression)

Compute element-wise asinh of a tensor

Tensor<double,2,3,4> a; 
auto b = asinh(a);

acosh(Fastor::Expression)

Compute element-wise acosh of a tensor

Tensor<double,2,3,4> a; 
auto b = acosh(a);

atanh(Fastor::Expression)

Compute element-wise atanh of a tensor

Tensor<double,2,3,4> a; 
auto b = atanh(a);

round(Fastor::Expression)

Round a tensor element-wise

Tensor<double,2,3,4> a; 
auto b = round(a);

ceil(Fastor::Expression)

Ceil a tensor element-wise

Tensor<double,2,3,4> a; 
auto b = ceil(a);

floor(Fastor::Expression)

Floor a tensor element-wise

Tensor<double,2,3,4> a; 
auto b = floor(a);

trunc(Fastor::Expression)

Truncate a tensor element-wise

Tensor<double,2,3,4> a; 
auto b = trunc(a);

erf(Fastor::Expression)

Compute element-wise error function erf of a tensor

Tensor<double,2,3,4> a; 
auto b = erf(a);

tgamma(Fastor::Expression)

Compute element-wise gamma function tgamma of a tensor

Tensor<double,2,3,4> a; 
auto b = tgamma(a);

lgamma(Fastor::Expression)

Compute element-wise logarithmic gamma function lgamma of a tensor

Tensor<double,2,3,4> a; 
auto b = lgamma(a);

conj(Fastor::Expression)

Compute element-wise conjugate of a complex valued tensor

Tensor<std::complex<double>,2,3,4> a; 
auto b = conj(a);

arg(Fastor::Expression)

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)

Element-wise boolean operations

The following element-wise unary boolean operators are available all as free functions

!(Fastor::Expression)

Compute the element-wise not of a tensor expression

Tensor<double,2,3,4> a; 
Tensor<bool,2,3,4> b = !a;

isinf(Fastor::Expression)

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));

isnan(Fastor::Expression)

Check if the elements in the tensor expression are nan

Tensor<double,2,3,4> a; 
Tensor<bool,2,3,4> b = isnan(a);

isfinite(Fastor::Expression)

Check if the elements in the tensor expression are finite

Tensor<double,2,3,4> a; 
Tensor<bool,2,3,4> b = isfinite(a);
Clone this wiki locally