Java Code Examples for org.nd4j.linalg.factory.Nd4j#append()

The following examples show how to use org.nd4j.linalg.factory.Nd4j#append() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaddingTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppend() {
    INDArray appendTo = Nd4j.ones(3, 3);
    INDArray ret = Nd4j.append(appendTo, 3, 1, -1);
    assertArrayEquals(new long[] {3, 6}, ret.shape());

    INDArray linspace = Nd4j.linspace(1, 4, 4).reshape(2, 2);
    INDArray otherAppend = Nd4j.append(linspace, 3, 1.0, -1);
    INDArray assertion = Nd4j.create(new double[][] {{1, 3, 1, 1, 1}, {2, 4, 1, 1, 1}});

    assertEquals(assertion, otherAppend);


}
 
Example 2
Source File: PaddingTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrepend() {
    INDArray appendTo = Nd4j.ones(3, 3);
    INDArray ret = Nd4j.append(appendTo, 3, 1, -1);
    assertArrayEquals(new long[] {3, 6}, ret.shape());

    INDArray linspace = Nd4j.linspace(1, 4, 4).reshape(2, 2);
    INDArray assertion = Nd4j.create(new double[][] {{1, 1, 1, 1, 3}, {1, 1, 1, 2, 4}});

    INDArray prepend = Nd4j.prepend(linspace, 3, 1.0, -1);
    assertEquals(assertion, prepend);

}
 
Example 3
Source File: PaddingTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppend2() {
    INDArray ret = Nd4j.create(new double[] {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
                    4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
                    4, 4, 4, 4, 4, 4, 4, 4}, new int[] {1, 1, 8, 8});

    INDArray appendAssertion = Nd4j.create(new double[] {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
                    3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
                    3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0}, new int[] {1, 1, 9, 8});

    INDArray appended = Nd4j.append(ret, 1, 0, 2);
    assertArrayEquals(appendAssertion.shape(), appended.shape());
    assertEquals(appendAssertion, appended);
}
 
Example 4
Source File: PaddingTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppend() {
    INDArray linspace = Nd4j.linspace(1, 4, 4).reshape(2, 2);
    INDArray otherAppend = Nd4j.append(linspace, 3, 1.0, -1);
    INDArray assertion = Nd4j.create(new double[][] {{1, 2, 1, 1, 1}, {3, 4, 1, 1, 1}});

    assertEquals(assertion, otherAppend);
}
 
Example 5
Source File: PaddingTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppend() {
    INDArray appendTo = Nd4j.ones(DataType.DOUBLE,3, 3);
    INDArray ret = Nd4j.append(appendTo, 3, 1, -1);
    assertArrayEquals(new long[] {3, 6}, ret.shape());

    INDArray linspace = Nd4j.linspace(1, 4, 4, DataType.DOUBLE).reshape(2, 2);
    INDArray otherAppend = Nd4j.append(linspace, 3, 1.0, -1);
    INDArray assertion = Nd4j.create(new double[][] {{1, 3, 1, 1, 1}, {2, 4, 1, 1, 1}});

    assertEquals(assertion, otherAppend);


}
 
Example 6
Source File: PaddingTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrepend() {
    INDArray appendTo = Nd4j.ones(DataType.DOUBLE, 3, 3);
    INDArray ret = Nd4j.append(appendTo, 3, 1, -1);
    assertArrayEquals(new long[] {3, 6}, ret.shape());

    INDArray linspace = Nd4j.linspace(1, 4, 4, DataType.DOUBLE).reshape(2, 2);
    INDArray assertion = Nd4j.create(new double[][] {{1, 1, 1, 1, 3}, {1, 1, 1, 2, 4}});

    INDArray prepend = Nd4j.prepend(linspace, 3, 1.0, -1);
    assertEquals(assertion, prepend);

}
 
Example 7
Source File: PaddingTestsC.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppend2() {
    INDArray ret = Nd4j.create(new double[] {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
                    4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
                    4, 4, 4, 4, 4, 4, 4, 4}, new int[] {1, 1, 8, 8});

    INDArray appendAssertion = Nd4j.create(new double[] {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
                    3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3,
                    3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0}, new int[] {1, 1, 9, 8});

    INDArray appended = Nd4j.append(ret, 1, 0, 2);
    assertArrayEquals(appendAssertion.shape(), appended.shape());
    assertEquals(appendAssertion, appended);
}
 
Example 8
Source File: PaddingTestsC.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppend() {
    INDArray linspace = Nd4j.linspace(1, 4, 4, DataType.DOUBLE).reshape(2, 2);
    INDArray otherAppend = Nd4j.append(linspace, 3, 1.0, -1);
    INDArray assertion = Nd4j.create(new double[][] {{1, 2, 1, 1, 1}, {3, 4, 1, 1, 1}});

    assertEquals(assertion, otherAppend);
}