gov.sandia.cognition.math.matrix.custom

## Class DiagonalMatrix

• All Implemented Interfaces:
Matrix, Vectorizable, Ring<Matrix>, CloneableSerializable, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<MatrixEntry>

```public class DiagonalMatrix
extends AbstractMatrix```
Diagonal matrices are a special case, but a rather common one with very quick and simple solutions to multiplications, inverses, etc. This can't magically change type, however. So if you will ever add an off-diagonal element, don't use this! NOTE: This only supports square diagonal matrices.
Since:
3.4.3
Author:
Jeremy D. Wendt
Serialized Form
• ### Constructor Summary

Constructors
Modifier Constructor and Description
`protected ` `DiagonalMatrix()`
This should never be called by anything or anyone other than Java's serialization code.
` ` `DiagonalMatrix(DiagonalMatrix d)`
Copy constructor.
` ` `DiagonalMatrix(int n)`
Creates a square (n x n) diagonal matrix initialized to zero.
` ` `DiagonalMatrix(Matrix m)`
Creates a diagonal matrix as a copy of the given matrix.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`protected void` `checkSolveDimensions(Matrix b)`
Checks that the input matrix has the same numRows as this's numRows (otherwise, there can be no soluation for Ax = b).
`protected void` `checkSolveDimensions(Vector b)`
Checks that the input vector has the same dimensionality as this's numRows (otherwise, there can be no solution for Ax = b).
`protected void` ```checkSubmatrixRange(int minRow, int maxRow, int minCol, int maxCol)```
Helper method checks that the input submatrix range is acceptable for this matrix, including that the max is greater than or equal to the min.
`Matrix` `clone()`
This makes public the clone method on the `Object` class and removes the exception that it throws.
`void` `convertFromVector(Vector parameters)`
uploads a matrix from a column-stacked vector of parameters, so that v(k) = A(i,j) = A( k%M, k/M )
`Vector` `convertToVector()`
Creates a column-stacked version of this, so that v(k) = A(i,j) = v(j*M+i)
`Matrix` `dotTimes(Matrix other)`
Element-wise multiplication of `this` and `other`
`void` `dotTimesEquals(DenseMatrix other)`
Type-specific version of dotTimesEquals for combining whatever type this is with the input dense matrix.
`void` `dotTimesEquals(DiagonalMatrix other)`
Type-specific version of dotTimesEquals for combining whatever type this is with the input diagonal matrix.
`void` `dotTimesEquals(Matrix other)`
Inline element-wise multiplication of `this` and `other`
`void` `dotTimesEquals(SparseMatrix other)`
Type-specific version of dotTimesEquals for combining whatever type this is with the input sparse matrix.
`double` ```get(int rowIndex, int columnIndex)```
Gets the value of the element of the matrix at the zero-based row and column indices.
`Vector` `getColumn(int columnIndex)`
Gets the specified column from the zero-based index and returns a vector that corresponds to that column.
`double` ```getElement(int rowIndex, int columnIndex)```
Returns the value stored at the input locations
`int` `getEntryCount()`
Gets the number of active entries in the matrix.
`MatrixFactory<?>` `getMatrixFactory()`
Gets a matrix factory, typically one associated with this type of matrix.
`int` `getNumColumns()`
Returns the number of columns in the Matrix
`int` `getNumRows()`
Returns the number of rows in the Matrix
`Vector` `getRow(int rowIndex)`
Gets the specified row from the zero-based index and returns a vector that corresponds to that column
`Matrix` ```getSubMatrix(int minRow, int maxRow, int minColumn, int maxColumn)```
Gets the embedded submatrix inside of the Matrix, specified by the inclusive, zero-based indices such that the result matrix will have size (maxRow-minRow+1) x (maxColum-minCcolumn+1)
`void` `identity()`
Formats the matrix as an identity matrix.
`Matrix` `inverse()`
Computes the full-blown inverse of `this`, which must be a square matrix
`boolean` `isSparse()`
Returns true if this matrix has a potentially sparse underlying structure.
`boolean` `isSquare()`
Determines if the matrix is square (numRows == numColumns)
`boolean` `isSymmetric(double effectiveZero)`
Determines if the matrix is effectively symmetric
`java.util.Iterator<MatrixEntry>` `iterator()`
`ComplexNumber` `logDeterminant()`
Computes the natural logarithm of the determinant of `this`.
`Matrix` `minus(Matrix other)`
Arithmetic subtraction of `other` from `this`
`void` `minusEquals(DenseMatrix other)`
Type-specific version of minusEquals for combining whatever type this is with the input dense matrix.
`void` `minusEquals(DiagonalMatrix other)`
Type-specific version of minusEquals for combining whatever type this is with the input diagonal matrix.
`void` `minusEquals(Matrix other)`
Inline arithmetic subtraction of `other` from `this`
`void` `minusEquals(SparseMatrix other)`
Type-specific version of minusEquals for combining whatever type this is with the input sparse matrix.
`double` `normFrobenius()`
Compute the Frobenius norm of `this`, which is just a fancy way of saying that I will square each element, add those up, and square root the result.
`double` `normFrobeniusSquared()`
Compute the squared Frobenius norm of `this`, which is just a fancy way of saying that I will square each element and add those up.
`Matrix` `plus(Matrix other)`
Arithmetic addition of `this` and `other`
`void` `plusEquals(DenseMatrix other)`
Type-specific version of plusEquals for combining whatever type this is with the input dense matrix.
`void` `plusEquals(DiagonalMatrix other)`
Type-specific version of plusEquals for combining whatever type this is with the input diagonal matrix.
`void` `plusEquals(Matrix other)`
Inline arithmetic addition of `this` and `other`
`void` `plusEquals(SparseMatrix other)`
Type-specific version of plusEquals for combining whatever type this is with the input sparse matrix.
`Vector` `preTimes(DenseVector vector)`
Type-specific version of pre-times for combining whatever type this is with the input dense vector.
`Vector` `preTimes(SparseVector vector)`
Type-specific version of pre-times for combining whatever type this is with the input sparse vector.
`Vector` `preTimes(Vector vector)`
Package-private method that puts the vector * matrix code in the matrix class instead of in the vector class (why should vectors know the internals of matrices?).
`Matrix` `pseudoInverse(double effectiveZero)`
Computes the effective pseudo-inverse of `this`, using a rather expensive procedure (SVD)
`int` `rank(double effectiveZero)`
Computes the effective rank of `this`, which is the number of linearly independent rows and columns in `this`.
`void` ```scaledPlusEquals(DenseMatrix other, double scaleFactor)```
Type-specific version of scaledPlusEquals for combining whatever type this is with the input dense matrix.
`void` ```scaledPlusEquals(DiagonalMatrix other, double scaleFactor)```
Type-specific version of scaledPlusEquals for combining whatever type this is with the input diagonal matrix.
`void` ```scaledPlusEquals(double scaleFactor, Matrix other)```
Inline arithmetic addition of `this` and `other` after element-wise scaling of `other` by `scaleFactor`.
`void` ```scaledPlusEquals(SparseMatrix other, double scaleFactor)```
Type-specific version of scaledPlusEquals for combining whatever type this is with the input sparse matrix.
`void` `scaleEquals(double scaleFactor)`
Inline element-wise scaling of `this` by `scaleFactor`
`void` ```set(int rowIndex, int columnIndex, double value)```
Sets the value of the element of the matrix at the zero-based row and column indices.
`void` ```setElement(int rowIndex, int columnIndex, double value)```
Set the value stored at the input locations to the input value
`Matrix` `solve(Matrix B)`
Solves for "X" in the equation: this*X = B
`Vector` `solve(Vector b)`
Solves for "x" in the equation: this*x = b
`Matrix` `times(DenseMatrix other)`
Type-specific version of times for combining whatever type this is with the input dense matrix.
`Vector` `times(DenseVector vector)`
Type-specific version of times for combining whatever type this is with the input dense vector.
`Matrix` `times(DiagonalMatrix other)`
Type-specific version of times for combining whatever type this is with the input diagonal matrix.
`Matrix` `times(Matrix other)`
Matrix multiplication of `this` and `matrix`, operates like the "`*`" operator in Matlab
`Matrix` `times(SparseMatrix other)`
Type-specific version of times for combining whatever type this is with the input sparse matrix.
`Vector` `times(SparseVector vector)`
Type-specific version of times for combining whatever type this is with the input sparse vector.
`Vector` `times(Vector vector)`
Returns the column vector from the equation return = this * vector
`java.lang.String` `toString(java.text.NumberFormat format)`
Converts the vector to a `String`, using the given formatter.
`Matrix` `transpose()`
Returns the transpose of `this`
• ### Methods inherited from class gov.sandia.cognition.math.matrix.AbstractMatrix

