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, numRows
Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
zeroElement
Fields 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 specifiedsize
filled withfillValue
.CMatrix
(int size, Complex128 fillValue) Creates a square matrix with the specifiedsize
filled withfillValue
.Constructs a complex matrix from a 2D array of strings.CMatrix
(Complex128[][] entries) Constructs a complex matrix from a 2D array.Constructs a copy of the specified matrix.Creates a zero matrix with the specifiedshape
.Constructs a complex matrix with specifiedshape
anddata
.Creates matrix with the specifiedshape
filled withfillValue
.CMatrix
(Shape shape, Complex128 fillValue) Creates a complex matrix with the specifiedshape
filled withfillValue
.CMatrix
(Shape shape, Complex128[] entries) Creates a complex matrix with the specifieddata
andshape
. -
Method Summary
Modifier and TypeMethodDescription<R> R
accept
(MatrixVisitor<R> visitor) Accepts a visitor that implements theMatrixVisitor
interface.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 CMatrix
diag
(Complex128... data) Constructs a diagonal matrix from an array specifying the diagonal elements of the matrix.static CMatrix
Constructs a diagonal matrix from a vector 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.boolean
Checks if an object is equal to this matrix object.static CMatrix
getEmpty
(int rows, int cols) Constructs an empty matrix with the specified number of rows and columns.int
hashCode()
static CMatrix
I
(int size) Constructs an identity matrix of the specified size.static CMatrix
I
(int numRows, int numCols) Constructs an identity-like matrix of the specified shape.static CMatrix
Constructs an identity-like matrix of the specified shape.boolean
Checks if any entry within this matrix has non-zero imaginary component.boolean
isReal()
Checks if all data of this matrix are real.boolean
Checks if this matrix is unitary.makeEmptyDataArray
(int length) Creates an empty array of the same type as the data array of this tensor.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.protected CooCMatrix
makeLikeCooTensor
(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 theshape
anddata
.protected CVector
makeLikeVector
(Complex128[] entries) Constructs a vector of a similar type as this matrix.protected CVector
makeLikeVector
(Shape shape, Complex128[] entries) Constructs a vector of a similar type as this matrix.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.double
norm()
// TODO: Update javadoc.double
norm
(double p) // TODO: Update javadoc.double
norm
(double p, double q) // TODO: Update javadoc.pow
(int n) Computes the matrix multiplication of this matrix with itselfn
times.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 withintol
of 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, sqrt
Methods inherited from class org.flag4j.arrays.backend.ring_arrays.AbstractDenseRingMatrix
H, H, isCloseToIdentity, isHermitian, norm, sub, subEq
Methods 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, mult, multTranspose, numCols, numRows, removeCol, removeCols, removeRow, removeRows, set, setCol, setCol, setRow, setRow, setSlice, setSliceCopy, setValues, stack, swapCols, swapRows, T, toVector, tr
Methods 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, tensorTr
Methods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, reshape, sameShape, totalEntries
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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, sum
Methods 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, mult, multTranspose, numCols, numRows, removeCol, removeCols, removeRow, removeRows, set, setCol, setRow, setSliceCopy, stack, stack, sub, swapCols, swapRows, T, toVector, tr, trace, vectorType
Methods inherited from interface org.flag4j.arrays.backend.ring_arrays.TensorOverRing
H, H, sub
-
Constructor Details
-
CMatrix
Creates a complex matrix with the specifieddata
andshape
.- Parameters:
shape
- Shape of this matrix.entries
- Entries of this matrix.
-
CMatrix
Creates a complex matrix with the specifiedshape
filled 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
ComplexNumberParser
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 with specifiedshape
anddata
.- 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 specifiedsize
filled withfillValue
.- Parameters:
size
- Size of the square matrix to construct.fillValue
- Value to fill matrix with.
-
CMatrix
Creates a square matrix with the specifiedsize
filled 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:
makeLikeVector
in 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:SemiringTensorMixin
Creates 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()// TODO: Update javadoc. Computes the Euclidean norm of this vector.- Returns:
- The Euclidean norm of this vector.
-
norm
public double norm(double p) // TODO: Update javadoc. Computes the p-norm of this vector.- Parameters:
p
-p
value in the p-norm.- Returns:
- The Euclidean norm of this vector.
-
norm
public double norm(double p, double q) // TODO: Update javadoc. Computes the p-norm of this vector.- Parameters:
p
-p
value in the p-norm.- Returns:
- The Euclidean norm of this vector.
-
makeLikeVector
Constructs a vector of a similar type as this matrix.- Specified by:
makeLikeVector
in 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:
makeLikeCooMatrix
in 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:
makeLikeCsrMatrix
in 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.
-
toCoo
Converts this matrix to an equivalent sparse COO matrix.- Overrides:
toCoo
in 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:
toCoo
in 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:
toCsr
in 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:
toCsr
in 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:
makeLikeCooTensor
in 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 theshape
anddata
. The resulting tensor will also have the same non-zero indices as this tensor.- Specified by:
makeLikeTensor
in interfaceTensorOverSemiring<CMatrix,
CMatrix, Complex128[], Complex128> - Specified by:
makeLikeTensor
in 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
shape
anddata
.
-
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
null
values) 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 andb
do 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 andb
do 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 andb
do 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 andb
do 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 andb
do 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 andb
do 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 andb
do 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 andb
do 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 andb
do not have the same shape.
-
div
-
toTensor
Converts this matrix to an equivalent tensor.- Specified by:
toTensor
in 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:
toTensor
in 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
newShape
and 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
n
times. This matrix must be square.For large
n
values, this method may be significantly more efficient than callingthis.mult(this)
a total ofn
times.- 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
- If the number of columns in this matrix do not equal the number of rows in matrixb
.
-
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:
true
if all data of this matrix are real;false
otherwise.
-
isComplex
public boolean isComplex()Checks if any entry within this matrix has non-zero imaginary component.- Returns:
true
if 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:
isUnitary
in classAbstractDenseFieldMatrix<CMatrix,
CVector, Complex128> - Returns:
true
if this matrix it is unitary;false
otherwise.
-
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 withintol
of 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
tol
of zero set to zero.
-
accept
Accepts a visitor that implements theMatrixVisitor
interface. 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
-