Tensor Operators¶
This page lists all built-in operators to MatX. Operators are categorized by unary (one input), binary (two inputs), and advanced. The advanced operators perform more complex operations on the input instead of a straight 1:1 mapping, such as an fftshift. Some advanced operators require that the input and output tensors be different to prevent a race condition in reading and writing the values.
Unary Operators¶
-
Op matx::sqrt(Op t)¶
Compute the square root of each value in a tensor.
- Parameters
t – Tensor or operator input
-
Op matx::exp(Op t)¶
Compute e^x of each value in a tensor.
- Parameters
t – Tensor or operator input
-
Op matx::expj(Op t)¶
Compute e^(jx) of each value in a tensor where j is sqrt(-1).
- Parameters
t – Tensor or operator input
-
Op matx::log10(Op t)¶
Compute log base 10 of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::log2(Op t)¶
Compute log base 2 of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::log(Op t)¶
Compute log base e (natural log) of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::loge(Op t)¶
Compute log base e (natural log) of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::conj(Op t)¶
Compute the complex conjugate of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::norm(Op t)¶
Compute the squared magnitude of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::abs(Op t)¶
Compute absolute value of every element in the tensor. For complex numbers this returns the magnitude, or sqrt(x^2+y^2)
- Parameters
t – Tensor or operator input
-
Op matx::sin(Op t)¶
Compute the sine of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::cos(Op t)¶
Compute cosine of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::tan(Op t)¶
Compute the tangent of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::asin(Op t)¶
Compute the arcsine of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::acos(Op t)¶
Compute arccosine of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::atan(Op t)¶
Compute the arctangent of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::sinh(Op t)¶
Compute the hyperbolic sine of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::cosh(Op t)¶
Compute hyperbolic cosine of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::tanh(Op t)¶
Compute the hyperbolic tangent of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::asinh(Op t)¶
Compute the hyperbolic arcsine of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::acosh(Op t)¶
Compute hyperbolic arccosine of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::atanh(Op t)¶
Compute hyperbolic the arctangent of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::angle(Op t)¶
Compute the angle of a complex number.
- Parameters
t – Tensor or operator input
-
Op matx::atan2(Op t)¶
Compute the principal value of the arctangent of y/x for complex numbers
- Parameters
t – Tensor or operator input
-
Op matx::floor(Op t)¶
Compute the floor of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::ceil(Op t)¶
Compute the ceiling of every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::round(Op t)¶
Round every element in the tensor
- Parameters
t – Tensor or operator input
-
Op matx::operator!(Op t)¶
Compute !t (logical NOT) of input tensor or operator
- Parameters
t – LHS tensor or operator input
Binary Operators¶
-
Op matx::operator+(Op t, Op t2)¶
Add two operators or tensors
- Parameters
t – Tensor or operator input
t2 – RHS second tensor or operator input
-
Op matx::operator-(Op t, Op t2)¶
Subtract two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS second tensor or operator input
-
Op matx::operator*(Op t, Op t2)¶
Multiply two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS second tensor or operator input
-
Op matx::mul(Op t, Op t2)¶
Multiply two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS second tensor or operator input
-
Op matx::operator/(Op t, Op t2)¶
Divide two operators or tensors
- Parameters
t – LHS tensor numerator
t2 – RHS tensor or operator denominator
-
Op matx::operator%(Op t, Op t2)¶
Modulo two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS second tensor or operator modulus
-
Op matx::pow(Op t, Op t2)¶
Compute the t^t2 of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator power
-
Op matx::max(Op t, Op t2)¶
Compute max(t, t2) of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator input
-
Op matx::min(Op t, Op t2)¶
Compute min(t, t2) of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator input
-
Op matx::operator<(Op t, Op t2)¶
Compute t < t2 of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator input
-
Op matx::operator>(Op t, Op t2)¶
Compute t > t2 of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator input
-
Op matx::operator<=(Op t, Op t2)¶
Compute t <= t2 of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator input
-
Op matx::operator>=(Op t, Op t2)¶
Compute t >= t2 of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator input
-
Op matx::operator==(Op t, Op t2)¶
Compute t == t2 of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator input
-
Op matx::operator!=(Op t, Op t2)¶
Compute t != t2 of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator input
-
Op matx::operator&&(Op t, Op t2)¶
Compute t && t2 (logical AND) of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator input
-
Op matx::operator||(Op t, Op t2)¶
Compute t || t2 (logical OR) of two operators or tensors
- Parameters
t – LHS tensor or operator input
t2 – RHS tensor or operator input
Advanced Operators¶
-
template<typename T, int RANK, typename Desc, typename Op>
class set : public matx::BaseOp<set<T, RANK, Desc, Op>>¶ Assignment from one operator/View into a View
The set function is used in lieu of the assignment operator to avoid ambiguity in certain scenarios. It can be used in the same scenarios as the assignment operator.
- tparam T
Type of operator
- tparam RANK
Rank of operator
- tparam Op
Operator to use as input
-
template<typename OutputTensor, typename InputTensor>
__MATX_INLINE__ void matx::copy(OutputTensor &out, const InputTensor &in, const cudaStream_t stream)¶ Make a deep copy of a view into another view
Copies the data from a view into another view. Views should normally be backed by different data objects, but it’s not necessary if there is no overlap between the soure and destination. If the source in destination overlap in any way, it is a race condition and the result of the operation is undefined.
Both tensor views must be the same rank and size in every dimension
- Parameters
out – Tensor to copy into
in – Tensor to copy from
stream – CUDA stream to operate in
-
template<class Op1, class Op2>
class CommaOp : public matx::BaseOp<CommaOp<Op1, Op2>>¶ Chain multiple operator statements
Takes a variable list of operator statements to execute concurrently. Chaining may improve performance over executing each operation separately.
-
template<int Dim, typename Op1, typename Op2>
class Concatenate : public matx::BaseOp<Concatenate<Dim, Op1, Op2>>¶ Concatenate two tensors
Class for concatening two tensors along a single dimension. Sizes of the tensors not being concatenated must be the same, and the new tensor has dimensions equal to the original tensors on non-index dimension, and the sum of sizes along the index dimension.
-
template<typename T1, typename T2>
class IF : public matx::BaseOp<IF<T1, T2>>¶ Conditionally execute an operator
Compares two operators or views and conditionally executes the second statement if the first is true. Values from an operator are executed individually, and the only requirement for the conditional is the comparison operator must be defined for the particular type. For example, operator< on two integers is okay, but the same operator on two complex numbers will give a compiler error.
-
template<typename C1, typename T1, typename T2>
class IFELSE : public matx::BaseOp<IFELSE<C1, T1, T2>>¶ Conditionally execute an operator, otherwise execute a different operator
Compares two operators or views and conditionally executes the second statement if the first is true, otherwise executes the third statement. Values from an operator are executed individually, and the only requirement for the conditional is the comparison operator must be defined for the particular type. For example, operator< on two integers is okay, but the same operator on two complex numbers will give a compiler error.
-
template<typename T1, int DIM>
class ReverseOp¶ Reverse the indexing of a View or operator on a single dimension
Allows a view or operator to be indexed in reverse order. After applying the operator, index 0 is the last element in the selected dimension, index 1 is second to last, etc.
-
template<typename T1>
auto __MATX_INLINE__ matx::reverseX(T1 t)¶ Helper function to reverse the indexing of the last dimension of a tensor
Requires a tensor of at least rank 1
-
template<typename T1>
auto __MATX_INLINE__ matx::reverseY(T1 t)¶ Helper function to reverse the indexing of the second-to-last dimension of a tensor
Requires a tensor of at least rank 2
-
template<typename T1>
auto __MATX_INLINE__ matx::reverseZ(T1 t)¶ Helper function to reverse the indexing of the third-to-last dimension of a tensor
Requires a tensor of at least rank 3
-
template<typename T1>
auto __MATX_INLINE__ matx::reverseW(T1 t)¶ Helper function to reverse the indexing of the first dimension of a tensor
Requires a tensor of rank 4
-
template<typename T1, int DIM>
class ShiftOp¶ Shifts the indexing of an operator or View by a given amount
ShiftOp allows adjusting the relative view of a tensor to start at a new offset. This may be useful to cut off part of a tensor that is meaningless, while maintaining a 0-based offset from the new location. A modulo is applied to the new index to allow wrapping around to the beginning. Negative shifts are allowed, and have the effect of moving back from the end of the tensor.
-
template<typename T1>
auto __MATX_INLINE__ matx::shift0(T1 t, index_t s)¶ Helper function to shift dimension 0 by a given amount
- Template Parameters
T1 – Type of operator or view
- Parameters
t – Operator or view to shift
s – Amount to shift forward
- Returns
New operator with shifted indices
-
template<typename T1>
auto __MATX_INLINE__ matx::shift1(T1 t, index_t s)¶ Helper function to shift dimension 1 by a given amount
- Template Parameters
T1 – Type of operator or view
- Parameters
t – Operator or view to shift
s – Amount to shift forward
- Returns
New operator with shifted indices
-
template<typename T1>
auto __MATX_INLINE__ matx::shift2(T1 t, index_t s)¶ Helper function to shift dimension 2 by a given amount
- Template Parameters
T1 – Type of operator or view
- Parameters
t – Operator or view to shift
s – Amount to shift forward
- Returns
New operator with shifted indices
-
template<typename T1>
auto __MATX_INLINE__ matx::shift3(T1 t, index_t s)¶ Helper function to shift dimension 3 by a given amount
- Template Parameters
T1 – Type of operator or view
- Parameters
t – Operator or view to shift
s – Amount to shift forward
- Returns
New operator with shifted indices
-
template<typename T1>
auto matx::fftshift1D(T1 t)¶ Perform an FFTShift operation on the last dimension of a tensor
Shifts the new indexing of the tensor’s last dimension to begin at Size()/2. MatX FFTs leave the sample order starting with DC, positive frequencies, then negative frequencies last. FFTShift gives a shifted view of a signal where the new order is negative frequencies, DC, then positive frequencies.
- Template Parameters
T1 – Type of View/Op
- Parameters
t – View/Op to shift
-
template<typename T1>
auto matx::fftshift2D(T1 t)¶ Perform an IFFTShift operation on a 2D tensor swapping the first quadrant with the third, and the second with the fourth.
Shifts the new indexing of the tensor’s last dimension to begin at Size()/2. MatX FFTs leave the sample order starting with DC, positive frequencies, then negative frequencies last. IFFTShift gives a shifted view of a signal where the new order is negative frequencies, DC, then positive frequencies.
- Template Parameters
T1 – Type of View/Op
- Parameters
t – View/Op to shift
-
template<typename T1>
auto __MATX_INLINE__ matx::repmat(T1 t, index_t reps)¶ Repeat a matrix an equal number of times in each dimension
- Template Parameters
T1 – Type of operator or view
- Parameters
t – Operator or view to repeat
reps – Amount to repeat
- Returns
New operator with repeated data
-
template<typename T1>
auto __MATX_INLINE__ matx::repmat(T1 t, const index_t (&reps)[])¶ Repeat a matrix a specific number of times in each direction
- Template Parameters
T1 – Type of operator or view
- Parameters
t – Operator or view to repeat
reps – Array of times to repeat in each dimension
- Returns
New operator with repeated data
-
template<typename T1>
auto __MATX_INLINE__ matx::repmat(T1 t, const index_t *reps)¶ Repeat a matrix a specific number of times in each direction
- Template Parameters
T1 – Type of operator or view
- Parameters
t – Operator or view to repeat
reps – Array of times to repeat in each dimension
- Returns
New operator with repeated data
-
template<typename T1, typename T2>
auto __MATX_INLINE__ matx::kron(T1 a, T2 b)¶ Kronecker tensor product
The Kronecker tensor product is formed by the matrix b by ever element in the matrix a. The resulting matrix has the number of rows and columns equal to the product of the rows and columns of matrices a and b, respectively.
- Template Parameters
T1 – Type of first input
T2 – Type of second input
- Parameters
a – Operator or view for first input
b – Operator or view for second input
- Returns
New operator of the kronecker product