`assertMultiplicationDimensions, assertSameDimensions, checkMultiplicationDimensions, checkSameDimensions, decrement, decrement, dotDivide, dotDivideEquals, equals, equals, getColumnInto, getRowInto, hashCode, increment, increment, isSymmetric, isZero, pseudoInverse, rank, setColumn, setRow, setSubMatrix, sumOfColumns, sumOfRows, toArray, trace, valuesAsList`
• ### Methods inherited from class gov.sandia.cognition.math.AbstractRing

`isZero, negative, negativeEquals, scale, scaledMinus, scaledMinusEquals, scaledPlus, zero`
• ### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, toString, wait, wait, wait`
• ### Methods inherited from interface gov.sandia.cognition.math.matrix.Matrix

`toString`
• ### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`
• ### Methods inherited from interface gov.sandia.cognition.math.Ring

`isZero, negative, negativeEquals, scale, scaledMinus, scaledMinusEquals, scaledPlus, zero`
• ### Constructor Detail

• #### DiagonalMatrix

`public DiagonalMatrix(int n)`
Creates a square (n x n) diagonal matrix initialized to zero.
Parameters:
`n` - The dimensions (num rows and num columns) of the matrix
• #### DiagonalMatrix

`public DiagonalMatrix(DiagonalMatrix d)`
Copy constructor. Creates a deep copy of d.
Parameters:
`d` - The diagonal matrix to copy
• #### DiagonalMatrix

