Example #1
0
  @Test
  public void testWrap() {
    IComplexNDArray c = Nd4j.createComplex(Nd4j.linspace(1, 4, 4).reshape(2, 2));
    assertEquals(true, Arrays.equals(new int[] {2, 2}, c.shape()));

    IComplexNDArray vec = Nd4j.createComplex(Nd4j.linspace(1, 4, 4));
    assertEquals(true, vec.isVector());
    assertEquals(true, Shape.shapeEquals(new int[] {4}, vec.shape()));
  }
 @Test
 public void testBroadcast() {
   IComplexNDArray arr = Nd4j.complexLinSpace(1, 5, 5);
   IComplexNDArray arrs = arr.broadcast(new int[] {5, 5});
   IComplexNDArray arrs3 = Nd4j.createComplex(5, 5);
   assertTrue(Arrays.equals(arrs.shape(), arrs3.shape()));
   for (int i = 0; i < arrs.slices(); i++) arrs3.putSlice(i, arr);
   assertEquals(arrs3, arrs);
 }
  @Test
  public void testDimShuffle() {
    IComplexNDArray n = Nd4j.complexLinSpace(1, 4, 4).reshape(2, 2);
    IComplexNDArray twoOneTwo =
        n.dimShuffle(new Object[] {0, 'x', 1}, new int[] {0, 1}, new boolean[] {false, false});
    assertTrue(Arrays.equals(new int[] {2, 1, 2}, twoOneTwo.shape()));

    IComplexNDArray reverse =
        n.dimShuffle(new Object[] {1, 'x', 0}, new int[] {1, 0}, new boolean[] {false, false});
    assertTrue(Arrays.equals(new int[] {2, 1, 2}, reverse.shape()));
  }
  @Test
  public void testLeadingOnes() {
    IComplexNDArray complexRand = Nd4j.complexRand(100, 1, 28, 28);
    assertArrayEquals(new int[] {100, 1, 28, 28}, complexRand.shape());
    IComplexNDArray arr = complexRand.linearView();
    for (int i = 0; i < arr.length(); i++) {
      arr.putScalar(i, arr.getComplex(i));
    }

    IComplexNDArray complexRand2 = Nd4j.complexRand(28, 28, 1);
    assertArrayEquals(new int[] {28, 28, 1}, complexRand2.shape());
    IComplexNDArray arr2 = complexRand.linearView();
    for (int i = 0; i < arr2.length(); i++) {
      arr2.putScalar(i, arr2.getComplex(i));
    }
  }