Class CMatrix
- All Implemented Interfaces:
Serializable,FieldTensorMixin<CMatrix,,CMatrix, Complex128> TensorOverField<CMatrix,,CMatrix, Complex128[], Complex128> MatrixMixin<CMatrix,,CMatrix, CVector, Complex128> RingTensorMixin<CMatrix,,CMatrix, Complex128> TensorOverRing<CMatrix,,CMatrix, Complex128[], Complex128> SemiringTensorMixin<CMatrix,,CMatrix, Complex128> TensorOverSemiring<CMatrix,CMatrix, Complex128[], Complex128>
Instances of this class represents a complex dense matrix backed by a Complex128 array. The CMatrix class
provides functionality for complex matrix operations, supporting mutable data with a fixed shape.
This class extends AbstractDenseFieldMatrix and offers additional methods optimized for complex
arithmetic and matrix computations.
A CMatrix is essentially equivalent to a rank-2 tensor but includes extended functionality
and may offer improved performance for certain operations compared to general rank-n tensors.
Key Features:
- Construction from various data types such as arrays of
Complex128,double, andString. - Support for standard matrix operations like addition, subtraction, multiplication, and exponentiation.
- Conversion methods to other matrix representations, such as COO (Coordinate) and CSR (Compressed Sparse Row) formats.
- Utility methods for checking properties like being unitary, real, or complex.
Example Usage:
// Constructing a complex matrix from a 2D array of complex numbers
Complex128[][] complexData = {
{ new Complex128(1, 2), new Complex128(3, 4) },
{ new Complex128(5, 6), new Complex128(7, 8) }
};
CMatrix matrix = new CMatrix(complexData);
// Performing matrix multiplication.
CMatrix result = matrix.mult(matrix);
// Performing matrix transpose.
CMatrix transpose = matrix.T();
// Performing matrix conjugate transpose (i.e. Hermitian transpose).
CMatrix conjugateTranspose = matrix.H();
// Checking if the matrix is unitary.
boolean isUnitary = matrix.isUnitary();
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringMatrix
numCols, numRowsFields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
zeroElementFields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape -
Constructor Summary
ConstructorsConstructorDescriptionCMatrix(double[][] aEntriesReal) Constructs a complex matrix from a 2D array of double values.CMatrix(int size) Creates a square zero matrix with the specifiedsize.CMatrix(int rows, int cols) Creates a zero matrix with the specified shape.CMatrix(int numRows, int numCols, double fillValue) Constructs a matrix with the specified shape filled withfillValue.CMatrix(int rows, int cols, Complex128 fillValue) Creates a complex matrix with the specified shape and filled withfillValue.CMatrix(int rows, int cols, Complex128[] entries) Creates a complex matrix with the specifieddata, and shape.Creates a square matrix with the specifiedsizefilled withfillValue.CMatrix(int size, Complex128 fillValue) Creates a square matrix with the specifiedsizefilled withfillValue.Constructs a complex matrix from a 2D array of strings.Constructs a copy of the specified matrix.Creates a zero matrix with the specifiedshape.Constructs a complex matrix with specifiedshapeanddata.Creates matrix with the specifiedshapefilled withfillValue.CMatrix(Shape shape, Complex128 fillValue) Creates a complex matrix with the specifiedshapefilled withfillValue.CMatrix(Shape shape, Complex128[] entries) Creates a complex matrix with the specifieddataandshape.CMatrix(Complex128[][] entries) Constructs a complex matrix from a 2D array. -
Method Summary
Modifier and TypeMethodDescription<R> Raccept(MatrixVisitor<R> visitor) Accepts a visitor that implements theMatrixVisitorinterface.Computes the element-wise sum between two tensors of the same shape.add(CooCMatrix b) Computes the element-wise sum between two tensors of the same shape.Computes the element-wise sum between two tensors of the same shape.static CMatrixConstructs a diagonal matrix from a vector specifying the diagonal elements of the matrix.static CMatrixdiag(Complex128... data) Constructs a diagonal matrix from an array specifying the diagonal elements of the matrix.Computes the element-wise quotient between two tensors.Computes the element-wise multiplication of two tensors of the same shape.Computes the element-wise multiplication of two tensors of the same shape.Computes the element-wise multiplication of two tensors of the same shape.booleanChecks if an object is equal to this matrix object.static CMatrixgetEmpty(int rows, int cols) Constructs an empty matrix with the specified number of rows and columns.inthashCode()static CMatrixI(int size) Constructs an identity matrix of the specified size.static CMatrixI(int numRows, int numCols) Constructs an identity-like matrix of the specified shape.static CMatrixConstructs an identity-like matrix of the specified shape.booleanChecks if any entry within this matrix has non-zero imaginary component.booleanisReal()Checks if all data of this matrix are real.booleanChecks if this matrix is unitary.makeEmptyDataArray(int length) Creates an empty array of the same type as the data array of this tensor.protected CooCMatrixmakeLikeCooMatrix(Shape shape, Complex128[] entries, int[] rowIndices, int[] colIndices) Constructs a sparse COO matrix which is of a similar type as this dense matrix.protected CooCMatrixmakeLikeCooTensor(Shape shape, Complex128[] entries, int[][] indices) Constructs a sparse COO tensor which is of a similar type as this dense tensor.makeLikeCsrMatrix(Shape shape, Complex128[] entries, int[] rowPointers, int[] colIndices) Constructs a sparse CSR matrix which is of a similar type as this dense matrix.makeLikeTensor(Shape shape, Complex128[] entries) Constructs a tensor of the same type as this tensor with the given theshapeanddata.protected CVectormakeLikeVector(Shape shape, Complex128[] entries) Constructs a vector of a similar type as this matrix.protected CVectormakeLikeVector(Complex128[] entries) Constructs a vector of a similar type as this matrix.Computes the matrix multiplication between two matrices.Computes the matrix multiplication between two matrices.Computes the matrix-vector multiplication between this matrix and a vector.mult(CooCMatrix b) Computes the matrix multiplication between two matrices.mult(CooCVector b) Computes the matrix-vector multiplication between this matrix and a vector.Computes the matrix multiplication between two matrices.Computes the matrix-vector multiplication between this matrix and a vector.mult(CsrCMatrix b) Computes the matrix multiplication between two matrices.Computes the matrix multiplication between two matrices.doublenorm()Computes the Frobenius (or \( L_{2, 2} \)) norm this matrix.doublenorm(double p) Computes the matrix operator norm of this matrix "induced" by the vector p-norm.doublenorm(double p, double q) Computes the \( L_{p,q} \) norm of this matrix.pow(int n) Computes the matrix multiplication of this matrix with itselfntimes.round()Rounds all data in this matrix to the nearest integer.round(int precision) Rounds all data within this matrix to the specified precision.roundToZero(double tolerance) Sets all elements of this matrix to zero if they are withintolof zero.Computes the element-wise difference between two tensors of the same shape.sub(CooCMatrix b) Computes the element-wise difference between two tensors of the same shape.Computes the element-wise difference between two tensors of the same shape.toCoo()Converts this matrix to an equivalent sparse COO matrix.toCoo(double estimatedSparsity) Converts this matrix to an equivalent sparse COO matrix.toCsr()Converts this matrix to an equivalent sparse CSR matrix.toCsr(double estimatedSparsity) Converts this matrix to an equivalent sparse CSR matrix.toReal()Converts this complex matrix to a real matrix.toString()Generates a human-readable string representing this matrix.toTensor()Converts this matrix to an equivalent tensor.Converts this matrix to an equivalent tensor with the specifiednewShape.Methods inherited from class org.flag4j.arrays.backend.field_arrays.AbstractDenseFieldMatrix
abs, allClose, allClose, div, H, isFinite, isInfinite, isNaN, sqrtMethods inherited from class org.flag4j.arrays.backend.ring_arrays.AbstractDenseRingMatrix
H, H, isCloseToIdentity, isHermitian, norm, sub, subEqMethods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringMatrix
augment, augment, dataLength, flatten, flatten, get, getCol, getDiag, getRow, getSlice, getTriL, getTriU, isI, isOrthogonal, isSymmetric, isTriL, isTriU, mult, multTranspose, numCols, numRows, removeCol, removeCols, removeRow, removeRows, set, setCol, setCol, setRow, setRow, setSlice, setSliceCopy, setValues, stack, swapCols, swapRows, T, toVector, trMethods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
add, addEq, argmax, argmin, copy, elemMult, get, getZeroElement, max, min, reshape, set, setZeroElement, T, T, tensorDot, tensorTrMethods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, reshape, sameShape, totalEntriesMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.flag4j.arrays.backend.field_arrays.FieldTensorMixin
add, add, addEq, addEq, argmax, argmaxAbs, argmin, argminAbs, conj, div, div, divEq, divEq, isOnes, isZeros, max, maxAbs, min, minAbs, mult, mult, multEq, multEq, prod, recip, sub, sub, subEq, subEq, sumMethods inherited from interface org.flag4j.arrays.backend.MatrixMixin
add, augment, augment, copy, dataLength, elemMult, fib, get, getCol, getCol, getDiag, getDiag, getRow, getRow, getShape, getSlice, getTriL, getTriL, getTriU, getTriU, isDiag, isHermitian, isI, isOrthogonal, isSquare, isSymmetric, isTri, isTriL, isTriU, isVector, mult, multTranspose, numCols, numRows, removeCol, removeCols, removeRow, removeRows, set, setCol, setRow, setSliceCopy, stack, stack, sub, swapCols, swapRows, T, toVector, tr, trace, vectorTypeMethods inherited from interface org.flag4j.arrays.backend.ring_arrays.TensorOverRing
H, H, sub
-
Constructor Details
-
CMatrix
Creates a complex matrix with the specifieddataandshape.- Parameters:
shape- Shape of this matrix.entries- Entries of this matrix.
-
CMatrix
Creates a complex matrix with the specifiedshapefilled withfillValue.- Parameters:
shape- Shape of this matrix.fillValue- Value to fill this matrix with.
-
CMatrix
Creates a zero matrix with the specifiedshape.- Parameters:
shape- Shape of this matrix.
-
CMatrix
public CMatrix(int size) Creates a square zero matrix with the specifiedsize.- Parameters:
size- Size of the zero matrix to construct. The resulting matrix will have shape(size, size)
-
CMatrix
Creates a complex matrix with the specifieddata, and shape.- Parameters:
rows- The number of rows in this matrix.cols- The number of columns in this matrix.entries- Entries of this matrix.
-
CMatrix
Creates a complex matrix with the specified shape and filled withfillValue.- Parameters:
rows- The number of rows in this matrix.cols- The number of columns in this matrix.fillValue- Value to fill this matrix with.
-
CMatrix
public CMatrix(int rows, int cols) Creates a zero matrix with the specified shape.- Parameters:
rows- The number of rows in this matrix.cols- The number of columns in this matrix.
-
CMatrix
Constructs a complex matrix from a 2D array. The matrix will have the same shape as the array.- Parameters:
entries- Entries of the matrix. Assumed to be a square array.
-
CMatrix
Constructs a complex matrix from a 2D array of strings. Each string must be formatted properly as a complex number that can be parsed by
ComplexNumberParserThe matrix will have the same shape as the array.
- Parameters:
entries- Entries of the matrix. Assumed to be a square array.
-
CMatrix
Constructs a complex matrix with specifiedshapeanddata.- Parameters:
shape- Shape of the matrix to construct.entries- Entries of the matrix.
-
CMatrix
public CMatrix(double[][] aEntriesReal) Constructs a complex matrix from a 2D array of double values.- Parameters:
aEntriesReal- Entries of the complex matrix to construct. Each value will be wrapped asComplex128's.
-
CMatrix
public CMatrix(int numRows, int numCols, double fillValue) Constructs a matrix with the specified shape filled withfillValue.- Parameters:
numRows- The number of rows in the matrix.numCols- The number of rows in the matrix.fillValue- Value to fill matrix with.
-
CMatrix
Creates a square matrix with the specifiedsizefilled withfillValue.- Parameters:
size- Size of the square matrix to construct.fillValue- Value to fill matrix with.
-
CMatrix
Creates a square matrix with the specifiedsizefilled withfillValue.- Parameters:
size- Size of the square matrix to construct.fillValue- Value to fill matrix with.
-
CMatrix
-
CMatrix
Constructs a copy of the specified matrix.- Parameters:
mat- Matrix to create copy of.
-
-
Method Details
-
makeLikeVector
Constructs a vector of a similar type as this matrix.- Specified by:
makeLikeVectorin classAbstractDenseSemiringMatrix<CMatrix,CVector, Complex128> - Parameters:
shape- Shape of the vector to construct. Must be rank 1.entries- Entries of the vector.- Returns:
- A vector of a similar type as this matrix.
-
makeEmptyDataArray
Description copied from interface:SemiringTensorMixinCreates an empty array of the same type as the data array of this tensor.- Parameters:
length- The length of the array to construct.- Returns:
- An empty array of the same type as the data array of this tensor.
-
norm
public double norm()Computes the Frobenius (or \( L_{2, 2} \)) norm this matrix.
The Frobenius norm is defined as the square root of the sum of absolute squares of all entries in the matrix.
- Returns:
- the Frobenius of this tensor.
-
norm
public double norm(double p) Computes the matrix operator norm of this matrix "induced" by the vector p-norm. Specifically, this method computes the operator norm of the matrix as: \[ ||A||_p = \sup_{x \ne 0} \cfrac{||Ax||_p}{||x||_p} \]
This method supports a limited set of
pvalues which yield simple formulas. Whenp < 1, the result this method returns is not a true mathematical norm. However, these values may still be useful for numerical purposes.p=1: The maximum absolute column sum.p=-1: The minimum absolute column sum.p=2: The spectral norm. Equivalent to the largest singular value of the matrix.p=-2: The smallest singular value of the matrix.p=Double.POSITIVE_INFINITY: The maximum absolute row sum.p=Double.NEGATIVE_INFINITY: The minimum absolute row sum.
- Parameters:
p- The p value in the "induced" p-norm. Must be one of the following:1,-1,2,-2,Double.POSITIVE_INFINITYorDouble.NEGATIVE_INFINITY.- Returns:
- Norm of the matrix.
- Throws:
IllegalArgumentException- Ifpis not one of the following:1,-1,2,-2,Double.POSITIVE_INFINITYorDouble.NEGATIVE_INFINITY.
-
norm
public double norm(double p, double q) Computes the \( L_{p,q} \) norm of this matrix.
Some common special cases are:
p=2,q=1: The sum of Euclidean norms of the column vectors of the matrix.p=2,q=2: The Frobenius norm. Equivalent to the Euclidean norm of the vector of singular values of the matrix.
The \( L_{p,q} \) norm is computed as if by:
double norm = 0; for(int j=0; j<src.numCols; j++) { double sum = 0; for(int i=0; i<src.numRows; i++) sum += Math.pow(src.get(i, j).mag(), p); norm += Math.pow(sum, q / p); } return Math.pow(norm, 1.0 / q);- Parameters:
p- p value in the \( L_{p,q} \) norm.q- q value in the \( L_{p,q} \) norm.- Returns:
- The \( L_{p,q} \) norm of
src.
-
makeLikeVector
Constructs a vector of a similar type as this matrix.- Specified by:
makeLikeVectorin classAbstractDenseSemiringMatrix<CMatrix,CVector, Complex128> - Parameters:
entries- Entries of the vector.- Returns:
- A vector of a similar type as this matrix.
-
makeLikeCooMatrix
protected CooCMatrix makeLikeCooMatrix(Shape shape, Complex128[] entries, int[] rowIndices, int[] colIndices) Constructs a sparse COO matrix which is of a similar type as this dense matrix.- Specified by:
makeLikeCooMatrixin classAbstractDenseSemiringMatrix<CMatrix,CVector, Complex128> - Parameters:
shape- Shape of the COO matrix.entries- Non-zero data of the COO matrix.rowIndices- Non-zero row indices of the COO matrix.colIndices- Non-zero column indices of the COO matrix.- Returns:
- A sparse COO matrix which is of a similar type as this dense matrix.
-
makeLikeCsrMatrix
public CsrCMatrix makeLikeCsrMatrix(Shape shape, Complex128[] entries, int[] rowPointers, int[] colIndices) Constructs a sparse CSR matrix which is of a similar type as this dense matrix.- Specified by:
makeLikeCsrMatrixin classAbstractDenseFieldMatrix<CMatrix,CVector, Complex128> - Parameters:
shape- Shape of the CSR matrix.entries- Non-zero data of the CSR matrix.rowPointers- Non-zero row pointers of the CSR matrix.colIndices- Non-zero column indices of the CSR matrix.- Returns:
- A sparse CSR matrix which is of a similar type as this dense matrix.
-
mult
Computes the matrix multiplication between two matrices.- Specified by:
multin interfaceMatrixMixin<CMatrix,CMatrix, CVector, Complex128> - Overrides:
multin classAbstractDenseSemiringMatrix<CMatrix,CVector, Complex128> - Parameters:
b- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix
b. - Throws:
LinearAlgebraException- Ifthis.numCols() != b.numRows().
-
toCoo
Converts this matrix to an equivalent sparse COO matrix.- Overrides:
toCooin classAbstractDenseSemiringMatrix<CMatrix,CVector, Complex128> - Returns:
- A sparse COO matrix that is equivalent to this dense matrix.
- See Also:
-
toCoo
Converts this matrix to an equivalent sparse COO matrix.- Overrides:
toCooin classAbstractDenseSemiringMatrix<CMatrix,CVector, Complex128> - Parameters:
estimatedSparsity- Estimated sparsity of the matrix. Must be between 0 and 1 inclusive. If this is an accurate estimation it may provide a slight speedup and can reduce unneeded memory consumption. If memory is a concern, it is better to over-estimate the sparsity. If speed is the concern it is better to under-estimate the sparsity.- Returns:
- A sparse COO matrix that is equivalent to this dense matrix.
- See Also:
-
toCsr
Converts this matrix to an equivalent sparse CSR matrix.- Overrides:
toCsrin classAbstractDenseSemiringMatrix<CMatrix,CVector, Complex128> - Returns:
- A sparse CSR matrix that is equivalent to this dense matrix.
- See Also:
-
toCsr
Converts this matrix to an equivalent sparse CSR matrix.- Overrides:
toCsrin classAbstractDenseSemiringMatrix<CMatrix,CVector, Complex128> - Parameters:
estimatedSparsity- Estimated sparsity of the matrix. Must be between 0 and 1 inclusive. If this is an accurate estimation it may provide a slight speedup and can reduce unneeded memory consumption. If memory is a concern, it is better to over-estimate the sparsity. If speed is the concern it is better to under-estimate the sparsity.- Returns:
- A sparse CSR matrix that is equivalent to this dense matrix.
- See Also:
-
makeLikeCooTensor
Constructs a sparse COO tensor which is of a similar type as this dense tensor.- Specified by:
makeLikeCooTensorin classAbstractDenseSemiringTensor<CMatrix,Complex128> - Parameters:
shape- Shape of the COO tensor.entries- Non-zero data of the COO tensor.indices-- Returns:
- A sparse COO tensor which is of a similar type as this dense tensor.
-
makeLikeTensor
Constructs a tensor of the same type as this tensor with the given theshapeanddata. The resulting tensor will also have the same non-zero indices as this tensor.- Specified by:
makeLikeTensorin interfaceTensorOverSemiring<CMatrix,CMatrix, Complex128[], Complex128> - Specified by:
makeLikeTensorin classAbstractTensor<CMatrix,Complex128[], Complex128> - Parameters:
shape- Shape of the tensor to construct.entries- Entries of the tensor to construct.- Returns:
- A tensor of the same type and with the same non-zero indices as this tensor with the given the
shapeanddata.
-
getEmpty
Constructs an empty matrix with the specified number of rows and columns. The data of the resulting matrix will be all benull.- Parameters:
rows- The number of rows in the matrix to construct.cols- The number of columns in the matrix to construct.- Returns:
- An empty matrix (i.e. filled with
nullvalues) with the specified shape.
-
add
Computes the element-wise sum between two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise sum.- Returns:
- The sum of this tensor with
b. - Throws:
TensorShapeException- If this tensor andbdo not have the same shape.
-
add
Computes the element-wise sum between two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise sum.- Returns:
- The sum of this tensor with
b. - Throws:
TensorShapeException- If this tensor andbdo not have the same shape.
-
add
Computes the element-wise sum between two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise sum.- Returns:
- The sum of this tensor with
b. - Throws:
TensorShapeException- If this tensor andbdo not have the same shape.
-
sub
Computes the element-wise difference between two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise difference.- Returns:
- The difference of this tensor with
b. - Throws:
TensorShapeException- If this tensor andbdo not have the same shape.
-
sub
Computes the element-wise difference between two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise difference.- Returns:
- The difference of this tensor with
b. - Throws:
TensorShapeException- If this tensor andbdo not have the same shape.
-
sub
Computes the element-wise difference between two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise difference.- Returns:
- The difference of this tensor with
b. - Throws:
TensorShapeException- If this tensor andbdo not have the same shape.
-
elemMult
Computes the element-wise multiplication of two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise product.- Returns:
- The element-wise product between this tensor and
b. - Throws:
IllegalArgumentException- If this tensor andbdo not have the same shape.
-
elemMult
Computes the element-wise multiplication of two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise product.- Returns:
- The element-wise product between this tensor and
b. - Throws:
IllegalArgumentException- If this tensor andbdo not have the same shape.
-
elemMult
Computes the element-wise multiplication of two tensors of the same shape.- Parameters:
b- Second tensor in the element-wise product.- Returns:
- The element-wise product between this tensor and
b. - Throws:
IllegalArgumentException- If this tensor andbdo not have the same shape.
-
div
-
toTensor
Converts this matrix to an equivalent tensor.- Specified by:
toTensorin classAbstractDenseSemiringMatrix<CMatrix,CVector, Complex128> - Returns:
- A tensor with the same shape and data as this matrix.
-
toTensor
Converts this matrix to an equivalent tensor with the specifiednewShape.- Specified by:
toTensorin classAbstractDenseSemiringMatrix<CMatrix,CVector, Complex128> - Parameters:
newShape- Shape of the tensor. Can be any rank but must be broadcastable to the shape of this matrix.- Returns:
- A tensor with the specified
newShapeand the same data as this matrix.
-
I
Constructs an identity matrix of the specified size.- Parameters:
size- Size of the identity matrix.- Returns:
- An identity matrix of specified size.
- Throws:
IllegalArgumentException- If the specified size is less than 1.- See Also:
-
I
Constructs an identity-like matrix of the specified shape. That is, a matrix of zeros with ones along the principle diagonal.- Parameters:
numRows- Number of rows in the identity-like matrix.numCols- Number of columns in the identity-like matrix.- Returns:
- An identity matrix of specified shape.
- Throws:
IllegalArgumentException- If the specified number of rows or columns is less than 1.- See Also:
-
I
Constructs an identity-like matrix of the specified shape. That is, a matrix of zeros with ones along the principle diagonal.- Parameters:
shape- Shape of the identity-like matrix.- Returns:
- An identity matrix of specified size.
- Throws:
IllegalArgumentException- If the specified shape is not rank 2.- See Also:
-
diag
Constructs a diagonal matrix from an array specifying the diagonal elements of the matrix.- Parameters:
data- Diagonal elements of the matrix. All other values will be zero.- Returns:
- A diagonal matrix whose diagonal elements are equal to
data. - See Also:
-
diag
Constructs a diagonal matrix from a vector specifying the diagonal elements of the matrix.- Parameters:
vec- Diagonal elements of the matrix. All other values will be zero.- Returns:
- A diagonal matrix whose diagonal elements are equal to the entries of
vec. - See Also:
-
pow
Computes the matrix multiplication of this matrix with itself
ntimes. This matrix must be square.For large
nvalues, this method may be significantly more efficient than callingthis.mult(this)a total ofntimes.- Parameters:
n- Number of times to multiply this matrix with itself. Must be non-negative.- Returns:
- If
n=0, then the identity - Throws:
IllegalArgumentException- If this matrix is not square (i.e.!this.isSquare()).
-
mult
Computes the matrix multiplication between two matrices.- Parameters:
b- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix
b. - Throws:
LinearAlgebraException- Ifthis.numCols != b.numRows.
-
mult
Computes the matrix-vector multiplication between this matrix and a vector.- Parameters:
b- Vector in the matrix-vector multiplication.- Returns:
- The result of matrix multiplying this matrix with vector
b. - Throws:
LinearAlgebraException- If the number of columns in this matrix do not equal the number of length of the vectorb.
-
mult
Computes the matrix multiplication between two matrices.- Parameters:
b- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix
b. - Throws:
LinearAlgebraException- Ifthis.numCols != b.numRows.
-
mult
Computes the matrix multiplication between two matrices.- Parameters:
b- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix
b. - Throws:
LinearAlgebraException- Ifthis.numCols != b.numRows.
-
mult
Computes the matrix multiplication between two matrices.- Parameters:
b- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix
b. - Throws:
LinearAlgebraException- Ifthis.numCols != b.numRows.
-
mult
Computes the matrix multiplication between two matrices.- Parameters:
b- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix
b. - Throws:
LinearAlgebraException- Ifthis.numCols() != b.numRows().
-
mult
Computes the matrix-vector multiplication between this matrix and a vector.- Parameters:
b- Vector in the matrix-vector multiplication.- Returns:
- The result of matrix multiplying this matrix with vector
b. - Throws:
LinearAlgebraException- If the number of columns in this matrix do not equal the number of length of the vectorb.
-
mult
Computes the matrix-vector multiplication between this matrix and a vector.- Parameters:
b- Vector in the matrix-vector multiplication.- Returns:
- The result of matrix multiplying this matrix with vector
b. - Throws:
LinearAlgebraException- If the number of columns in this matrix do not equal the number of length of the vectorb.
-
toReal
Converts this complex matrix to a real matrix. This conversion is done by taking the real component of each entry and ignoring the imaginary component.- Returns:
- A real matrix containing the real components of the data of this matrix.
-
isReal
public boolean isReal()Checks if all data of this matrix are real.- Returns:
trueif all data of this matrix are real;falseotherwise.
-
isComplex
public boolean isComplex()Checks if any entry within this matrix has non-zero imaginary component.- Returns:
trueif any entry of this matrix has a non-zero imaginary component.
-
isUnitary
public boolean isUnitary()Checks if this matrix is unitary. That is, if the inverse of this matrix is approximately equal to its conjugate transpose.- Overrides:
isUnitaryin classAbstractDenseFieldMatrix<CMatrix,CVector, Complex128> - Returns:
trueif this matrix it is unitary;falseotherwise.
-
round
Rounds all data in this matrix to the nearest integer. The real and imaginary components will be rounded independently.- Returns:
- A new matrix containing the data of this matrix rounded to the nearest integer.
-
round
Rounds all data within this matrix to the specified precision. The real and imaginary components will be rounded independently.- Parameters:
precision- The precision to round to (i.e. the number of decimal places to round to). Must be non-negative.- Returns:
- A new matrix containing the data of this matrix rounded to the specified precision.
-
roundToZero
Sets all elements of this matrix to zero if they are withintolof zero. This is not done in place.- Parameters:
precision- The precision to round to (i.e. the number of decimal places to round to). Must be non-negative.- Returns:
- A copy of this matrix with all data within
tolof zero set to zero.
-
accept
Accepts a visitor that implements theMatrixVisitorinterface. This method is part of the "Visitor Pattern" and allows operations to be performed on the matrix without modifying the matrix's class directly.- Type Parameters:
R- The return type of the visitor's operation.- Parameters:
visitor- The visitor implementing the operation to be performed.- Returns:
- The result of the visitor's operation, typically another matrix or a scalar value.
- Throws:
NullPointerException- if the visitor isnull.
-
equals
Checks if an object is equal to this matrix object. -
hashCode
-
toString
-