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;
}
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);
}
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.
}
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);
}
}
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;
}
Aggregations