Search in sources :

Example 86 with Operator

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);
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 87 with Operator

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();
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 88 with Operator

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);
    }
}
Also used : Operator(gov.sandia.n2a.language.Operator)

Example 89 with Operator

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;
}
Also used : Operator(gov.sandia.n2a.language.Operator) Matrix(gov.sandia.n2a.language.type.Matrix) Constant(gov.sandia.n2a.language.Constant) MatrixDense(gov.sandia.n2a.linear.MatrixDense)

Example 90 with Operator

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