3.5. Tensor Operations

VSIPL++ Tensor objects represent three-dimensional sets of data. The type of values stored in the tensor is given by the first template argument.

3.5.1. Tensor Generation Functions

A = 0
Clears tensor to value 0.
A = value
Fills tensor with scalar value value.

3.5.2. Tensor Copy

Z = A
Copies value from tensor A into tensor Z.

3.5.3. Tensor Arithmetic Elementwise Unary Operations and Functions

The following elementwise unary operations can be performed on tensors, producing a tensor result:

acos(A)
Trigonometric arc cosine (section 4.2.1)
arg(A)
Phase angle of complex (section 4.2.4)
asin(A)
Trigonometric arc sine (section 4.2.5)
atan(A)
Trigonometric arc tangent (section 4.2.6)
bnot(A)
Boolean not (section 4.2.35)
ceil(A)
Round floating-point value up to next integral value (section 4.2.12)
conj(A)
Complex conjugate (section 4.2.13)
cos(A)
Trigonometric cosine (section 4.2.14)
cosh(A)
Hyperbolic cosine (section 4.2.15)
euler(A)
Rotate complex unit vector by angle (section 4.2.18)
exp(A)
Natural exponential (section 4.2.19)
exp10(A)
Base-10 exponential (section 4.2.20)
floor(A)
Round floating-point value down to next integral value (section 4.2.22)
imag(A)
Imaginary part of complex (section 4.2.27)
is_finite(A)
Is floating-point value finite (section 4.2.29)
is_nan(A)
Is floating-point value not a number (NaN) (section 4.2.29)
is_normal(A)
Is floating-point value normal (section 4.2.30)
lnot(A)
Logical not (section 4.2.35)
log(A)
Base-e logarithm (section 4.2.36)
log10(A)
Base-10 logarithm (section 4.2.37)
mag(A)
Magnitude (section 4.2.42)
magsq(A)
Magnitude squared (section 4.2.43)
neg(A)
Negation (section 4.2.53)
real(A)
Real part of complex (section 4.2.55)
recip(A)
Recipricol (section 4.2.56)
rsqrt(A)
Recipricol square root (section 4.2.57)
sin(A)
Trigonometric sine (section 4.2.59)
sinh(A)
Hyperbolic sine (section 4.2.60)
sq(A)
Square (section 4.2.61)
sqrt(A)
Square root (section 4.2.62)
tan(A)
Trigonometric tangent (section 4.2.64)
tanh(A)
Hyperbolic tangent (section 4.2.65)

3.5.4. Tensor Arithmetic Elementwise Binary Operations and Functions

The following elementwise binary operations can be performed on tensors, producing a tensor result:

add(A)
Addition (section 4.2.2)
atan2(A)
Arc tangent of quotient (section 4.2.7)
band(A)
Bitwise and (section 4.2.8)
bor(A)
Bitwise or (section 4.2.9)
bxor(A)
Bitwise exclusive or (section 4.2.11)
div(A)
Division (section 4.2.16)
eq(A)
Equality comparison (section 4.2.17)
fmod(A)
Floating-point modulo (remainder after division) (section 4.2.23)
ge(A)
Greater-than or equal comparison (section 4.2.24)
gt(A)
Greater-than comparison (section 4.2.25)
hypot(A)
Hypotenuse of right triangle (section 4.2.26)
jmul(A)
Conjugate multiply (section 4.2.32)
land(A)
Logical and (section 4.2.33)
le(A)
Less-than or equal comparison (section 4.2.34)
lor(A)
Logical or (section 4.2.38)
lt(A)
Less-than comparison (section 4.2.39)
lxor(A)
Logical exclusive or (section 4.2.40)
max(A)
Maxima (section 4.2.44)
maxmg(A)
Magnitude maxima (section 4.2.45)
maxmgsq(A)
Magnitude squared maxima (section 4.2.46)
min(A)
Minima (section 4.2.47)
minmg(A)
Magnitude minima (section 4.2.48)
minmgsq(A)
Magnitude squared minima (section 4.2.49)
mul(A)
Multiplication (section 4.2.51)
ne(A)
Not equal comparison (section 4.2.52)
pow(A)
Raise to power (section 4.2.54)
sub(A)
Subtract (section 4.2.63)

3.5.5. Tensor Arithmetic Elementwise Ternary Operations and Functions

The following elementwise ternary operations can be performed on tensors, producing a tensor result:

am(A)
Fused addition-multiplication (section 4.2.3)
expoavg(A)
Exponential average (section 4.2.21)
ite(A)
Addition (section 4.2.31)
ma(A)
Fused multiplication-addition (section 4.2.41)
msb(A)
Fused multiplication-subtraction (section 4.2.50)
sbm(A)
Fused subtraction-multiplication (section 4.2.58)

3.5.6. Tensor Type Conversions

A tensor with one type of values can be converted a tensor with another type of values using view_cast.

