Package ptolemy.data

Examples of ptolemy.data.ArrayToken


     @exception IllegalActionException If there is no director.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        if (input.hasToken(0)) {
            ArrayToken token = (ArrayToken) input.get(0);
            output.broadcast(new IntToken(token.length()));
        }
    }
View Full Code Here


        if (input.hasToken(0) && signature.hasToken(0) && (_publicKey != null)) {
            // Process the input data to generate a signature.
            byte[] signatureData = ArrayToken
                    .arrayTokenToUnsignedByteArray((ArrayToken) signature
                            .get(0));
            ArrayToken inputToken = (ArrayToken) input.get(0);

            try {
                _signature.initVerify(_publicKey);
                _signature.update(ArrayToken
                        .arrayTokenToUnsignedByteArray(inputToken));
View Full Code Here

     *   if sorting is not supported for the input array.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        if (input.hasToken(0)) {
            ArrayToken token = (ArrayToken) input.get(0);
            Type inputElementType = token.getElementType();
            if (token.length() == 0) {
                output.send(0, token);
                return;
            }

            boolean ascendingValue = ((BooleanToken) ascending.getToken())
                    .booleanValue();
            ArrayToken result = null;

            try {
                if (ascendingValue) {
                    result = UtilityFunctions.sort(token);
                } else {
                    result = UtilityFunctions.sortDescending(token);
                }
            } catch (ClassCastException ex) {
                // The call to sort() above throws ClassCastException if
                // sorting is not supported.  This is not ideal, so we
                // remap this to IllegalActionException.
                throw new IllegalActionException(this, ex.getMessage());
            }

            boolean allowDuplicatesValue = ((BooleanToken) allowDuplicates
                    .getToken()).booleanValue();

            if (!allowDuplicatesValue) {
                // Strip out duplicates.
                ArrayList list = new ArrayList();
                Token previous = result.getElement(0);
                list.add(previous);

                for (int i = 1; i < result.length(); i++) {
                    Token next = result.getElement(i);

                    if (!next.isEqualTo(previous).booleanValue()) {
                        list.add(next);
                        previous = next;
                    }
                }

                // Dummy array to give the run-time type to toArray().
                Token[] dummy = new Token[0];
                result = new ArrayToken(inputElementType, (Token[]) list
                        .toArray(dummy));
            }

            output.send(0, result);
        }
View Full Code Here

            if (width == 1) {
                for (int i = 0; i < newValues.length; i++) {
                    if (newValues[i] instanceof Token[]) {
                        // Handle width of 1, ArrayToken
                        newTokens[i] = new ArrayToken((Token[]) newValues[i]);
                    } else {
                        newTokens[i] = (Token) newValues[i];
                    }
                }
            } else {
                for (int i = 0; i < newValues.length; i++) {
                    ArrayList entry = (ArrayList) newValues[i];

                    // Entry may be an empty array, in which case,
                    // we cannot do the update, so we return.
                    if (entry.size() < 1) {
                        System.err.println("Warning: '" + getFullName()
                                + "': Unable to train. "
                                + "Zero tokens received in iteration " + i);
                        return;
                    }

                    Object[] entries = entry.toArray();
                    Token[] newEntry = new Token[entries.length];

                    for (int j = 0; j < entries.length; j++) {
                        newEntry[j] = (Token) entries[j];
                    }

                    newTokens[i] = new ArrayToken(newEntry);
                }
            }

            correctValues.setToken(new ArrayToken(newTokens));
            correctValues.setPersistent(true);
        }

        if (training
                && ((_trainingTokens == null) || (_trainingTokens.size() == 0))) {
View Full Code Here

            Token token2, double epsilon) throws IllegalActionException {
        if (!(token1 instanceof ArrayToken) || !(token2 instanceof ArrayToken)) {
            return false;
        }

        ArrayToken array1 = (ArrayToken) token1;
        ArrayToken array2 = (ArrayToken) token2;
        if (array1.length() != array2.length()) {
            return false;
        }

        for (int i = 0; i < array1.length(); i++) {
            // Here is where isCloseTo() differs from isEqualTo().
            // Note that we return false the first time we hit an
            // element token that is not close to our current element token.
            BooleanToken result = array1.getElement(i).isCloseTo(
                    array2.getElement(i), epsilon);

            // If the tokens are not close and array1[i] and is not nil, then
            // the arrays really aren't close.
            if (result.booleanValue() == false) {
                if (array1.getElement(i).isNil()
                        && array2.getElement(i).isNil()) {
                    // They are not close, but both are nil, so for
                    // our purposes, the are close.
                } else {
                    return false;
                }
View Full Code Here

        for (int i = 0; i < size; i++) {
            valueArray[i] = input.get(i);
        }

        output.send(0, new ArrayToken(input.getType(), valueArray));
    }
View Full Code Here

            if (dir != null) {
                dir.requestInitialization(this);
            }
        } else if (attribute == denominator) {
            // Check that a_0 is not 0.0
            ArrayToken aToken = (ArrayToken) (denominator.getToken());

            if (((DoubleToken) aToken.getElement(0)).doubleValue() == 0.0) {
                throw new IllegalActionException(this,
                        "The denominator coefficient cannot start with 0.");
            }

            // Set this composite to opaque.
View Full Code Here

     *  or any contained actors throw it in its preinitialize() method
     *  .
     */
    public void preinitialize() throws IllegalActionException {
        // Construct local double[] and Check dimensions.
        ArrayToken bToken = (ArrayToken) numerator.getToken();
        int m = bToken.length();
        double[] bRow = new double[m];

        for (int i = 0; i < m; i++) {
            bRow[i] = ((DoubleToken) bToken.getElement(i)).doubleValue();
        }

        ArrayToken aToken = (ArrayToken) denominator.getToken();
        int n = aToken.length();
        double[] a = new double[n];

        for (int i = 0; i < n; i++) {
            a[i] = ((DoubleToken) aToken.getElement(i)).doubleValue();
        }

        if (m > n) {
            throw new IllegalActionException(this,
                    "The order of the denominator must be greater than or "
View Full Code Here

        super(container, name);

        StringToken[] empty = new StringToken[1];
        stateVariableNames = new Parameter(this, "stateVariableNames");
        empty[0] = new StringToken("");
        stateVariableNames.setToken(new ArrayToken(BaseType.STRING, empty));
        initialStates = new Parameter(this, "initialStates");
        initialStates.setTypeEquals(BaseType.DOUBLE_MATRIX);

        setClassName("ptolemy.domains.ct.lib.DifferentialSystem");
View Full Code Here

     */
    public void preinitialize() throws IllegalActionException {
        // Check parameters.
        _checkParameters();

        ArrayToken stateNames = (ArrayToken) stateVariableNames.getToken();
        int n = stateNames.length();
        int m = inputPortList().size();
        int r = outputPortList().size();

        // FIXME: Why does this get the token and then do nothing with the value?
        //DoubleMatrixToken initial = (DoubleMatrixToken) initialStates
        //        .getToken();

        try {
            _workspace.getWriteAccess();
            removeAllEntities();
            removeAllRelations();

            // Create the model
            Integrator[] integrators = new Integrator[n];
            String[] states = new String[n];
            IORelation[] stateRelations = new IORelation[n];
            Expression[] equations = new Expression[n];

            // Integrators and feedback expressions
            for (int i = 0; i < n; i++) {
                states[i] = ((StringToken) stateNames.getElement(i))
                        .stringValue().trim();
                integrators[i] = new Integrator(this, states[i]);
                integrators[i].initialState.setExpression("initialStates(0,"
                        + i + ")");
                stateRelations[i] = new TypedIORelation(this, "relation_"
View Full Code Here

TOP

Related Classes of ptolemy.data.ArrayToken

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.