ch.javasoft.jsmat.variable
Class MatMatrix<A>

java.lang.Object
  extended by ch.javasoft.jsmat.variable.MatVariable
      extended by ch.javasoft.jsmat.variable.MatAllocated
          extended by ch.javasoft.jsmat.variable.MatMatrix<A>
Type Parameters:
A - the matrix type, typically an array of a java primitive type
Direct Known Subclasses:
MatCharMatrix, MatDoubleMatrix, MatMatrix.MatGenericMatrix

public abstract class MatMatrix<A>
extends MatAllocated

A MatMatrix is a matrix with data. The data must be allocated when instantiating the matrix, that is, it is kept in memory. They are simple to use, but MatReservedMatrix might be an option for large matrices which allow writing the data piecewise without preallocating it in memory.


Nested Class Summary
protected static class MatMatrix.MatGenericMatrix<A>
          Generic class for internal use in static create...
 
Field Summary
protected  MatType mMatType
           
 
Fields inherited from class ch.javasoft.jsmat.variable.MatVariable
DEFAULT_NAME, mDims, mMatClass
 
Constructor Summary
MatMatrix(MatClass matClass, MatType matType, int[] dims)
           
 
Method Summary
static MatMatrix<double[]> createDoubleMatrix(double[] values, int[] dims)
          Creates a double matrix
static MatMatrix<double[]> createDoubleMatrix(double[] values, int rows, int cols)
          Creates a double matrix
static MatMatrix<int[]> createIntMatrix(int[] values, int[] dims)
          Creates a integer matrix
static MatMatrix<int[]> createIntMatrix(int[] values, int rows, int cols)
          Creates a integer matrix
 MatMatrix<char[]> createUtf8Matrix(byte[] values)
          Creates a utf8 encoded character matrix with 1 row
 MatMatrix<char[]> createUtf8Matrix(byte[] values, int[] dims)
          Creates a utf8 encoded character matrix
protected abstract  int getMatrixSize()
          Returns the matrix size, typically the overall array length of the underlying data
protected  int getRawDataSize()
           
abstract  void writeRawData(DataOutput out)
          Write the raw data to the given output, excluding type, size, name etc.
 
Methods inherited from class ch.javasoft.jsmat.variable.MatAllocated
write
 
Methods inherited from class ch.javasoft.jsmat.variable.MatVariable
checkRawDataSizeOverflow, checkValueLength, getDimLength, getFlags, getSize, writeStart
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mMatType

protected final MatType mMatType
Constructor Detail

MatMatrix

public MatMatrix(MatClass matClass,
                 MatType matType,
                 int[] dims)
Method Detail

getRawDataSize

protected int getRawDataSize()
Specified by:
getRawDataSize in class MatVariable
Returns:
size of raw data excluding type(4) and size(4) and name

getMatrixSize

protected abstract int getMatrixSize()
Returns the matrix size, typically the overall array length of the underlying data


writeRawData

public abstract void writeRawData(DataOutput out)
                           throws IOException
Write the raw data to the given output, excluding type, size, name etc. This method is implemented by the type specific subclasses.

Specified by:
writeRawData in class MatAllocated
Parameters:
out - the data output to write to
Throws:
IOException - if any io exception occurs

createDoubleMatrix

public static MatMatrix<double[]> createDoubleMatrix(double[] values,
                                                     int rows,
                                                     int cols)
Creates a double matrix

Parameters:
values - the data values, column packed (FORTRAN like)
rows - number of rows
cols - number of columns
Returns:
the double matrix

createDoubleMatrix

public static MatMatrix<double[]> createDoubleMatrix(double[] values,
                                                     int[] dims)
Creates a double matrix

Parameters:
values - the data values, column packed (FORTRAN like)
dims - the dimensions
Returns:
the double matrix

createIntMatrix

public static MatMatrix<int[]> createIntMatrix(int[] values,
                                               int rows,
                                               int cols)
Creates a integer matrix

Parameters:
values - the data values, column packed (FORTRAN like)
rows - number of rows
cols - number of columns
Returns:
the integer matrix

createIntMatrix

public static MatMatrix<int[]> createIntMatrix(int[] values,
                                               int[] dims)
Creates a integer matrix

Parameters:
values - the data values, column packed (FORTRAN like)
dims - the dimensions
Returns:
the integer matrix

createUtf8Matrix

public MatMatrix<char[]> createUtf8Matrix(byte[] values)
Creates a utf8 encoded character matrix with 1 row

Parameters:
values - the data values, column packed (FORTRAN like)
Returns:
the utf8 encoded character matrix

createUtf8Matrix

public MatMatrix<char[]> createUtf8Matrix(byte[] values,
                                          int[] dims)
Creates a utf8 encoded character matrix

Parameters:
values - the data values, column packed (FORTRAN like)
dims - the dimensions
Returns:
the utf8 encoded character matrix