ptolemy.data
Class IntMatrixToken

java.lang.Object
  extended byptolemy.data.Token
      extended byptolemy.data.MatrixToken
          extended byptolemy.data.IntMatrixToken
All Implemented Interfaces:
java.io.Serializable

public class IntMatrixToken
extends MatrixToken

A token that contains a 2-D int matrix.

Since:
Ptolemy II 0.2
Version:
$Id: IntMatrixToken.java,v 1.94 2004/04/13 03:21:39 cxh Exp $
Author:
Yuhong Xiong, Jeff Tsay, Steve Neuendorffer
See Also:
Serialized Form
Accepted Rating:
Yellow (wbwu)
Proposed Rating:
Green (neuendor)

Field Summary
 
Fields inherited from class ptolemy.data.MatrixToken
DO_COPY, DO_NOT_COPY
 
Constructor Summary
IntMatrixToken()
          Construct an IntMatrixToken with a one by one matrix.
IntMatrixToken(int[][] value)
          Construct a IntMatrixToken with the specified 2-D matrix.
IntMatrixToken(int[][] value, int copy)
          Construct a IntMatrixToken with the specified 2-D matrix.
IntMatrixToken(int[] value, int rows, int columns)
          Construct a IntMatrixToken with the specified 1-D matrix.
IntMatrixToken(int[] value, int rows, int columns, int copy)
          Construct a IntMatrixToken with the specified 1-D matrix.
IntMatrixToken(java.lang.String init)
          Construct an IntMatrixToken from the specified string.
IntMatrixToken(Token[] tokens, int rows, int columns)
          Construct an IntMatrixToken from the specified array of tokens.
 
Method Summary
protected  MatrixToken _add(MatrixToken rightArgument)
          Return a new token whose value is the value of the argument Token added to the value of this Token.
protected  MatrixToken _addElement(Token rightArgument)
          Return a new token whose value is the value of the argument Token added to the value of each element of this Token.
protected  MatrixToken _divideElement(Token rightArgument)
          Return a new token whose elements are the result of dividing the elements of this token by the argument.
protected  int[] _getInternalIntArray()
          Return a reference to the internal 2-D matrix of ints that represents this Token.
protected  MatrixToken _moduloElement(Token rightArgument)
          Return a new token whose elements are the remainders of the elements of this token when divided by the argument.
protected  MatrixToken _multiply(MatrixToken rightArgument)
          Return a new token whose value is the value of this token multiplied by the value of the argument token.
protected  MatrixToken _multiplyElement(Token rightArgument)
          Return a new token whose value is the value of this token multiplied by the value of the argument scalar token.
protected  MatrixToken _subtract(MatrixToken rightArgument)
          Return a new token whose value is the value of the argument token subtracted from the value of this token.
protected  MatrixToken _subtractElement(Token rightArgument)
          Return a new token whose value is the value of the argument Token subtracted from the value of each element of this Token.
protected  MatrixToken _subtractElementReverse(Token rightArgument)
          Return a new token whose value is the value of the argument Token subtracted from the value of each element of this Token.
 Complex[][] complexMatrix()
          Return the content of this token as a 2-D Complex matrix.
static Token convert(ScalarToken token, int size)
          Convert the specified scalar token into an instance of IntMatrixToken.
static IntMatrixToken convert(Token token)
          Convert the specified token into an instance of IntMatrixToken.
 double[][] doubleMatrix()
          Return the content of this token as a 2-D double matrix.
 boolean equals(java.lang.Object object)
          Return true if the argument is an instance of IntMatrixToken of the same dimensions and the corresponding elements of the matrices are equal.
 int getColumnCount()
          Return the number of columns in the matrix.
 Token getElementAsToken(int row, int column)
          Return the element of the matrix at the specified row and column in a IntToken.
 int getElementAt(int row, int column)
          Return the element of the contained matrix at the specified row and column.
 Type getElementType()
          Return the Type of the tokens contained in this matrix token.
 int getRowCount()
          Return the number of rows in the matrix.
 Type getType()
          Return the type of this token.
 int hashCode()
          Return a hash code value for this token.
 int[][] intMatrix()
          Return the content in the token as a 2-D int matrix.
 long[][] longMatrix()
          Return the content of this token as a 2-D long matrix.
 Token one()
          Return a new Token representing the left multiplicative identity.
 Token oneRight()
          Return a new Token representing the right multiplicative identity.
 Token zero()
          Return a new Token representing the additive identity.
 
