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

The following examples show how to use org.nd4j.linalg.factory.Nd4j#tensorMmul() . 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: LoneTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void reshapeTensorMmul() {
    INDArray a = Nd4j.linspace(1, 2, 12).reshape(2, 3, 2);
    INDArray b = Nd4j.linspace(3, 4, 4).reshape(2, 2);
    int[][] axes = new int[2][];
    axes[0] = new int[]{0, 1};
    axes[1] = new int[]{0, 2};

    //this was throwing an exception
    INDArray c = Nd4j.tensorMmul(b, a, axes);
}
 
Example 2
Source File: NDArrayTestsFortran.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testTensorDot() {
    INDArray oneThroughSixty = Nd4j.arange(60).reshape('f', 3, 4, 5);
    INDArray oneThroughTwentyFour = Nd4j.arange(24).reshape('f', 4, 3, 2);
    INDArray result = Nd4j.tensorMmul(oneThroughSixty, oneThroughTwentyFour, new int[][] {{1, 0}, {0, 1}});
    assertArrayEquals(new long[] {5, 2}, result.shape());
    INDArray assertion = Nd4j.create(new double[][] {{440., 1232.}, {1232., 3752.}, {2024., 6272.}, {2816., 8792.},
                    {3608., 11312.}});
    assertEquals(assertion, result);

}
 
Example 3
Source File: MiscOpValidation.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testTensorMmulShape2(){
    INDArray a = Nd4j.create(new double[]{2}).reshape(1);
    INDArray b = Nd4j.create(new double[]{1, 2, 3, 4}).reshape(2, 1, 2);
    INDArray c = Nd4j.tensorMmul(a, b, new int[][]{new int[]{0}, new int[]{1}});
    assertArrayEquals(new long[]{2,2}, c.shape());
}
 
Example 4
Source File: LoneTest.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void reshapeTensorMmul() {
    INDArray a = Nd4j.linspace(1, 2, 12).reshape(2, 3, 2);
    INDArray b = Nd4j.linspace(3, 4, 4).reshape(2, 2);
    int[][] axes = new int[2][];
    axes[0] = new int[]{0, 1};
    axes[1] = new int[]{0, 2};

    //this was throwing an exception
    INDArray c = Nd4j.tensorMmul(b, a, axes);
}
 
Example 5
Source File: NDArrayTestsFortran.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void testTensorDot() {
    INDArray oneThroughSixty = Nd4j.arange(60).reshape('f', 3, 4, 5).castTo(DataType.DOUBLE);
    INDArray oneThroughTwentyFour = Nd4j.arange(24).reshape('f', 4, 3, 2).castTo(DataType.DOUBLE);
    INDArray result = Nd4j.tensorMmul(oneThroughSixty, oneThroughTwentyFour, new int[][] {{1, 0}, {0, 1}});
    assertArrayEquals(new long[] {5, 2}, result.shape());
    INDArray assertion = Nd4j.create(new double[][] {{440., 1232.}, {1232., 3752.}, {2024., 6272.}, {2816., 8792.},
                    {3608., 11312.}});
    assertEquals(assertion, result);

}