Package ptolemy.data.type

Examples of ptolemy.data.type.Type


     */
    public final Token multiplyReverse(Token leftArgument)
            throws IllegalActionException {
        // Get the corresponding element type for this matrix type,
        // and try a scalar operation.
        Type elementType = getElementType();
        int typeInfo = TypeLattice.compare(leftArgument, elementType);

        if (typeInfo == CPO.LOWER) {
            Token convertedArgument = elementType.convert(leftArgument);

            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, leftArgument));
            }
        } else if (typeInfo == CPO.SAME) {
            Token result = _multiplyElement(leftArgument);
            return result;
        }

        // Must be a matrix or incomparable.
        typeInfo = TypeLattice.compare(leftArgument, getType());

        // We would normally expect this to be LOWER, since this will almost
        // always be called by subtract, so put that case first.
        if (typeInfo == CPO.LOWER) {
            MatrixToken convertedArgument = (MatrixToken) getType().convert(
                    leftArgument);

            try {
                Token result = convertedArgument._doMultiply(this);
                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(
                        "multiplyReverse", this, leftArgument));
            }
        } else if (typeInfo == CPO.SAME) {
            Token result = ((MatrixToken) leftArgument)._doMultiply(this);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            Token result = leftArgument.multiply(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(), leftArgument.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()))) {
View Full Code Here


     */
    public final Token subtract(Token rightArgument)
            throws IllegalActionException {
        // 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 = _subtractElement(rightArgument);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            Token convertedArgument = elementType.convert(rightArgument);

            try {
                Token result = _subtractElement(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(
                        "subtract", this, rightArgument));
            }
        }

        // If we get here, then either our element type is lower than
        // the rightArgument or incomparable to it.
        typeInfo = TypeLattice.compare(getType(), rightArgument);

        if (typeInfo == CPO.SAME) {
            Token result = _doSubtract(rightArgument);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            MatrixToken convertedArgument = (MatrixToken) getType().convert(
                    rightArgument);

            try {
                Token result = _doSubtract(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(
                        "subtract", this, rightArgument));
            }
        } else if (typeInfo == CPO.LOWER) {
            Token result = rightArgument.subtractReverse(this);
            return result;
        } else {
            // Items being subracted are incomparable.
            // However, subtraction 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()))) {
View Full Code Here

     */
    public final Token subtractReverse(Token leftArgument)
            throws IllegalActionException {
        // Get the corresponding element type for this matrix type,
        // and try a scalar operation.
        Type elementType = getElementType();
        int typeInfo = TypeLattice.compare(leftArgument, elementType);

        if (typeInfo == CPO.LOWER) {
            Token convertedArgument = elementType.convert(leftArgument);

            try {
                Token result = _subtractElementReverse(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(
                        "subtract", this, leftArgument));
            }
        } else if (typeInfo == CPO.SAME) {
            Token result = _subtractElementReverse(leftArgument);
            return result;
        }

        // If we get here, then either our element type is lower than
        // the rightArgument or incomparable to it.
        typeInfo = TypeLattice.compare(leftArgument, getType());

        // We would normally expect this to be LOWER, since this will almost
        // always be called by subtract, so put that case first.
        if (typeInfo == CPO.LOWER) {
            MatrixToken convertedArgument = (MatrixToken) getType().convert(
                    leftArgument);

            try {
                Token result = convertedArgument._doSubtract(this);
                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(
                        "subtractReverse", this, leftArgument));
            }
        } else if (typeInfo == CPO.SAME) {
            Token result = ((MatrixToken) leftArgument)._doSubtract(this);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            Token result = leftArgument.subtract(this);
            return result;
        } else {
            // Items being subtracted are incomparable.
            // However, subtraction may still be possible because
            // the LUB of the types might support it. E.g., complex-[double],
            // where the LUB is [complex].
            Type lubType = (Type) TypeLattice.lattice().leastUpperBound(
                    getType(), leftArgument.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()))) {
View Full Code Here

     @param type The type of the argument to the corresponding function.
     *  @return The type of the value returned from the corresponding function.
     */
    public static Type toArrayReturnType(Type type) {
        if (type instanceof MatrixType) {
            Type elementType = ((MatrixType) type).getElementType();
            return new ArrayType(elementType);
        } else {
            return BaseType.UNKNOWN;
        }
    }
View Full Code Here

     *   does not make sense for the given types.
     */
    public Token add(Token rightArgument) throws IllegalActionException {
        // 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 = _addElement(rightArgument);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            Token convertedArgument = elementType.convert(rightArgument);

            try {
                Token result = _addElement(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(
                        "add", this, rightArgument));
            }
        }

        // If we get here, then either our element type is lower than
        // the rightArgument or incomparable to it.
        typeInfo = TypeLattice.compare(getType(), rightArgument);

        if (typeInfo == CPO.SAME) {
            Token result = _doAdd(rightArgument);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            MatrixToken convertedArgument = (MatrixToken) getType().convert(
                    rightArgument);

            try {
                Token result = _doAdd(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(
                        "add", this, rightArgument));
            }
        } else if (typeInfo == CPO.LOWER) {
            Token result = rightArgument.addReverse(this);
            return result;
        } else {
            // Items being added are incomparable.
            // However, addition 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()))) {
View Full Code Here

     */
    public Token addReverse(ptolemy.data.Token leftArgument)
            throws IllegalActionException {
        // Get the corresponding element type for this matrix type,
        // and try a scalar operation.
        Type elementType = getElementType();
        int typeInfo = TypeLattice.compare(leftArgument, elementType);

        if (typeInfo == CPO.LOWER) {
            Token convertedArgument = elementType.convert(leftArgument);

            try {
                Token result = _addElement(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(
                        "add", this, leftArgument));
            }
        } else if (typeInfo == CPO.SAME) {
            Token result = _addElement(leftArgument);
            return result;
        }

        // If we get here, then either our element type is lower than
        // the leftArgument or incomparable to it.
        typeInfo = TypeLattice.compare(leftArgument, getType());

        // We would normally expect this to be LOWER, since this will almost
        // always be called by subtract, so put that case first.
        if (typeInfo == CPO.LOWER) {
            MatrixToken convertedArgument = (MatrixToken) getType().convert(
                    leftArgument);

            try {
                Token result = convertedArgument._doAdd(this);
                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(
                        "addReverse", this, leftArgument));
            }
        } else if (typeInfo == CPO.SAME) {
            Token result = ((MatrixToken) leftArgument)._doAdd(this);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            Token result = leftArgument.add(this);
            return result;
        } else {
            // Items being added are incomparable.
            // However, addition may still be possible because
            // the LUB of the types might support it. E.g., complex+[double],
            // where the LUB is [complex].
            Type lubType = (Type) TypeLattice.lattice().leastUpperBound(
                    getType(), leftArgument.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()))) {
View Full Code Here

    public static MatrixToken arrayToMatrix(Token[] tokens, int rows,
            int columns) throws IllegalActionException {
        Object[] typeTerms = new Object[tokens.length];

        // Find the first non-nil element and get its type
        Type baseType = BaseType.GENERAL;
        for (int i = 0; i < tokens.length; i++) {
            if (!tokens[i].isNil()) {
                baseType = tokens[i].getType();
                break;
            }
        }

        // If a token is nil, then default to the first type that we
        // found.
        for (int i = 0; i < tokens.length; i++) {
            if (tokens[i].isNil()) {
                typeTerms[i] = baseType;
            } else {
                typeTerms[i] = tokens[i].getType();
            }
        }

        Type type = (Type) TypeLattice.lattice().leastUpperBound(typeTerms);

        return arrayToMatrix(type, tokens, rows, columns);
    }
View Full Code Here

     */
    public static Type arrayToMatrixReturnType(Type type1, Type type2,
            Type type3) throws IllegalActionException {
        // FIXME: why are type2 and type3 isgnored here?
        if (type1 instanceof ArrayType) {
            Type elementType = ((ArrayType) type1).getElementType();
            return MatrixType.getMatrixTypeForElementType(elementType);
        } else {
            return BaseType.UNKNOWN;
        }
    }
View Full Code Here

     */
    public final Token divide(Token rightArgument)
            throws IllegalActionException {
        // 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 = _divideElement(rightArgument);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            Token convertedArgument = elementType.convert(rightArgument);

            try {
                Token result = _divideElement(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(
                        "divide", this, rightArgument));
            }
        }

        // If we get here, then either our element type is lower than
        // the rightArgument or incomparable to it.
        typeInfo = TypeLattice.compare(getType(), rightArgument);

        if (typeInfo == CPO.SAME
                && ((MatrixToken) rightArgument).getRowCount() == 1
                && ((MatrixToken) rightArgument).getColumnCount() == 1) {
            // Dividing a matrix by a matrix. If the divisor has
            // only one element, then this is OK.
            return _divideElement(rightArgument);
        } else if (typeInfo == CPO.HIGHER
                && ((MatrixToken) rightArgument).getRowCount() == 1
                && ((MatrixToken) rightArgument).getColumnCount() == 1) {
            // Dividing a matrix by something that can be converted
            // to a matrix, which if it has one element is OK.
            Token convertedArgument = getType().convert(rightArgument);

            try {
                return _divideElement(convertedArgument);
            } 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(
                        "divide", this, rightArgument));
            }
        } else if (typeInfo == CPO.INCOMPARABLE) {
            // Items being divided are incomparable.
            // However, division 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()))) {
View Full Code Here

         notSupportedMessage("modulo", this, rightArgument));
         */

        // Get the corresponding element type for this matrix type,
        // and try a scalar operation.
        Type elementType = getElementType();

        /*
         // If this is a complex array, throw an error message as modulo
         // can't be performed on it
         if (elementType == BaseType.COMPLEX)
         throw new IllegalActionException(
         notSupportedMessage("modulo", this, rightArgument));
         */
        int typeInfo = TypeLattice.compare(elementType, rightArgument);

        if (typeInfo == CPO.SAME) {
            Token result = _moduloElement(rightArgument);
            return result;
        } else if (typeInfo == CPO.HIGHER) {
            Token convertedArgument = elementType.convert(rightArgument);

            try {
                Token result = _moduloElement(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(
                        "modulo", this, rightArgument));
            }
        }

        // If we get here, then either our element type is lower than
        // the rightArgument or incomparable to it.
        typeInfo = TypeLattice.compare(getType(), rightArgument);

        if (typeInfo == CPO.SAME) {
            // Dividing a matrix by a matrix. If the divisor has
            // only one element, then this is OK.
            return _moduloElement(rightArgument);
        } else if (typeInfo == CPO.HIGHER) {
            // Dividing a matrix by something that can be converted
            // to a matrix, which if it has one element is OK.
            Token convertedArgument = getType().convert(rightArgument);

            try {
                return _moduloElement(convertedArgument);
            } 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(
                        "modulo", this, rightArgument));
            }
        } else if (typeInfo == CPO.INCOMPARABLE) {
            // Items being added are incomparable.
            // However, division 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()))) {
View Full Code Here

TOP

Related Classes of ptolemy.data.type.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.