MatVecOp { public static double sumAbsDiff(Vector vec1, Vector vec2) { if (vec1 instanceof DenseVector) { if (vec2 instanceof DenseVector) { return MatVecOp.applySum((DenseVector)vec1, (DenseVector)vec2, (a, b) -> Math.abs(a - b)); } else { return MatVecOp.applySum((DenseVector)vec1, (SparseVector)vec2, (a, b) -> Math.abs(a - b)); } } else { if (vec2 instanceof DenseVector) { return MatVecOp.applySum((SparseVector)vec1, (DenseVector)vec2, (a, b) -> Math.abs(a - b)); } else { return MatVecOp.applySum((SparseVector)vec1, (SparseVector)vec2, (a, b) -> Math.abs(a - b)); } } }  static Vector plus(Vector vec1, Vector vec2); static Vector minus(Vector vec1, Vector vec2); static double dot(Vector vec1, Vector vec2); static double sumAbsDiff(Vector vec1, Vector vec2); static double sumSquaredDiff(Vector vec1, Vector vec2); static void apply(DenseMatrix x, DenseMatrix y, Function<Double, Double> func); static void apply(DenseMatrix x1, DenseMatrix x2, DenseMatrix y,
                             BiFunction<Double, Double, Double> func); static void apply(DenseVector x, DenseVector y, Function<Double, Double> func); static void apply(DenseVector x1, DenseVector x2, DenseVector y,
                             BiFunction<Double, Double, Double> func); static SparseVector apply(SparseVector x1, SparseVector x2, BiFunction<Double, Double, Double> func); static double applySum(DenseVector x1, DenseVector x2, BiFunction<Double, Double, Double> func); static double applySum(SparseVector x1, SparseVector x2, BiFunction<Double, Double, Double> func); static double applySum(DenseVector x1, SparseVector x2, BiFunction<Double, Double, Double> func); static double applySum(SparseVector x1, DenseVector x2, BiFunction<Double, Double, Double> func); static double applySum(DenseMatrix x1, DenseMatrix x2, BiFunction<Double, Double, Double> func); static void appendVectorToMatrix(DenseMatrix matrix, boolean trans, int index, Vector vector);  }
@Test public void testSumAbsDiff() throws Exception { Assert.assertEquals(MatVecOp.sumAbsDiff(dv, sv), 8.0, TOL); Assert.assertEquals(MatVecOp.sumAbsDiff(sv, dv), 8.0, TOL); Assert.assertEquals(MatVecOp.sumAbsDiff(sv, sv), 0.0, TOL); Assert.assertEquals(MatVecOp.sumAbsDiff(dv, dv), 0.0, TOL); }