`public DiagonalMatrix(Matrix m)`
Creates a diagonal matrix as a copy of the given matrix. It must be a diagonal one as well.
Parameters:
`m` - The matrix to copy.
• #### DiagonalMatrix

`protected DiagonalMatrix()`
This should never be called by anything or anyone other than Java's serialization code.
• ### Method Detail

• #### clone

`public final Matrix clone()`
Description copied from class: `AbstractCloneableSerializable`
This makes public the clone method on the `Object` class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call `super.clone()` to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in `ObjectUtil` may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use `super.clone()` as the basis for your implementation.
Specified by:
`clone` in interface `Matrix`
Specified by:
`clone` in interface `Vectorizable`
Specified by:
`clone` in interface `Ring<Matrix>`
Specified by:
`clone` in interface `CloneableSerializable`
Overrides:
`clone` in class `AbstractRing<Matrix>`
Returns:
A clone of this object.
• #### scaledPlusEquals

```public void scaledPlusEquals(SparseMatrix other,
double scaleFactor)```
Type-specific version of scaledPlusEquals for combining whatever type this is with the input sparse matrix.
Parameters:
`other` - A sparse matrix to add to this
`scaleFactor` - The amount to scale other by
Throws:
`java.lang.IllegalArgumentException` - if the input has any non-zero off-axis elements as that would make this a non-diagonal matrix
• #### scaledPlusEquals

