use of gov.sandia.n2a.language.Operator in project n2a by frothga.
the class Signum method determineExponent.
public void determineExponent(ExponentContext context) {
Operator op = operands[0];
op.determineExponent(context);
int centerNew = MSB / 2;
int exponentNew = MSB - centerNew;
updateExponent(context, exponentNew, centerNew);
}
use of gov.sandia.n2a.language.Operator in project n2a by frothga.
the class Signum method determineExponentNext.
public void determineExponentNext() {
Operator op = operands[0];
op.exponentNext = op.exponent;
op.determineExponentNext();
}
use of gov.sandia.n2a.language.Operator in project n2a by frothga.
the class Sphere 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 {
// Current implementation never quite reaches 1, only [0,1).
updateExponent(context, -1, MSB);
}
}
use of gov.sandia.n2a.language.Operator in project n2a by frothga.
the class Sphere method simplify.
public Operator simplify(Variable from, boolean evalOnly) {
if (operands.length == 0) {
// No need to set from.changed
operands = new Operator[1];
Operator sigma = new Constant(new MatrixDense(3, 1, 1));
sigma.parent = this;
operands[0] = sigma;
return this;
}
// Any number of operands >= 1. We only pay attention to first operand.
operands[0] = operands[0].simplify(from, evalOnly);
Operator sigma = operands[0];
if (sigma.isScalar()) {
if (sigma.getDouble() == 0) {
// Needed because we are replacing ourself with a simpler constant.
from.changed = true;
sigma.parent = parent;
return sigma;
}
// No need to set from.changed
operands = new Operator[1];
sigma = new Constant(new MatrixDense(3, 1, sigma.getDouble()));
sigma.parent = this;
operands[0] = sigma;
return this;
} else if (sigma instanceof Constant) {
Constant cs = (Constant) sigma;
if (cs.value instanceof Matrix) {
// No need to set from.changed for any of the transforms below ...
Matrix A = (Matrix) cs.value;
int rows = A.rows();
int cols = A.columns();
if (rows == 1 && cols > 1) {
cs.value = A = A.transpose();
rows = cols;
cols = 1;
}
if (// Check for zeroes in single column.
cols == 1) {
int rank = (int) A.norm(0);
if (rank < rows) {
from.changed = true;
MatrixDense B = new MatrixDense(rows, rank);
cs.value = B;
int c = 0;
for (int r = 0; r < rows; r++) {
double value = A.get(r);
if (value != 0)
B.set(r, c++, value);
}
}
}
// Don't bother checking for columns that are all zeroes.
// Since sigma is a constant, this should be obvious to the user.
}
}
return this;
}
use of gov.sandia.n2a.language.Operator in project n2a by frothga.
the class SquareRoot method determineExponentNext.
public void determineExponentNext() {
Operator op = operands[0];
op.exponentNext = op.exponent;
op.determineExponentNext();
}
Aggregations