SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.matrix.doubles.operation
Class ImmutableKroneckerProduct

java.lang.Object
  extended by com.numericalmethod.suanshu.matrix.doubles.operation.ImmutableKroneckerProduct
All Implemented Interfaces:
DeepCopyable, AbelianGroup<Matrix>, Monoid<Matrix>, Ring<Matrix>, Matrix, MatrixAccessor, MatrixRing, MatrixDimension

public class ImmutableKroneckerProduct
extends java.lang.Object
implements Matrix

This immutable version of KroneckerProduct is fast and efficient for construction and read-only operations. The constructor just copies and stores the two input matrices, hence, saves much memory space. The accessor method, get(int, int) computes the requested entry value from the two matrices upon each call.

However, if the Kronecker product is reused for matrix operations frequently, the class KroneckerProduct, in which all entries are computed at construction, should be used instead.

See Also:
KroneckerProduct

Constructor Summary
ImmutableKroneckerProduct(Matrix a, Matrix b)
          Construct a read-only Kronecker product representation.
 
Method Summary
 Matrix add(Matrix that)
          this + that
 Matrix deepCopy()
          Return 'this' as this Matrix is immutable.
 double get(int row, int col)
          Get the matrix entry at [row, col].
 Vector getColumn(int col)
          Get a specified column as a vector.
 Vector getRow(int row)
          Get a specified row as a vector.
 Matrix minus(Matrix that)
          this - that
 Matrix multiply(Matrix that)
          this %*% that
 Vector multiply(Vector v)
          Right multiply this matrix, A by a vector.
 int nCols()
          Get the number of columns.
 int nRows()
          Get the number of rows.
 Matrix ONE()
          Get an identity matrix that has the same dimension as this matrix.
 Matrix opposite()
          Get the opposite of this matrix.
 Matrix scaled(double scalar)
          scalar * this
 void set(int row, int col, double value)
          Set the matrix entry at [row, col] to value.
 Matrix t()
          t(this) Compute the transpose of this matrix.
 Matrix ZERO()
          Get a zero matrix that has the same dimension as this matrix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImmutableKroneckerProduct

public ImmutableKroneckerProduct(Matrix a,
                                 Matrix b)
Construct a read-only Kronecker product representation.

Parameters:
a - a matrix
b - another matrix
Method Detail

nRows

public int nRows()
Description copied from interface: MatrixDimension
Get the number of rows. Rows count from 1.

Specified by:
nRows in interface MatrixDimension
Returns:
the number of rows

nCols

public int nCols()
Description copied from interface: MatrixDimension
Get the number of columns. Columns count from 1.

Specified by:
nCols in interface MatrixDimension
Returns:
the number of columns

set

public void set(int row,
                int col,
                double value)
         throws MatrixAccessException
Description copied from interface: MatrixAccessor
Set the matrix entry at [row, col] to value.

This is the only method that may change the entries of a matrix.

Specified by:
set in interface MatrixAccessor
Parameters:
row - the row index
col - the column index
value - the value to set A[row, col] to
Throws:
MatrixAccessException - if row or col is out of range

get

public double get(int row,
                  int col)
           throws MatrixAccessException
Description copied from interface: MatrixAccessor
Get the matrix entry at [row, col].

Specified by:
get in interface MatrixAccessor
Parameters:
row - the row index
col - the column index
Returns:
A[row, col]
Throws:
MatrixAccessException - if row or col is out of range

getRow

public Vector getRow(int row)
              throws MatrixAccessException
Description copied from interface: MatrixAccessor
Get a specified row as a vector.

Specified by:
getRow in interface MatrixAccessor
Parameters:
row - the row index
Returns:
a vector A[row, ]
Throws:
MatrixAccessException - when row < 1, or when row > number of rows

getColumn

public Vector getColumn(int col)
                 throws MatrixAccessException
Description copied from interface: MatrixAccessor
Get a specified column as a vector.

Specified by:
getColumn in interface MatrixAccessor
Parameters:
col - the column index
Returns:
a vector A[, col]
Throws:
MatrixAccessException - when col < 1, or when col > number of columns

add

public Matrix add(Matrix that)
Description copied from interface: MatrixRing
this + that

Specified by:
add in interface AbelianGroup<Matrix>
Specified by:
add in interface MatrixRing
Parameters:
that - another matrix
Returns:
the sum of this and that

minus

public Matrix minus(Matrix that)
Description copied from interface: MatrixRing
this - that

Specified by:
minus in interface AbelianGroup<Matrix>
Specified by:
minus in interface MatrixRing
Parameters:
that - another matrix
Returns:
the difference between this and that

multiply

public Matrix multiply(Matrix that)
Description copied from interface: MatrixRing
this %*% that

Specified by:
multiply in interface Monoid<Matrix>
Specified by:
multiply in interface MatrixRing
Parameters:
that - another matrix
Returns:
the product of this and that

multiply

public Vector multiply(Vector v)
Description copied from interface: Matrix
Right multiply this matrix, A by a vector.

Specified by:
multiply in interface Matrix
Parameters:
v - a vector
Returns:
A %*% v

scaled

public Matrix scaled(double scalar)
Description copied from interface: Matrix
scalar * this

Specified by:
scaled in interface Matrix
Parameters:
scalar - a double
Returns:
scalar * this

opposite

public Matrix opposite()
Description copied from interface: MatrixRing
Get the opposite of this matrix.

Specified by:
opposite in interface AbelianGroup<Matrix>
Specified by:
opposite in interface MatrixRing
Returns:
-this
See Also:
Wikipedia: Additive inverse

ZERO

public Matrix ZERO()
Description copied from interface: MatrixRing
Get a zero matrix that has the same dimension as this matrix.

Specified by:
ZERO in interface AbelianGroup<Matrix>
Specified by:
ZERO in interface MatrixRing
Returns:
the 0 matrix

ONE

public Matrix ONE()
Description copied from interface: MatrixRing
Get 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:
ONE in interface Monoid<Matrix>
Specified by:
ONE in interface MatrixRing
Returns:
an identity matrix

t

public Matrix t()
Description copied from interface: MatrixRing
t(this)

Compute the transpose of this matrix. The original matrix does not change. The returned value is independent and can be modified anyhow.

This is the involution on the matrix ring.

Specified by:
t in interface MatrixRing
Returns:
the transpose of this matrix, of the same type

deepCopy

public Matrix deepCopy()
Return 'this' as this Matrix is immutable. To produce a mutable copy, please use KroneckerProduct.

Specified by:
deepCopy in interface DeepCopyable
Specified by:
deepCopy in interface Matrix
Returns:
'this'

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.