Methods inherited from class ptolemy.data.MatrixToken
_isCloseTo, _isEqualTo, add, addReverse, arrayToMatrix, arrayToMatrix, arrayToMatrixReturnType, create, createSequence, createSequenceReturnType, createTokenSequence, determineSequenceLength, divide, divideReverse, isCloseTo, isEqualTo, matrixToArray, matrixToArrayReturnType, modulo, moduloReverse, multiply, multiplyReverse, subtract, subtractReverse, toArray, toArrayReturnType, toString
 
Methods inherited from class ptolemy.data.Token
isCloseTo, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, pow, zeroReturnType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IntMatrixToken

public IntMatrixToken()
Construct an IntMatrixToken with a one by one matrix. The only element in the matrix has value 0.0


IntMatrixToken

public IntMatrixToken(int[] value,
                      int rows,
                      int columns)
               throws IllegalActionException
Construct a IntMatrixToken with the specified 1-D matrix. Make a copy of the matrix and store the copy, so that changes on the specified matrix after this token is constructed will not affect the content of this token.

Throws:
IllegalActionException - If the specified matrix is null.

IntMatrixToken

public IntMatrixToken(int[] value,
                      int rows,
                      int columns,
                      int copy)
               throws IllegalActionException
Construct a IntMatrixToken with the specified 1-D matrix. If copy is DO_COPY, make a copy of the matrix and store the copy, so that changes on the specified matrix after this token is constructed will not affect the content of this token. If copy is DO_NOT_COPY, just reference the matrix (do not copy its contents). This saves some time and memory. The argument matrix should NOT be modified after this constructor is called to preserve immutability.

Throws:
IllegalActionException - If the specified matrix is null.

IntMatrixToken

public IntMatrixToken(int[][] value)
               throws IllegalActionException
Construct a IntMatrixToken with the specified 2-D matrix. Make a copy of the matrix and store the copy, so that changes on the specified matrix after this token is constructed will not affect the content of this token.

Throws:
IllegalActionException - If the specified matrix is null.

IntMatrixToken

public IntMatrixToken(int[][] value,
                      int copy)
               throws IllegalActionException
Construct a IntMatrixToken with the specified 2-D matrix. If copy is DO_COPY, make a copy of the matrix and store the copy, so that changes on the specified matrix after this token is constructed will not affect the content of this token. If copy is DO_NOT_COPY, just reference the matrix (do not copy its contents). This saves some time and memory. The argument matrix should NOT be modified after this constructor is called to preserve immutability.

Since the DO_NOT_COPY option requires some care, this constructor is protected.

Throws:
IllegalActionException - If the specified matrix is null.

IntMatrixToken

public IntMatrixToken(java.lang.String init)
               throws IllegalActionException
Construct an IntMatrixToken from the specified string.

Parameters:
init - A string expression of a 2-D int matrix.
Throws:
IllegalActionException - If the string does not contain a parsable 2-D int matrix.

IntMatrixToken

public IntMatrixToken(Token[] tokens,
                      int rows,
                      int columns)
               throws IllegalActionException
Construct an IntMatrixToken from the specified array of tokens. The tokens in the array must be scalar tokens convertible into integers.

Parameters:
tokens - The array of tokens, which must contains rows * columns ScalarTokens.
rows - The number of rows in the matrix to be created.
columns - The number of columns in the matrix to be created.
Throws:
IllegalActionException - If the array of tokens is null, or the length of the array is not correct, or if one of the elements of the array is null, or if one of the elements of the array cannot be losslessly converted to an integer.
Method Detail

complexMatrix

public Complex[][] complexMatrix()
Return the content of this token as a 2-D Complex matrix.

Overrides:
complexMatrix in class MatrixToken
Returns:
A 2-D Complex matrix

convert

public static IntMatrixToken convert(Token token)
                              throws IllegalActionException
