Search in sources :

Example 71 with Operator

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

the class Max method simplify.

public Operator simplify(Variable from, boolean evalOnly) {
    Operator result = super.simplify(from, evalOnly);
    if (result != this)
        return result;
    // Check if Max appears as an operand. If so, merge its operands into ours
    ArrayList<Operator> newOperands = new ArrayList<Operator>(operands.length);
    boolean changed = false;
    for (Operator o : operands) {
        if (o instanceof Max) {
            Max m = (Max) o;
            newOperands.addAll(Arrays.asList(m.operands));
            changed = true;
        } else {
            newOperands.add(o);
        }
    }
    if (changed) {
        from.changed = true;
        Max newMax = new Max();
        newMax.parent = parent;
        newMax.operands = newOperands.toArray(new Operator[0]);
        for (Operator o : newMax.operands) o.parent = newMax;
        return newMax;
    }
    return this;
}
Also used : Operator(gov.sandia.n2a.language.Operator) ArrayList(java.util.ArrayList)

Example 72 with Operator

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

the class Norm method determineUnit.

public void determineUnit(boolean fatal) throws Exception {
    // A
    Operator op0 = operands[0];
    op0.determineUnit(fatal);
    unit = op0.unit;
    // n
    if (operands.length > 1)
        operands[1].determineUnit(fatal);
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 73 with Operator

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

the class Delay method determineExponent.

public void determineExponent(ExponentContext context) {
    for (int i = 0; i < operands.length; i++) operands[i].determineExponent(context);
    // value to delay
    Operator value = operands[0];
    updateExponent(context, value.exponent, value.center);
    // Need to record the exponent for time, since we avoid passing context to determineExponentNext().
    if (operands.length > 1)
        operands[1].exponentNext = context.exponentTime;
// Assume that defaultValue is representable in the same range as value,
// so don't bother incorporating it into the estimate of our output exponent.
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 74 with Operator

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

the class Gaussian method determineExponent.

public void determineExponent(ExponentContext context) {
    if (operands.length > 0) {
        Operator op = operands[0];
        op.determineExponent(context);
        if (op.exponent != UNKNOWN)
            updateExponent(context, op.exponent, op.center);
    } else {
        // The largest Gaussian PRNG output is determined by the bit precision of the underlying
        // uniform PRNG output. The Box-Muller implementation in the C Backend runtime will not
        // exceed 6.66 standard deviations when using 32-bit uniform numbers. Thus, 7 std is safe.
        // log2(7)~=2.81, so magnitude of msb is 2
        // Since about 68% of all results are less than 1 sigma, center can point to bit holding 2^-1.
        updateExponent(context, 2, MSB - 3);
    }
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 75 with Operator

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

the class Gaussian method simplify.

public Operator simplify(Variable from, boolean evalOnly) {
    if (operands.length > 0) {
        operands[0] = operands[0].simplify(from, evalOnly);
        Operator sigma = operands[0];
        if (sigma.isScalar() && sigma.getDouble() == 0) {
            from.changed = true;
            sigma.parent = parent;
            return sigma;
        }
    }
    return this;
}
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