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

The following examples show how to use org.nd4j.linalg.factory.Nd4j#pile() . 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: VPTree.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param items the items to use
 * @param similarityFunction the similarity function to use
 * @param workers number of parallel workers for tree building (increases memory requirements!)
 * @param invert whether to invert the metric (different optimization objective)
 */
public VPTree(List<DataPoint> items, String similarityFunction, int workers, boolean invert) {
    this.workers = workers;

    val list = new INDArray[items.size()];

    // build list of INDArrays first
    for (int i = 0; i < items.size(); i++)
        list[i] = items.get(i).getPoint();
        //this.items.putRow(i, items.get(i).getPoint());

    // just stack them out with concat :)
    this.items = Nd4j.pile(list);

    this.invert = invert;
    this.similarityFunction = similarityFunction;
    root = buildFromPoints(this.items);
}
 
Example 2
Source File: SameDiffTests.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testTensorArray3() {
    SameDiff sd = SameDiff.create();
    TensorArray tensorArray = sd.tensorArray(DataType.FLOAT);
    INDArray arr1 = Nd4j.create(new double[]{1, 2, 3, 4}, new int[]{2, 2});
    INDArray arr2 = Nd4j.create(new double[]{5, 6, 7, 8}, new int[]{2, 2});
    INDArray arr3 = Nd4j.pile(arr1, arr2);
    SDVariable var = sd.var(arr3);
    SDVariable unstack = tensorArray.unstack(var, var);
    SDVariable result1 = tensorArray.read(0);
    SDVariable result2 = tensorArray.read(1);
    result1.addControlDependency(unstack);
    result2.addControlDependency(unstack);
    assertEquals(arr1, result1.eval());
    assertEquals(arr2, result2.eval());
}
 
Example 3
Source File: OpExecutionerTestsC.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
    public void testTear1() {
        List<INDArray> arrays = new ArrayList<>();
        val num = 10;
        for (int i = 0; i < num; i++) {
            arrays.add(Nd4j.create(5, 20).assign(i));
        }

        INDArray pile = Nd4j.pile(arrays);

//        log.info("Pile: {}", pile);

        INDArray[] tears = Nd4j.tear(pile, 1, 2);

        for (int i = 0; i < num; i++) {
            assertEquals((float) i, tears[i].meanNumber().floatValue(), 0.01f);
        }
    }
 
Example 4
Source File: OpExecutionerTestsC.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile1() {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    assertEquals(3, pile.rank());
    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, pile.tensorAlongDimension(i, 1, 2).getDouble(0), 0.01);
    }
}
 
Example 5
Source File: OpExecutionerTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testTear1() {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    INDArray[] tears = Nd4j.tear(pile, 1, 2);

    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, tears[i].meanNumber().floatValue(), 0.01f);
    }
}
 
Example 6
Source File: OpExecutionerTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile4() {
    val arrayW = Nd4j.create(1, 5);
    val arrayX = Nd4j.create(1, 5);
    val arrayY = Nd4j.create(1, 5);

    val arrayZ = Nd4j.pile(arrayW, arrayX, arrayY);

    assertArrayEquals(new long[]{3, 1, 5}, arrayZ.shape());
}
 
Example 7
Source File: OpExecutionerTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile3() {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create( 10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    assertEquals(3, pile.rank());
    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, pile.tensorAlongDimension(i, 1, 2).getDouble(0), 0.01);
    }
}
 
Example 8
Source File: OpExecutionerTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile2() {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    assertEquals(4, pile.rank());
    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, pile.tensorAlongDimension(i, 1, 2, 3).getDouble(0), 0.01);
    }
}
 
Example 9
Source File: OpExecutionerTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile1() {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    assertEquals(3, pile.rank());
    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, pile.tensorAlongDimension(i, 1, 2).getDouble(0), 0.01);
    }
}
 
Example 10
Source File: OpExecutionerTestsC.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile2() {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    assertEquals(4, pile.rank());
    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, pile.tensorAlongDimension(i, 1, 2, 3).getDouble(0), 0.01);
    }
}
 
Example 11
Source File: OpExecutionerTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile1() throws Exception {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    assertEquals(3, pile.rank());
    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, pile.tensorAlongDimension(i, 1, 2).getDouble(0), 0.01);
    }
}
 
Example 12
Source File: OpExecutionerTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testTear1() {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    INDArray[] tears = Nd4j.tear(pile, 1, 2);

    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, tears[i].meanNumber().floatValue(), 0.01f);
    }
}
 
Example 13
Source File: OpExecutionerTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile3() throws Exception {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(1, 10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    assertEquals(3, pile.rank());
    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, pile.tensorAlongDimension(i, 1, 2).getDouble(0), 0.01);
    }
}
 
Example 14
Source File: OpExecutionerTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile2() throws Exception {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    assertEquals(4, pile.rank());
    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, pile.tensorAlongDimension(i, 1, 2, 3).getDouble(0), 0.01);
    }
}
 
Example 15
Source File: OpExecutionerTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile1() throws Exception {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    assertEquals(3, pile.rank());
    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, pile.tensorAlongDimension(i, 1, 2).getDouble(0), 0.01);
    }
}
 
Example 16
Source File: OpExecutionerTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testTear1() {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    INDArray[] tears = Nd4j.tear(pile, 1, 2);

    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, tears[i].meanNumber().floatValue(), 0.01f);
    }
}
 
Example 17
Source File: OpExecutionerTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testPile2() throws Exception {
    List<INDArray> arrays = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        arrays.add(Nd4j.create(10, 10, 10).assign(i));
    }

    INDArray pile = Nd4j.pile(arrays);

    assertEquals(4, pile.rank());
    for (int i = 0; i < 10; i++) {
        assertEquals((float) i, pile.tensorAlongDimension(i, 1, 2, 3).getDouble(0), 0.01);
    }
}