Examples of DoubleMatrixToken


Examples of ptolemy.data.DoubleMatrixToken

     @exception IllegalActionException If there is a problem
     *   playing audio.
     */
    public boolean postfire() throws IllegalActionException {
        if (input.hasToken(0)) {
            DoubleMatrixToken token = (DoubleMatrixToken) input.get(0);
            double[][] data = token.doubleMatrix();

            // This method is most efficient if repeated calls pass the same size
            // array. In this case, it does not re-allocate the byte array that
            // it returns, but rather reuses the same array on the heap.
            int numberOfSamples = data[0].length;
View Full Code Here

Examples of ptolemy.data.DoubleMatrixToken

        } else if (object instanceof int[][]) {
            returnValue = new IntMatrixToken((int[][]) object);
        } else if (object instanceof long[][]) {
            returnValue = new LongMatrixToken((long[][]) object);
        } else if (object instanceof double[][]) {
            returnValue = new DoubleMatrixToken((double[][]) object);
        } else if (object instanceof Complex[][]) {
            returnValue = new ComplexMatrixToken((Complex[][]) object);
        } else if (object instanceof FixPoint[][]) {
            returnValue = new FixMatrixToken((FixPoint[][]) object);
        } else if (object instanceof double[]) {
View Full Code Here

Examples of ptolemy.data.DoubleMatrixToken

                // The following conversion will fail if the member cannot
                // be converted to an int.
                DoubleToken singleMember = DoubleToken.convert(token);
                double[] matrix = new double[1];
                matrix[0] = singleMember.doubleValue();
                return new DoubleMatrixToken(matrix, 1, 1);
            }
        }
View Full Code Here

