Search in sources :

Example 26 with MatrixDense

use of gov.sandia.n2a.linear.MatrixDense in project n2a by frothga.

the class Scalar method subtract.

public Type subtract(Type that) throws EvaluationException {
    if (that instanceof Scalar)
        return new Scalar(value - ((Scalar) that).value);
    if (that instanceof Matrix) {
        Matrix B = (Matrix) that;
        int w = B.columns();
        int h = B.rows();
        MatrixDense result = new MatrixDense(h, w);
        for (int c = 0; c < w; c++) {
            for (int r = 0; r < h; r++) {
                result.set(r, c, value - B.get(r, c));
            }
        }
        return result;
    }
    throw new EvaluationException("type mismatch");
}
Also used : MatrixDense(gov.sandia.n2a.linear.MatrixDense) EvaluationException(gov.sandia.n2a.language.EvaluationException)

Example 27 with MatrixDense

use of gov.sandia.n2a.linear.MatrixDense in project n2a by frothga.

the class Scalar method max.

public Type max(Type that) {
    if (that instanceof Scalar)
        return new Scalar(Math.max(value, ((Scalar) that).value));
    if (that instanceof Matrix) {
        Matrix B = (Matrix) that;
        int w = B.columns();
        int h = B.rows();
        MatrixDense result = new MatrixDense(h, w);
        for (int c = 0; c < w; c++) {
            for (int r = 0; r < h; r++) {
                result.set(r, c, Math.max(value, B.get(r, c)));
            }
        }
        return result;
    }
    throw new EvaluationException("type mismatch");
}
Also used : MatrixDense(gov.sandia.n2a.linear.MatrixDense) EvaluationException(gov.sandia.n2a.language.EvaluationException)

Example 28 with MatrixDense

use of gov.sandia.n2a.linear.MatrixDense in project n2a by frothga.

the class Scalar method GT.

public Type GT(Type that) throws EvaluationException {
    if (that instanceof Scalar)
        return new Scalar((value > ((Scalar) that).value) ? 1 : 0);
    if (that instanceof Matrix) {
        Matrix B = (Matrix) that;
        int w = B.columns();
        int h = B.rows();
        MatrixDense result = new MatrixDense(h, w);
        for (int c = 0; c < w; c++) {
            for (int r = 0; r < h; r++) {
                result.set(r, c, (value > B.get(r, c)) ? 1 : 0);
            }
        }
        return result;
    }
    throw new EvaluationException("type mismatch");
}
Also used : MatrixDense(gov.sandia.n2a.linear.MatrixDense) EvaluationException(gov.sandia.n2a.language.EvaluationException)

Example 29 with MatrixDense

use of gov.sandia.n2a.linear.MatrixDense in project n2a by frothga.

the class Scalar method power.

public Type power(Type that) throws EvaluationException {
    if (that instanceof Scalar)
        return new Scalar(Math.pow(value, ((Scalar) that).value));
    if (that instanceof Matrix) {
        Matrix B = (Matrix) that;
        int w = B.columns();
        int h = B.rows();
        MatrixDense result = new MatrixDense(h, w);
        for (int c = 0; c < w; c++) {
            for (int r = 0; r < h; r++) {
                result.set(r, c, Math.pow(value, B.get(r, c)));
            }
        }
        return result;
    }
    throw new EvaluationException("type mismatch");
}
Also used : MatrixDense(gov.sandia.n2a.linear.MatrixDense) EvaluationException(gov.sandia.n2a.language.EvaluationException)

Example 30 with MatrixDense

use of gov.sandia.n2a.linear.MatrixDense in project n2a by frothga.

the class Scalar method LE.

public Type LE(Type that) throws EvaluationException {
    if (that instanceof Scalar)
        return new Scalar((value <= ((Scalar) that).value) ? 1 : 0);
    if (that instanceof Matrix) {
        Matrix B = (Matrix) that;
        int w = B.columns();
        int h = B.rows();
        MatrixDense result = new MatrixDense(h, w);
        for (int c = 0; c < w; c++) {
            for (int r = 0; r < h; r++) {
                result.set(r, c, (value <= B.get(r, c)) ? 1 : 0);
            }
        }
        return result;
    }
    throw new EvaluationException("type mismatch");
}
Also used : MatrixDense(gov.sandia.n2a.linear.MatrixDense) EvaluationException(gov.sandia.n2a.language.EvaluationException)

Aggregations

MatrixDense (gov.sandia.n2a.linear.MatrixDense)36 EvaluationException (gov.sandia.n2a.language.EvaluationException)24 Matrix (gov.sandia.n2a.language.type.Matrix)7 Scalar (gov.sandia.n2a.language.type.Scalar)7 Type (gov.sandia.n2a.language.Type)5 Text (gov.sandia.n2a.language.type.Text)4 Simulator (gov.sandia.n2a.backend.internal.Simulator)3 Random (java.util.Random)3 Variable (gov.sandia.n2a.eqset.Variable)1 Constant (gov.sandia.n2a.language.Constant)1 Operator (gov.sandia.n2a.language.Operator)1 ASTConstant (gov.sandia.n2a.language.parse.ASTConstant)1 FactorQR (gov.sandia.n2a.linear.FactorQR)1 MatrixSparse (gov.sandia.n2a.linear.MatrixSparse)1 OutputParser (gov.sandia.n2a.ui.jobs.OutputParser)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1