Convert the specified token into an instance of IntMatrixToken. This method does lossless conversion. If the argument is already an instance of IntMatrixToken, it is returned without any change. Otherwise, if the argument is below IntMatrixToken in the type hierarchy, it is converted to an instance of IntMatrixToken or one of the subclasses of IntMatrixToken and returned. If none of the above condition is met, an exception is thrown.

Parameters:
token - The token to be converted to a IntMatrixToken.
Returns:
A IntMatrixToken
Throws:
IllegalActionException - If the conversion cannot be carried out.

convert

public static Token convert(ScalarToken token,
                            int size)
                     throws IllegalActionException
Convert the specified scalar token into an instance of IntMatrixToken. The resulting matrix will be square, with the number of rows and columns equal to the given size. This method does lossless conversion.

Parameters:
token - The token to be converted to a IntMatrixToken.
Returns:
A IntMatrixToken
Throws:
IllegalActionException - If the conversion cannot be carried out.

doubleMatrix

public double[][] doubleMatrix()
Return the content of this token as a 2-D double matrix.

Overrides:
doubleMatrix in class MatrixToken
Returns:
A 2-D double matrix.

equals

public boolean equals(java.lang.Object object)
Return true if the argument is an instance of IntMatrixToken of the same dimensions and the corresponding elements of the matrices are equal.

Parameters:
object - An instance of Object.
Returns:
True if the argument is an instance of IntMatrixToken of the same dimensions and the corresponding elements of the matrices are equal.

getColumnCount

public int getColumnCount()
Return the number of columns in the matrix.

Specified by:
getColumnCount in class MatrixToken
Returns:
The number of columns in the matrix.

getElementAsToken

public Token getElementAsToken(int row,
                               int column)
                        throws java.lang.ArrayIndexOutOfBoundsException
Return the element of the matrix at the specified row and column in a IntToken.

Specified by:
getElementAsToken in class MatrixToken
Parameters:
row - The row index of the desired element.
column - The column index of the desired element.
Returns:
A IntToken containing the matrix element.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the specified row or column number is outside the range of the matrix.

getElementAt

public int getElementAt(int row,
                        int column)
Return the element of the contained matrix at the specified row and column.

Parameters:
row - The row index of the desired element.
column - The column index of the desired element.
Returns:
The int at the specified matrix entry.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the specified row or column number is outside the range of the matrix.

getElementType

public Type getElementType()
Return the Type of the tokens contained in this matrix token. This must be a type representing a scalar token.

Specified by:
getElementType in class MatrixToken
Returns:
BaseType.INT.

getRowCount

public int getRowCount()
Return the number of rows in the matrix.

Specified by:
getRowCount in class MatrixToken
Returns:
The number of rows in the matrix.

getType

public Type getType()
Return the type of this token.

Overrides:
getType in class Token
Returns:
BaseType.INT_MATRIX

hashCode

public int hashCode()
Return a hash code value for this token. This method returns the sum of the elements.

Returns:
A hash code value for this token.

intMatrix

public int[][] intMatrix()
Return the content in the token as a 2-D int matrix. The returned matrix is a copy so the caller is free to modify it.

Overrides:
intMatrix in class MatrixToken
Returns:
A 2-D int matrix.

longMatrix

public long[][] longMatrix()
Return the content of this token as a 2-D long matrix.

Overrides:
longMatrix in class MatrixToken
Returns:
A 2-D long matrix.

one

public Token one()
Return a new Token representing the left multiplicative identity. The returned token contains an identity matrix whose dimensions are the same as the number of rows of the matrix contained in this token.

Overrides:
one in class Token
Returns:
A new IntMatrixToken containing the left multiplicative identity.

oneRight

public Token oneRight()
Return a new Token representing the right multiplicative identity. The returned token contains an identity matrix whose dimensions are the same as the number of columns of the matrix contained in this token.

Overrides:
oneRight in class MatrixToken
Returns:
A new IntMatrixToken containing the right multiplicative identity.

zero

public Token zero()
Return a new Token representing the additive identity. The returned token contains a matrix whose elements are all zero, and the size of the matrix is the same as the matrix contained in this token.

Overrides:
zero in class Token
Returns:
A new IntMatrixToken containing the additive identity.

_add