Examples of ptolemy.data.DoubleMatrixToken

                result[i][j] = (raw * standardDeviation) + mean;
            }
        }

        try {
            return new DoubleMatrixToken(result);
        } catch (IllegalActionException illegalAction) {
            // This should not happen since result should not be null.
            throw new InternalErrorException("UtilityFunction.gaussian: "
                    + "Cannot create the DoubleMatrixToken that contains "
                    + "Gaussian random numbers.");
View Full Code Here

Examples of ptolemy.data.DoubleMatrixToken

                result[i][j] = Math.random();
            }
        }

        try {
            return new DoubleMatrixToken(result);
        } catch (IllegalActionException illegalAction) {
            // This should not happen since result should not be null.
            throw new InternalErrorException("UtilityFunction.random: "
                    + "Cannot create the DoubleMatrixToken that contains "
                    + "random numbers.");
View Full Code Here

Examples of ptolemy.data.DoubleMatrixToken

     @exception IllegalActionException If the file cannot be opened.
     *  @deprecated Use eval(readFile()) instead.
     */
    public static DoubleMatrixToken readMatrix(String filename)
            throws IllegalActionException {
        DoubleMatrixToken returnMatrix = null;

        File file = new File(filename);
        FileReader fin = null;

        // Vector containing the matrix
        Vector k = null;

        // Parameters for the Matrix
        int row = -1;
        int column = -1;

        int rowPosition = 0;
        int columnPosition = 0;
        double[][] mtr = null;

        if (file.exists()) {
            try {
                // Open the matrix file
                fin = new FileReader(file);
            } catch (FileNotFoundException e) {
                throw new IllegalActionException("FIle Not FOUND");
            }

            // Read the file and convert it into a matrix
            if (_matrixParser == null) {
                _matrixParser = new MatrixParser(System.in);
            }

            MatrixParser.ReInit(fin);
            k = _matrixParser.readMatrix();

            if (column == -1) {
                // The column size of the matrix
                column = k.size();
            }

            Iterator i = k.iterator();

            while (i.hasNext()) {
                Vector l = (Vector) i.next();

                if (row == -1) {
                    // the row size.
                    row = l.size();

                    // create a new matrix definition
                    mtr = new double[column][row];
                } else {
                    if (row != l.size()) {
                        throw new IllegalActionException(" The Row"
                                + " size needs to be the same for all"
                                + " rows");
                    }
                }

                Iterator j = l.iterator();

                while (j.hasNext()) {
                    Double s = (Double) j.next();
                    mtr[columnPosition][rowPosition++] = s.doubleValue();
                }

                rowPosition = 0;
                columnPosition++;
            }

            // Vectors have now become obsolete, data is stored
            // in double[][].
            k.removeAll(k);
            returnMatrix = new DoubleMatrixToken(mtr);
        } else {
            throw new IllegalActionException("ReadMatrix: File " + filename
                    + " not Found");
        }

View Full Code Here

Examples of ptolemy.data.DoubleMatrixToken

     @return The zero matrix with the given number of rows and
     *   columns.
     */
    public static DoubleMatrixToken zeroMatrixDouble(int rows, int columns) {
        double[][] mtr = new double[rows][columns];
        DoubleMatrixToken result = null;

        try {
            result = new DoubleMatrixToken(mtr, DoubleMatrixToken.DO_NOT_COPY);
        } catch (IllegalActionException ex) {
            throw new InternalErrorException("UtilityFunctions"
                    + ".zeroMatrixDouble: "
                    + "Cannot create DoubleMatrixToken. " + ex.getMessage());
        }
View Full Code Here

Examples of ptolemy.data.DoubleMatrixToken

        initialStates = new Parameter(this, "initialStates");
        initialStates.setExpression("[0.0]");
        initialStates.setTypeEquals(BaseType.DOUBLE_MATRIX);

        double[][] zero = { { 0.0 } };
        _x = new DoubleMatrixToken(zero);
        _initialStateChanged = true;

        // icon
        _attachText("_iconDescription", "<svg>\n"
                + "<rect x=\"-75\" y=\"-30\" " + "width=\"150\" height=\"60\" "
View Full Code Here

Examples of ptolemy.data.DoubleMatrixToken

     */
    public void attributeChanged(Attribute attribute)
            throws IllegalActionException {
        if (attribute == A) {
            // Check that it is a square matrix.
            DoubleMatrixToken token = (DoubleMatrixToken) A.getToken();

            if ((token.getRowCount() == 0) || (token.getColumnCount() == 0)
                    || (token.getRowCount() != token.getColumnCount())) {
                throw new IllegalActionException(this,
                        "The A matrix must be a nonempty square matrix.");
            }
        } else if (attribute == B) {
            // Check that B is a matrix.
            DoubleMatrixToken token = (DoubleMatrixToken) B.getToken();

            if ((token.getRowCount() == 0) || (token.getColumnCount() == 0)) {
                throw new IllegalActionException(this,
                        "The B matrix must be a nonempty matrix.");
            }
        } else if (attribute == C) {
            // Check that C is a matrix.
            DoubleMatrixToken token = (DoubleMatrixToken) C.getToken();

            if ((token.getRowCount() == 0) || (token.getColumnCount() == 0)) {
                throw new IllegalActionException(this,
                        "The C matrix must be a nonempty matrix.");
            }
        } else if (attribute == D) {
            DoubleMatrixToken token = (DoubleMatrixToken) D.getToken();

            if ((token.getRowCount() == 0) || (token.getColumnCount() == 0)) {
                throw new IllegalActionException(this,
                        "The D matrix must be a nonempty matrix.");
            }
        } else if (attribute == initialStates) {
            // The initialStates parameter should be a row vector.
            DoubleMatrixToken token = (DoubleMatrixToken) initialStates
                    .getToken();

            if ((token.getColumnCount() != 1) || (token.getRowCount() < 1)) {
                throw new IllegalActionException(this,
                        "The initialStates must be a column vector.");
            }

            _initialStateChanged = true;
View Full Code Here

Examples of ptolemy.data.DoubleMatrixToken

     *  match.
     */
    public void preinitialize() throws IllegalActionException {
        super.preinitialize();

        DoubleMatrixToken a = (DoubleMatrixToken) A.getToken();
        int n = a.getRowCount();
        DoubleMatrixToken b = (DoubleMatrixToken) B.getToken();

        if (b.getRowCount() != n) {
            throw new IllegalActionException(this,
                    "The number of rows of the B matrix should equal to "
                            + "the number of rows of the A matrix.");
        }

        if (n == 1) {
            _singleState = true;
            state.setTypeEquals(BaseType.DOUBLE);
        } else {
            _singleState = false;
            state.setTypeEquals(BaseType.DOUBLE_MATRIX);
        }

        int m = b.getColumnCount();

        if (m == 1) {
            input.setTypeEquals(BaseType.DOUBLE);
        } else {
            input.setTypeEquals(BaseType.DOUBLE_MATRIX);
        }

        DoubleMatrixToken c = (DoubleMatrixToken) C.getToken();

        if (c.getColumnCount() != n) {
            throw new IllegalActionException(this,
                    "The number of columns of the C matrix should equal to "
                            + "the number of rows of the A matrix.");
        }

        int r = c.getRowCount();

        if (r == 1) {
            _singleOutput = true;
            output.setTypeEquals(BaseType.DOUBLE);
        } else {
            _singleOutput = false;
            output.setTypeEquals(BaseType.DOUBLE_MATRIX);
        }

        DoubleMatrixToken d = (DoubleMatrixToken) D.getToken();

        if (c.getRowCount() != d.getRowCount()) {
            throw new IllegalActionException(this,
                    "The number of rows of the D matrix should equal to "
                            + "the number of rows of the C matrix.");
        }

        DoubleMatrixToken x0 = (DoubleMatrixToken) initialStates.getToken();

        if (x0.getRowCount() != n) {
            throw new IllegalActionException(this,
                    "The number of initial states should equal to "
                            + "the number of columns of the A matrix.");
        }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.