Class FastKroneckerProduct
- java.lang.Object
-
- dev.nm.algebra.linear.matrix.doubles.operation.FastKroneckerProduct
-
- All Implemented Interfaces:
Matrix,MatrixAccess,MatrixRing,MatrixTable,AbelianGroup<Matrix>,Monoid<Matrix>,Ring<Matrix>,Table,DeepCopyable
public class FastKroneckerProduct extends Object implements Matrix
This is a fast and memory-saving implementation of computing the Kronecker product. It computes the matrix entry values only on demand by calling theget(int, int)method. If, however, the Kronecker product is used for matrix operations frequently, the classKroneckerProduct, which computes all entries at construction, should be used instead. This class is immutable.- See Also:
KroneckerProduct
-
-
Constructor Summary
Constructors Constructor Description FastKroneckerProduct(Matrix A, Matrix B)Construct a Kronecker product for read-only.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrixadd(Matrix that)this + thatFastKroneckerProductdeepCopy()Returnthisas thisMatrixis immutable.doubleget(int i, int j)Get the matrix entry at [i,j].DenseVectorgetColumn(int j)Get the specified column in the matrix as a vector.DenseVectorgetRow(int i)Get the specified row in the matrix as a vector.Matrixminus(Matrix that)this - thatMatrixmultiply(Matrix that)this * thatVectormultiply(Vector v)Right multiply this matrix, A, by a vector.intnCols()Gets the number of columns.intnRows()Gets the number of rows.DenseMatrixONE()Get an identity matrix that has the same dimension as this matrix.Matrixopposite()Get the opposite of this matrix.Matrixscaled(double scalar)Scale this matrix, A, by a constant.voidset(int i, int j, double value)Set the matrix entry at [i,j] to a value.Matrixt()Get the transpose of this matrix.DenseMatrixZERO()Get a zero matrix that has the same dimension as this matrix.
-
-
-
Method Detail
-
nRows
public int nRows()
Description copied from interface:TableGets the number of rows. Rows count from 1.
-
nCols
public int nCols()
Description copied from interface:TableGets the number of columns. Columns count from 1.
-
set
public void set(int i, int j, double value) throws MatrixAccessExceptionDescription copied from interface:MatrixAccessSet the matrix entry at [i,j] to a value. This is the only method that may change a matrix.- Specified by:
setin interfaceMatrixAccess- Parameters:
i- the row indexj- the column indexvalue- the value to set A[i,j] to- Throws:
MatrixAccessException- if i or j is out of range
-
get
public double get(int i, int j) throws MatrixAccessExceptionDescription copied from interface:MatrixAccessGet the matrix entry at [i,j].- Specified by:
getin interfaceMatrixAccess- Parameters:
i- the row indexj- the column index- Returns:
- A[i,j]
- Throws:
MatrixAccessException- if i or j is out of range
-
getRow
public DenseVector getRow(int i) throws MatrixAccessException
Description copied from interface:MatrixGet the specified row in the matrix as a vector.- Specified by:
getRowin interfaceMatrix- Parameters:
i- the row index- Returns:
- the vector A[i, ]
- Throws:
MatrixAccessException- when i < 1, or when i > the number of rows
-
getColumn
public DenseVector getColumn(int j) throws MatrixAccessException
Description copied from interface:MatrixGet the specified column in the matrix as a vector.- Specified by:
getColumnin interfaceMatrix- Parameters:
j- the column index- Returns:
- a vector A[, j]
- Throws:
MatrixAccessException- when j < 1, or when j > the number of columns
-
add
public Matrix add(Matrix that)
Description copied from interface:MatrixRingthis + that- Specified by:
addin interfaceAbelianGroup<Matrix>- Specified by:
addin interfaceMatrixRing- Parameters:
that- a matrix- Returns:
- the sum of
thisandthat
-
minus
public Matrix minus(Matrix that)
Description copied from interface:MatrixRingthis - that- Specified by:
minusin interfaceAbelianGroup<Matrix>- Specified by:
minusin interfaceMatrixRing- Parameters:
that- a matrix- Returns:
- the difference between
thisandthat
-
multiply
public Matrix multiply(Matrix that)
Description copied from interface:MatrixRingthis * that- Specified by:
multiplyin interfaceMatrixRing- Specified by:
multiplyin interfaceMonoid<Matrix>- Parameters:
that- a matrix- Returns:
- the product of
thisandthat
-
multiply
public Vector multiply(Vector v)
Description copied from interface:MatrixRight multiply this matrix, A, by a vector.
-
scaled
public Matrix scaled(double scalar)
Description copied from interface:MatrixScale this matrix, A, by a constant.
-
opposite
public Matrix opposite()
Description copied from interface:MatrixRingGet the opposite of this matrix.- Specified by:
oppositein interfaceAbelianGroup<Matrix>- Specified by:
oppositein interfaceMatrixRing- Returns:
- -this
- See Also:
- Wikipedia: Additive inverse
-
ZERO
public DenseMatrix ZERO()
Description copied from interface:MatrixRingGet a zero matrix that has the same dimension as this matrix.- Specified by:
ZEROin interfaceAbelianGroup<Matrix>- Specified by:
ZEROin interfaceMatrixRing- Returns:
- the 0 matrix
-
ONE
public DenseMatrix ONE()
Description copied from interface:MatrixRingGet an identity matrix that has the same dimension as this matrix. For a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).- Specified by:
ONEin interfaceMatrixRing- Specified by:
ONEin interfaceMonoid<Matrix>- Returns:
- an identity matrix
-
t
public Matrix t()
Description copied from interface:MatrixRingGet the transpose of this matrix. This is the involution on the matrix ring.- Specified by:
tin interfaceMatrixRing- Returns:
- the transpose of this matrix
-
deepCopy
public FastKroneckerProduct deepCopy()
Returnthisas thisMatrixis immutable.- Specified by:
deepCopyin interfaceDeepCopyable- Specified by:
deepCopyin interfaceMatrix- Returns:
this
-
-