smile.math.matrix

## Class IMatrix<T>

• java.lang.Object
• smile.math.matrix.IMatrix<T>
• All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
DMatrix, SMatrix

```public abstract class IMatrix<T>
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable```
An abstract interface of matrix. The most important method is the matrix vector multiplication, which is the only operation needed in many iterative matrix algorithms, e.g. biconjugate gradient method for solving linear equations and power iteration and Lanczos algorithm for eigen decomposition, which are usually very efficient for very large and sparse matrices.

A matrix is a rectangular array of numbers. An item in a matrix is called an entry or an element. Entries are often denoted by a variable with two subscripts. Matrices of the same size can be added and subtracted entrywise and matrices of compatible size can be multiplied. These operations have many of the properties of ordinary arithmetic, except that matrix multiplication is not commutative, that is, AB and BA are not equal in general.

Matrices are a key tool in linear algebra. One use of matrices is to represent linear transformations and matrix multiplication corresponds to composition of linear transformations. Matrices can also keep track of the coefficients in a system of linear equations. For a square matrix, the determinant and inverse matrix (when it exists) govern the behavior of solutions to the corresponding system of linear equations, and eigenvalues and eigenvectors provide insight into the geometry of the associated linear transformation.

There are several methods to render matrices into a more easily accessible form. They are generally referred to as matrix transformation or matrix decomposition techniques. The interest of all these decomposition techniques is that they preserve certain properties of the matrices in question, such as determinant, rank or inverse, so that these quantities can be calculated after applying the transformation, or that certain matrix operations are algorithmically easier to carry out for some types of matrices.

The LU decomposition factors matrices as a product of lower (L) and an upper triangular matrices (U). Once this decomposition is calculated, linear systems can be solved more efficiently, by a simple technique called forward and back substitution. Likewise, inverses of triangular matrices are algorithmically easier to calculate. The QR decomposition factors matrices as a product of an orthogonal (Q) and a right triangular matrix (R). QR decomposition is often used to solve the linear least squares problem, and is the basis for a particular eigenvalue algorithm, the QR algorithm. Singular value decomposition expresses any matrix A as a product UDV', where U and V are unitary matrices and D is a diagonal matrix. The eigendecomposition or diagonalization expresses A as a product VDV-1, where D is a diagonal matrix and V is a suitable invertible matrix. If A can be written in this form, it is called diagonalizable.

Serialized Form
• ### Constructor Summary

Constructors
Constructor and Description
`IMatrix()`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`java.lang.String` `colName(int i)`
Returns the name of i-th column.
`java.lang.String[]` `colNames()`
Returns the column names.
`void` `colNames(java.lang.String[] names)`
Sets the column names.
`abstract T` `mv(T x)`
Returns the matrix-vector multiplication A * x.
`abstract void` ```mv(T work, int inputOffset, int outputOffset)```
Matrix-vector multiplication A * x.
`abstract void` ```mv(T x, T y)```
Matrix-vector multiplication y = A * x.
`abstract int` `ncols()`
Returns the number of columns.
`abstract int` `nrows()`
Returns the number of rows.
`java.lang.String` `rowName(int i)`
Returns the name of i-th row.
`java.lang.String[]` `rowNames()`
Returns the row names.
`void` `rowNames(java.lang.String[] names)`
Sets the row names.
`abstract long` `size()`
Returns the number of stored matrix elements.
`java.lang.String` `toString()`
`java.lang.String` `toString(boolean full)`
Returns the string representation of matrix.
`java.lang.String` ```toString(int m, int n)```
Returns the string representation of matrix.
`abstract T` `tv(T x)`
Returns Matrix-vector multiplication A' * x.
`abstract void` ```tv(T work, int inputOffset, int outputOffset)```
Matrix-vector multiplication A' * x.
`abstract void` ```tv(T x, T y)```
Matrix-vector multiplication y = A' * x.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### IMatrix

`public IMatrix()`
• ### Method Detail

• #### nrows

`public abstract int nrows()`
Returns the number of rows.
• #### ncols

`public abstract int ncols()`
Returns the number of columns.
• #### size

`public abstract long size()`
Returns the number of stored matrix elements. For conventional matrix, it is simplify nrows * ncols. But it is usually much less for band, packed or sparse matrix.
• #### rowNames

`public java.lang.String[] rowNames()`
Returns the row names.
• #### rowNames

`public void rowNames(java.lang.String[] names)`
Sets the row names.
• #### rowName

`public java.lang.String rowName(int i)`
Returns the name of i-th row.
• #### colNames

`public java.lang.String[] colNames()`
Returns the column names.
• #### colName

`public java.lang.String colName(int i)`
Returns the name of i-th column.
• #### colNames

`public void colNames(java.lang.String[] names)`
Sets the column names.
• #### toString

`public java.lang.String toString()`
Overrides:
`toString` in class `java.lang.Object`
• #### toString

`public java.lang.String toString(boolean full)`
Returns the string representation of matrix.
Parameters:
`full` - Print the full matrix if true. Otherwise, print only top left 7 x 7 submatrix.
• #### toString

```public java.lang.String toString(int m,
int n)```
Returns the string representation of matrix.
Parameters:
`m` - the number of rows to print.
`n` - the number of columns to print.
• #### mv

`public abstract T mv(T x)`
Returns the matrix-vector multiplication A * x.
• #### mv

```public abstract void mv(T x,
T y)```
Matrix-vector multiplication y = A * x.
• #### mv

```public abstract void mv(T work,
int inputOffset,
int outputOffset)```
Matrix-vector multiplication A * x.
Parameters:
`work` - the workspace for both input and output vector.
`inputOffset` - the offset of input vector in workspace.
`outputOffset` - the offset of output vector in workspace.
• #### tv

`public abstract T tv(T x)`
Returns Matrix-vector multiplication A' * x.
• #### tv

```public abstract void tv(T x,
T y)```
Matrix-vector multiplication y = A' * x.
• #### tv

```public abstract void tv(T work,
int inputOffset,
int outputOffset)```
Matrix-vector multiplication A' * x.
Parameters:
`work` - the workspace for both input and output vector.
`inputOffset` - the offset of input vector in workspace.
`outputOffset` - the offset of output vector in workspace.