java.lang.Object
org.flag4j.linalg.ops.dense.DenseTranspose
This utility class provides methods for computing the transpose of a dense tensor.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Object[]
blockedMatrix
(Object[] src, int numRows, int numCols, Object[] dest) Transposes a matrix using a blocked algorithm.static Object[]
blockedMatrixConcurrent
(Object[] src, int numRows, int numCols, Object[] dest) Computes the transpose of a matrix using a blocked concurrent algorithm.static <T> Object[]
Computes the transpose of a tensor.static Object[]
Transposes tensor along specified axes using a standard transpose algorithm.static <T> Object[]
standardConcurrent
(Object[] src, Shape shape, int[] axes, Object[] dest) Computes the transpose of a tensor using a concurrent implementation.static <T> Object[]
standardConcurrent
(Object[] src, Shape shape, int axis1, int axis2, Object[] dest) Transposes tensor along specified axes using a standard concurrent transpose algorithm.static <T> Object[]
standardMatrix
(Object[] src, int numRows, int numCols, Object[] dest) Transposes a matrix using the standard algorithm.static Object[]
standardMatrixConcurrent
(Object[] src, int numRows, int numCols, Object[] dest) Computes the transpose of a matrix using a standard concurrent algorithm.
-
Constructor Details
-
DenseTranspose
private DenseTranspose()
-
-
Method Details
-
standard
Transposes tensor along specified axes using a standard transpose algorithm. In this context, transposing a tensor is equivalent to swapping a pair of axes.- Parameters:
src
- Entries of the tensor.shape
- Shape of the tensor to transpose.axis1
- First axis to swap in transpose.axis2
- Second axis to swap in transpose.dest
- Array to store the transpose result in. May benull
. If not null, must satisfy:dest.length >= src.length
.- Returns:
- If
dest != null
, a reference todest
is returned. Ifdest == null
then a new array of appropriate size will be constructed and returned.
-
standardConcurrent
public static <T> Object[] standardConcurrent(Object[] src, Shape shape, int axis1, int axis2, Object[] dest) Transposes tensor along specified axes using a standard concurrent transpose algorithm. In this context, transposing a tensor is equivalent to swapping a pair of axes.- Parameters:
src
- Entries of the tensor.shape
- Shape of the tensor to transpose.axis1
- First axis to swap in transpose.axis2
- Second axis to swap in transpose.dest
- Array to store the transpose result in. May benull
. If not null, must satisfy:dest.length >= src.length
.- Returns:
- If
dest != null
, a reference todest
is returned. Ifdest == null
then a new array of appropriate size will be constructed and returned.
-
standard
Computes the transpose of a tensor. That is, interchanges the axes of the tensor so that it matches the specified axes permutation.- Parameters:
src
- Entries of the tensor.shape
- Shape of the tensor to transpose.axes
- Permutation of tensor axis. If the tensor has rankN
, then this must be an array of lengthN
which is a permutation of{0, 1, 2, ..., N-1}
.dest
- Array to store the transpose result in. May benull
. If not null, must satisfy:dest.length >= src.length
.- Returns:
- If
dest != null
, a reference todest
is returned. Ifdest == null
then a new array of appropriate size will be constructed and returned. - Throws:
IllegalArgumentException
- If theaxes
array is not a permutation of{0, 1, 2, ..., N-1}
.IllegalArgumentException
- If theshape
rank is less than 2.
-
standardConcurrent
Computes the transpose of a tensor using a concurrent implementation. That is, interchanges the axes of the tensor so that it matches the specified axes permutation.- Parameters:
src
- Entries of the tensor.shape
- Shape of the tensor to transpose.axes
- Permutation of tensor axis. If the tensor has rankN
, then this must be an array of lengthN
which is a permutation of{0, 1, 2, ..., N-1}
.dest
- Array to store the transpose result in. May benull
. If not null, must satisfy:dest.length >= src.length
.- Returns:
- If
dest != null
, a reference todest
is returned. Ifdest == null
then a new array of appropriate size will be constructed and returned. - Throws:
IllegalArgumentException
- If theaxes
array is not a permutation of{0, 1, 2, ..., N-1}
.IllegalArgumentException
- If theshape
rank is less than 2.
-
standardMatrix
Transposes a matrix using the standard algorithm.- Parameters:
src
- Entries of the matrix to transpose.numRows
- Number of rows in the matrix.numCols
- Number of columns in the matrix.dest
- Array to store the transpose result in. May benull
. If not null, must satisfy:dest.length >= src.length
.- Returns:
- If
dest != null
, a reference todest
is returned. Ifdest == null
then a new array of appropriate size will be constructed and returned.
-
blockedMatrix
Transposes a matrix using a blocked algorithm. To get or set the block size seeConfigurations.getBlockSize()
orConfigurations.setBlockSize(int)
.- Parameters:
src
- Source matrix in the transpose.numRows
- Number of rows in the matrix.numCols
- Number of columns in the matrix.dest
- Array to store the transpose result in. May benull
. If not null, must satisfy:dest.length >= src.length
.- Returns:
- If
dest != null
, a reference todest
is returned. Ifdest == null
then a new array of appropriate size will be constructed and returned.
-
standardMatrixConcurrent
public static Object[] standardMatrixConcurrent(Object[] src, int numRows, int numCols, Object[] dest) Computes the transpose of a matrix using a standard concurrent algorithm.- Parameters:
src
- Entries of the matrix to transpose.numRows
- Number of rows in source matrix.numCols
- Number of columns in source matrix.dest
- Array to store the transpose result in. May benull
. If not null, must satisfy:dest.length >= src.length
.- Returns:
- If
dest != null
, a reference todest
is returned. Ifdest == null
then a new array of appropriate size will be constructed and returned.
-
blockedMatrixConcurrent
public static Object[] blockedMatrixConcurrent(Object[] src, int numRows, int numCols, Object[] dest) Computes the transpose of a matrix using a blocked concurrent algorithm.- Parameters:
src
- Entries of the matrix to transpose.numRows
- Number of rows in source matrix.numCols
- Number of columns in source matrix.dest
- Array to store the transpose result in. May benull
. If not null, must satisfy:dest.length >= src.length
.- Returns:
- If
dest != null
, a reference todest
is returned. Ifdest == null
then a new array of appropriate size will be constructed and returned.
-