For example, to convert a tensor of floats A into a tensor of ints Z:

Tensor<float> A(size);
Tensor<int>   Z(size);
Z = view_cast<int>(A)

3.5.7. Tensor Arithmetic Elementwise Binary Operations and Functions

The following arithmetic elementwise binary operations and functions are available on tensors:

Z = add(A, B)
Addition, Z(n) = A(n) + B(n)(section 4.2.2)
Z = div(A, B)
Division, Z(n) = A(n) / B(n)(section 4.2.16)
Z = max(A, B)
Maximum of A(n) and B(n)
Z = min(A, B)
Minimum of A(n) and B(n)
Z = mul(A, B)
Multiplication, Z(n) = A(n) * B(n)(section 4.2.51)
Z = sub(A, B)
Subtraction, Z(n) = A(n) - B(n)(section 4.2.63)

Addition, subtraction, multiplication, and division can also be written in operator form:

Z = A + B
equivalent to Z = add(A, B)
Z = A - B
equivalent to Z = sub(A, B)
Z = A * B
equivalent to Z = mul(A, B)
Z = A / B
equivalent to Z = div(A, B)

In all the preceding functions and operations, either of the tensor operands can be replaced with scalar operands.

For example, to perform a scalar-tensor multiply:

Z = a * B;

or

Z = mul(a, B);

3.5.8. Tensor Logical Elementwise Binary Operations and Functions

Z = eq(A, B)
Z(n) = A(n) == B(n)
Z = gt(A, B)
Z(n) = A(n) > B(n)
Z = gte(A, B)
Z(n) = A(n) >= B(n)
Z = lt(A, B)
Z(n) = A(n) < B(n)
Z = lte(A, B)
Z(n) = A(n) <= B(n)
Z = ne(A, B)
Z(n) = A(n) != B(n)

3.5.9. Tensor Arithmetic Elementwise Ternary Operations and Functions

The following arithmetic elementwise ternary operations and functions are available on tensors:

Z = ma(A, B, C)
Multiply-add, Z(n) = A(n) * B(n) + C(n)
Z = am(A, B, C)
Add-multiply, Z(n) = A(n) + B(n) * C(n)

In all the preceding functions and operations, one or more of the tensor operands can be replaced with scalar operands.

For example, to scale a tensor, then apply an offset:

Z = scale * A + offset;

or

Z = ma(scale, A, offset);

(where scale and offset are scalar values)

3.5.10. Tensor Non-Arithmetic Elementwise Ternary Operations and Functions

Z = ite(bool_tensor, A, B)
For the m,n,pth element of Z, sets value to nth element ofA if m,n,pth element of bool_tensor is true, otherwise sets value to the m,n,pth element of B. Notionally equivalent to C ?: operator. (Foreach n) Z[m, n, p] = bool_tensor[m, n, p] ? A[m, n, p] : B[m, n, p]

In all the preceding functions and operations, one or more of the tensor operands can be replaced with scalar operands.

For example, the apply a scalar threshold b to a tensor:

Z = ite(A > b, A, b);

3.5.11. Tensor Reductions

The following functions reduce a tensor to a single value:

z = alltrue(A)
When the element type of A is bool, the function returns true if all the elements are true; otherwise false. When the element type is something else, see (section 4.3.1) for more information.
z = anytrue(A)
When the element type of A is bool, the function returns true if any elements are true; otherwise false. When the element type is something else, see (section 4.3.2) for more information.
z = sumval(A)
Return the sum of A's values.
z = sumsqval(A)
Return the sum of the squares of A's values.
z = meanval(A)
Return the mean of A's values.
z = meansqval(A)
Return the mean of the squares of A's values.

The following functions reduce a tensor to a single value that corresponds to an element within the vector.

z = maxval(A, idx)
return the maximum value of A. Set idx to the index of this element (A.get(idx[0], idx[1], idx[2]) == z).
z = maxmgval(A, idx)
return the maximum value of the magnitude of A. Set idx to the index of this element (mag(A.get(idx[0], idx[1], idx[2])) == z).
z = maxmgsqval(A, idx)
return the maximum value of the magnitude squared of A. Set idx to the index of this element (magsq(A.get(idx[0], idx[1], idx[2])) == z).
z = minval(A, idx)
return the minimum value of A. Set idx to the index of this element (A.get(idx[0], idx[1], idx[2]) == z).
z = minmgval(A, idx)
return the minimum value of the magnitude of A. Set idx to the index of this element (mag(A.get(idx[0], idx[1], idx[2])) == z).
z = minmgsqval(A, idx)
return the minimum value of the magnitude squared of A. Set idx to the index of this element (magsq(A.get(idx[0], idx[1], idx[2])) == z).

3.5.12. Tensor Random Number Generation

VSIPL++ provides facilities to generate tensors of random number through the class template Rand. Once constructed with compile-time selections, a Rand object can generate a tensor of random numbers through the invocation of one of its member functions.