Package ptolemy.data

Examples of ptolemy.data.ArrayToken


                        .get(jj)).intValue();
            }
        }

        if (data.hasToken(0)) {
            ArrayToken dataArrayToken = (ArrayToken) data.get(0);

            byte[] dataBytes = new byte[dataArrayToken.length()];

            for (int j = 0; j < dataArrayToken.length(); j++) {
                UnsignedByteToken token = (UnsignedByteToken) dataArrayToken
                        .getElement(j);
                dataBytes[j] = token.byteValue();
            }

            DatagramPacket packet = new DatagramPacket(dataBytes,
View Full Code Here


     @exception IllegalActionException If the input is not a decodable code.
     */
    public void fire() throws IllegalActionException {
        super.fire();

        ArrayToken alphabetArrayToken = (ArrayToken) alphabet.getToken();
        Token[] alphabetTokens = new Token[_pmf.length];

        for (int i = 0; i < _pmf.length; i++) {
            alphabetTokens[i] = alphabetArrayToken.getElement(i);
        }

        // Get the input token. Ready for output.
        if (!input.hasToken(0) && !_code.equals("")) {
            throw new IllegalActionException(this,
View Full Code Here

     *  encode the input into booleans and send them to the output port.
     */
    public void fire() throws IllegalActionException {
        super.fire();

        ArrayToken alphabetArrayToken = (ArrayToken) alphabet.getToken();
        Token[] alphabetTokens = new Token[_pmf.length];

        for (int i = 0; i < _pmf.length; i++) {
            alphabetTokens[i] = alphabetArrayToken.getElement(i);
        }

        // Get the input token. Ready for output.
        Token inputToken = input.get(0);

View Full Code Here

    public void attributeChanged(Attribute attribute)
            throws IllegalActionException {
        _parametersInvalid = true;

        if (attribute == pmf) {
            ArrayToken pmfValue = (ArrayToken) pmf.getToken();
            _pmf = new double[pmfValue.length()];

            double sum = 0.0;

            for (int i = 0; i < _pmf.length; i++) {
                _pmf[i] = ((DoubleToken) pmfValue.getElement(i)).doubleValue();

                if (_pmf[i] <= 0.0) {
                    throw new IllegalActionException(this,
                            "Probabilities must be positive!");
                }
View Full Code Here

    /** Generate the Huffman codebook for the given <i>pmf</i>, and
     *  encode the input into booleans and send them to the output port.
     */
    public void fire() throws IllegalActionException {
        super.fire();
        ArrayToken alphabetArrayToken = (ArrayToken) alphabet.getToken();

        if (_pmf.length != alphabetArrayToken.length()) {
            throw new IllegalActionException(this,
                    "uncoded alphabet and pmf are required to be arrays"
                            + "with same length.");
        }

        Token[] alphabetTokens = new Token[_pmf.length];

        for (int i = 0; i < _pmf.length; i++) {
            alphabetTokens[i] = alphabetArrayToken.getElement(i);
        }

        if (_parametersInvalid) {
            _parametersInvalid = false;
            _codeBook = generateCodeBook(_pmf);

            // FIXME: only produce the code book if the parameters
            // have been updated.
            StringToken[] codeBookTokens = new StringToken[_pmf.length];

            for (int i = 0; i < _pmf.length; i++) {
                codeBookTokens[i] = new StringToken(_codeBook[i]);
            }

            huffmanCodeBook.send(0, new ArrayToken(BaseType.STRING,
                    codeBookTokens));
        }
    }
View Full Code Here

     *   increasing.
     */
    public void attributeChanged(Attribute attribute)
            throws IllegalActionException {
        if (attribute == levels) {
            ArrayToken levelsValue = (ArrayToken) levels.getToken();
            double[] _levels = new double[levelsValue.length()];
            double previous = Double.NEGATIVE_INFINITY;

            for (int i = 0; i < levelsValue.length(); i++) {
                _levels[i] = ((DoubleToken) levelsValue.getElement(i))
                        .doubleValue();

                // Check nondecreasing property.
                if (_levels[i] < previous) {
                    throw new IllegalActionException(this,
View Full Code Here

        for (int i = 0; i < _bins.length; i++) {
            values[i] = new IntToken(_bins[i]);
        }

        output.send(0, new ArrayToken(BaseType.INT, values));
    }
View Full Code Here

            _inputNumberInvalid = true;

            // Set the input consumption rate.
            _inputRate.setToken(new IntToken(_inputNumber));
        } else if (attribute == polynomialArray) {
            ArrayToken maskToken = ((ArrayToken) polynomialArray.getToken());
            _maskNumber = maskToken.length();
            _mask = new int[_maskNumber];
            _maxPolyValue = 0;

            for (int i = 0; i < _maskNumber; i++) {
                _mask[i] = ((IntToken) maskToken.getElement(i)).intValue();

                if (_mask[i] <= 0) {
                    throw new IllegalActionException(this,
                            "Polynomial is required to be strictly positive.");
                }
View Full Code Here

                _reflectionCoefficientsCache[i] = 0.0;
            }
        }

        // Reinitialize the reflection coefficients from the parameter value.
        ArrayToken value = (ArrayToken) reflectionCoefficients.getToken();
        for (int i = 0; i < _order; i++) {
            _reflectionCoefficients[i] = ((DoubleToken) value.getElement(i))
                    .doubleValue();
        }
    }
View Full Code Here

            outputArray[i - 1] = new DoubleToken(newCoefficient);
            _reflectionCoefficientsCache[i - 1] = newCoefficient;
            _estimatedErrorPowerCache[i] = newError;
        }

        adaptedReflectionCoefficients.send(0, new ArrayToken(BaseType.DOUBLE,
                outputArray));
    }
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.