```public void scaledPlusEquals(DenseMatrix other,
double scaleFactor)```
Type-specific version of scaledPlusEquals for combining whatever type this is with the input dense matrix.
Parameters:
`other` - A dense matrix to add to this
`scaleFactor` - The amount to scale other by
Throws:
`java.lang.IllegalArgumentException` - if the input has any non-zero off-axis elements as that would make this a non-diagonal matrix
• #### scaledPlusEquals

```public void scaledPlusEquals(DiagonalMatrix other,
double scaleFactor)```
Type-specific version of scaledPlusEquals for combining whatever type this is with the input diagonal matrix.
Parameters:
`other` - A diagonal matrix to add to this
`scaleFactor` - The amount to scale other by
• #### plusEquals

`public final void plusEquals(SparseMatrix other)`
Type-specific version of plusEquals for combining whatever type this is with the input sparse matrix.
Parameters:
`other` - A sparse matrix to add to this
Throws:
`java.lang.IllegalArgumentException` - if the input has any non-zero off-axis elements as that would make this a non-diagonal matrix
• #### plusEquals

`public final void plusEquals(DenseMatrix other)`
Type-specific version of plusEquals for combining whatever type this is with the input dense matrix.
Parameters:
`other` - A dense matrix to add to this
Throws:
`java.lang.IllegalArgumentException` - if the input has any non-zero off-axis elements as that would make this a non-diagonal matrix
• #### plusEquals

`public final void plusEquals(DiagonalMatrix other)`
Type-specific version of plusEquals for combining whatever type this is with the input diagonal matrix.
Parameters:
`other` - A diagonal matrix to add to this
• #### minusEquals

`public final void minusEquals(SparseMatrix other)`
Type-specific version of minusEquals for combining whatever type this is with the input sparse matrix.
Parameters:
`other` - A sparse matrix to subtract from this
Throws:
`java.lang.IllegalArgumentException` - if the input has any non-zero off-axis elements as that would make this a non-diagonal matrix
• #### minusEquals

`public final void minusEquals(DenseMatrix other)`
Type-specific version of minusEquals for combining whatever type this is with the input dense matrix.
Parameters:
`other` - A dense matrix to subtract from this
Throws:
`java.lang.IllegalArgumentException` - if the input has any non-zero off-axis elements as that would make this a non-diagonal matrix
• #### minusEquals

`public final void minusEquals(DiagonalMatrix other)`
Type-specific version of minusEquals for combining whatever type this is with the input diagonal matrix.
Parameters:
`other` - A diagonal matrix to subtract from this
• #### dotTimesEquals

`public final void dotTimesEquals(SparseMatrix other)`
Type-specific version of dotTimesEquals for combining whatever type this is with the input sparse matrix.
Parameters:
`other` - A sparse matrix to dot with this
• #### dotTimesEquals

`public final void dotTimesEquals(DenseMatrix other)`
Type-specific version of dotTimesEquals for combining whatever type this is with the input dense matrix.
Parameters:
`other` - A dense matrix to dot with this
• #### dotTimesEquals

`public final void dotTimesEquals(DiagonalMatrix other)`
Type-specific version of dotTimesEquals for combining whatever type this is with the input diagonal matrix.
Parameters:
`other` - A diagonal matrix to dot with this
• #### times

`public final Matrix times(SparseMatrix other)`
Type-specific version of times for combining whatever type this is with the input sparse matrix.
Parameters:
`other` - A sparse matrix to multiply with this
• #### times

`public final Matrix times(DenseMatrix other)`
Type-specific version of times for combining whatever type this is with the input dense matrix.
Parameters:
`other` - A dense matrix to multiply with this
• #### times

`public final Matrix times(DiagonalMatrix other)`
Type-specific version of times for combining whatever type this is with the input diagonal matrix.
Parameters:
`other` - A diagonal matrix to multiply with this
• #### times

`public final Vector times(SparseVector vector)`
Type-specific version of times for combining whatever type this is with the input sparse vector.
Parameters:
`vector` - A sparse vector to multiply with this
• #### times

