Java Code Examples for org.nd4j.linalg.api.ops.executioner.OpExecutioner#exec()

The following examples show how to use org.nd4j.linalg.api.ops.executioner.OpExecutioner#exec() . 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: OpExecutionerTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testMul() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.ones(5);
    INDArray xDup = x.dup();
    INDArray solution = Nd4j.valueArrayOf(5, 1.0);
    opExecutioner.exec(new OldMulOp(x, xDup, x));
    assertEquals(solution, x);
}
 
Example 2
Source File: OpExecutionerTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testSoftMax() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray arr = Nd4j.linspace(1, 6, 6, DataType.DOUBLE).reshape(1, -1);
    val softMax = new SoftMax(arr);
    opExecutioner.exec((CustomOp) softMax);
    assertEquals(getFailureMessage(), 1.0, softMax.outputArguments().get(0).sumNumber().doubleValue(), 1e-1);
}
 
Example 3
Source File: OpExecutionerTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testSoftMax() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray arr = Nd4j.linspace(1, 6, 6);
    OldSoftMax softMax = new OldSoftMax(arr);
    opExecutioner.exec(softMax);
    assertEquals(getFailureMessage(), 1.0, softMax.z().sumNumber().doubleValue(), 1e-1);
}
 
Example 4
Source File: OpExecutionerTestsC.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecutioner() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.ones(5);
    INDArray xDup = x.dup();
    INDArray solution = Nd4j.valueArrayOf(5, 2.0);
    opExecutioner.exec(new AddOp(new INDArray[]{x, xDup},new INDArray[]{ x}));
    assertEquals(getFailureMessage(), solution, x);
    Sum acc = new Sum(x.dup());
    opExecutioner.exec(acc);
    assertEquals(getFailureMessage(), 10.0, acc.getFinalResult().doubleValue(), 1e-1);
    Prod prod = new Prod(x.dup());
    opExecutioner.exec(prod);
    assertEquals(getFailureMessage(), 32.0, prod.getFinalResult().doubleValue(), 1e-1);
}
 
Example 5
Source File: OpExecutionerTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testStridedLog() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray arr = Nd4j.linspace(1, 6, 6).reshape(2, 3);
    INDArray slice = arr.slice(0);
    Log log = new Log(slice);
    opExecutioner.exec(log);
    INDArray assertion = Nd4j.create(Nd4j.createBuffer(new float[] {0.f, 1.09861229f, 1.60943791f}));
    assertEquals(getFailureMessage(), assertion, slice);
}
 
Example 6
Source File: OpExecutionerTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testRowSoftmax() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray arr = Nd4j.linspace(1, 6, 6);
    OldSoftMax softMax = new OldSoftMax(arr);
    opExecutioner.exec(softMax);
    assertEquals(getFailureMessage(), 1.0, softMax.z().sumNumber().doubleValue(), 1e-1);
}
 
Example 7
Source File: OpExecutionerTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testDescriptiveStatsDouble() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.linspace(1, 5, 5, DataType.DOUBLE);

    Mean mean = new Mean(x);
    opExecutioner.exec(mean);
    assertEquals(3.0, mean.getFinalResult().doubleValue(), 1e-1);

    Variance variance = new Variance(x.dup(), true);
    opExecutioner.exec(variance);
    assertEquals(getFailureMessage(), 2.5, variance.getFinalResult().doubleValue(), 1e-1);
}
 
Example 8
Source File: OpExecutionerTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testMul() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.ones(5);
    INDArray xDup = x.dup();
    INDArray solution = Nd4j.valueArrayOf(5, 1.0);
    opExecutioner.exec(new MulOp(x, xDup, x));
    assertEquals(solution, x);
}
 
Example 9
Source File: OpExecutionerTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testMaxMin() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.linspace(1, 5, 5);
    Max max = new Max(x);
    opExecutioner.exec(max);
    assertEquals(5, max.getFinalResult().doubleValue(), 1e-1);
    Min min = new Min(x);
    opExecutioner.exec(min);
    assertEquals(1, min.getFinalResult().doubleValue(), 1e-1);
}
 
Example 10
Source File: OpExecutionerTestsC.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testDescriptiveStats() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.linspace(1, 5, 5, DataType.DOUBLE);

    Mean mean = new Mean(x);
    opExecutioner.exec(mean);
    assertEquals(getFailureMessage(), 3.0, mean.getFinalResult().doubleValue(), 1e-1);

    Variance variance = new Variance(x.dup(), true);
    opExecutioner.exec(variance);
    assertEquals(getFailureMessage(), 2.5, variance.getFinalResult().doubleValue(), 1e-1);
}
 
Example 11
Source File: OpExecutionerTestsC.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testStridedExp() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray arr = Nd4j.linspace(1, 6, 6, DataType.DOUBLE).reshape(2, 3);
    INDArray slice = arr.slice(0);
    val expected = new double[(int) slice.length()];
    for (int i = 0; i < slice.length(); i++)
        expected[i] = (float) Math.exp(slice.getDouble(i));
    Exp exp = new Exp(slice);
    opExecutioner.exec(exp);
    assertEquals(getFailureMessage(), Nd4j.create(expected), slice);
}
 
