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