`public final Vector times(DenseVector vector)`
Type-specific version of times for combining whatever type this is with the input dense vector.
Parameters:
`vector` - A dense vector to multiply with this
• #### scaleEquals

`public final void scaleEquals(double scaleFactor)`
Description copied from interface: `Ring`
Inline element-wise scaling of `this` by `scaleFactor`
Parameters:
`scaleFactor` - amount to scale the elements of `this`
• #### getNumRows

`public final int getNumRows()`
Description copied from interface: `Matrix`
Returns the number of rows in the Matrix
Returns:
Number of rows in the Matrix
• #### getNumColumns

`public final int getNumColumns()`
Description copied from interface: `Matrix`
Returns the number of columns in the Matrix
Returns:
Number of columns in the Matrix
• #### get

```public double get(int rowIndex,
int columnIndex)```
Description copied from interface: `Matrix`
Gets the value of the element of the matrix at the zero-based row and column indices. It throws an ArrayIndexOutOfBoundsException if either index is out of range. It is a convenience method for `getElement`.
Parameters:
`rowIndex` - The zero-based row index. Must be between 0 (inclusive) and the number of rows (exclusive).
`columnIndex` - The zero-based column index. Must be between 0 (inclusive) and the number of columns (exclusive).
Returns:
The value at the given row and column in the matrix.
• #### getElement

```public final double getElement(int rowIndex,
int columnIndex)```
Returns the value stored at the input locations
Parameters:
`rowIndex` - The row index
`columnIndex` - The column index
Returns:
the value stored at the input locations
Throws:
`java.lang.ArrayIndexOutOfBoundsException` - if the input values are outside the matrix
• #### set

```public void set(int rowIndex,
int columnIndex,
double value)```
Description copied from interface: `Matrix`
Sets the value of the element of the matrix at the zero-based row and column indices. It throws an ArrayIndexOutOfBoundsException if either index is out of range. It is a convenience method for `setElement`.
Parameters:
`rowIndex` - The zero-based row index. Must be between 0 (inclusive) and the number of rows (exclusive).
`columnIndex` - The zero-based column index. Must be between 0 (inclusive) and the number of columns (exclusive).
`value` - The value to set at the given row and column in the matrix.
• #### setElement

```public final void setElement(int rowIndex,
int columnIndex,
double value)```
Set the value stored at the input locations to the input value
Parameters:
`rowIndex` - The row index
`columnIndex` - The column index
`value` - The new value for the input location
Throws:
`java.lang.ArrayIndexOutOfBoundsException` - if the input indices are outside the matrix
`java.lang.IllegalArgumentException` - if the input indices attempt to set a non-zero value off the main axis
• #### getSubMatrix

```public final Matrix getSubMatrix(int minRow,
int maxRow,
int minColumn,
int maxColumn)```
Description copied from interface: `Matrix`
Gets the embedded submatrix inside of the Matrix, specified by the inclusive, zero-based indices such that the result matrix will have size (maxRow-minRow+1) x (maxColum-minCcolumn+1)
Parameters:
`minRow` - Zero-based index into the rows of the Matrix, must be less than or equal to maxRow
`maxRow` - Zero-based index into the rows of the Matrix, must be greater than or equal to minRow
`minColumn` - Zero-based index into the rows of the Matrix, must be less than or equal to maxColumn
`maxColumn` - Zero-based index into the rows of the Matrix, must be greater than or equal to minColumn
Returns:
the Matrix of dimension (maxRow-minRow+1)x(maxColumn-minColumn+1)
• #### isSymmetric

`public final boolean isSymmetric(double effectiveZero)`
Description copied from interface: `Matrix`
Determines if the matrix is effectively symmetric
Parameters:
`effectiveZero` - tolerance to determine symmetry
Returns:
true if effectively symmetric, false otherwise
• #### transpose

