Search in sources :

Example 6 with MatrixDense

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

the class Scalar method min.

public Type min(Type that) {
    if (that instanceof Scalar)
        return new Scalar(Math.min(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.min(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 7 with MatrixDense

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

the class Scalar method divide.

public Type divide(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 8 with MatrixDense

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

the class Scalar method OR.

public Type OR(Type that) throws EvaluationException {
    if (that instanceof Scalar)
        return new Scalar((Math.abs(value) + Math.abs(((Scalar) that).value) != 0) ? 1 : 0);
    if (that instanceof Matrix) {
        double scalar = Math.abs(value);
        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, (scalar + Math.abs(B.get(r, c)) != 0) ? 1 : 0);
            }
        }
        return result;
    }
    throw new EvaluationException("type mismatch");
}
Also used : MatrixDense(gov.sandia.n2a.linear.MatrixDense) EvaluationException(gov.sandia.n2a.language.EvaluationException)

Example 9 with MatrixDense

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

the class Scalar method NE.

public Type NE(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 10 with MatrixDense

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

the class Scalar method AND.

public Type AND(Type that) throws EvaluationException {
    if (that instanceof Scalar)
        return new Scalar((value * ((Scalar) that).value != 0) ? 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) != 0) ? 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