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