public final Token multiply(Token rightArgument)
throws IllegalActionException {
// MatrixType type = (MatrixType)getType();
// Get the corresponding element type for this matrix type,
// and try a scalar operation.
Type elementType = getElementType();
int typeInfo = TypeLattice.compare(elementType, rightArgument);
if (typeInfo == CPO.SAME) {
Token result = _multiplyElement(rightArgument);
return result;
} else if (typeInfo == CPO.HIGHER) {
Token convertedArgument = elementType.convert(rightArgument);
try {
Token result = _multiplyElement(convertedArgument);
return result;
} catch (IllegalActionException ex) {
// If the type-specific operation fails, then create a better
// error message that has the types of the arguments that were
// passed in.
throw new IllegalActionException(null, ex, notSupportedMessage(
"multiply", this, rightArgument));
}
}
// Argument must be a matrix or incomparable.
typeInfo = TypeLattice.compare(getType(), rightArgument);
if (typeInfo == CPO.SAME) {
Token result = _doMultiply(rightArgument);
return result;
} else if (typeInfo == CPO.HIGHER) {
MatrixToken convertedArgument = (MatrixToken) getType().convert(
rightArgument);
try {
Token result = _doMultiply(convertedArgument);
return result;
} catch (IllegalActionException ex) {
// If the type-specific operation fails, then create a
// better error message that has the types of the
// arguments that were passed in.
throw new IllegalActionException(null, ex, notSupportedMessage(
"multiply", this, rightArgument));
}
} else if (typeInfo == CPO.LOWER) {
Token result = rightArgument.multiplyReverse(this);
return result;
} else {
// Items being multiplied are incomparable.
// However, multiplication may still be possible because
// the LUB of the types might support it. E.g., [double]*complex,
// where the LUB is [complex].
Type lubType = (Type) TypeLattice.lattice().leastUpperBound(
getType(), rightArgument.getType());
// If the LUB is a new type, try it.
if (!lubType.equals(getType())) {
Token lub = lubType.convert(this);
// Caution: convert() might return this again, e.g.
// if lubType is general. Only proceed if the conversion
// returned a new type.
if (!(lub.getType().equals(getType()))) {