mikera.matrixx
Class Matrixx
- java.lang.Object
-
- mikera.matrixx.Matrixx
-
public class Matrixx extends java.lang.ObjectStatic method class for matrices
-
-
Constructor Summary
Constructors Constructor and Description Matrixx()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static Matrixcreate(AMatrix m)Creates a mutable deep copy of a matrixstatic Matrixcreate(double[][] data)Creates a matrix using the given double[][] datastatic AMatrixcreate(IMatrix m)Creates a mutable copy of a matrixstatic Matrixcreate(java.util.List<java.lang.Object> rows)Create a matrix from a list of rowsstatic AMatrixcreate(java.lang.Object... vs)Creates a matrix using the given objects to generate individual rowsstatic Matrix22create2DRotationMatrix(double angle)static DiagonalMatrixcreateDiagonalMatrix(AVector diagonalValues)Creates a diagonal matrix using the given vector of values on the main diagonal.static DiagonalMatrixcreateDiagonalMatrix(double... diagonalValues)Creates a diagonal matrix, using the given diagonal values.static MatrixcreateFromVector(AVector source, int rows, int columns)Creates a new matrix using the elements in the specified vector.static AMatrixcreateFromVectors(INDArray... data)Create a matrix using as array of vectors which represent the data for each rowstatic AMatrixcreateFromVectors(java.util.List<INDArray> data)Create a matrix using a list of vectors as the data for each rowstatic AMatrixcreateIdentityMatrix(int dimensions)Creates an identity matrixstatic IdentityMatrixcreateImmutableIdentityMatrix(int dimensions)Creates a sparse, immutable identity matrix.static ZeroMatrixcreateImmutableZeroMatrix(int rows, int columns)Creates an immutable zero-filled matrixAMatrixcreateInverse(AMatrix m)Computes the inverse of a matrix.static AMatrixcreateMutableIdentityMatrix(int dimensions)Creates a fully mutable identity matrixstatic AMatrixcreateRandomMatrix(int rows, int columns)Creates a mutable matrix containing random double values in the range [0.0 , 1.0)static AMatrixcreateRandomMatrix(int rows, int columns, java.util.Random rand)Creates a mutable matrix containing random double values in the range [0.0 , 1.0)static MatrixcreateRandomSquareMatrix(int dimensions)static MatrixcreateRandomSquareMatrix(int dimensions, java.util.Random rand)static Matrix33createRotationMatrix(AVector v, double angle)Create a 3x3 rotation matrix using the given rotation axis and angle in radiansstatic Matrix33createRotationMatrix(double x, double y, double z, double angle)Create a 3x3 rotation matrix using the given rotation axis and angle in radiansstatic Matrix33createRotationMatrix(Vector3 axis, double angle)Creates a 3D rotation matrix for a given angle or rotation in radians around an axis vector.static ADiagonalMatrixcreateScalarMatrix(int dimensions, double factor)Creates a scalar matrix with the given scale factor.static DiagonalMatrixcreateScaleMatrix(double... scalingFactors)Creates a diagonal scaling matrix with the given scale factors for each dimensionstatic ADiagonalMatrixcreateScaleMatrix(int dimensions, double factor)Creates a diagonal scaling matrix (same factor on every element of main diagonal, 0.0 elsewhere) Mutable only on main diagonal.static AMatrixcreateSparse(AMatrix m)Creates a sparse matrix from the given matrix, ignoring zerosstatic AMatrixcreateSparse(int columnCount, Index[] indexes, AVector[] weights)Create a sparse array, given an Index of column positions and AVector of corresponding values for each row in the sparse array Performs a defensive copy of underlying data.static SparseRowMatrixcreateSparse(int rowCount, int columnCount)Creates a sparse matrix of the given size, initially zero-filled.static AMatrixcreateSparse(java.lang.Iterable<INDArray> slices)Creates a sparse matrix using the given arrays as slicesstatic AMatrixcreateSparse(java.lang.Object... slices)Creates a sparse matrix using the given objects as slicesstatic java.util.ArrayList<AVector>createSparseArray(java.util.Iterator<AVector> vecIterator)Creates a sparse matrix from the given iterator.static SparseColumnMatrixcreateSparseColumns(AMatrix m)Creates a SparseColumnMatrix from the given matrix, ignoring zerosstatic SparseColumnMatrixcreateSparseColumns(java.util.Iterator<AVector> colIterator)static AMatrixcreateSparseRows(AMatrix m)Creates a SparseRowMatrix matrix from the given matrix, ignoring zerosstatic SparseRowMatrixcreateSparseRows(INDArray a)Creates a SparseRowMatrix matrix from the given INDArray, ignoring zerosstatic SparseRowMatrixcreateSparseRows(java.lang.Iterable<AVector> rows)Creates a sparse matrix from the given matrix, ignoring zeros.static SparseRowMatrixcreateSparseRows(java.util.Iterator<AVector> rowIterator)static Matrix33createXAxisRotationMatrix(double angle)Create a 3x3 rotation matrix using the given rotation angle in radians around the x-axisstatic Matrix33createYAxisRotationMatrix(double angle)Create a 3x3 rotation matrix using the given rotation angle in radians around the y-axisstatic Matrix33createZAxisRotationMatrix(double angle)Create a 3x3 rotation matrix using the given rotation angle in radians around the z-axisstatic AMatrixextractLowerTriangular(AMatrix a)Extracts a lower triangular matrix from a matrixstatic AMatrixextractUpperTriangular(AMatrix a)Extracts an upper triangular matrix from a matrixstatic voidfillRandomValues(AMatrix m)Fills a matrix with uniform random numbersstatic voidfillRandomValues(AMatrix m, java.util.Random rand)Fills a matrix with uniform random numbers, using the specified Random instancestatic AMatrixnewMatrix(int rows, int columns)Creates an empty (zero-filled) mutable matrix of the specified size.static AMatrixparse(java.lang.String ednString)Parse a matrix in edn formatstatic AMatrixtoMatrix(INDArray a)Coerce an object to a matrix format, on a best effort basis.static AMatrixtoMatrix(java.lang.Object o)Coerce an object to a matrix format, on a best effort basis.static AStridedMatrixwrapStrided(double[] data, int rows, int cols, int offset, int rowStride, int colStride)Wraps double[] data in a strided matrix of the most efficient available type.
-
-
-
Method Detail
-
createIdentityMatrix
public static AMatrix createIdentityMatrix(int dimensions)
Creates an identity matrix
-
createImmutableIdentityMatrix
public static IdentityMatrix createImmutableIdentityMatrix(int dimensions)
Creates a sparse, immutable identity matrix. This is the most efficient format for identity matrices
-
createMutableIdentityMatrix
public static AMatrix createMutableIdentityMatrix(int dimensions)
Creates a fully mutable identity matrix
-
toMatrix
public static AMatrix toMatrix(INDArray a)
Coerce an object to a matrix format, on a best effort basis. Can handle: - Existing matrices - Vectors (will be broadcast to a n x 1 column matrix) - Scalars (will be broadcast to a 1 x 1 matrix)
-
toMatrix
public static AMatrix toMatrix(java.lang.Object o)
Coerce an object to a matrix format, on a best effort basis. Can handle: - INDArray instances of suitable shape (will be broadcast to a matrix if needed) - Iterable objects representing a list of rows
-
createSparse
public static AMatrix createSparse(AMatrix m)
Creates a sparse matrix from the given matrix, ignoring zeros
-
createSparse
public static SparseRowMatrix createSparse(int rowCount, int columnCount)
Creates a sparse matrix of the given size, initially zero-filled. Uses row-based storage by default
-
createSparseRows
public static SparseRowMatrix createSparseRows(java.lang.Iterable<AVector> rows)
Creates a sparse matrix from the given matrix, ignoring zeros. Uses row-based storage by default
-
createSparseArray
public static java.util.ArrayList<AVector> createSparseArray(java.util.Iterator<AVector> vecIterator)
Creates a sparse matrix from the given iterator. Each vector in the iterator will be copied to a row in the new sparse matrix
-
createSparseRows
public static SparseRowMatrix createSparseRows(java.util.Iterator<AVector> rowIterator)
-
createSparseColumns
public static SparseColumnMatrix createSparseColumns(java.util.Iterator<AVector> colIterator)
-
createSparse
public static AMatrix createSparse(int columnCount, Index[] indexes, AVector[] weights)
Create a sparse array, given an Index of column positions and AVector of corresponding values for each row in the sparse array Performs a defensive copy of underlying data.
-
createSparseColumns
public static SparseColumnMatrix createSparseColumns(AMatrix m)
Creates a SparseColumnMatrix from the given matrix, ignoring zeros
-
createSparseRows
public static AMatrix createSparseRows(AMatrix m)
Creates a SparseRowMatrix matrix from the given matrix, ignoring zeros
-
createSparseRows
public static SparseRowMatrix createSparseRows(INDArray a)
Creates a SparseRowMatrix matrix from the given INDArray, ignoring zeros
-
createImmutableZeroMatrix
public static ZeroMatrix createImmutableZeroMatrix(int rows, int columns)
Creates an immutable zero-filled matrix
-
createScaleMatrix
public static ADiagonalMatrix createScaleMatrix(int dimensions, double factor)
Creates a diagonal scaling matrix (same factor on every element of main diagonal, 0.0 elsewhere) Mutable only on main diagonal.- Parameters:
dimensions-factor-- Returns:
-
createScalarMatrix
public static ADiagonalMatrix createScalarMatrix(int dimensions, double factor)
Creates a scalar matrix with the given scale factor. Scalar matrices are efficient, lightweight and immutable.
-
createScaleMatrix
public static DiagonalMatrix createScaleMatrix(double... scalingFactors)
Creates a diagonal scaling matrix with the given scale factors for each dimension
-
createDiagonalMatrix
public static DiagonalMatrix createDiagonalMatrix(double... diagonalValues)
Creates a diagonal matrix, using the given diagonal values. Performs a defensive copy of the data.
-
createDiagonalMatrix
public static DiagonalMatrix createDiagonalMatrix(AVector diagonalValues)
Creates a diagonal matrix using the given vector of values on the main diagonal.
-
createRotationMatrix
public static Matrix33 createRotationMatrix(Vector3 axis, double angle)
Creates a 3D rotation matrix for a given angle or rotation in radians around an axis vector. The axis vector need not be normalised.
-
createRotationMatrix
public static Matrix33 createRotationMatrix(double x, double y, double z, double angle)
Create a 3x3 rotation matrix using the given rotation axis and angle in radians- Parameters:
angle- Rotation angle in radiansx- x-element of rotation vectory- y-element of rotation vectorz- z-element of rotation vector
-
createRotationMatrix
public static Matrix33 createRotationMatrix(AVector v, double angle)
Create a 3x3 rotation matrix using the given rotation axis and angle in radians- Parameters:
angle- Rotation angle in radiansv- Rotation axis vector
-
createXAxisRotationMatrix
public static Matrix33 createXAxisRotationMatrix(double angle)
Create a 3x3 rotation matrix using the given rotation angle in radians around the x-axis- Parameters:
angle- Rotation angle in radians
-
createYAxisRotationMatrix
public static Matrix33 createYAxisRotationMatrix(double angle)
Create a 3x3 rotation matrix using the given rotation angle in radians around the y-axis- Parameters:
angle- Rotation angle in radians
-
createZAxisRotationMatrix
public static Matrix33 createZAxisRotationMatrix(double angle)
Create a 3x3 rotation matrix using the given rotation angle in radians around the z-axis- Parameters:
angle- Rotation angle in radians
-
create2DRotationMatrix
public static Matrix22 create2DRotationMatrix(double angle)
-
createRandomSquareMatrix
public static Matrix createRandomSquareMatrix(int dimensions)
-
createRandomSquareMatrix
public static Matrix createRandomSquareMatrix(int dimensions, java.util.Random rand)
-
createRandomMatrix
public static AMatrix createRandomMatrix(int rows, int columns)
Creates a mutable matrix containing random double values in the range [0.0 , 1.0)- Parameters:
rows-columns-- Returns:
-
createRandomMatrix
public static AMatrix createRandomMatrix(int rows, int columns, java.util.Random rand)
Creates a mutable matrix containing random double values in the range [0.0 , 1.0)- Parameters:
rows-columns-rand- A random number generator to use as the seed- Returns:
-
newMatrix
public static AMatrix newMatrix(int rows, int columns)
Creates an empty (zero-filled) mutable matrix of the specified size. Uses mutable primitive matrices for small sizes (1x1, 2x2, 3x3)- Parameters:
rows-columns-- Returns:
-
createFromVector
public static Matrix createFromVector(AVector source, int rows, int columns)
Creates a new matrix using the elements in the specified vector. Truncates or zero-pads the data as required to fill the new matrix- Parameters:
data-rows-columns-- Returns:
-
createInverse
public AMatrix createInverse(AMatrix m)
Computes the inverse of a matrix. Returns null if the matrix is singular. Throws an Exception is the matrix is not square- Parameters:
m-- Returns:
-
extractLowerTriangular
public static AMatrix extractLowerTriangular(AMatrix a)
Extracts a lower triangular matrix from a matrix
-
extractUpperTriangular
public static AMatrix extractUpperTriangular(AMatrix a)
Extracts an upper triangular matrix from a matrix
-
create
public static Matrix create(java.util.List<java.lang.Object> rows)
Create a matrix from a list of rows- Parameters:
rows-- Returns:
-
fillRandomValues
public static void fillRandomValues(AMatrix m)
Fills a matrix with uniform random numbers- Parameters:
m-
-
fillRandomValues
public static void fillRandomValues(AMatrix m, java.util.Random rand)
Fills a matrix with uniform random numbers, using the specified Random instance- Parameters:
m-
-
createFromVectors
public static AMatrix createFromVectors(INDArray... data)
Create a matrix using as array of vectors which represent the data for each row- Parameters:
data-- Returns:
-
createFromVectors
public static AMatrix createFromVectors(java.util.List<INDArray> data)
Create a matrix using a list of vectors as the data for each row- Parameters:
data-- Returns:
-
parse
public static AMatrix parse(java.lang.String ednString)
Parse a matrix in edn format- Parameters:
ednString-- Returns:
-
create
public static AMatrix create(java.lang.Object... vs)
Creates a matrix using the given objects to generate individual rows- Parameters:
vs-- Returns:
-
create
public static Matrix create(double[][] data)
Creates a matrix using the given double[][] data- Parameters:
data-- Returns:
-
wrapStrided
public static AStridedMatrix wrapStrided(double[] data, int rows, int cols, int offset, int rowStride, int colStride)
Wraps double[] data in a strided matrix of the most efficient available type.- Parameters:
array-arrayOffset-reverse-reverse2-- Returns:
-
createSparse
public static AMatrix createSparse(java.lang.Iterable<INDArray> slices)
Creates a sparse matrix using the given arrays as slices- Parameters:
slices- An iterable object containing n length m vectors to use as matrix rows- Returns:
-
createSparse
public static AMatrix createSparse(java.lang.Object... slices)
Creates a sparse matrix using the given objects as slices- Parameters:
slices-- Returns:
-
-
DMelt 3.0 © DataMelt by jWork.ORG