Package ptolemy.data
Class ComplexMatrixToken
- java.lang.Object
-
- ptolemy.data.Token
-
- ptolemy.data.MatrixToken
-
- ptolemy.data.ComplexMatrixToken
-
public class ComplexMatrixToken extends MatrixToken
A token that contains a 2-D Complex matrix.- Since:
- Ptolemy II 0.2
- Version:
- $Id$
- Author:
- Yuhong Xiong, Christopher Hylands, Steve Neuendorffer
- See Also:
Complex
- Pt.AcceptedRating:
- Yellow (cxh)
- Pt.ProposedRating:
- Green (neuendor)
-
-
Field Summary
-
Fields inherited from class ptolemy.data.MatrixToken
_nils, DO_COPY, DO_NOT_COPY
-
-
Constructor Summary
Constructors Constructor Description ComplexMatrixToken()
Construct an ComplexMatrixToken with a one by one matrix.ComplexMatrixToken(java.lang.String init)
Construct an ComplexMatrixToken from the specified string.ComplexMatrixToken(Token[] tokens, int rows, int columns)
Construct an ComplexMatrixToken from the specified array of tokens.ComplexMatrixToken(Complex[][] value)
Construct a ComplexMatrixToken with the specified 2-D matrix.ComplexMatrixToken(Complex[][] value, int copy)
Construct a ComplexMatrixToken with the specified 2-D matrix.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 Complex[][]
_getInternalComplexMatrix()
Return a reference to the internal 2-D matrix of complex numbers that represents this Token.protected MatrixToken
_multiply(MatrixToken rightArgument)
Return a new token whose value is the value of the argument Token multiplied to the value of this 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 token.protected MatrixToken
_subtract(MatrixToken rightArgument)
Return a new token whose value is the value of the argument Token subtracted to 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 new 2-D Complex matrix.static ComplexMatrixToken
convert(Token token)
Convert the specified token into an instance of ComplexMatrixToken.MatrixToken
crop(int rowStart, int colStart, int rowSpan, int colSpan)
Return a new matrix that is a sub-matrix of this matrix.boolean
equals(java.lang.Object object)
Return true if the argument is an instance of ComplexMatrixToken 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 ComplexToken.Complex
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.MatrixToken
join(MatrixToken[][] matrices)
Join a matrix of matrices into a single matrix by tiling.Token
one()
Return a new Token representing the left multiplicative identity.Token
oneRight()
Return a new Token representing the right multiplicative identity.MatrixToken[][]
split(int[] rows, int[] columns)
Split this matrix into multiple matrices.Token
zero()
Return a new Token representing the additive identity.-
Methods inherited from class ptolemy.data.MatrixToken
_elementIsNil, _isCloseTo, _isEqualTo, _moduloElement, add, addReverse, arrayToMatrix, arrayToMatrix, arrayToMatrixReturnType, booleanMatrix, create, createSequence, createSequenceReturnType, createTokenSequence, determineSequenceLength, divide, divideReverse, doubleMatrix, fixMatrix, intMatrix, isCloseTo, isEqualTo, longMatrix, matrixToArray, matrixToArrayReturnType, modulo, moduloReverse, multiply, multiplyReverse, subtract, subtractReverse, toArray, toArrayColumnMajor, toArrayReturnType, toString
-
Methods inherited from class ptolemy.data.Token
isCloseTo, isNil, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, zeroReturnType
-
-
-
-
Constructor Detail
-
ComplexMatrixToken
public ComplexMatrixToken()
Construct an ComplexMatrixToken with a one by one matrix. The only element in the matrix has value 0.0
-
ComplexMatrixToken
public ComplexMatrixToken(Complex[][] value) throws IllegalActionException
Construct a ComplexMatrixToken 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. This constructor also ensures that the matrix is initialized with zeros if any of the specifies values is null.- Parameters:
value
- The 2-D Complex matrix.- Throws:
IllegalActionException
- If the specified matrix is null.
-
ComplexMatrixToken
public ComplexMatrixToken(Complex[][] value, int copy) throws IllegalActionException
Construct a ComplexMatrixToken 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.
- Parameters:
value
- The 2-D Complex matrix.copy
- IfMatrixToken.DO_COPY
, the the value matrix is copied, IfMatrixToken.DO_NOT_COPY
, then the value matrix is not copied.- Throws:
IllegalActionException
- If the specified matrix is null.
-
ComplexMatrixToken
public ComplexMatrixToken(java.lang.String init) throws IllegalActionException
Construct an ComplexMatrixToken from the specified string.- Parameters:
init
- A string expression of a 2-D complex matrix.- Throws:
IllegalActionException
- If the string does not contain a parsable 2-D complex matrix.
-
ComplexMatrixToken
public ComplexMatrixToken(Token[] tokens, int rows, int columns) throws IllegalActionException
Construct an ComplexMatrixToken from the specified array of tokens. The tokens in the array must be scalar tokens convertible into complex numbers.- 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 new 2-D Complex matrix.- Overrides:
complexMatrix
in classMatrixToken
- Returns:
- A 2-D Complex matrix
-
convert
public static ComplexMatrixToken convert(Token token) throws IllegalActionException
Convert the specified token into an instance of ComplexMatrixToken. This method does lossless conversion. If the argument is already an instance of ComplexMatrixToken, it is returned without any change. Otherwise, if the argument is below ComplexMatrixToken in the type hierarchy, it is converted to an instance of ComplexMatrixToken or one of the subclasses of ComplexMatrixToken and returned. If none of the above condition is met, an exception is thrown.- Parameters:
token
- The token to be converted to a ComplexMatrixToken.- Returns:
- A ComplexMatrixToken
- Throws:
IllegalActionException
- If the conversion cannot be carried out.
-
crop
public MatrixToken crop(int rowStart, int colStart, int rowSpan, int colSpan) throws IllegalActionException
Return a new matrix that is a sub-matrix of this matrix.- Overrides:
crop
in classMatrixToken
- Parameters:
rowStart
- The row to start on.colStart
- The column to start on.rowSpan
- The number of rows to copy.colSpan
- The number of columns to copy.- Returns:
- a sub-matrix of this matrix.
- Throws:
IllegalActionException
- If the returned matrix is empty or if the specified parameters result in out of bounds accesses.
-
equals
public boolean equals(java.lang.Object object)
Return true if the argument is an instance of ComplexMatrixToken of the same dimensions and the corresponding elements of the matrices are equal.- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- An instance of Object.- Returns:
- True if the argument is an instance of ComplexMatrixToken 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 classMatrixToken
- 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 ComplexToken.- Specified by:
getElementAsToken
in classMatrixToken
- Parameters:
row
- The row index of the desired element.column
- The column index of the desired element.- Returns:
- A ComplexToken containing the matrix element.
- Throws:
java.lang.ArrayIndexOutOfBoundsException
- If the specified row or column number is outside the range of the matrix.
-
getElementAt
public Complex 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 Complex 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 classMatrixToken
- Returns:
- BaseType.COMPLEX.
-
getRowCount
public int getRowCount()
Return the number of rows in the matrix.- Specified by:
getRowCount
in classMatrixToken
- Returns:
- The number of rows in the matrix.
-
getType
public Type getType()
Return the type of this token.
-
hashCode
public int hashCode()
Return a hash code value for this token. This method returns the integer portion of the magnitude of the sum of the elements.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- A hash code value for this token.
-
join
public MatrixToken join(MatrixToken[][] matrices) throws IllegalActionException
Join a matrix of matrices into a single matrix by tiling. All matrices in the matrix must be of the same type, the same type as this matrix. But none of them needs to actually be this matrix. This base class simply throws an exception. Derived classes provide the implementation. The number of columns in the resulting matrix is the sum of the number of columns in the first row of the argument. The number of rows in the resulting matrix is the sum of the number of rows in the first column of the argument. The matrices are copied into the result starting at the position determined by the first row or column. If the matrices overlap, then while copying left to right, top-to-bottom, data will be overwritten. If there are gaps, the resulting matrix will be filled with zeros.- Overrides:
join
in classMatrixToken
- Parameters:
matrices
- A two-dimensional array of matrix tokens.- Returns:
- A new matrix token of the same type as the elements in the input matrix of matrix tokens.
- Throws:
IllegalActionException
- If the types of the matrices in the input are not all the same, or if tiling fails due to size incompatibilities, or if the input matrix has no tokens.
-
split
public MatrixToken[][] split(int[] rows, int[] columns)
Split this matrix into multiple matrices. See the base class for documentation.- Overrides:
split
in classMatrixToken
- Parameters:
rows
- The number of rows per submatrix.columns
- The number of columns per submatrix.- Returns:
- An array of matrix tokens.
-
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.
-
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 classMatrixToken
- Returns:
- A new ComplexMatrixToken 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.
-
_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 ComplexMatrixToken.- Overrides:
_add
in classMatrixToken
- Parameters:
rightArgument
- The token to add to this token.- Returns:
- A new ComplexMatrixToken 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 or is a matrix with one element.- Overrides:
_addElement
in classMatrixToken
- Parameters:
rightArgument
- The token to add to this token.- Returns:
- A new ComplexMatrixToken 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 or is a matrix with one element.- Overrides:
_divideElement
in classMatrixToken
- 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.
-
_getInternalComplexMatrix
protected Complex[][] _getInternalComplexMatrix()
Return a reference to the internal 2-D matrix of complex numbers that represents this Token. Because no copying is done, the contents must NOT be modified to preserve the immutability of Token.- Returns:
- A 2-D complex Java matrix.
-
_multiply
protected MatrixToken _multiply(MatrixToken rightArgument) throws IllegalActionException
Return a new token whose value is the value of the argument Token multiplied to the value of this Token. It is assumed that the type of the argument is ComplexMatrixToken.- Overrides:
_multiply
in classMatrixToken
- Parameters:
rightArgument
- The token to multiply this token by.- Returns:
- A new ComplexMatrixToken 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 token.- Overrides:
_multiplyElement
in classMatrixToken
- Parameters:
rightArgument
- The token to multiply this token by.- Returns:
- A new ComplexMatrixToken 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 to the value of this Token. It is assumed that the type of the argument is ComplexMatrixToken.- Overrides:
_subtract
in classMatrixToken
- Parameters:
rightArgument
- The token to subtract to this token.- Returns:
- A new ComplexMatrixToken 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 or is a matrix with one element.- Overrides:
_subtractElement
in classMatrixToken
- 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 or is a matrix with one element.- Overrides:
_subtractElementReverse
in classMatrixToken
- 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.
-
-