`public final Matrix transpose()`
Description copied from interface: `Matrix`
Returns the transpose of `this`
Returns:
Matrix whose elements are equivalent to: ```this.getElement(i, j) == this.transpose().getElement(j, i) ``` for any valid `i, j`.
• #### inverse

`public final Matrix inverse()`
Computes the full-blown inverse of `this`, which must be a square matrix
Returns:
Inverse of `this`, such that ```this.times(this.inverse()) == this.inverse().times(this) == ```identity matrix
Throws:
`java.lang.UnsupportedOperationException` - if this doesn't span the space, so can't be inverted.
• #### pseudoInverse

`public final Matrix pseudoInverse(double effectiveZero)`
Description copied from interface: `Matrix`
Computes the effective pseudo-inverse of `this`, using a rather expensive procedure (SVD)
Parameters:
`effectiveZero` - effective zero to pass along to the SVD
Returns:
effective pseudo-inverse of `this`
• #### logDeterminant

`public final ComplexNumber logDeterminant()`
Description copied from interface: `Matrix`
Computes the natural logarithm of the determinant of `this`. Very computationally intensive. Please THINK LONG AND HARD before invoking this method on sparse matrices, as they have to be converted to a DenseMatrix first.
Returns:
natural logarithm of the determinant of `this`
• #### rank

`public final int rank(double effectiveZero)`
Description copied from interface: `Matrix`
Computes the effective rank of `this`, which is the number of linearly independent rows and columns in `this`. Rank is typically based on the SVD, which is a fairly computationally expensive procedure and should be used carefully
Parameters:
`effectiveZero` - parameter to pass along to SVD to determine linear dependence
Returns:
rank of `this`, equivalent to the number of linearly indepenedent rows and columns in `this`
• #### normFrobeniusSquared

`public double normFrobeniusSquared()`
Description copied from interface: `Matrix`
Compute the squared Frobenius norm of `this`, which is just a fancy way of saying that I will square each element and add those up.
Returns:
Frobenius norm of `this`
• #### normFrobenius

`public final double normFrobenius()`
Description copied from interface: `Matrix`
Compute the Frobenius norm of `this`, which is just a fancy way of saying that I will square each element, add those up, and square root the result. This is probably the most intuitive of the matrix norms
Returns:
Frobenius norm of `this`
• #### isSquare

`public final boolean isSquare()`
Description copied from interface: `Matrix`
Determines if the matrix is square (numRows == numColumns)
Specified by:
`isSquare` in interface `Matrix`
Overrides:
`isSquare` in class `AbstractMatrix`
Returns:
true if square, false if nonsquare
• #### solve

`public final Matrix solve(Matrix B)`
Description copied from interface: `Matrix`
Solves for "X" in the equation: this*X = B
Parameters:
`B` - Must satisfy this.getNumColumns() == B.getNumRows();
Returns:
X Matrix with dimensions (this.getNumColumns() x B.getNumColumns())
• #### solve

`public final Vector solve(Vector b)`
Description copied from interface: `Matrix`
Solves for "x" in the equation: this*x = b
Parameters:
`b` - must satisfy this.getNumColumns() == b.getDimensionality()
Returns:
x Vector with dimensions (this.getNumColumns())
• #### identity

`public final void identity()`
Description copied from interface: `Matrix`
Formats the matrix as an identity matrix. This does not have to be square.
• #### getColumn

`public final Vector getColumn(int columnIndex)`
Description copied from interface: `Matrix`
Gets the specified column from the zero-based index and returns a vector that corresponds to that column.
Parameters:
`columnIndex` - zero-based index into the matrix
Returns:
Vector with elements equal to the number of rows in this
• #### getRow

`public final Vector getRow(int rowIndex)`
Description copied from interface: `Matrix`
Gets the specified row from the zero-based index and returns a vector that corresponds to that column
Parameters:
`rowIndex` - zero-based index into the matrix
Returns:
Vector with elements equal to the number of columns in this
• #### convertFromVector

