Package de.labathome.trustconstr.matrix
Class MatrixOps
java.lang.Object
de.labathome.trustconstr.matrix.MatrixOps
Small static helpers that operate on
double[] vectors and
Matrix instances.-
Method Summary
Modifier and TypeMethodDescriptionstatic Matrixdiag(double[] diagonal) Build a sparse diagonal matrix with the given entries on the diagonal.static doubledot(double[] a, double[] b) Dot product of two equal-length vectors.static doublenorm2(double[] v) Euclidean (2-)norm of a vector.static MatrixMaterialise the non-zero entries of a possibly-dense matrix into aSparseMatrix(DOK-backed).
-
Method Details
-
norm2
public static double norm2(double[] v) Euclidean (2-)norm of a vector.- Parameters:
v- vector- Returns:
sqrt(sum_i v[i]^2)
-
dot
public static double dot(double[] a, double[] b) Dot product of two equal-length vectors.- Parameters:
a- left operandb- right operand (must have the same length asa)- Returns:
sum_i a[i] * b[i]
-
diag
Build a sparse diagonal matrix with the given entries on the diagonal.- Parameters:
diagonal- length-narray of diagonal values- Returns:
n x nSparseMatrixwith the diagonal populated and zeros elsewhere
-
sparse
Materialise the non-zero entries of a possibly-dense matrix into aSparseMatrix(DOK-backed). Used by tests that exercise the sparse code paths against a dense reference.- Parameters:
A- source matrix- Returns:
SparseMatrixwith the same shape and non-zero entries
-