3.4. Matrix Operations

VSIPL++ Matrix objects represent two-dimensional sets of data. The type of values stored in the matrix is given by the first template argument.

3.4.1. Matrix Generation Functions

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

3.4.2. Matrix Copy

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

3.4.3. Matrix Arithmetic Elementwise Unary Operations and Functions

The following elementwise unary operations can be performed on matrices, producing a matrix 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.4.4. Matrix Arithmetic Elementwise Binary Operations and Functions

The following elementwise binary operations can be performed on matrices, producing a matrix 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.4.5. Matrix Arithmetic Elementwise Ternary Operations and Functions

The following elementwise ternary operations can be performed on matrices, producing a matrix 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.4.6. Matrix Type Conversions

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

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

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

3.4.7. Matrix Arithmetic Elementwise Binary Operations and Functions

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

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 vector operands can be replaced with scalar operands.

For example, to perform a scalar-vector multiply:

Z = a * B;

or

Z = mul(a, B);

3.4.8. Matrix 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.4.9. Matrix Arithmetic Elementwise Ternary Operations and Functions

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

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 matrix operands can be replaced with scalar operands.

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

Z = scale * A + offset;

or

Z = ma(scale, A, offset);

(where scale and offset are scalar values)

3.4.10. Matrix Non-Arithmetic Elementwise Ternary Operations and Functions

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

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

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

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

3.4.11. Matrix Reductions

The following functions reduce a matrix 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 matrix to a single value that corresponds to an element within the matrix.

z = maxval(A, idx)
return the maximum value of A. Set idx to the index of this element (A.get(idx[0], idx[1]) == 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])) == 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])) == z).
z = minval(A, idx)
return the minimum value of A. Set idx to the index of this element (A.get(idx) == 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])) == 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])) == z).

3.4.12. Matrix Linear Algebra

Z = conj(A)
conjugate (section 4.2.13)
Z = herm(A)
hermetian (conjugate-transpose) (section 4.4.6)
Z = prod(A, B)
product (section 4.4.10)
Z = prod3(A, B)
3x3 product (section 4.4.11)
Z = prod4(A, B)
4x4 product (section 4.4.12)
Z = prodh(A, B)
hermetian product (section 4.4.13)
Z = prodj(A, B)
conjugate product (section 4.4.14)
Z = prodt(A, B)
transpose product (section 4.4.15)
Z = trans(A)
transpose (section 4.4.16)

3.4.13. Matrix Convolution

VSIPL++ provides facilities to perform convolutions on matrices through the class template Convolution. Once constructed with compile-time selections, a convolution object can be applied to an input matrix to produce results in an output matrix.

3.4.14. Matrix Correlation

VSIPL++ provides facilities to perform correlations on matrices through the class template Correlation. Once constructed with compile-time selections, a correlation object can be applied to an input matrix and a kernel matrix. to produce results in an output matrix.

3.4.15. Matrix Histogram

VSIPL++ provides facilities to perform an histogram on matrices through the class template Histogram. Once constructed with compile-time selections, a histogram object can be applied to an input matrix to produce results in an output vector.

3.4.16. Matrix Random Number Generation

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

3.4.17. Matrix Frequency Swap

VSIPL++ provides a function freqswap to swap quadrants of matrices. (section 4.7.3)