`public final void convertFromVector(Vector parameters)`
uploads a matrix from a column-stacked vector of parameters, so that v(k) = A(i,j) = A( k%M, k/M )
Parameters:
`parameters` - column-stacked version of this
Throws:
`java.lang.IllegalArgumentException` - if input vector doesn't have enough elements to cover all elements of this or if the input vector specifies non-zero values in off-diagonal elements.
• #### convertToVector

`public final Vector convertToVector()`
Description copied from interface: `Matrix`
Creates a column-stacked version of this, so that v(k) = A(i,j) = v(j*M+i)
Returns:
column-stacked Vector representing this
• #### preTimes

`public final Vector preTimes(SparseVector vector)`
Type-specific version of pre-times for combining whatever type this is with the input sparse vector.
Parameters:
`vector` - A sparse vector to multiply with this
• #### preTimes

`public final Vector preTimes(DenseVector vector)`
Type-specific version of pre-times for combining whatever type this is with the input dense vector.
Parameters:
`vector` - A dense vector to multiply with this
• #### isSparse

`public boolean isSparse()`
Description copied from interface: `Matrix`
Returns true if this matrix has a potentially sparse underlying structure. This can indicate that it is faster to only process the non-zero elements rather than to do dense operations on it. Of course, even with a sparse structure, there may be no zero elements or conversely even with a non-sparse (dense) structure there may be many zero elements.
Returns:
True if the matrix has a potentially sparse structure. Otherwise, false.
• #### getMatrixFactory

`public MatrixFactory<?> getMatrixFactory()`
Description copied from interface: `Matrix`
Gets a matrix factory, typically one associated with this type of matrix.
Returns:
A matrix factory.
• #### getEntryCount

`public int getEntryCount()`
Description copied from interface: `Matrix`
Gets the number of active entries in the matrix. Must be between 0 and the number of rows times the number of columns.
Returns:
The number of active entries in the matrix.
• #### plus

`public final Matrix plus(Matrix other)`
Description copied from interface: `Ring`
Arithmetic addition of `this` and `other`
Specified by:
`plus` in interface `Ring<Matrix>`
Overrides:
`plus` in class `AbstractRing<Matrix>`
Parameters:
`other` - object to add to `this`
Returns:
sum of `this` and `other`
• #### minus

`public final Matrix minus(Matrix other)`
Description copied from interface: `Ring`
Arithmetic subtraction of `other` from `this`
Specified by:
`minus` in interface `Ring<Matrix>`
Overrides:
`minus` in class `AbstractRing<Matrix>`
Parameters:
`other` - object to subtract from `this`
Returns:
difference of `this` and `other`
• #### dotTimes

`public final Matrix dotTimes(Matrix other)`
Description copied from interface: `Ring`
Element-wise multiplication of `this` and `other`
Specified by:
`dotTimes` in interface `Ring<Matrix>`
Overrides:
`dotTimes` in class `AbstractRing<Matrix>`
Parameters:
`other` - elements of other will be multiplied to the corresponding elements of `this`
Returns:
element-wise multiplication of `this` and `other`
• #### plusEquals

`public final void plusEquals(Matrix other)`
Description copied from interface: `Ring`
Inline arithmetic addition of `this` and `other`
Specified by:
`plusEquals` in interface `Ring<Matrix>`
Overrides:
`plusEquals` in class `AbstractMatrix`
Parameters:
`other` - object to add to `this`
• #### scaledPlusEquals

```public final void scaledPlusEquals(double scaleFactor,
Matrix other)```
Description copied from interface: `Ring`
Inline arithmetic addition of `this` and `other` after element-wise scaling of `other` by `scaleFactor`. If this is x, other is y, and scaleFactor is a, then this method is equivalent to x += a * y. It is typically a more efficient way of doing `this.plusEquals(other.scale(scaleFactor))` since it can avoid intermediate object creation.
Specified by:
`scaledPlusEquals` in interface `Ring<Matrix>`
Overrides:
`scaledPlusEquals` in class `AbstractMatrix`
Parameters:
`scaleFactor` - The scale factor to multiply by the elements of other before adding to the elements of this.
`other` - Object to scale and then add to this.
• #### minusEquals

