public virtual void test_combine() { DoubleMatrix test1 = DoubleMatrix.of(2, 3, 1d, 2d, 3d, 4d, 5d, 6d); DoubleMatrix test2 = DoubleMatrix.of(2, 3, 0.5d, 0.6d, 0.7d, 0.5d, 0.6d, 0.7d); assertMatrix(test1.combine(test2, (a, b) => a * b), 0.5d, 2d * 0.6d, 3d * 0.7d, 4d * 0.5d, 5d * 0.6d, 6d * 0.7d); assertThrows(() => test1.combine(DoubleMatrix.EMPTY, (a, b) => a * b), typeof(System.ArgumentException)); }
public virtual void test_minus() { DoubleMatrix test1 = DoubleMatrix.of(2, 3, 1d, 2d, 3d, 4d, 5d, 6d); DoubleMatrix test2 = DoubleMatrix.of(2, 3, 0.5d, 0.6d, 0.7d, 0.5d, 0.6d, 0.7d); assertMatrix(test1.minus(test2), 0.5d, 1.4d, 2.3d, 3.5d, 4.4d, 5.3d); assertThrows(() => test1.minus(DoubleMatrix.EMPTY), typeof(System.ArgumentException)); }
public virtual void test_of_values() { assertMatrix(DoubleMatrix.of(0, 0)); assertMatrix(DoubleMatrix.of(1, 0)); assertMatrix(DoubleMatrix.of(0, 1)); assertMatrix(DoubleMatrix.of(2, 3, 1d, 2d, 3d, 4d, 5d, 6d), 1d, 2d, 3d, 4d, 5d, 6d); assertMatrix(DoubleMatrix.of(6, 1, 1d, 2d, 3d, 4d, 5d, 6d), 1d, 2d, 3d, 4d, 5d, 6d); assertThrowsIllegalArg(() => DoubleMatrix.of(1, 2, 1d)); }
//------------------------------------------------------------------------- public virtual void test_of_intintlambda() { assertMatrix(DoubleMatrix.of(0, 0, (i, j) => { throw new AssertionError(); })); assertMatrix(DoubleMatrix.of(0, 2, (i, j) => { throw new AssertionError(); })); assertMatrix(DoubleMatrix.of(2, 0, (i, j) => { throw new AssertionError(); })); AtomicInteger counter = new AtomicInteger(2); assertMatrix(DoubleMatrix.of(1, 2, (i, j) => counter.AndIncrement), 2d, 3d); assertMatrix(DoubleMatrix.of(2, 2, (i, j) => (i + 1) * (j + 1)), 1d, 2d, 2d, 4d); }
//------------------------------------------------------------------------- public virtual void coverage() { coverImmutableBean(DoubleMatrix.EMPTY); coverImmutableBean(DoubleMatrix.of(2, 3, 1d, 2d, 3d, 4d, 5d, 6d)); }
public virtual void test_of() { assertMatrix(DoubleMatrix.of()); }
//------------------------------------------------------------------------- /// <summary> /// Transposes the matrix. /// <para> /// This converts a matrix of {@code m x n} into a matrix of {@code n x m}. /// Each element is moved to the opposite position. /// /// </para> /// </summary> /// <returns> the transposed matrix </returns> public DoubleMatrix transpose() { return(DoubleMatrix.of(columns, rows, (i, j) => array[j][i])); }