Package org.flag4j.arrays.dense
Class Matrix
java.lang.Object
- All Implemented Interfaces:
Serializable
,DenseMatrixMixin<Matrix,
,Double> DenseMixin<Double>
,MatrixComparisonsMixin<Matrix>
,MatrixManipulationsMixin<Matrix,
,Double> MatrixMixin<Matrix,
,Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> MatrixOperationsMixin<Matrix,
,Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> MatrixPropertiesMixin
,RealMatrixMixin<Matrix,
,CMatrix> RealTensorMixin<Matrix,
,CMatrix> TensorComparisonsMixin
,TensorManipulationsMixin<Matrix>
,TensorOperationsMixin<Matrix,
,Matrix, CMatrix, CMatrix, Matrix, Double> TensorPropertiesMixin
public class Matrix
extends RealDenseTensorBase<Matrix,CMatrix>
implements MatrixMixin<Matrix,Matrix,CooMatrix,CMatrix,CooCMatrix,Double,Vector,Vector>, RealMatrixMixin<Matrix,CMatrix>, DenseMatrixMixin<Matrix,Double>
Real dense matrix. Stored in row major format. This class is mostly equivalent to a
real dense tensor
.
However, specialized methods are provided for this class which may result in slightly better performance than
equivalent operations with a real dense tensor
of rank 2. Additionally, methods specific to matrices
which may not be available for tensors are provided.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionfinal int
The number of columns in this matrix.final int
The number of rows in this matrix.Fields inherited from class org.flag4j.core.TensorBase
DEFAULT_ROUND_TO_ZERO_THRESHOLD, entries, shape
-
Constructor Summary
ConstructorDescriptionMatrix
(double[][] entries) Creates a real dense matrix whose entries are specified by a double array.Matrix
(int size) Constructs a square real dense matrix of a specified size.Matrix
(int[][] entries) Creates a real dense matrix whose entries are specified by a double array.Matrix
(int size, double value) Creates a square real dense matrix with a specified fill value.Matrix
(int rows, int cols) Creates a real dense matrix of a specified shape filled with zeros.Matrix
(int rows, int cols, double value) Creates a real dense matrix with a specified shape and fills the matrix with the specified value.Matrix
(int numRows, int numCols, double[] entries) Constructs a matrix with specified shape and entries.Creates a real dense matrix whose entries are specified by a double array.Creates a real dense matrix whose entries are specified by a double array.Creates a real dense matrix which is a copy of a specified matrix.Creates a real dense matrix with specified shape filled with zeros.Creates a real dense matrix with specified shape filled with a specific value.Constructs a matrix with specified shape and entries. -
Method Summary
Modifier and TypeMethodDescriptionComputes the element-wise addition between two tensors of the same rank.add
(CooCMatrix B) Computes the element-wise addition between two tensors of the same rank.Computes the element-wise addition between two tensors of the same rank.add
(CsrCMatrix B) Computes the element-wise addition between two tensors of the same rank.Computes the element-wise addition between two tensors of the same rank.void
Computes the element-wise subtraction of two tensors of the same rank and stores the result in this tensor.Adds a vector to each column of a matrix.Adds a vector to each column of a matrix.Adds a vector to each column of a matrix.Adds a vector to each column of a matrix.Adds a vector to each row of a matrix.Adds a vector to each row of a matrix.Adds a vector to each row of a matrix.Adds a vector to each row of a matrix.Stacks matrices along rows.Augments a matrix with a vector.Stacks matrices along rows.Augments a matrix with a vector.Stacks matrices along rows.Augments a matrix with a vector.Stacks matrices along rows.Augments a matrix with a vector.det()
Computes the determinant of a square matrix.Computes the element-wise division between two matrices.Computes the element-wise multiplication (Hadamard product) between two matrices.Computes the element-wise multiplication (Hadamard product) between two matrices.Computes the element-wise multiplication (Hadamard product) between two matrices.boolean
Checks if an object is equal to this matrix object.Computes the Frobenius inner product of two matrices.Computes the Frobenius inner product of two matrices.fib
(CooCMatrix B) Computes the Frobenius inner product of two matrices.Computes the Frobenius inner product of two matrices.flatten()
Flattens a matrix to have a single row.flatten
(int axis) Flattens a matrix along a specified axis.get
(int... indices) Gets the element in this tensor at the specified indices.getCol
(int colIdx) Get the column of this matrix at the specified index.getCol
(int colIdx, int rowStart, int rowEnd) Gets a specified column of this matrix betweenrowStart
(inclusive) androwEnd
(exclusive).getColAsVector
(int colIdx) Get the column of this matrix at the specified index.getColBelow
(int rowStart, int colIdx) Get a specified column of this matrix at and below a specified row.getDiag()
Extracts the diagonal elements of this matrix and returns them as a vector.getRow
(int rowIdx) Get the row of this matrix at the specified index.getRowAfter
(int colStart, int rowIdx) Get a specified row of this matrix at and after a specified column.getRowAsVector
(int rowIdx) Get the row of this matrix at the specified index.protected Matrix
getSelf()
Simply returns this tensor.getSlice
(int rowStart, int rowEnd, int colStart, int colEnd) Gets a specified slice of this matrix.H()
Compute the transpose of this matrix.static Matrix
I
(int size) Constructs an identity matrix of the specified size.static Matrix
I
(int numRows, int numCols) Constructs an identity-like matrix of the specified shape.static Matrix
Constructs an identity-like matrix of the specified shape.boolean
Checks if a matrix is anti-symmetric.boolean
Checks that this matrix is close to the identity matrix according toRealProperties.allClose(double[], double[])
boolean
Checks if a matrix has full rank.boolean
isI()
Checks if this matrix is the identity matrix.boolean
Checks if this matrix is orthogonal.boolean
Checks if a matrix is singular.boolean
isSquare()
Checks if this matrix is square.boolean
Checks if a matrix is symmetric.boolean
isTriL()
Checks if this matrix is lower triangular.boolean
isTriU()
Checks if this matrix is upper triangular.boolean
isVector()
Checks if a matrix can be represented as a vector.protected CMatrix
makeComplexTensor
(Shape shape, double[] entries) Factory to create a complex tensor with the specified shape and size.protected CMatrix
makeComplexTensor
(Shape shape, CNumber[] entries) Factory to create a complex tensor with the specified shape and size.protected Matrix
makeTensor
(Shape shape, double[] entries) Factory to create a tensor with the specified shape and size.int
Computes the rank of this matrix (i.e.Computes the matrix multiplication between two matrices.Computes matrix-vector multiplication.Computes the matrix multiplication between two matrices.Computes matrix-vector multiplication.mult
(CooCMatrix B) Computes the matrix multiplication between two matrices.mult
(CooCVector b) Computes matrix-vector multiplication.Computes the matrix multiplication between two matrices.Computes matrix-vector multiplication.mult
(CsrCMatrix B) Computes the matrix multiplication between two matrices.Computes the matrix multiplication between two matrices.int
numCols()
Gets the number of columns in this matrix.int
numRows()
Gets the number of rows in this matrix.pow
(int exponent) Computes the matrix power with a given exponent.removeCol
(int colIndex) Removes a specified column from this matrix.removeCols
(int... colIndices) Removes a specified set of columns from this matrix.removeRow
(int rowIndex) Removes a specified row from this matrix.removeRows
(int... rowIndices) Removes a specified set of rows from this matrix.private String
rowToString
(int i, int colStopIndex, List<Integer> maxList) Gets row of matrix formatted as a human-readable String.set
(double value, int row, int col) Sets an index of this matrix to the specified value.Sets an index of this matrix to the specified value.setCol
(double[] values, int colIndex) Sets a column of this matrix at the given index to the specified values.setCol
(int[] values, int colIndex) Sets a column of this matrix at the given index to the specified values.Sets a column of this matrix at the given index to the specified values.Sets a column of this matrix at the given index to the specified values.Sets a column of this matrix at the given index to the specified values.Sets a column of this matrix at the given index to the specified values.setRow
(double[] values, int rowIndex) Sets a row of this matrix at the given index to the specified values.setRow
(int[] values, int rowIndex) Sets a row of this matrix at the given index to the specified values.Sets a row of this matrix at the given index to the specified values.Sets a row of this matrix at the given index to the specified values.setSlice
(double[][] values, int rowStart, int colStart) Sets a slice of this matrix to the specified values.setSlice
(int[][] values, int rowStart, int colStart) Sets a slice of this matrix to the specified values.Sets a slice of this matrix to the specified values.Sets a slice of this matrix to the specified values.Sets a slice of this matrix to the specified values.Sets a slice of this matrix to the specified values.setSliceCopy
(double[][] values, int rowStart, int colStart) Creates a copy of this matrix and sets a slice of the copy to the specified values.setSliceCopy
(int[][] values, int rowStart, int colStart) Creates a copy of this matrix and sets a slice of the copy to the specified values.setSliceCopy
(Double[][] values, int rowStart, int colStart) Creates a copy of this matrix and sets a slice of the copy to the specified values.setSliceCopy
(Integer[][] values, int rowStart, int colStart) Creates a copy of this matrix and sets a slice of the copy to the specified values.setSliceCopy
(Matrix values, int rowStart, int colStart) Creates a copy of this matrix and sets a slice of the copy to the specified values.setSliceCopy
(CooMatrix values, int rowStart, int colStart) Creates a copy of this matrix and sets a slice of the copy to the specified values.setValues
(double[][] values) Sets the value of this matrix using a 2D array.setValues
(int[][] values) Sets the value of this matrix using a 2D array.Sets the value of this matrix using a 2D array.Sets the value of this matrix using a 2D array.shape()
Gets the shape of this matrix.Computes the complex element-wise square root of a tensor.Stacks matrices along columns.Stacks vector to this matrix along columns.Stacks matrices along columns.Stacks vector to this matrix along columns.stack
(CooCMatrix B) Stacks matrices along columns.stack
(CooCVector b) Stacks vector to this matrix along columns.Stacks matrices along columns.Stacks vector to this matrix along columns.Computes the element-wise subtraction of two tensors of the same rank.sub
(CooCMatrix B) Computes the element-wise subtraction of two tensors of the same rank.Computes the element-wise subtraction of two tensors of the same rank.sub
(CsrCMatrix B) Computes the element-wise subtraction of two tensors of the same rank.Computes the element-wise subtraction of two tensors of the same rank.void
Computes the element-wise subtraction of two tensors of the same rank and stores the result in this tensor.sumCols()
Sums together the columns of a matrix as if each column was a column vector.sumRows()
Sums together the rows of a matrix as if each row was a row vector.swapCols
(int colIndex1, int colIndex2) Swaps specified columns in the matrix.swapRows
(int rowIndex1, int rowIndex2) Swaps specified rows in the matrix.T()
Computes the transpose of a tensor.toCoo()
Converts this matrix to a sparse COO matrix.toCsr()
Converts this matrix to an equivalent sparse CSR matrix.toString()
Formats matrix contents as a human-readable String.toTensor()
Converts this matrix to an equivalent complex tensor.toVector()
Converts this matrix to an equivalent vector.tr()
Computes the trace of this matrix.trace()
Computes the trace of this matrix.int
Checks what type of vector this matrix is.Methods inherited from class org.flag4j.core.dense_base.RealDenseTensorBase
abs, add, add, add, addEq, addEq, allClose, argMax, argMin, copy, div, div, elemDiv, elemMult, hashCode, isNeg, isOnes, isPos, isZeros, max, maxAbs, min, minAbs, mult, mult, recip, reshape, reshape, round, round, roundToZero, roundToZero, set, sqrt, sub, sub, sub, subEq, subEq, sum, toComplex
Methods inherited from class org.flag4j.core.TensorBase
allClose, getEntries, getRank, getShape, sameLength, sameShape, tensorEquals, totalEntries
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.flag4j.core.dense_base.DenseMatrixMixin
addEq, subEq
Methods inherited from interface org.flag4j.core.MatrixOperationsMixin
add, augment, augment, copy, elemDiv, elemMult, mult, multTranspose, multTranspose, stack, stack, stack, stack, stack, stack, stack, stack, stack, stack, stack, stack, sub
Methods inherited from interface org.flag4j.core.MatrixPropertiesMixin
isDiag, isInvertible, isTri
Methods inherited from interface org.flag4j.core.TensorOperationsMixin
transpose
-
Field Details
-
numRows
public final int numRowsThe number of rows in this matrix. -
numCols
public final int numColsThe number of columns in this matrix.
-
-
Constructor Details
-
Matrix
public Matrix(int size) Constructs a square real dense matrix of a specified size. The entries of the matrix will default to zero.- Parameters:
size
- Size of the square matrix.- Throws:
IllegalArgumentException
- if size negative.
-
Matrix
public Matrix(int size, double value) Creates a square real dense matrix with a specified fill value.- Parameters:
size
- Size of the square matrix.value
- Value to fill this matrix with.- Throws:
IllegalArgumentException
- if size negative.
-
Matrix
public Matrix(int rows, int cols) Creates a real dense matrix of a specified shape filled with zeros.- Parameters:
rows
- The number of rows in the matrix.cols
- The number of columns in the matrix.- Throws:
IllegalArgumentException
- if either m or n is negative.
-
Matrix
public Matrix(int rows, int cols, double value) Creates a real dense matrix with a specified shape and fills the matrix with the specified value.- Parameters:
rows
- Number of rows in the matrix.cols
- Number of columns in the matrix.value
- Value to fill this matrix with.- Throws:
IllegalArgumentException
- if either m or n is negative.
-
Matrix
Creates a real dense matrix whose entries are specified by a double array.- Parameters:
entries
- Entries of the real dense matrix.
-
Matrix
Creates a real dense matrix whose entries are specified by a double array.- Parameters:
entries
- Entries of the real dense matrix.
-
Matrix
public Matrix(double[][] entries) Creates a real dense matrix whose entries are specified by a double array.- Parameters:
entries
- Entries of the real dense matrix.
-
Matrix
public Matrix(int[][] entries) Creates a real dense matrix whose entries are specified by a double array.- Parameters:
entries
- Entries of the real dense matrix.
-
Matrix
Creates a real dense matrix which is a copy of a specified matrix.- Parameters:
A
- The matrix defining the entries for this matrix.
-
Matrix
Creates a real dense matrix with specified shape filled with zeros.- Parameters:
shape
- Shape of matrix.- Throws:
IllegalArgumentException
- If theshape
is not of rank 2.
-
Matrix
Creates a real dense matrix with specified shape filled with a specific value.- Parameters:
shape
- Shape of matrix.value
- Value to fill matrix with.- Throws:
IllegalArgumentException
- If theshape
is not of rank 2.
-
Matrix
Constructs a matrix with specified shape and entries. Note, unlike other constructors, the entries' parameter is not copied.- Parameters:
shape
- Shape of the matrixentries
- Entries of the matrix.- Throws:
IllegalArgumentException
- If theshape
is not of rank 2.
-
Matrix
public Matrix(int numRows, int numCols, double[] entries) Constructs a matrix with specified shape and entries. Note, unlike other constructors, the entries' parameter is not copied.- Parameters:
numRows
- Number of rows in this matrix.numCols
- Number of columns in this matrix.entries
- Entries of the matrix.
-
-
Method Details
-
makeTensor
Factory to create a tensor with the specified shape and size.- Specified by:
makeTensor
in classDenseTensorBase<Matrix,
CMatrix, Matrix, double[], Double> - Parameters:
shape
- Shape of the tensor to make.entries
- Entries of the tensor to make.- Returns:
- A new tensor with the specified shape and entries.
-
makeComplexTensor
Factory to create a complex tensor with the specified shape and size.- Specified by:
makeComplexTensor
in classRealDenseTensorBase<Matrix,
CMatrix> - Parameters:
shape
- Shape of the tensor to make.entries
- Entries of the tensor to make.- Returns:
- A new tensor with the specified shape and entries.
-
makeComplexTensor
Factory to create a complex tensor with the specified shape and size.- Specified by:
makeComplexTensor
in classRealDenseTensorBase<Matrix,
CMatrix> - Parameters:
shape
- Shape of the tensor to make.entries
- Entries of the tensor to make.- Returns:
- A new tensor with the specified shape and entries.
-
getSelf
-
numRows
public int numRows()Gets the number of rows in this matrix.- Specified by:
numRows
in interfaceMatrixMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Returns:
- The number of rows in this matrix.
-
numCols
public int numCols()Gets the number of columns in this matrix.- Specified by:
numCols
in interfaceMatrixMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Returns:
- The number of columns in this matrix.
-
shape
-
toTensor
Converts this matrix to an equivalent complex tensor.- Returns:
- A tensor which is equivalent to this matrix.
-
toVector
Converts this matrix to an equivalent vector. If this matrix is not shaped as a row/column vector, it will be flattened then converted to a vector.- Specified by:
toVector
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Returns:
- A vector equivalent to this matrix.
-
toCoo
-
toCsr
Converts this matrix to an equivalent sparse CSR matrix.- Returns:
- A sparse coo matrix equivalent to this matrix.
- See Also:
-
isI
public boolean isI()Checks if this matrix is the identity matrix. That is, checks if this matrix is square and contains only ones along the principle diagonal and zeros everywhere else.- Specified by:
isI
in interfaceMatrixComparisonsMixin<Matrix>
- Returns:
- True if this matrix is the identity matrix. Otherwise, returns false.
- See Also:
-
isCloseToI
public boolean isCloseToI()Checks that this matrix is close to the identity matrix according toRealProperties.allClose(double[], double[])
- Returns:
- True if this matrix is approximately the identity matrix.
- See Also:
-
equals
Checks if an object is equal to this matrix object.- Specified by:
equals
in interfaceTensorComparisonsMixin
- Overrides:
equals
in classObject
- Parameters:
object
- Object to check equality with this matrix.- Returns:
- True if the two matrices have the same shape, are numerically equivalent, and are of type
Matrix
. False otherwise.
-
flatten
Flattens a matrix to have a single row. To flatten matrix to a single column, seeflatten(int)
.- Specified by:
flatten
in interfaceTensorManipulationsMixin<Matrix>
- Returns:
- The flat version of this matrix.
-
flatten
Flattens a matrix along a specified axis. Also seeflatten()
.- Specified by:
flatten
in interfaceTensorManipulationsMixin<Matrix>
- Parameters:
axis
- - If axis=0, flattens to a row vector.
- If axis=1, flattens to a column vector.- Returns:
- The flat version of this matrix.
-
set
Sets an index of this matrix to the specified value.- Specified by:
set
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
value
- Value to set.row
- Row index to set.col
- Column index to set.- Returns:
- A reference to this matrix.
-
set
-
setValues
Sets the value of this matrix using a 2D array.- Specified by:
setValues
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
values
- New values of the matrix.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different shape then this matrix.
-
setValues
Sets the value of this matrix using a 2D array.- Specified by:
setValues
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
values
- New values of the matrix.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different shape then this matrix.
-
setValues
Sets the value of this matrix using a 2D array.- Parameters:
values
- New values of the matrix.- Throws:
IllegalArgumentException
- If the values array has a different shape then this matrix.
-
setValues
Sets the value of this matrix using a 2D array.- Specified by:
setValues
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
values
- New values of the matrix.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different shape then this matrix.
-
setCol
Sets a column of this matrix at the given index to the specified values.- Specified by:
setCol
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the column.colIndex
- The index of the column which is to be set.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different length than the number of rows of this matrix.
-
setCol
Sets a column of this matrix at the given index to the specified values.- Specified by:
setCol
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the column.colIndex
- The index of the column which is to be set.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different length than the number of rows of this matrix.
-
setCol
Sets a column of this matrix at the given index to the specified values.- Specified by:
setCol
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the column.colIndex
- The index of the column which is to be set.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different length than the number of rows of this matrix.
-
setCol
Sets a column of this matrix at the given index to the specified values.- Specified by:
setCol
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the column.colIndex
- The index of the column which is to be set.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different length than the number of rows of this matrix.
-
setCol
Sets a column of this matrix at the given index to the specified values.- Specified by:
setCol
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
values
- New values for the column.colIndex
- The index of the column which is to be set.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If thevalues
vector has a different length than the number of rows of this matrix.
-
setCol
Sets a column of this matrix at the given index to the specified values.- Parameters:
values
- New values for the column. This method assumes that the indices of the sparse vector are sorted. If this is not the case, callCooVector.sortIndices()
first.colIndex
- The index of the column which is to be set.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If thevalues
vector has a different length than the number of rows of this matrix.
-
setRow
Sets a row of this matrix at the given index to the specified values.- Specified by:
setRow
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the row.rowIndex
- The index of the column which is to be set.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different length than the number of columns of this matrix.
-
setRow
Sets a row of this matrix at the given index to the specified values.- Specified by:
setRow
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the row.rowIndex
- The index of the column which is to be set.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different length than the number of columns of this matrix.
-
setRow
Sets a row of this matrix at the given index to the specified values.- Specified by:
setRow
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the row.rowIndex
- The index of the column which is to be set.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different length than the number of columns of this matrix.
-
setRow
Sets a row of this matrix at the given index to the specified values.- Specified by:
setRow
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the row.rowIndex
- The index of the column which is to be set.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If the values array has a different length than the number of columns of this matrix.
-
getSlice
Gets a specified slice of this matrix.- Specified by:
getSlice
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
rowStart
- Starting row index of slice (inclusive).rowEnd
- Ending row index of slice (exclusive).colStart
- Starting column index of slice (inclusive).colEnd
- Ending row index of slice (exclusive).- Returns:
- The specified slice of this matrix. This is a completely new matrix and NOT a view into the matrix.
- Throws:
ArrayIndexOutOfBoundsException
- If any of the indices are out of bounds of this matrix.IllegalArgumentException
- IfrowEnd
is not greater thanrowStart
or ifcolEnd
is not greater thancolStart
.
-
setSlice
Sets a slice of this matrix to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set within this matrix.- Specified by:
setSlice
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSlice
Sets a slice of this matrix to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSlice
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSlice
Sets a slice of this matrix to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSlice
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSlice
Sets a slice of this matrix to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSlice
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSlice
Sets a slice of this matrix to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSlice
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSlice
Sets a slice of this matrix to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSlice
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSliceCopy
Creates a copy of this matrix and sets a slice of the copy to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSliceCopy
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A copy of this matrix with the given slice set to the specified values.
- Throws:
IndexOutOfBoundsException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSliceCopy
Creates a copy of this matrix and sets a slice of the copy to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSliceCopy
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A copy of this matrix with the given slice set to the specified values.
- Throws:
IndexOutOfBoundsException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSliceCopy
Creates a copy of this matrix and sets a slice of the copy to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSliceCopy
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A copy of this matrix with the given slice set to the specified values.
- Throws:
IndexOutOfBoundsException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSliceCopy
Creates a copy of this matrix and sets a slice of the copy to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSliceCopy
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A copy of this matrix with the given slice set to the specified values.
- Throws:
IndexOutOfBoundsException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSliceCopy
Creates a copy of this matrix and sets a slice of the copy to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSliceCopy
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A copy of this matrix with the given slice set to the specified values.
- Throws:
IndexOutOfBoundsException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
setSliceCopy
Creates a copy of this matrix and sets a slice of the copy to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
setSliceCopy
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
values
- New values for the specified slice.rowStart
- Starting row index for the slice (inclusive).colStart
- Starting column index for the slice (inclusive).- Returns:
- A copy of this matrix with the given slice set to the specified values.
- Throws:
IndexOutOfBoundsException
- If rowStart or colStart are not within the matrix.IllegalArgumentException
- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
-
removeRow
Removes a specified row from this matrix.- Specified by:
removeRow
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
rowIndex
- Index of the row to remove from this matrix.- Returns:
- A copy of this matrix with the specified column removed.
-
removeRows
Removes a specified set of rows from this matrix.- Specified by:
removeRows
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
rowIndices
- The indices of the rows to remove from this matrix. Assumed to contain unique values.- Returns:
- a copy of this matrix with the specified column removed.
-
removeCol
Removes a specified column from this matrix.- Specified by:
removeCol
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
colIndex
- Index of the column to remove from this matrix.- Returns:
- a copy of this matrix with the specified column removed.
-
removeCols
Removes a specified set of columns from this matrix.- Specified by:
removeCols
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
colIndices
- Indices of the columns to remove from this matrix. Assumed to contain unique values.- Returns:
- a copy of this matrix with the specified column removed.
-
add
Computes the element-wise addition between two tensors of the same rank.- Specified by:
add
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If A and B have different shapes.
-
add
Computes the element-wise addition between two tensors of the same rank.- Specified by:
add
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If A and B have different shapes.
-
add
Computes the element-wise addition between two tensors of the same rank.- Specified by:
add
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If A and B have different shapes.
-
add
Computes the element-wise addition between two tensors of the same rank.- Specified by:
add
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If A and B have different shapes.
-
add
Computes the element-wise addition between two tensors of the same rank.- Specified by:
add
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second tensor in the addition.- Returns:
- The result of adding the tensor B to this tensor element-wise.
- Throws:
IllegalArgumentException
- If A and B have different shapes.
-
subEq
Computes the element-wise subtraction of two tensors of the same rank and stores the result in this tensor.- Specified by:
subEq
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
B
- Second tensor in the subtraction.- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
addEq
Computes the element-wise subtraction of two tensors of the same rank and stores the result in this tensor.- Specified by:
addEq
in interfaceDenseMatrixMixin<Matrix,
Double> - Parameters:
B
- Second tensor in the subtraction.- Throws:
IllegalArgumentException
- If this tensor and B have different shapes.
-
T
Computes the transpose of a tensor. Same asTensorOperationsMixin.transpose()
. -
sub
Computes the element-wise subtraction of two tensors of the same rank.- Specified by:
sub
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second tensor in the subtraction.- Returns:
- The result of subtracting the tensor B from this tensor element-wise.
- Throws:
IllegalArgumentException
- If A and B have different shapes.
-
sub
Computes the element-wise subtraction of two tensors of the same rank.- Specified by:
sub
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second tensor in the subtraction.- Returns:
- The result of subtracting the tensor B from this tensor element-wise.
- Throws:
IllegalArgumentException
- If A and B have different shapes.
-
sub
Computes the element-wise subtraction of two tensors of the same rank.- Specified by:
sub
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second tensor in the subtraction.- Returns:
- The result of subtracting the tensor B from this tensor element-wise.
- Throws:
IllegalArgumentException
- If A and B have different shapes.
-
sub
Computes the element-wise subtraction of two tensors of the same rank.- Specified by:
sub
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second tensor in the subtraction.- Returns:
- The result of subtracting the tensor B from this tensor element-wise.
- Throws:
IllegalArgumentException
- If A and B have different shapes.
-
sub
Computes the element-wise subtraction of two tensors of the same rank.- Specified by:
sub
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second tensor in the subtraction.- Returns:
- The result of subtracting the tensor B from this tensor element-wise.
- Throws:
IllegalArgumentException
- If A and B have different shapes.
-
mult
Computes the matrix multiplication between two matrices.- Specified by:
mult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix B.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix do not equal the number of rows in matrix B.
-
mult
Computes the matrix multiplication between two matrices.- Specified by:
mult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix B.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix do not equal the number of rows in matrix B.
-
mult
Computes the matrix multiplication between two matrices.- Specified by:
mult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix B.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix do not equal the number of rows in matrix B.
-
mult
Computes the matrix multiplication between two matrices.- Specified by:
mult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix B.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix do not equal the number of rows in matrix B.
-
mult
Computes the matrix multiplication between two matrices.- Specified by:
mult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix B.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix do not equal the number of rows in matrix B.
-
mult
Computes the matrix multiplication between two matrices.- Specified by:
mult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix B.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix do not equal the number of rows in matrix B.
-
mult
Computes matrix-vector multiplication.- Specified by:
mult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector in the matrix-vector multiplication.- Returns:
- The result of matrix multiplying this matrix with vector b.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix do not equal the number of entries in the vector b.
-
mult
Computes matrix-vector multiplication.- Specified by:
mult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector in the matrix-vector multiplication.- Returns:
- The result of matrix multiplying this matrix with vector b.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix do not equal the number of entries in the vector b.
-
mult
Computes matrix-vector multiplication.- Specified by:
mult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector in the matrix-vector multiplication.- Returns:
- The result of matrix multiplying this matrix with vector b.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix do not equal the number of entries in the vector b.
-
mult
Computes matrix-vector multiplication.- Specified by:
mult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector in the matrix-vector multiplication.- Returns:
- The result of matrix multiplying this matrix with vector b.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix do not equal the number of entries in the vector b.
-
multTranspose
Multiplies this matrix with the transpose of theB
tensor as if bythis.
mult
(B.
T
())
. For large matrices, this method may be significantly faster than directly computing the transpose followed by the multiplication asthis.mult(B.T())
.- Specified by:
multTranspose
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- The second matrix in the multiplication and the matrix to transpose/- Returns:
- The result of multiplying this matrix with the transpose of
B
.
-
multTranspose
Multiplies this matrix with the transpose of theB
tensor as if bythis.
mult
(B.
T
())
. For large matrices, this method may be significantly faster than directly computing the transpose followed by the multiplication asthis.mult(B.T())
.- Specified by:
multTranspose
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- The second matrix in the multiplication and the matrix to transpose/- Returns:
- The result of multiplying this matrix with the transpose of
B
.
-
multTranspose
Multiplies this matrix with the transpose of theB
tensor as if bythis.
mult
(B.
T
())
. For large matrices, this method may be significantly faster than directly computing the transpose followed by the multiplication asthis.mult(B.T())
.- Specified by:
multTranspose
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- The second matrix in the multiplication and the matrix to transpose/- Returns:
- The result of multiplying this matrix with the transpose of
B
.
-
multTranspose
Multiplies this matrix with the transpose of theB
tensor as if bythis.
mult
(B.
T
())
. For large matrices, this method may be significantly faster than directly computing the transpose followed by the multiplication asthis.mult(B.T())
.- Specified by:
multTranspose
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- The second matrix in the multiplication and the matrix to transpose/- Returns:
- The result of multiplying this matrix with the transpose of
B
.
-
pow
Computes the matrix power with a given exponent. This is equivalent to multiplying a matrix to itself 'exponent' times. Note, this method is preferred over repeated multiplication of a matrix as this method will be significantly faster.- Specified by:
pow
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
exponent
- The exponent in the matrix power.- Returns:
- The result of multiplying this matrix with itself 'exponent' times. If the exponent is zero, then the identity matrix is returned.
- Throws:
IllegalArgumentException
- If this matrix is not square or if exponent is negative.
-
elemMult
Computes the element-wise multiplication (Hadamard product) between two matrices.- Specified by:
elemMult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the element-wise multiplication.- Returns:
- The result of element-wise multiplication of this matrix with the matrix B.
- Throws:
IllegalArgumentException
- If this matrix and B have different shapes.
-
elemMult
Computes the element-wise multiplication (Hadamard product) between two matrices.- Specified by:
elemMult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the element-wise multiplication.- Returns:
- The result of element-wise multiplication of this matrix with the matrix B.
- Throws:
IllegalArgumentException
- If this matrix and B have different shapes.
-
elemMult
Computes the element-wise multiplication (Hadamard product) between two matrices.- Specified by:
elemMult
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the element-wise multiplication.- Returns:
- The result of element-wise multiplication of this matrix with the matrix B.
- Throws:
IllegalArgumentException
- If this matrix and B have different shapes.
-
elemDiv
Computes the element-wise division between two matrices.- Specified by:
elemDiv
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the element-wise division.- Returns:
- The result of element-wise division of this matrix with the matrix B.
- Throws:
IllegalArgumentException
- If this matrix and B have different shapes.ArithmeticException
- If B contains any zero entries.
-
det
Computes the determinant of a square matrix.- Specified by:
det
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Returns:
- The determinant of this matrix.
- Throws:
IllegalArgumentException
- If this matrix is not square.
-
fib
Computes the Frobenius inner product of two matrices.- Specified by:
fib
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the Frobenius inner product- Returns:
- The Frobenius inner product of this matrix and matrix B.
- Throws:
IllegalArgumentException
- If this matrix and B have different shapes.
-
fib
Computes the Frobenius inner product of two matrices.- Specified by:
fib
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the Frobenius inner product- Returns:
- The Frobenius inner product of this matrix and matrix B.
- Throws:
IllegalArgumentException
- If this matrix and B have different shapes.
-
fib
Computes the Frobenius inner product of two matrices.- Specified by:
fib
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the Frobenius inner product- Returns:
- The Frobenius inner product of this matrix and matrix B.
- Throws:
IllegalArgumentException
- If this matrix and B have different shapes.
-
fib
Computes the Frobenius inner product of two matrices.- Specified by:
fib
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Second matrix in the Frobenius inner product- Returns:
- The Frobenius inner product of this matrix and matrix B.
- Throws:
IllegalArgumentException
- If this matrix and B have different shapes.
-
sumCols
Sums together the columns of a matrix as if each column was a column vector.- Specified by:
sumCols
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Returns:
- The result of summing together all columns of the matrix as column vectors. If this matrix is an m-by-n matrix, then the result will be a vectors of length m.
-
sumRows
Sums together the rows of a matrix as if each row was a row vector.- Specified by:
sumRows
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Returns:
- The result of summing together all rows of the matrix as row vectors. If this matrix is an m-by-n matrix, then the result will be a vector of length n.
-
addToEachCol
Adds a vector to each column of a matrix. The vector need not be a column vector. If it is a row vector it will be treated as if it were a column vector.- Specified by:
addToEachCol
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to add to each column of this matrix.- Returns:
- The result of adding the vector b to each column of this matrix.
- Throws:
IllegalArgumentException
- If the vector has a different number of entries as rows in the matrix.
-
addToEachCol
Adds a vector to each column of a matrix. The vector need not be a column vector. If it is a row vector it will be treated as if it were a column vector.- Specified by:
addToEachCol
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to add to each column of this matrix.- Returns:
- The result of adding the vector b to each column of this matrix.
-
addToEachCol
Adds a vector to each column of a matrix. The vector need not be a column vector. If it is a row vector it will be treated as if it were a column vector.- Specified by:
addToEachCol
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to add to each column of this matrix.- Returns:
- The result of adding the vector b to each column of this matrix.
-
addToEachCol
Adds a vector to each column of a matrix. The vector need not be a column vector. If it is a row vector it will be treated as if it were a column vector.- Specified by:
addToEachCol
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to add to each column of this matrix.- Returns:
- The result of adding the vector b to each column of this matrix.
-
addToEachRow
Adds a vector to each row of a matrix. The vector need not be a row vector. If it is a column vector it will be treated as if it were a row vector for this operation.- Specified by:
addToEachRow
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to add to each row of this matrix.- Returns:
- The result of adding the vector b to each row of this matrix.
-
addToEachRow
Adds a vector to each row of a matrix. The vector need not be a row vector. If it is a column vector it will be treated as if it were a row vector for this operation.- Specified by:
addToEachRow
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to add to each row of this matrix.- Returns:
- The result of adding the vector b to each row of this matrix.
-
addToEachRow
Adds a vector to each row of a matrix. The vector need not be a row vector. If it is a column vector it will be treated as if it were a row vector for this operation.- Specified by:
addToEachRow
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to add to each row of this matrix.- Returns:
- The result of adding the vector b to each row of this matrix.
-
addToEachRow
Adds a vector to each row of a matrix. The vector need not be a row vector. If it is a column vector it will be treated as if it were a row vector for this operation.- Specified by:
addToEachRow
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to add to each row of this matrix.- Returns:
- The result of adding the vector b to each row of this matrix.
-
stack
Stacks matrices along columns.
Also seeMatrixOperationsMixin.stack(Matrix, int)
andaugment(Matrix)
.- Specified by:
stack
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Matrix to stack to this matrix.- Returns:
- The result of stacking this matrix on top of the matrix B.
- Throws:
IllegalArgumentException
- If this matrix and matrix B have a different number of columns.
-
stack
Stacks matrices along columns.
Also seeMatrixOperationsMixin.stack(Matrix, int)
andaugment(Matrix)
.- Specified by:
stack
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Matrix to stack to this matrix.- Returns:
- The result of stacking this matrix on top of the matrix B.
- Throws:
IllegalArgumentException
- If this matrix and matrix B have a different number of columns.
-
stack
Stacks matrices along columns.
Also seeMatrixOperationsMixin.stack(Matrix, int)
andaugment(Matrix)
.- Specified by:
stack
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Matrix to stack to this matrix.- Returns:
- The result of stacking this matrix on top of the matrix B.
- Throws:
IllegalArgumentException
- If this matrix and matrix B have a different number of columns.
-
stack
Stacks matrices along columns.
Also seeMatrixOperationsMixin.stack(Matrix, int)
andaugment(Matrix)
.- Specified by:
stack
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Matrix to stack to this matrix.- Returns:
- The result of stacking this matrix on top of the matrix B.
- Throws:
IllegalArgumentException
- If this matrix and matrix B have a different number of columns.
-
augment
- Specified by:
augment
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Matrix to stack to this matrix.- Returns:
- The result of stacking B to the right of this matrix.
- Throws:
IllegalArgumentException
- If this matrix and matrix B have a different number of rows.
-
augment
- Specified by:
augment
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Matrix to stack to this matrix.- Returns:
- The result of stacking B to the right of this matrix.
- Throws:
IllegalArgumentException
- If this matrix and matrix B have a different number of rows.
-
augment
- Specified by:
augment
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Matrix to stack to this matrix.- Returns:
- The result of stacking B to the right of this matrix.
- Throws:
IllegalArgumentException
- If this matrix and matrix B have a different number of rows.
-
augment
- Specified by:
augment
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
B
- Matrix to stack to this matrix.- Returns:
- The result of stacking B to the right of this matrix.
- Throws:
IllegalArgumentException
- If this matrix and matrix B have a different number of rows.
-
stack
Stacks vector to this matrix along columns. Note that the orientation of the vector (i.e. row/column vector) does not affect the output of this function. All vectors will be treated as row vectors.
Also seeMatrixOperationsMixin.stack(Vector, int)
andaugment(Vector)
.- Specified by:
stack
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to stack to this matrix.- Returns:
- The result of stacking this matrix on top of the vector b.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix is different from the number of entries in the vector b.
-
stack
Stacks vector to this matrix along columns. Note that the orientation of the vector (i.e. row/column vector) does not affect the output of this function. All vectors will be treated as row vectors.
Also seeMatrixOperationsMixin.stack(CooVector, int)
andaugment(CooVector)
.- Specified by:
stack
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to stack to this matrix.- Returns:
- The result of stacking this matrix on top of the vector b.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix is different from the number of entries in the vector b.
-
stack
Stacks vector to this matrix along columns. Note that the orientation of the vector (i.e. row/column vector) does not affect the output of this function. All vectors will be treated as row vectors.
Also seeMatrixOperationsMixin.stack(CVector, int)
andaugment(CVector)
.- Specified by:
stack
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to stack to this matrix.- Returns:
- The result of stacking this matrix on top of the vector b.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix is different from the number of entries in the vector b.
-
stack
Stacks vector to this matrix along columns. Note that the orientation of the vector (i.e. row/column vector) does not affect the output of this function. All vectors will be treated as row vectors.
Also seeMatrixOperationsMixin.stack(CooCVector, int)
andaugment(CooCVector)
.- Specified by:
stack
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- Vector to stack to this matrix.- Returns:
- The result of stacking this matrix on top of the vector b.
- Throws:
IllegalArgumentException
- If the number of columns in this matrix is different from the number of entries in the vector b.
-
augment
Augments a matrix with a vector. That is, stacks a vector along the rows to the right side of a matrix. Note that the orientation of the vector (i.e. row/column vector) does not affect the output of this function. The vector will be treated as a column vector regardless of the true orientation.
Also seestack(Vector)
andMatrixOperationsMixin.stack(Vector, int)
.- Specified by:
augment
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- vector to augment to this matrix.- Returns:
- The result of augmenting b to the right of this matrix.
- Throws:
IllegalArgumentException
- If this matrix has a different number of rows as entries in b.
-
augment
Augments a matrix with a vector. That is, stacks a vector along the rows to the right side of a matrix. Note that the orientation of the vector (i.e. row/column vector) does not affect the output of this function. The vector will be treated as a column vector regardless of the true orientation.
Also seestack(CooVector)
andMatrixOperationsMixin.stack(CooVector, int)
.- Specified by:
augment
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- vector to augment to this matrix.- Returns:
- The result of augmenting b to the right of this matrix.
- Throws:
IllegalArgumentException
- If this matrix has a different number of rows as entries in b.
-
augment
Augments a matrix with a vector. That is, stacks a vector along the rows to the right side of a matrix. Note that the orientation of the vector (i.e. row/column vector) does not affect the output of this function. The vector will be treated as a column vector regardless of the true orientation.
Also seestack(CVector)
andMatrixOperationsMixin.stack(CVector, int)
.- Specified by:
augment
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- vector to augment to this matrix.- Returns:
- The result of augmenting b to the right of this matrix.
- Throws:
IllegalArgumentException
- If this matrix has a different number of rows as entries in b.
-
augment
Augments a matrix with a vector. That is, stacks a vector along the rows to the right side of a matrix. Note that the orientation of the vector (i.e. row/column vector) does not affect the output of this function. The vector will be treated as a column vector regardless of the true orientation.
Also seestack(CooCVector)
andMatrixOperationsMixin.stack(CooCVector, int)
.- Specified by:
augment
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
b
- vector to augment to this matrix.- Returns:
- The result of augmenting b to the right of this matrix.
- Throws:
IllegalArgumentException
- If this matrix has a different number of rows as entries in b.
-
getRow
Get the row of this matrix at the specified index.- Specified by:
getRow
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
rowIdx
- Index of row to get.- Returns:
- The specified row of this matrix.
- Throws:
ArrayIndexOutOfBoundsException
- IfrowIdx
is less than zero or greater than/equal to the number of rows in this matrix.
-
getRowAsVector
Get the row of this matrix at the specified index.- Parameters:
rowIdx
- Index of row to get.- Returns:
- The specified row of this matrix as a vector.
- Throws:
ArrayIndexOutOfBoundsException
- IfrowIdx
is less than zero or greater than/equal to the number of rows in this matrix.
-
getCol
Get the column of this matrix at the specified index.- Specified by:
getCol
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
colIdx
- Index of column to get.- Returns:
- The specified column of this matrix.
- Throws:
ArrayIndexOutOfBoundsException
- IfcolIdx
is less than zero or greater than/equal to the number of columns in this matrix.
-
getColBelow
Get a specified column of this matrix at and below a specified row.- Specified by:
getColBelow
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
rowStart
- Index of the row to begin at.colIdx
- Index of column to get.- Returns:
- The specified column of this matrix beginning at the specified row.
- Throws:
NegativeArraySizeException
- IfrowStart
is larger than the number of rows in this matrix.ArrayIndexOutOfBoundsException
- IfrowStart
orcolIdx
is outside the bounds of this matrix.
-
getCol
Gets a specified column of this matrix betweenrowStart
(inclusive) androwEnd
(exclusive).- Specified by:
getCol
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
colIdx
- Index of the column of this matrix to get.rowStart
- Starting row of the column (inclusive).rowEnd
- Ending row of the column (exclusive).- Returns:
- The column at index
colIdx
of this matrix between therowStart
androwEnd
indices. - Throws:
IllegalArgumentException
- IfrowStart
is less than 0.NegativeArraySizeException
- IfrowEnd
is less thanrowStart
.
-
getRowAfter
Get a specified row of this matrix at and after a specified column.- Specified by:
getRowAfter
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Parameters:
colStart
- Index of the row to begin at.rowIdx
- Index of the row to get.- Returns:
- The specified row of this matrix beginning at the specified column.
- Throws:
NegativeArraySizeException
- IfcolStart
is larger than the number of columns in this matrix.ArrayIndexOutOfBoundsException
- IfrowIdx
orcolStart
is outside the bounds of this matrix.
-
getColAsVector
Get the column of this matrix at the specified index.- Parameters:
colIdx
- Index of column to get.- Returns:
- The specified column of this matrix as a vector.
- Throws:
ArrayIndexOutOfBoundsException
- IfcolIdx
is less than zero or greater than/equal to the number of rows in this matrix.
-
trace
Computes the trace of this matrix. That is, the sum of elements along the principle diagonal of this matrix. Same astr()
- Specified by:
trace
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Returns:
- The trace of this matrix.
- Throws:
IllegalArgumentException
- If this matrix is not square.
-
tr
Computes the trace of this matrix. That is, the sum of elements along the principle diagonal of this matrix. Same astrace()
.- Specified by:
tr
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Returns:
- The trace of this matrix.
- Throws:
IllegalArgumentException
- If this matrix is not square.
-
getDiag
-
H
Compute the transpose of this matrix. That is, the complex conjugate transpose of this matrix. Since this is a real matrix, this is equivalent to thestandard transpose
.- Specified by:
H
in interfaceMatrixOperationsMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Returns:
- The conjugate transpose of 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:
-
isSquare
public boolean isSquare()Checks if this matrix is square.- Specified by:
isSquare
in interfaceMatrixPropertiesMixin
- Returns:
- True if the matrix is square (i.e. the number of rows equals the number of columns). Otherwise, returns false.
-
isVector
public boolean isVector()Checks if a matrix can be represented as a vector. That is, if a matrix has only one row or one column.- Specified by:
isVector
in interfaceMatrixPropertiesMixin
- Returns:
- True if this matrix can be represented as either a row or column vector.
-
vectorType
public int vectorType()Checks what type of vector this matrix is. i.e. not a vector, a 1x1 matrix, a row vector, or a column vector.- Specified by:
vectorType
in interfaceMatrixPropertiesMixin
- Returns:
- - If this matrix can not be represented as a vector, then returns -1.
- If this matrix is a 1x1 matrix, then returns 0.
- If this matrix is a row vector, then returns 1.
- If this matrix is a column vector, then returns 2.
-
isTriL
public boolean isTriL()Checks if this matrix is lower triangular.- Specified by:
isTriL
in interfaceMatrixPropertiesMixin
- Returns:
- True is this matrix is lower triangular. Otherwise, returns false.
- See Also:
-
isTriU
public boolean isTriU()Checks if this matrix is upper triangular.- Specified by:
isTriU
in interfaceMatrixPropertiesMixin
- Returns:
- True is this matrix is upper triangular. Otherwise, returns false.
- See Also:
-
isFullRank
public boolean isFullRank()Checks if a matrix has full rank. That is, if a matrices rank is equal to the number of rows in the matrix.- Specified by:
isFullRank
in interfaceMatrixPropertiesMixin
- Returns:
- True if this matrix has full rank. Otherwise, returns false.
-
isSingular
public boolean isSingular()Checks if a matrix is singular. That is, if the matrix is NOT invertible.
Also seeMatrixPropertiesMixin.isInvertible()
.- Specified by:
isSingular
in interfaceMatrixPropertiesMixin
- Returns:
- True if this matrix is singular or non-square. Otherwise, returns false.
-
swapRows
Swaps specified rows in the matrix. This is done in place.- Specified by:
swapRows
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
rowIndex1
- Index of the first row to swap.rowIndex2
- Index of the second row to swap.- Returns:
- A reference to this matrix.
- Throws:
ArrayIndexOutOfBoundsException
- If either index is outside the matrix bounds.
-
swapCols
Swaps specified columns in the matrix. This is done in place.- Specified by:
swapCols
in interfaceMatrixManipulationsMixin<Matrix,
Double> - Parameters:
colIndex1
- Index of the first column to swap.colIndex2
- Index of the second column to swap.- Returns:
- A reference to this matrix.
- Throws:
ArrayIndexOutOfBoundsException
- If either index is outside the matrix bounds.
-
get
Description copied from class:RealDenseTensorBase
Gets the element in this tensor at the specified indices.- Specified by:
get
in interfaceMatrixMixin<Matrix,
Matrix, CooMatrix, CMatrix, CooCMatrix, Double, Vector, Vector> - Specified by:
get
in interfaceTensorOperationsMixin<Matrix,
Matrix, CMatrix, CMatrix, Matrix, Double> - Overrides:
get
in classRealDenseTensorBase<Matrix,
CMatrix> - Parameters:
indices
- Indices of element.- Returns:
- The element at the specified indices.
-
matrixRank
public int matrixRank()Computes the rank of this matrix (i.e. the number of linearly independent rows/columns in this matrix). Note that here, rank is NOT the same as a tensor rank (i.e. number of indices needed to specify an entry in the tensor).- Specified by:
matrixRank
in interfaceMatrixPropertiesMixin
- Returns:
- The matrix rank of this matrix.
-
isSymmetric
public boolean isSymmetric()Checks if a matrix is symmetric. That is, if the matrix is square and equal to its transpose.- Specified by:
isSymmetric
in interfaceRealMatrixMixin<Matrix,
CMatrix> - Returns:
- True if this matrix is symmetric. Otherwise, returns false.
- See Also:
-
isAntiSymmetric
public boolean isAntiSymmetric()Checks if a matrix is anti-symmetric. That is, if the matrix is equal to the negative of its transpose.- Specified by:
isAntiSymmetric
in interfaceRealMatrixMixin<Matrix,
CMatrix> - Returns:
- True if this matrix is anti-symmetric. Otherwise, returns false.
- See Also:
-
isOrthogonal
public boolean isOrthogonal()Checks if this matrix is orthogonal. That is, if the inverse of this matrix is equal to its transpose.- Specified by:
isOrthogonal
in interfaceRealMatrixMixin<Matrix,
CMatrix> - Returns:
- True if this matrix it is orthogonal. Otherwise, returns false.
-
sqrtComplex
Computes the complex element-wise square root of a tensor. That is, ff this tensor contains negative values, the resulting root will be complex rather thenDouble.NaN
.- Specified by:
sqrtComplex
in interfaceRealMatrixMixin<Matrix,
CMatrix> - Returns:
- The result of applying an element-wise square root to this tensor. Note, this method will compute the principle square root i.e. the square root with positive real part.
-
rowToString
Gets row of matrix formatted as a human-readable String. Helper method fortoString()
method.- Parameters:
i
- Index of row to get.colStopIndex
- Stopping index for printing columns.maxList
- List of maximum string representation lengths for each column of this matrix. This is used to align columns when printing.- Returns:
- A human-readable String representation of the specified row.
-
toString
-