`public final void minusEquals(Matrix other)`
Description copied from interface: `Ring`
Inline arithmetic subtraction of `other` from `this`
Specified by:
`minusEquals` in interface `Ring<Matrix>`
Overrides:
`minusEquals` in class `AbstractMatrix`
Parameters:
`other` - object to subtract from `this`
• #### dotTimesEquals

`public final void dotTimesEquals(Matrix other)`
Description copied from interface: `Ring`
Inline element-wise multiplication of `this` and `other`
Specified by:
`dotTimesEquals` in interface `Ring<Matrix>`
Overrides:
`dotTimesEquals` in class `AbstractMatrix`
Parameters:
`other` - elements of other will be multiplied to the corresponding elements of `this`
• #### times

`public final Matrix times(Matrix other)`
Description copied from interface: `Matrix`
Matrix multiplication of `this` and `matrix`, operates like the "`*`" operator in Matlab
Specified by:
`times` in interface `Matrix`
Overrides:
`times` in class `AbstractMatrix`
Parameters:
`other` - `this.getNumColumns()==matrix.getNumRows()`
Returns:
Matrix multiplication of `this` and `matrix`, will `this.getNumRows()` rows and `matrix.getNumColumns()` columns
• #### times

`public final Vector times(Vector vector)`
Description copied from interface: `Matrix`
Returns the column vector from the equation return = this * vector
Specified by:
`times` in interface `Matrix`
Overrides:
`times` in class `AbstractMatrix`
Parameters:
`vector` - Vector by which to post-multiply this, must have the same number of rows as this
Returns:
Vector with the same dimensionality as the number of rows as this and vector
• #### preTimes

`public final Vector preTimes(Vector vector)`
Package-private method that puts the vector * matrix code in the matrix class instead of in the vector class (why should vectors know the internals of matrices?).
Parameters:
`vector` - The vector to pre-multiply this by
Returns:
The resulting vector from input * this
Throws:
`DimensionalityMismatchException` - if the input vectors's dimensions doesn't match this's numRows.
• #### checkSubmatrixRange

```protected final void checkSubmatrixRange(int minRow,
int maxRow,
int minCol,
int maxCol)```
Helper method checks that the input submatrix range is acceptable for this matrix, including that the max is greater than or equal to the min. Note that the input mins and maxs are inclusive.
Parameters:
`minRow` - The minimum row to return (inclusive)
`maxRow` - The maximum row to return (inclusive)
`minCol` - The minimum column to return (inclusive)
`maxCol` - The maximum column to return (inclusive)
Throws:
`java.lang.ArrayIndexOutOfBoundsException` - if the input range is illegal or outside the bounds of this.
• #### checkSolveDimensions

`protected final void checkSolveDimensions(Vector b)`
Checks that the input vector has the same dimensionality as this's numRows (otherwise, there can be no solution for Ax = b).
Parameters:
`b` - The RHS vector
Throws:
`java.lang.IllegalArgumentException` - if the input's size doesn't match this's numRows
• #### checkSolveDimensions

`protected final void checkSolveDimensions(Matrix b)`
Checks that the input matrix has the same numRows as this's numRows (otherwise, there can be no soluation for Ax = b).
Parameters:
`b` - The RHS matrix
Throws:
`java.lang.IllegalArgumentException` - if the input's size doesn't match this's numRows
• #### toString

`public final java.lang.String toString(java.text.NumberFormat format)`
Description copied from interface: `Matrix`
Converts the vector to a `String`, using the given formatter.
Parameters:
`format` - The number format to use.
Returns:
The String representation of the Matrix.
• #### iterator

`public java.util.Iterator<MatrixEntry> iterator()`