Java Code Examples for org.nd4j.linalg.ops.transforms.Transforms#or()
The following examples show how to use
org.nd4j.linalg.ops.transforms.Transforms#or() .
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: TransformsTest.java From nd4j with Apache License 2.0 | 5 votes |
@Test public void testOr1() { INDArray x = Nd4j.create(new double[] {0, 0, 1, 0, 0}); INDArray y = Nd4j.create(new double[] {0, 0, 1, 1, 0}); INDArray z = Transforms.or(x, y); assertEquals(y, z); }
Example 2
Source File: TransformsTest.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test public void testOr1() { INDArray x = Nd4j.create(new double[] {0, 0, 1, 0, 0}); INDArray y = Nd4j.create(new double[] {0, 0, 1, 1, 0}); val e = Nd4j.create(new boolean[] {false, false, true, true, false}); INDArray z = Transforms.or(x, y); assertEquals(e, z); }
Example 3
Source File: SpecialTests.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Test public void testYoloStyle(){ WorkspaceConfiguration WS_ALL_LAYERS_ACT_CONFIG = WorkspaceConfiguration.builder() .initialSize(0) .overallocationLimit(0.05) .policyLearning(LearningPolicy.FIRST_LOOP) .policyReset(ResetPolicy.BLOCK_LEFT) .policySpill(SpillPolicy.REALLOCATE) .policyAllocation(AllocationPolicy.OVERALLOCATE) .build(); for( int i=0; i<10; i++ ){ try(val ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(WS_ALL_LAYERS_ACT_CONFIG, "ws")){ // System.out.println("STARTING: " + i); INDArray objectPresentMask = Nd4j.create(DataType.BOOL, 1,4,4); long[] shape = {1,3,2,4,4}; INDArray noIntMask1 = Nd4j.createUninitialized(DataType.BOOL, shape, 'c'); INDArray noIntMask2 = Nd4j.createUninitialized(DataType.BOOL, shape, 'c'); noIntMask1 = Transforms.or(noIntMask1.get(all(), all(), point(0), all(), all()), noIntMask1.get(all(), all(), point(1), all(), all()) ); //Shape: [mb, b, H, W]. Values 1 if no intersection noIntMask2 = Transforms.or(noIntMask2.get(all(), all(), point(0), all(), all()), noIntMask2.get(all(), all(), point(1), all(), all()) ); INDArray noIntMask = Transforms.or(noIntMask1, noIntMask2 ); Nd4j.getExecutioner().commit(); INDArray intMask = Transforms.not(noIntMask); //Values 0 if no intersection Nd4j.getExecutioner().commit(); Broadcast.mul(intMask, objectPresentMask, intMask, 0, 2, 3); Nd4j.getExecutioner().commit(); // System.out.println("DONE: " + i); } } }
Example 4
Source File: SameDiffTests.java From nd4j with Apache License 2.0 | 4 votes |
@Test public void testPairwiseBooleanTransforms() { /* eq, neq, gt, lt, gte, lte, or, and, xor */ //Test transforms (pairwise) Nd4j.getRandom().setSeed(12345); for (int i = 0; i < 11; i++) { SameDiff sd = SameDiff.create(); int nOut = 4; int minibatch = 5; INDArray ia = Nd4j.randn(minibatch, nOut); INDArray ib = Nd4j.randn(minibatch, nOut); SDVariable in1 = sd.var("in1", ia); SDVariable in2 = sd.var("in2", ib); SDVariable t; INDArray expOut; switch (i) { case 0: t = sd.eq(in1, in2); expOut = ia.eq(ib); break; case 1: t = sd.neq(in1, in2); expOut = ia.neq(ib); break; case 2: t = sd.gt(in1, in2); expOut = ia.gt(ib); break; case 3: t = sd.lt(in1, in2); expOut = ia.lt(ib); break; case 4: t = sd.gte(in1, in2); expOut = ia.dup(); Nd4j.getExecutioner().exec(new GreaterThanOrEqual(new INDArray[]{ia, ib}, new INDArray[]{expOut})); break; case 5: t = sd.lte(in1, in2); expOut = ia.dup(); Nd4j.getExecutioner().exec(new LessThanOrEqual(new INDArray[]{ia, ib}, new INDArray[]{expOut})); break; case 6: ia = Nd4j.getExecutioner().exec(new BernoulliDistribution(ia, 0.5)); ib = Nd4j.getExecutioner().exec(new BernoulliDistribution(ib, 0.5)); t = sd.or(in1, in2); expOut = Transforms.or(ia, ib); break; case 7: t = sd.max(in1, in2); expOut = Nd4j.getExecutioner().execAndReturn(new OldMax(ia, ib, ia.dup(), ia.length())); break; case 8: t = sd.min(in1, in2); expOut = Nd4j.getExecutioner().execAndReturn(new OldMin(ia, ib, ia.dup(), ia.length())); break; case 9: ia = Nd4j.getExecutioner().exec(new BernoulliDistribution(ia, 0.5)); ib = Nd4j.getExecutioner().exec(new BernoulliDistribution(ib, 0.5)); t = sd.and(in1, in2); expOut = Transforms.and(ia, ib); break; case 10: ia = Nd4j.getExecutioner().exec(new BernoulliDistribution(ia, 0.5)); ib = Nd4j.getExecutioner().exec(new BernoulliDistribution(ib, 0.5)); t = sd.xor(in1, in2); expOut = Transforms.xor(ia, ib); break; default: throw new RuntimeException(); } log.info("Executing: " + i); INDArray out = sd.execAndEndResult(); assertEquals(expOut, out); } }
Example 5
Source File: SameDiffTests.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Test public void testPairwiseBooleanTransforms() { /* eq, neq, gt, lt, gte, lte, or, and, xor */ //Test transforms (pairwise) Nd4j.getRandom().setSeed(12345); for (int i = 0; i < 11; i++) { SameDiff sd = SameDiff.create(); int nOut = 4; int minibatch = 5; INDArray ia = Nd4j.randn(minibatch, nOut); INDArray ib = Nd4j.randn(minibatch, nOut); SDVariable in1 = sd.var("in1", ia); SDVariable in2 = sd.var("in2", ib); SDVariable t; INDArray expOut; switch (i) { case 0: t = sd.eq(in1, in2); expOut = ia.eq(ib); break; case 1: t = sd.neq(in1, in2); expOut = ia.neq(ib); break; case 2: t = sd.gt(in1, in2); expOut = ia.gt(ib); break; case 3: t = sd.lt(in1, in2); expOut = ia.lt(ib); break; case 4: t = sd.gte(in1, in2); expOut = Nd4j.create(DataType.BOOL, ia.shape()); Nd4j.exec(new GreaterThanOrEqual(new INDArray[]{ia, ib}, new INDArray[]{expOut})); break; case 5: t = sd.lte(in1, in2); expOut = Nd4j.create(DataType.BOOL, ia.shape()); Nd4j.exec(new LessThanOrEqual(new INDArray[]{ia, ib}, new INDArray[]{expOut})); break; case 6: ia = Nd4j.exec(new BernoulliDistribution(ia, 0.5)); ib = Nd4j.exec(new BernoulliDistribution(ib, 0.5)); t = sd.math().or(in1.castTo(DataType.BOOL), in2.castTo(DataType.BOOL)); expOut = Transforms.or(ia, ib); break; case 7: t = sd.max(in1, in2); expOut = Nd4j.exec(new Max(ia, ib, ia.dup()))[0]; break; case 8: t = sd.min(in1, in2); expOut = Nd4j.exec(new Min(ia, ib, ia.dup()))[0]; break; case 9: ia = Nd4j.exec(new BernoulliDistribution(ia, 0.5)); ib = Nd4j.exec(new BernoulliDistribution(ib, 0.5)); t = sd.math().and(in1.castTo(DataType.BOOL), in2.castTo(DataType.BOOL)); expOut = Transforms.and(ia, ib); break; case 10: ia = Nd4j.exec(new BernoulliDistribution(ia, 0.5)); ib = Nd4j.exec(new BernoulliDistribution(ib, 0.5)); t = sd.math().xor(in1.castTo(DataType.BOOL), in2.castTo(DataType.BOOL)); expOut = Transforms.xor(ia, ib); break; default: throw new RuntimeException(); } log.info("Executing: " + i); INDArray out = t.eval(); assertEquals(expOut, out); } }