Example 12
Source File: OpExecutionerTestsC.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testMaxMin() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.linspace(1, 5, 5, DataType.DOUBLE);
    Max max = new Max(x);
    opExecutioner.exec(max);
    assertEquals(5, max.getFinalResult().doubleValue(), 1e-1);
    Min min = new Min(x);
    opExecutioner.exec(min);
    assertEquals(1, min.getFinalResult().doubleValue(), 1e-1);
}
 
Example 13
Source File: OpExecutionerTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testStridedExp() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray arr = Nd4j.linspace(1, 6, 6).reshape(2, 3);
    INDArray slice = arr.slice(0);
    // FIXME: int cast
    float[] expected = new float[(int) slice.length()];
    for (int i = 0; i < slice.length(); i++)
        expected[i] = (float) Math.exp(slice.getDouble(i));
    Exp exp = new Exp(slice);
    opExecutioner.exec(exp);
    assertEquals(getFailureMessage(), Nd4j.create(Nd4j.createBuffer(expected)), slice);
}
 
Example 14
Source File: OpExecutionerTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testStridedLog() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray arr = Nd4j.linspace(1, 6, 6).reshape(2, 3);
    INDArray slice = arr.slice(0);
    Log exp = new Log(slice);
    opExecutioner.exec(exp);
    INDArray assertion = Nd4j.create(Nd4j.createBuffer(new double[] {0.0, 0.6931471824645996, 1.0986123085021973}));
    assertEquals(getFailureMessage(), assertion, slice);
}
 
Example 15
Source File: OpExecutionerTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testRowSoftmax() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray arr = Nd4j.linspace(1, 6, 6);
    OldSoftMax softMax = new OldSoftMax(arr);
    opExecutioner.exec(softMax);
    assertEquals(getFailureMessage(), 1.0, softMax.z().sumNumber().doubleValue(), 1e-1);
}
 
Example 16
Source File: OpExecutionerTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecutioner() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.ones(5);
    INDArray xDup = x.dup();
    INDArray solution = Nd4j.valueArrayOf(5, 2.0);
    opExecutioner.exec(new AddOp(new INDArray[]{x, xDup},new INDArray[]{x}));
    assertEquals(getFailureMessage(), solution, x);
    Sum acc = new Sum(x.dup());
    opExecutioner.exec(acc);
    assertEquals(getFailureMessage(), 10.0, acc.getFinalResult().doubleValue(), 1e-1);
    Prod prod = new Prod(x.dup());
    opExecutioner.exec(prod);
    assertEquals(getFailureMessage(), 32.0, prod.getFinalResult().doubleValue(), 1e-1);
}
 
Example 17
Source File: OpExecutionerTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testDescriptiveStatsDouble() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.linspace(1, 5, 5);

    Mean mean = new Mean(x);
    opExecutioner.exec(mean);
    assertEquals(3.0, mean.getFinalResult().doubleValue(), 1e-1);

    Variance variance = new Variance(x.dup(), true);
    opExecutioner.exec(variance);
    assertEquals(getFailureMessage(), 2.5, variance.getFinalResult().doubleValue(), 1e-1);
}
 
Example 18
Source File: OpExecutionerTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testMaxMin() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.linspace(1, 5, 5, DataType.DOUBLE);
    Max max = new Max(x);
    opExecutioner.exec(max);
    assertEquals(5, max.getFinalResult().doubleValue(), 1e-1);
    Min min = new Min(x);
    opExecutioner.exec(min);
    assertEquals(1, min.getFinalResult().doubleValue(), 1e-1);
}
 
Example 19
Source File: OpExecutionerTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testExecutioner() throws IllegalOpException {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.ones(5);
    INDArray xDup = x.dup();
    INDArray solution = Nd4j.valueArrayOf(5, 2.0);
    opExecutioner.exec(new AddOp(new INDArray[]{x, xDup},new INDArray[]{ x}));
    assertEquals(getFailureMessage(), solution, x);
    Sum acc = new Sum(x.dup());
    opExecutioner.exec(acc);
    assertEquals(getFailureMessage(), 10.0, acc.getFinalResult().doubleValue(), 1e-1);
    Prod prod = new Prod(x.dup());
    opExecutioner.exec(prod);
    assertEquals(getFailureMessage(), 32.0, prod.getFinalResult().doubleValue(), 1e-1);
}
 
Example 20
Source File: OpExecutionerTestsC.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testMul() {
    OpExecutioner opExecutioner = Nd4j.getExecutioner();
    INDArray x = Nd4j.ones(5);
    INDArray xDup = x.dup();
    INDArray solution = Nd4j.valueArrayOf(5, 1.0);
    opExecutioner.exec(new OldMulOp(x, xDup, x));
    assertEquals(solution, x);
}