Search in sources :

Example 91 with Operator

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

the class SquareRoot method determineExponent.

public void determineExponent(ExponentContext context) {
    Operator op = operands[0];
    op.determineExponent(context);
    if (op.exponent == UNKNOWN)
        return;
    int pow = op.centerPower() / 2;
    int centerNew = MSB / 2;
    int exponentNew = pow + MSB - centerNew;
    updateExponent(context, exponentNew, centerNew);
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 92 with Operator

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

the class SumSquares method determineExponentNext.

public void determineExponentNext() {
    // A
    Operator op0 = operands[0];
    op0.exponentNext = op0.exponent;
    op0.determineExponentNext();
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 93 with Operator

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

the class SumSquares method determineExponent.

public void determineExponent(ExponentContext context) {
    // This function is related to both Norm and Power. See those classes for similar processing.
    // A
    Operator op0 = operands[0];
    op0.determineExponent(context);
    // Determine number of elements in A
    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();
    if (op0.exponent != UNKNOWN) {
        // log2(Asize)
        int shift = (int) Math.floor(Math.log(Asize) / Math.log(2));
        int centerNew = MSB / 2;
        int exponentNew = op0.centerPower() * 2 + shift + MSB - centerNew;
        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)

Example 94 with Operator

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

the class Uniform method determineExponent.

public void determineExponent(ExponentContext context) {
    if (operands.length == 0) {
        // Current implementation never quite reaches 1, only [0,1).
        updateExponent(context, -1, MSB);
        return;
    }
    for (int i = 0; i < operands.length; i++) operands[i].determineExponent(context);
    if (operands.length == 1) {
        Operator op = operands[0];
        if (op.exponent != UNKNOWN)
            updateExponent(context, op.exponent, op.center);
        return;
    }
    // operands.length >= 2
    // lo
    Operator op0 = operands[0];
    // hi
    Operator op1 = operands[1];
    int exp = Math.max(op0.exponent, op1.exponent);
    int cent = (op0.center + op1.center) / 2;
    if (exp != UNKNOWN)
        updateExponent(context, exp, cent);
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 95 with Operator

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

the class AND method simplify.

public Operator simplify(Variable from, boolean evalOnly) {
    Operator result = super.simplify(from, evalOnly);
    if (result != this)
        return result;
    if (operand0.isScalar()) {
        from.changed = true;
        result = operand1;
        if (operand0.getDouble() == 0) {
            if (!evalOnly)
                operand1.releaseDependencies(from);
            result = new Constant(0);
        }
        result.parent = parent;
        return result;
    } else if (operand1.isScalar()) {
        from.changed = true;
        result = operand0;
        if (operand1.getDouble() == 0) {
            if (!evalOnly)
                operand0.releaseDependencies(from);
            result = new Constant(0);
        }
        result.parent = parent;
        return result;
    }
    return this;
}
Also used : Operator(gov.sandia.n2a.language.Operator) Constant(gov.sandia.n2a.language.Constant)

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