protected MatrixToken _add(MatrixToken rightArgument)
                    throws IllegalActionException
Return a new token whose value is the value of the argument Token added to the value of this Token. It is assumed that the type of the argument is IntMatrixToken.

Overrides:
_add in class MatrixToken
Parameters:
rightArgument - The token to add to this token.
Returns:
A new IntMatrixToken containing the result.
Throws:
IllegalActionException - If the units are not compatible, or this operation is not supported by the derived class.

_addElement

protected MatrixToken _addElement(Token rightArgument)
                           throws IllegalActionException
Return a new token whose value is the value of the argument Token added to the value of each element of this Token. It is assumed that the type of the argument is the same as the type of each element of this class.

Overrides:
_addElement in class MatrixToken
Parameters:
rightArgument - The token to add to this token.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If this operation is not supported by the derived class.

_divideElement

protected MatrixToken _divideElement(Token rightArgument)
                              throws IllegalActionException
Return a new token whose elements are the result of dividing the elements of this token by the argument. It is assumed that the type of the argument is the same as the type of each element of this class.

Overrides:
_divideElement in class MatrixToken
Parameters:
rightArgument - The token that divides this token.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If this operation is not supported by the derived class.

_getInternalIntArray

protected int[] _getInternalIntArray()
Return a reference to the internal 2-D matrix of ints that represents this Token. Because no copying is done, the contents must NOT be modified to preserve the immutability of Token.

Returns:
An int matrix.

_moduloElement

protected MatrixToken _moduloElement(Token rightArgument)
                              throws IllegalActionException
Return a new token whose elements are the remainders of the elements of this token when divided by the argument. It is guaranteed by the caller that the type of the argument is the same as the type of each element of this class.

Overrides:
_moduloElement in class MatrixToken
Parameters:
rightArgument - The token that performs modulo on this token.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If this operation is not supported by the derived class.

_multiply

protected MatrixToken _multiply(MatrixToken rightArgument)
                         throws IllegalActionException
Return a new token whose value is the value of this token multiplied by the value of the argument token. It is assumed that the type of the argument is IntMatrixToken.

Overrides:
_multiply in class MatrixToken
Parameters:
rightArgument - The token to multiply this token by.
Returns:
A new IntMatrixToken containing the result.
Throws:
IllegalActionException - If the units are not compatible, or this operation is not supported by the derived class.

_multiplyElement

protected MatrixToken _multiplyElement(Token rightArgument)
                                throws IllegalActionException
Return a new token whose value is the value of this token multiplied by the value of the argument scalar token. This method should be overridden in derived classes to provide type specific actions for multiply.

Overrides:
_multiplyElement in class MatrixToken
Parameters:
rightArgument - The token to multiply this token by.
Returns:
A new IntMatrixToken containing the result.
Throws:
IllegalActionException - If this method is not supported by the derived class.

_subtract

protected MatrixToken _subtract(MatrixToken rightArgument)
                         throws IllegalActionException
Return a new token whose value is the value of the argument token subtracted from the value of this token. It is assumed that the type of the argument is IntMatrixToken.

Overrides:
_subtract in class MatrixToken
Parameters:
rightArgument - The token to subtract from this token.
Returns:
A new IntMatrixToken containing the result.
Throws:
IllegalActionException - If the units are not compatible, or this operation is not supported by the derived class.

_subtractElement

protected MatrixToken _subtractElement(Token rightArgument)
                                throws IllegalActionException
Return a new token whose value is the value of the argument Token subtracted from the value of each element of this Token. It is assumed that the type of the argument is the same as the type of each element of this class.

Overrides:
_subtractElement in class MatrixToken
Parameters:
rightArgument - The token to subtract from this token.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If this operation is not supported by the derived class.

_subtractElementReverse

protected MatrixToken _subtractElementReverse(Token rightArgument)
                                       throws IllegalActionException
Return a new token whose value is the value of the argument Token subtracted from the value of each element of this Token. It is assumed that the type of the argument is the same as the type of each element of this class.

Overrides:
_subtractElementReverse in class MatrixToken
Parameters:
rightArgument - The token to subtract from this token.
Returns:
A new Token containing the result.
Throws:
IllegalActionException - If this operation is not supported by the derived class.