Package ptolemy.data.type
Class MatrixType
- java.lang.Object
-
- ptolemy.data.type.StructuredType
-
- ptolemy.data.type.MatrixType
-
- All Implemented Interfaces:
java.lang.Cloneable
,Type
- Direct Known Subclasses:
MatrixType.BooleanMatrixType
,MatrixType.ComplexMatrixType
,MatrixType.DoubleMatrixType
,MatrixType.FixMatrixType
,MatrixType.IntMatrixType
,MatrixType.LongMatrixType
public class MatrixType extends StructuredType implements java.lang.Cloneable
The base type of matrix token classes. This type functions as a union of the various matrix types. It allows for the creation of arrays that consist of diverse matrix types, because the array type will be {matrix}.- Since:
- Ptolemy II 5.2
- Version:
- $Id$
- Author:
- Steve Neuendorffer and Edward A. Lee
- Pt.AcceptedRating:
- Red
- Pt.ProposedRating:
- Red (yuhong)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MatrixType.BooleanMatrixType
The boolean matrix data type.static class
MatrixType.ComplexMatrixType
The complex matrix data type.static class
MatrixType.DoubleMatrixType
The double matrix data type.static class
MatrixType.FixMatrixType
The fix matrix data type.static class
MatrixType.IntMatrixType
The integer matrix data type.static class
MatrixType.LongMatrixType
The long matrix data type.
-
Field Summary
-
Fields inherited from class ptolemy.data.type.StructuredType
MAXDEPTHBOUND
-
Fields inherited from interface ptolemy.data.type.Type
HASH_INVALID
-
-
Constructor Summary
Constructors Constructor Description MatrixType(java.lang.Class c, Type type, java.lang.String name)
Construct a new matrix type that represents matrix tokens of the given class with the given number of rows and columns.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
_compare(StructuredType type)
Compare this type with the specified type.protected StructuredType
_getRepresentative()
Return a static instance of this structured type.protected StructuredType
_greatestLowerBound(StructuredType type)
Return the greatest lower bound of this type with the specified type.protected StructuredType
_leastUpperBound(StructuredType type)
Return the least upper bound of this type with the specified type.java.lang.Object
clone()
Return this, that is, return the reference to this object.Token
convert(Token token)
If the argument is an instance of this class or a subclass, then return the token.boolean
equals(java.lang.Object object)
Determine if the argument represents the same MatrixType as this object.Type
getElementType()
Return the type of the elements contained in an instance of this matrix type.static MatrixType
getMatrixTypeForElementType(Type elementType)
Return a matrix type whose element type is the given element type.java.lang.Class
getTokenClass()
Return the class for tokens that this type represents.int
hashCode()
Return a hash code value for this object.void
initialize(Type type)
Set the elements that have declared type BaseType.UNKNOWN to the specified type.boolean
isAbstract()
Return true if the element type is abstract.boolean
isCompatible(Type type)
Test if the argument type is compatible with this type.boolean
isConstant()
Test if this Type is a constant.boolean
isInstantiable()
Return true, indicating that instances of this type can exist.boolean
isSubstitutionInstance(Type type)
Test if the argument is a substitution instance of this type.java.lang.String
toString()
Return the string representation of this type.void
updateType(StructuredType newType)
Update this StructuredType to the specified Structured Type.-
Methods inherited from class ptolemy.data.type.StructuredType
add, depth, divide, getTypeHash, modulo, multiply, one, subtract, zero
-
-
-
-
Constructor Detail
-
MatrixType
public MatrixType(java.lang.Class c, Type type, java.lang.String name)
Construct a new matrix type that represents matrix tokens of the given class with the given number of rows and columns.- Parameters:
c
- The token class.type
- The element type.name
- The name.
-
-
Method Detail
-
clone
public java.lang.Object clone()
Return this, that is, return the reference to this object.- Specified by:
clone
in interfaceType
- Specified by:
clone
in classStructuredType
- Returns:
- A MatrixType.
-
convert
public Token convert(Token token) throws IllegalActionException
If the argument is an instance of this class or a subclass, then return the token. Otherwise, throw an exception.- Specified by:
convert
in interfaceType
- Parameters:
token
- A token.- Returns:
- An instance of this class.
- Throws:
IllegalActionException
- If the argument is not an instance of this class.
-
equals
public boolean equals(java.lang.Object object)
Determine if the argument represents the same MatrixType as this object.
-
getElementType
public Type getElementType()
Return the type of the elements contained in an instance of this matrix type. Tokens of the type returned by this method will be returned by the getElementAsToken of matrices that have this type. If this is an instance of this base class rather than the specific matrix types, then return null.- Returns:
- The type of the elements.
-
getMatrixTypeForElementType
public static MatrixType getMatrixTypeForElementType(Type elementType) throws IllegalActionException
Return a matrix type whose element type is the given element type.- Parameters:
elementType
- The type of the element.- Returns:
- The matrix type.
- Throws:
IllegalActionException
- If the elementType is not a type that has a corresponding matrix type.
-
getTokenClass
public java.lang.Class getTokenClass()
Return the class for tokens that this type represents.- Specified by:
getTokenClass
in interfaceType
- Returns:
- A class that represents a matrix token.
-
hashCode
public int hashCode()
Return a hash code value for this object.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- The hash code for the token class of this type.
-
initialize
public void initialize(Type type)
Set the elements that have declared type BaseType.UNKNOWN to the specified type.- Specified by:
initialize
in classStructuredType
- Parameters:
type
- A Type.
-
isAbstract
public boolean isAbstract()
Return true if the element type is abstract.- Specified by:
isAbstract
in interfaceType
- Overrides:
isAbstract
in classStructuredType
- Returns:
- True.
-
isCompatible
public boolean isCompatible(Type type)
Test if the argument type is compatible with this type. The method returns true if this type is UNKNOWN, since any type is a substitution instance of it. If this type is not UNKNOWN, this method returns true if the argument type is less than or equal to this type in the type lattice, and false otherwise.- Specified by:
isCompatible
in interfaceType
- Parameters:
type
- An instance of Type.- Returns:
- True if the argument is compatible with this type.
-
isConstant
public boolean isConstant()
Test if this Type is a constant. A Type is a constant if it does not contain BaseType.UNKNOWN in any level within it.- Specified by:
isConstant
in interfaceType
- Returns:
- False.
-
isInstantiable
public boolean isInstantiable()
Return true, indicating that instances of this type can exist.- Specified by:
isInstantiable
in interfaceType
- Returns:
- True.
-
isSubstitutionInstance
public boolean isSubstitutionInstance(Type type)
Test if the argument is a substitution instance of this type.- Specified by:
isSubstitutionInstance
in interfaceType
- Parameters:
type
- A Type.- Returns:
- False.
-
toString
public java.lang.String toString()
Return the string representation of this type.
-
updateType
public void updateType(StructuredType newType) throws IllegalActionException
Update this StructuredType to the specified Structured Type. The specified type must have the same structure as this type. This method will only update the component type that is BaseType.UNKNOWN, and leave the constant part of this type intact.- Overrides:
updateType
in classStructuredType
- Parameters:
newType
- A StructuredType.- Throws:
IllegalActionException
- If the specified type has a different structure.
-
_compare
protected int _compare(StructuredType type)
Compare this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown. This method returns one of ptolemy.graph.CPO.LOWER, ptolemy.graph.CPO.SAME, ptolemy.graph.CPO.HIGHER, ptolemy.graph.CPO.INCOMPARABLE, indicating this type is lower than, equal to, higher than, or incomparable with the specified type in the type hierarchy, respectively.- Specified by:
_compare
in classStructuredType
- Parameters:
type
- a StructuredType.- Returns:
- An integer.
- Throws:
java.lang.IllegalArgumentException
- If the specified type is not the same structured type as this one.
-
_getRepresentative
protected StructuredType _getRepresentative()
Return a static instance of this structured type. The return value is used by TypeLattice to represent this type.- Specified by:
_getRepresentative
in classStructuredType
- Returns:
- a StructuredType.
-
_greatestLowerBound
protected StructuredType _greatestLowerBound(StructuredType type)
Return the greatest lower bound of this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown.- Specified by:
_greatestLowerBound
in classStructuredType
- Parameters:
type
- a StructuredType.- Returns:
- a StructuredType.
- Throws:
java.lang.IllegalArgumentException
- If the specified type is not the same structured type as this one.
-
_leastUpperBound
protected StructuredType _leastUpperBound(StructuredType type)
Return the least upper bound of this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown.- Specified by:
_leastUpperBound
in classStructuredType
- Parameters:
type
- a StructuredType.- Returns:
- a StructuredType.
- Throws:
java.lang.IllegalArgumentException
- If the specified type is not the same structured type as this one.
-
-