ch.javasoft.jsmat.variable
Class MatVariable

java.lang.Object
  extended by ch.javasoft.jsmat.variable.MatVariable
Direct Known Subclasses:
MatAllocated, MatReserved

public abstract class MatVariable
extends Object

MatVariable is the superclass of all (non primitive) matlab data types.

Most subclasses are matrices of different primitive type, such as MatDoubleMatrix or MatCharMatrix. However, some special cases exist, such as MatCell, MatStructure etc.

Note that for matrices, the data is column packed (FORTRAN like), that is, the first column is written, then the second etc (column by column, not row by row as in java or c). For m dimensions, the first dimension is iterated first (i.e. the rows), then the second (columns), third etc. (again, opposite iteration order than java or c).


Field Summary
protected static String DEFAULT_NAME
           
protected  int[] mDims
           
protected  MatClass mMatClass
           
 
Constructor Summary
MatVariable(MatClass matClass, int[] dims)
          Constructor with matrix class constant and dimensions
 
Method Summary
protected  void checkRawDataSizeOverflow(int typeSize)
          Throws an exception if the raw data size is larger than Integer.MAX_VALUE.
protected  void checkValueLength(int len)
          Check whether the given len is equal to the expected length, computed from the dimensions (see getDimLength()).
 int getDimLength()
           
 int getFlags()
           
protected abstract  int getRawDataSize()
           
 int getSize(String name)
           
protected  void writeStart(String name, DataOutput out)
          Writes the start of the data block to the given data output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_NAME

protected static final String DEFAULT_NAME
See Also:
Constant Field Values

mMatClass

protected MatClass mMatClass

mDims

protected int[] mDims
Constructor Detail

MatVariable

public MatVariable(MatClass matClass,
                   int[] dims)
Constructor with matrix class constant and dimensions

Parameters:
matClass - matrix class constant
dims - dimensions
Method Detail

getDimLength

public int getDimLength()
Returns:
product of all dimensions

checkValueLength

protected void checkValueLength(int len)
                         throws IllegalArgumentException
Check whether the given len is equal to the expected length, computed from the dimensions (see getDimLength()).

If the check fails, an IllegalArgumentException is thrown.

Parameters:
len - the actual value count, to be compared with the reserved size computed from the dimensions
Throws:
IllegalArgumentException - if the check fails

getFlags

public int getFlags()

getRawDataSize

protected abstract int getRawDataSize()
Returns:
size of raw data excluding type(4) and size(4) and name

checkRawDataSizeOverflow

protected void checkRawDataSizeOverflow(int typeSize)
                                 throws ArithmeticException
Throws an exception if the raw data size is larger than Integer.MAX_VALUE. The raw data size is computed from the given type size times the overall dimension length.

Parameters:
typeSize - the size of a single value
Throws:
ArithmeticException - if the computed size is out of integer range

getSize

public int getSize(String name)
Returns:
size of all data including flags, dimensions, names, etc.

writeStart

protected void writeStart(String name,
                          DataOutput out)
                   throws IOException
Writes the start of the data block to the given data output.

Throws:
IOException