コード例 #1
0
  @Test
  public void testGetReal() {
    DataBuffer data = Nd4j.linspace(1, 8, 8).data();
    int[] shape = new int[] {1, 8};
    IComplexNDArray arr = Nd4j.createComplex(shape);
    for (int i = 0; i < arr.length(); i++) arr.put(i, Nd4j.scalar(data.getFloat(i)));
    INDArray arr2 = Nd4j.create(data, shape);
    assertEquals(arr2, arr.getReal());

    INDArray ones = Nd4j.ones(10);
    IComplexNDArray n2 = Nd4j.complexOnes(10);
    assertEquals(getFailureMessage(), ones, n2.getReal());
  }
コード例 #2
0
 @Test
 public void testCreateComplexFromReal() {
   INDArray n = Nd4j.create(new double[] {1, 2, 3, 4, 5, 6, 7, 8}, new int[] {2, 4});
   IComplexNDArray nComplex = Nd4j.createComplex(n);
   for (int i = 0; i < n.vectorsAlongDimension(0); i++) {
     INDArray vec = n.vectorAlongDimension(i, 0);
     IComplexNDArray vecComplex = nComplex.vectorAlongDimension(i, 0);
     assertEquals(vec.length(), vecComplex.length());
     for (int j = 0; j < vec.length(); j++) {
       IComplexNumber currComplex = vecComplex.getComplex(j);
       double curr = vec.getFloat(j);
       assertEquals(curr, currComplex.realComponent().doubleValue(), 1e-1);
     }
     assertEquals(vec, vecComplex.getReal());
   }
 }
コード例 #3
0
 @Test
 public void testMultiDimensionalCreation() {
   INDArray fourTwoTwo = Nd4j.linspace(1, 16, 16).reshape(4, 2, 2);
   IComplexNDArray multiRow = Nd4j.createComplex(fourTwoTwo);
   assertEquals(fourTwoTwo, multiRow.getReal());
 }