public abstract class MatrixToken extends Token
Modifier and Type | Field and Description |
---|---|
protected java.util.Set |
_nils
HashSet of nil elements, where each element is the index of the
element in _value[] that should be nil.
|
static int |
DO_COPY
A constant indicating to constructors that contents of an argument 2-D
matrix should be copied.
|
static int |
DO_NOT_COPY
A constant indicating to constructors not to copy the contents
of an argument 2-D matrix, but instead to just copy the
pointer to the matrix.
|
Constructor and Description |
---|
MatrixToken() |
Modifier and Type | Method and 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 void |
_elementIsNil(int element)
Add the element to the _nils Set.
|
protected BooleanToken |
_isCloseTo(MatrixToken token,
double distance)
Test whether the value of this token is close to the first
argument, where "close" means that the distance between their
elements is less than or equal to the second argument.
|
protected BooleanToken |
_isEqualTo(MatrixToken rightArgument)
Test for equality of the values of this Token and the argument
Token.
|
protected MatrixToken |
_moduloElement(Token rightArgument)
Return a new token whose elements are the modulo of
the elements of this token 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 each element of
this Token subtracted from the value the argument Token.
|
Token |
add(Token rightArgument)
Return a new token whose value is the sum of this token and
the argument.
|
Token |
addReverse(Token leftArgument)
Return a new token whose value is the sum of this token
and the argument.
|
static MatrixToken |
arrayToMatrix(Token[] tokens,
int rows,
int columns)
Create a new instance of a MatrixToken subclass with the
given number of rows and columns.
|
static MatrixToken |
arrayToMatrix(Type type,
Token[] tokens,
int rows,
int columns)
Create a new instance of a MatrixToken subclass with the given
element type and number of rows and columns.
|
static Type |
arrayToMatrixReturnType(Type type1,
Type type2,
Type type3)
Return the (exact) return type of the arrayToMatrix function
above.
|
boolean[][] |
booleanMatrix()
Return the content of this token as a 2-D boolean matrix.
|
Complex[][] |
complexMatrix()
Return a copy of the content of this token as a 2-D Complex matrix.
|
static MatrixToken |
create(Token[] tokens,
int rows,
int columns)
Deprecated.
Use arrayToMatrix() instead.
|
static Token[] |
createSequence(Token start,
Token increment,
int length)
Create an array of tokens of the given length.
|
static Type |
createSequenceReturnType(Type type1,
Type type2,
Type type3)
Return the (exact) return type of the createSequence function
above.
|
static Token[] |
createTokenSequence(Token start,
Token increment,
int length)
Deprecated.
Use createSequence() instead.
|
MatrixToken |
crop(int rowStart,
int colStart,
int rowSpan,
int colSpan)
Return a new matrix that is a sub-matrix of this matrix.
|
static int |
determineSequenceLength(ScalarToken start,
ScalarToken increment,
ScalarToken end)
Count the number of tokens differing by the given increment
that fit in a range between the given start token and the
given end token.
|
Token |
divide(Token rightArgument)
Return a new token whose value is the value of this token
divided by the value of the argument token.
|
Token |
divideReverse(Token leftArgument)
Return a new token whose value is the value of the argument
token divided by the value of this token.
|
double[][] |
doubleMatrix()
Return the content of this token as a 2-D double matrix.
|
FixPoint[][] |
fixMatrix()
Return the content of this token as a 2-D fixed point matrix.
|
abstract int |
getColumnCount()
Return the number of columns of the matrix.
|
abstract Token |
getElementAsToken(int row,
int column)
Return the element of the matrix at the specified
row and column wrapped in a token.
|
abstract Type |
getElementType()
Return the Type of the tokens contained in this matrix token.
|
abstract int |
getRowCount()
Return the number of rows of the matrix.
|
int[][] |
intMatrix()
Return the content of this token as a 2-D integer matrix.
|
BooleanToken |
isCloseTo(Token rightArgument,
double epsilon)
Test whether the value of this Token is close to the argument
Token.
|
BooleanToken |
isEqualTo(Token rightArgument)
Test for equality of the values of this Token and the argument
Token.
|
MatrixToken |
join(MatrixToken[][] matrices)
Join a matrix of matrices into a single matrix by tiling.
|
long[][] |
longMatrix()
Return the content of this matrix as a 2-D long matrix.
|
static ArrayToken |
matrixToArray(MatrixToken matrix)
Create a new instance of ArrayToken that contains the values
in the specified matrix.
|
static Type |
matrixToArrayReturnType(Type type)
Return the (exact) return type of the toArray function above.
|
Token |
modulo(Token rightArgument)
Return a new token whose value is this token
modulo the value of the argument token.
|
Token |
moduloReverse(Token leftArgument)
Return a new token whose value is the value of the argument token
modulo the value of this token.
|
Token |
multiply(Token rightArgument)
Return a new token whose value is the value of this token
multiplied by the value of the argument token.
|
Token |
multiplyReverse(Token leftArgument)
Return a new token whose value is the value of the argument token
multiplied by the value of this token.
|
Token |
oneRight()
Return a new Token representing the right multiplicative
identity.
|
MatrixToken[][] |
split(int[] rows,
int[] columns)
Split this matrix into multiple matrices.
|
Token |
subtract(Token rightArgument)
Return a new token whose value is the value of the argument token
subtracted from the value of this token.
|
Token |
subtractReverse(Token leftArgument)
Return a new token whose value is the value of this token
subtracted from the value of the argument token.
|
ArrayToken |
toArray()
Return an ArrayToken containing the all the values of this
matrix token.
|
ArrayToken |
toArrayColumnMajor()
Return an ArrayToken containing the all the values of this
matrix token.
|
static Type |
toArrayReturnType(Type type)
Return the (exact) return type of the toArray function above.
|
java.lang.String |
toString()
Return the value of this token as a string that can be parsed
by the expression language to recover a token with the same value.
|
getType, isCloseTo, isNil, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, one, pow, zero, zeroReturnType
public static final int DO_COPY
public static final int DO_NOT_COPY
protected java.util.Set _nils
public Token add(Token rightArgument) throws IllegalActionException
add
in class Token
rightArgument
- The token to add to this token.IllegalActionException
- If the argument token
and this token are of incomparable types, or the operation
does not make sense for the given types.public Token addReverse(Token leftArgument) throws IllegalActionException
addReverse
in class Token
leftArgument
- The token to add this token to.IllegalActionException
- If the argument token
is not of a type that can be added to this token, or
the units of this token and the argument token are not the same.public static MatrixToken arrayToMatrix(Token[] tokens, int rows, int columns) throws IllegalActionException
tokens
- an array of Token objectsrows
- The number of rows.columns
- The number of columns.IllegalActionException
- If no type exists for the
matrix token, or the array of tokens is not the right size, or
the array is null.public static MatrixToken arrayToMatrix(Type type, Token[] tokens, int rows, int columns) throws IllegalActionException
type
- The type of the MatrixToken.tokens
- an array of Token objectsrows
- The number of rows.columns
- The number of columns.IllegalActionException
- If the type is not possible,
or the array of tokens is not the right size, or the array is
null.public static Type arrayToMatrixReturnType(Type type1, Type type2, Type type3) throws IllegalActionException
type1
- The type of the first argument to the
corresponding function.type2
- The type of the second argument to the
corresponding function.type3
- The type of the third argument to the
corresponding function.IllegalActionException
- If thrown while getting the matrix
type for type1.public boolean[][] booleanMatrix() throws IllegalActionException
IllegalActionException
- If the token cannot be represented
as requested (always thrown in this base class).public Complex[][] complexMatrix() throws IllegalActionException
IllegalActionException
- If the token cannot be represented
as requested (always thrown in this base class).@Deprecated public static MatrixToken create(Token[] tokens, int rows, int columns) throws IllegalActionException
tokens
- an array of Token objects.rows
- The number of rows.columns
- The number of columns.IllegalActionException
- If no type exists for the
matrix token, or the array of tokens is not the right size, or
the array is null.public static Token[] createSequence(Token start, Token increment, int length) throws IllegalActionException
start
- The value of the first element of the returned array.increment
- The difference between elements in the array.length
- The size of the array to create, which must not be
negative.IllegalActionException
- If the length is negative, or
tokens of the given type cannot be added together.public static Type createSequenceReturnType(Type type1, Type type2, Type type3) throws IllegalActionException
type1
- The type of the first argument to the
corresponding function.type2
- The type of the second argument to the
corresponding function.type3
- The type of the third argument to the
corresponding function.IllegalActionException
- If thrown while creating a
new ArrayType object.@Deprecated public static Token[] createTokenSequence(Token start, Token increment, int length) throws IllegalActionException
start
- The value of the first element of the returned array.increment
- The difference between elements in the array.length
- The size of the array to create, which must not be
negative.IllegalActionException
- If the length is negative, or
tokens of the given type cannot be added together.public MatrixToken crop(int rowStart, int colStart, int rowSpan, int colSpan) throws IllegalActionException
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.IllegalActionException
- If the operation is not
supported. Always thrown in this base class.public static int determineSequenceLength(ScalarToken start, ScalarToken increment, ScalarToken end) throws IllegalActionException
start
- The given start token.increment
- The increment.end
- The given end tokenIllegalActionException
- If the length of the
sequence cannot be determined, or the tokens provided do not
support the zero, isEqualTo, isLessThan, add, divide, or
subtract operations, or is not convertible to a double token.public final Token divide(Token rightArgument) throws IllegalActionException
divide
in class Token
rightArgument
- The token that divides this token.IllegalActionException
- If the operation
does not make sense for the given types.public Token divideReverse(Token leftArgument) throws IllegalActionException
divideReverse
in class Token
leftArgument
- The token to be divided by the value of this token.IllegalActionException
- If the argument token and
this token are of incomparable types, or the operation does
not make sense for the given types.public double[][] doubleMatrix() throws IllegalActionException
IllegalActionException
- If the token cannot be represented
as requested (always thrown in this base class).public FixPoint[][] fixMatrix() throws IllegalActionException
IllegalActionException
- If the token cannot be represented
as requested (always thrown in this base class).public abstract int getColumnCount()
public abstract Token getElementAsToken(int row, int column) throws java.lang.ArrayIndexOutOfBoundsException
row
- The row index of the desired element.column
- The column index of the desired element.java.lang.ArrayIndexOutOfBoundsException
- If the specified
row or column number is outside the range of the matrix.public abstract Type getElementType()
public abstract int getRowCount()
public int[][] intMatrix() throws IllegalActionException
IllegalActionException
- If the token cannot be represented
as requested (always thrown in this base class).public final BooleanToken isCloseTo(Token rightArgument, double epsilon) throws IllegalActionException
isCloseTo
in class Token
rightArgument
- The token to test closeness of this token with.epsilon
- The value that we use to determine whether two
tokens are close. In this base class, the epsilon argument is
ignored.IllegalActionException
- If the argument token is
not of a type that can be compared with this token.isEqualTo(ptolemy.data.Token)
public final BooleanToken isEqualTo(Token rightArgument) throws IllegalActionException
isEqualTo
in class Token
rightArgument
- The token with which to test equality.IllegalActionException
- If this method is not
supported by the derived class.isCloseTo(ptolemy.data.Token, double)
public MatrixToken join(MatrixToken[][] matrices) throws IllegalActionException
matrices
- A two-dimensional array of matrix tokens.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, or the operation is not supported by this matrix class.public long[][] longMatrix() throws IllegalActionException
IllegalActionException
- If the token cannot be represented
as requested (always thrown in this base class).public static ArrayToken matrixToArray(MatrixToken matrix)
matrix
- The given matrix.public static Type matrixToArrayReturnType(Type type)
type
- The type of the argument to the corresponding function.public final Token modulo(Token rightArgument) throws IllegalActionException
modulo
in class Token
rightArgument
- The token that performs modulo on this token.IllegalActionException
- If the operation
does not make sense for the given types.public final Token moduloReverse(Token leftArgument) throws IllegalActionException
moduloReverse
in class Token
leftArgument
- The token to apply modulo to by the value
of this token.IllegalActionException
- If the the operation does
not make sense for the given types.public final Token multiply(Token rightArgument) throws IllegalActionException
multiply
in class Token
rightArgument
- The token to multiply this token by.IllegalActionException
- If the argument token
and this token are of incomparable types, or the operation
does not make sense for the given types.public final Token multiplyReverse(Token leftArgument) throws IllegalActionException
multiplyReverse
in class Token
leftArgument
- The token to be multiplied by the value of
this token.IllegalActionException
- If the argument token
is not of a type that can be multiplied by this token.public Token oneRight() throws IllegalActionException
IllegalActionException
- If this method is not
supported by the derived class.public MatrixToken[][] split(int[] rows, int[] columns) throws IllegalActionException
The matrices are produced from submatrices extracted left-to-right, top-to-bottom, in a raster scan pattern. For example, if rowSplit = {1, 2}, columnSplit = {2, 1}, and the input matrix is as follows:
1 2 3 4 5 6 7 8 9then the first matrix out is a column vector:
1 4The second matrix out is
2 3 5 6The third is
7(a 1x1 matrix) and the fourth is
8 9a row vector. If the input does not have enough elements to fill the specified output matrices, then zeros (of the same type as the input elements) are used. If the input is larger than is required to fill the specified output, then the additional values are discarded.
rows
- The number of rows per submatrix.columns
- The number of columns per submatrix.IllegalActionException
- If the operation is not supported.public final Token subtract(Token rightArgument) throws IllegalActionException
subtract
in class Token
rightArgument
- The token to subtract from this token.IllegalActionException
- If the argument token
and this token are of incomparable types, or the operation
does not make sense for the given types.public final Token subtractReverse(Token leftArgument) throws IllegalActionException
subtractReverse
in class Token
leftArgument
- The token to subtract this token from.IllegalActionException
- If the argument token is not
of a type that can be subtracted to this token, or the units
of this token and the argument token are not the same.public ArrayToken toArray()
public ArrayToken toArrayColumnMajor()
public static Type toArrayReturnType(Type type)
type
- The type of the argument to the corresponding function.public java.lang.String toString()
protected MatrixToken _add(MatrixToken rightArgument) throws IllegalActionException
rightArgument
- The token to add to this token.IllegalActionException
- If this method is not
supported by the derived class.protected MatrixToken _addElement(Token rightArgument) throws IllegalActionException
rightArgument
- The token to add to this token.IllegalActionException
- If this operation is not
supported by the derived class.protected MatrixToken _divideElement(Token rightArgument) throws IllegalActionException
rightArgument
- The token that divides this token.IllegalActionException
- If this operation is not
supported by the derived class.protected BooleanToken _isCloseTo(MatrixToken token, double distance) throws IllegalActionException
token
- The matrix token to compare to this token.distance
- The specified distance.IllegalActionException
- If a derived class throws it.protected BooleanToken _isEqualTo(MatrixToken rightArgument) throws IllegalActionException
rightArgument
- The token to compare to this token.IllegalActionException
- If this method is not
supported by a derived class.protected void _elementIsNil(int element)
element
- The element index. The format is rows * columnCount
+ column.protected MatrixToken _moduloElement(Token rightArgument) throws IllegalActionException
rightArgument
- The token that performs modulo on this token.IllegalActionException
- If this operation is not
supported by the derived class.protected MatrixToken _multiply(MatrixToken rightArgument) throws IllegalActionException
rightArgument
- The token to multiply this token by.IllegalActionException
- If this method is not
supported by the derived class.protected MatrixToken _multiplyElement(Token rightArgument) throws IllegalActionException
rightArgument
- The token to multiply this token by.IllegalActionException
- If this method is not
supported by the derived class.protected MatrixToken _subtract(MatrixToken rightArgument) throws IllegalActionException
rightArgument
- The token to subtract from this token.IllegalActionException
- If this method is not
supported by the derived class.protected MatrixToken _subtractElement(Token rightArgument) throws IllegalActionException
rightArgument
- The token to subtract from this token.IllegalActionException
- If this operation is not
supported by the derived class.protected MatrixToken _subtractElementReverse(Token rightArgument) throws IllegalActionException
rightArgument
- The token to subtract this token from.IllegalActionException
- If this operation is not
supported by the derived class.