OGMatrixAlgebra extends MatrixAlgebra { @Override public DoubleMatrix2D getOuterProduct(final Matrix<?> m1, final Matrix<?> m2) { Validate.notNull(m1, "m1"); Validate.notNull(m2, "m2"); if (m1 instanceof DoubleMatrix1D && m2 instanceof DoubleMatrix1D) { final double[] a = ((DoubleMatrix1D) m1).getData(); final double[] b = ((DoubleMatrix1D) m2).getData(); final int m = a.length; final int n = b.length; final double[][] res = new double[m][n]; int i, j; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { res[i][j] = a[i] * b[j]; } } return new DoubleMatrix2D(res); } throw new IllegalArgumentException("Can only find outer product of DoubleMatrix1D; have " + m1.getClass() + " and " + m2.getClass()); }  @Override double getCondition(final Matrix<?> m); @Override double getDeterminant(final Matrix<?> m); @Override double getInnerProduct(final Matrix<?> m1, final Matrix<?> m2); @Override DoubleMatrix2D getInverse(final Matrix<?> m); @Override double getNorm1(final Matrix<?> m); @Override double getNorm2(final Matrix<?> m); @Override double getNormInfinity(final Matrix<?> m); @Override DoubleMatrix2D getOuterProduct(final Matrix<?> m1, final Matrix<?> m2); @Override DoubleMatrix2D getPower(final Matrix<?> m, final int p); @Override double getTrace(final Matrix<?> m); @Override DoubleMatrix2D getTranspose(final Matrix<?> m); @Override Matrix<?> multiply(final Matrix<?> m1, final Matrix<?> m2); @Override DoubleMatrix2D getPower(final Matrix<?> m, final double p);  }
@Test public void testOuterProduct() { final DoubleMatrix2D res = ALGEBRA.getOuterProduct(E, F); final int rows = res.getNumberOfRows(); final int cols = res.getNumberOfColumns(); int i, j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { assertEquals(res.getEntry(i, j), E.getEntry(i) * F.getEntry(j), 1e-15); } } }