Java Code Examples for org.nd4j.linalg.api.ndarray.INDArray#addiColumnVector()
The following examples show how to use
org.nd4j.linalg.api.ndarray.INDArray#addiColumnVector() .
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: SporadicTests.java From nd4j with Apache License 2.0 | 6 votes |
@Test public void testBroadcastEquality2() { INDArray array = Nd4j.zeros(new int[]{4, 5}, 'c'); INDArray array2 = Nd4j.zeros(new int[]{4, 5}, 'c'); INDArray column = Nd4j.create(new float[]{1, 2, 3, 4}).reshape(4,1); array.addiColumnVector(column); System.out.println(array); System.out.println("-------"); ScalarAdd add = new ScalarAdd(array2, column, array2, array2.length(), 0.0f); add.setDimension(1); Nd4j.getExecutioner().exec(add); System.out.println(array2); assertEquals(array, array2); }
Example 2
Source File: NativeOpExecutionerTest.java From nd4j with Apache License 2.0 | 6 votes |
@Test public void testBroadcastEquality2() { INDArray array = Nd4j.zeros(new int[]{4, 5}, 'c'); INDArray array2 = Nd4j.zeros(new int[]{4, 5}, 'c'); INDArray column = Nd4j.create(new float[]{1, 2, 3, 4}).reshape(4,1); array.addiColumnVector(column); System.out.println(array); System.out.println("-------"); ScalarAdd add = new ScalarAdd(array2, column, array2, array2.length(), 0.0f); add.setDimension(1); Nd4j.getExecutioner().exec(add); System.out.println(array2); assertEquals(array, array2); }
Example 3
Source File: Nd4jMatrix.java From jstarcraft-ai with Apache License 2.0 | 5 votes |
@Override public MathMatrix addColumnVector(MathVector vector) { if (vector instanceof Nd4jVector) { Nd4jEnvironmentThread thread = EnvironmentThread.getThread(Nd4jEnvironmentThread.class); try (MemoryWorkspace workspace = thread.getSpace()) { INDArray thisArray = this.getArray(); INDArray thatArray = Nd4jVector.class.cast(vector).getArray(); thisArray.addiColumnVector(thatArray); return this; } } else { return MathMatrix.super.addColumnVector(vector); } }
Example 4
Source File: NDArrayTestsFortran.java From nd4j with Apache License 2.0 | 5 votes |
@Test public void testColumnVectorOpsFortran() { INDArray twoByTwo = Nd4j.create(new float[] {1, 2, 3, 4}, new long[] {2, 2}); INDArray toAdd = Nd4j.create(new float[] {1, 2}, new long[] {2, 1}); twoByTwo.addiColumnVector(toAdd); INDArray assertion = Nd4j.create(new float[] {2, 4, 4, 6}, new long[] {2, 2}); assertEquals(assertion, twoByTwo); }
Example 5
Source File: NDArrayTestsFortran.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test public void testColumnVectorOpsFortran() { INDArray twoByTwo = Nd4j.create(new float[] {1, 2, 3, 4}, new long[] {2, 2}); INDArray toAdd = Nd4j.create(new float[] {1, 2}, new long[] {2, 1}); twoByTwo.addiColumnVector(toAdd); INDArray assertion = Nd4j.create(new float[] {2, 4, 4, 6}, new long[] {2, 2}); assertEquals(assertion, twoByTwo); }
Example 6
Source File: CrashTest.java From nd4j with Apache License 2.0 | 2 votes |
protected void op(INDArray x, INDArray y, int i) { // broadcast along row & column INDArray row = Nd4j.ones(64); INDArray column = Nd4j.ones(1024, 1); x.addiRowVector(row); x.addiColumnVector(column); // casual scalar x.addi(i * 2); // reduction along all dimensions float sum = x.sumNumber().floatValue(); // index reduction Nd4j.getExecutioner().exec(new IMax(x), Integer.MAX_VALUE); // casual transform Nd4j.getExecutioner().exec(new Sqrt(x, x)); // dup INDArray x1 = x.dup(x.ordering()); INDArray x2 = x.dup(x.ordering()); INDArray x3 = x.dup('c'); INDArray x4 = x.dup('f'); // vstack && hstack INDArray vstack = Nd4j.vstack(x, x1, x2, x3, x4); INDArray hstack = Nd4j.hstack(x, x1, x2, x3, x4); // reduce3 call Nd4j.getExecutioner().exec(new ManhattanDistance(x, x2)); // flatten call INDArray flat = Nd4j.toFlattened(x, x1, x2, x3, x4); // reduction along dimension: row & column INDArray max_0 = x.max(0); INDArray max_1 = x.max(1); // index reduction along dimension: row & column INDArray imax_0 = Nd4j.argMax(x, 0); INDArray imax_1 = Nd4j.argMax(x, 1); // logisoftmax, softmax & softmax derivative Nd4j.getExecutioner().exec(new OldSoftMax(x)); Nd4j.getExecutioner().exec(new SoftMaxDerivative(x)); Nd4j.getExecutioner().exec(new LogSoftMax(x)); // BooleanIndexing BooleanIndexing.replaceWhere(x, 5f, Conditions.lessThan(8f)); // assing on view BooleanIndexing.assignIf(x, x1, Conditions.greaterThan(-1000000000f)); // std var along all dimensions float std = x.stdNumber().floatValue(); // std var along row & col INDArray xStd_0 = x.std(0); INDArray xStd_1 = x.std(1); // blas call float dot = (float) Nd4j.getBlasWrapper().dot(x, x1); // mmul for (boolean tA : paramsA) { for (boolean tB : paramsB) { INDArray xT = tA ? x.dup() : x.dup().transpose(); INDArray yT = tB ? y.dup() : y.dup().transpose(); Nd4j.gemm(xT, yT, tA, tB); } } // specially for views, checking here without dup and rollover Nd4j.gemm(x, y, false, false); log.debug("Iteration passed: " + i); }
Example 7
Source File: CrashTest.java From deeplearning4j with Apache License 2.0 | 2 votes |
protected void op(INDArray x, INDArray y, int i) { // broadcast along row & column INDArray row = Nd4j.ones(64); INDArray column = Nd4j.ones(1024, 1); x.addiRowVector(row); x.addiColumnVector(column); // casual scalar x.addi(i * 2); // reduction along all dimensions float sum = x.sumNumber().floatValue(); // index reduction Nd4j.getExecutioner().exec(new ArgMax(x)); // casual transform Nd4j.getExecutioner().exec(new Sqrt(x, x)); // dup INDArray x1 = x.dup(x.ordering()); INDArray x2 = x.dup(x.ordering()); INDArray x3 = x.dup('c'); INDArray x4 = x.dup('f'); // vstack && hstack INDArray vstack = Nd4j.vstack(x, x1, x2, x3, x4); INDArray hstack = Nd4j.hstack(x, x1, x2, x3, x4); // reduce3 call Nd4j.getExecutioner().exec(new ManhattanDistance(x, x2)); // flatten call INDArray flat = Nd4j.toFlattened(x, x1, x2, x3, x4); // reduction along dimension: row & column INDArray max_0 = x.max(0); INDArray max_1 = x.max(1); // index reduction along dimension: row & column INDArray imax_0 = Nd4j.argMax(x, 0); INDArray imax_1 = Nd4j.argMax(x, 1); // logisoftmax, softmax & softmax derivative Nd4j.getExecutioner().exec((CustomOp) new SoftMax(x)); Nd4j.getExecutioner().exec((CustomOp) new LogSoftMax(x)); // BooleanIndexing BooleanIndexing.replaceWhere(x, 5f, Conditions.lessThan(8f)); // assing on view BooleanIndexing.assignIf(x, x1, Conditions.greaterThan(-1000000000f)); // std var along all dimensions float std = x.stdNumber().floatValue(); // std var along row & col INDArray xStd_0 = x.std(0); INDArray xStd_1 = x.std(1); // blas call float dot = (float) Nd4j.getBlasWrapper().dot(x, x1); // mmul for (boolean tA : paramsA) { for (boolean tB : paramsB) { INDArray xT = tA ? x.dup() : x.dup().transpose(); INDArray yT = tB ? y.dup() : y.dup().transpose(); Nd4j.gemm(xT, yT, tA, tB); } } // specially for views, checking here without dup and rollover Nd4j.gemm(x, y, false, false); log.debug("Iteration passed: " + i); }