Search in sources :

Example 46 with Operator

use of gov.sandia.n2a.language.Operator in project n2a by frothga.

the class Input method determineExponentNext.

public void determineExponentNext() {
    String mode = getMode();
    boolean time = mode.contains("time") || mode.contains("smooth");
    if (operands.length > 1) {
        Operator op = operands[1];
        if (time)
            op.exponentNext = exponentTime;
        else
            // We expect an integer.
            op.exponentNext = MSB;
        op.determineExponentNext();
    }
    if (operands.length > 2) {
        Operator op = operands[2];
        // We expect an integer.
        op.exponentNext = MSB;
        op.determineExponentNext();
    }
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 47 with Operator

use of gov.sandia.n2a.language.Operator in project n2a by frothga.

the class Norm method determineExponent.

public void determineExponent(ExponentContext context) {
    // A
    Operator op0 = operands[0];
    op0.determineExponent(context);
    // n
    Operator op1 = null;
    if (operands.length > 1) {
        op1 = operands[1];
        op1.determineExponent(context);
    }
    Instance instance = new Instance() {

        // all AccessVariable objects will reach here first, and get back the Variable.type field
        public Type get(VariableReference r) throws EvaluationException {
            return r.variable.type;
        }
    };
    Matrix A = (Matrix) op0.eval(instance);
    int Asize = A.rows() * A.columns();
    int centerNew = center;
    int exponentNew = exponent;
    if (op0.exponent != UNKNOWN) {
        // For n==1 (sum of elements), which is the most expensive in terms of bits.
        int shift = (int) Math.floor(Math.log(Asize) / Math.log(2));
        // Don't shift center into negative territory.
        shift = Math.min(op0.center, shift);
        centerNew = op0.center - shift;
        exponentNew = op0.exponent + shift;
    }
    if (op1 instanceof Constant) {
        double n = op1.getDouble();
        if (n == 0) {
            // Result is an integer
            centerNew = 0;
            exponentNew = MSB;
        } else if (Double.isInfinite(n)) {
            centerNew = op0.center;
            exponentNew = op0.exponent;
        }
    // It would be nice to have some way to interpolate between the 3 bounding cases.
    }
    updateExponent(context, exponentNew, centerNew);
}
Also used : Operator(gov.sandia.n2a.language.Operator) Matrix(gov.sandia.n2a.language.type.Matrix) VariableReference(gov.sandia.n2a.eqset.VariableReference) Instance(gov.sandia.n2a.language.type.Instance) Constant(gov.sandia.n2a.language.Constant)

Example 48 with Operator

use of gov.sandia.n2a.language.Operator in project n2a by frothga.

the class Norm method determineExponentNext.

public void determineExponentNext() {
    // A
    Operator op0 = operands[0];
    op0.exponentNext = op0.exponent;
    op0.determineExponentNext();
    if (operands.length > 1) {
        // n
        Operator op1 = operands[1];
        op1.exponentNext = Operator.MSB / 2;
        op1.determineExponentNext();
    }
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 49 with Operator

use of gov.sandia.n2a.language.Operator in project n2a by frothga.

the class Atan method determineExponentNext.

public void determineExponentNext() {
    Operator y = operands[0];
    int next;
    if (operands.length == 1) {
        if (y.getType() instanceof Matrix) {
            next = y.exponent;
        } else {
            // atan(y) = atan2(y,1), so treat x as 1
            // If y is so small that all its bits are lost, then angle can be treated as zero.
            // If y is so large that all the bits of x are lost, then angle can be treated as pi.
            next = Math.max(0, y.exponent);
        }
    } else {
        Operator x = operands[1];
        next = Math.max(x.exponent, y.exponent);
        x.exponentNext = next;
        x.determineExponentNext();
    }
    y.exponentNext = next;
    y.determineExponentNext();
}
Also used : Operator(gov.sandia.n2a.language.Operator) Matrix(gov.sandia.n2a.language.type.Matrix)

Example 50 with Operator

use of gov.sandia.n2a.language.Operator in project n2a by frothga.

the class Delay method determineExponentNext.

public void determineExponentNext() {
    // Assumes that we simply output the same exponent as our inputs.
    exponent = exponentNext;
    Operator value = operands[0];
    // Passes the required exponent down to operands.
    value.exponentNext = exponentNext;
    value.determineExponentNext();
    if (operands.length > 1) {
        Operator delta = operands[1];
        // delta.exponentNext already set in determineExponent()
        delta.determineExponentNext();
    }
    if (operands.length > 2) {
        Operator defaultValue = operands[2];
        defaultValue.exponentNext = exponentNext;
        defaultValue.determineExponentNext();
    }
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Aggregations

Operator (gov.sandia.n2a.language.Operator)104 AccessVariable (gov.sandia.n2a.language.AccessVariable)41 Constant (gov.sandia.n2a.language.Constant)37 Visitor (gov.sandia.n2a.language.Visitor)26 Variable (gov.sandia.n2a.eqset.Variable)17 ArrayList (java.util.ArrayList)16 Type (gov.sandia.n2a.language.Type)14 Scalar (gov.sandia.n2a.language.type.Scalar)14 Output (gov.sandia.n2a.language.function.Output)13 EquationSet (gov.sandia.n2a.eqset.EquationSet)12 EquationEntry (gov.sandia.n2a.eqset.EquationEntry)10 Input (gov.sandia.n2a.language.function.Input)10 Text (gov.sandia.n2a.language.type.Text)10 Matrix (gov.sandia.n2a.language.type.Matrix)9 TreeSet (java.util.TreeSet)9 ReadMatrix (gov.sandia.n2a.language.function.ReadMatrix)8 Add (gov.sandia.n2a.language.operator.Add)8 BuildMatrix (gov.sandia.n2a.language.BuildMatrix)7 Event (gov.sandia.n2a.language.function.Event)7 Instance (gov.sandia.n2a.language.type.Instance)7