Skip to content

Commit 46645ee

Browse files
committed
Rebase fixes
Signed-off-by: Ryan Nett <rnett@calpoly.edu>
1 parent a50d06c commit 46645ee

File tree

5 files changed

+94
-86
lines changed

5 files changed

+94
-86
lines changed

tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/Ops.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,10 @@ public final class Ops {
354354

355355
public final SparseOps sparse;
356356

357-
public final TpuOps tpu;
358-
359357
public final BitwiseOps bitwise;
360358

359+
public final TpuOps tpu;
360+
361361
public final MathOps math;
362362

363363
public final AudioOps audio;
@@ -385,8 +385,8 @@ private Ops(Scope scope) {
385385
random = new RandomOps(this);
386386
strings = new StringsOps(this);
387387
sparse = new SparseOps(this);
388-
tpu = new TpuOps(this);
389388
bitwise = new BitwiseOps(this);
389+
tpu = new TpuOps(this);
390390
math = new MathOps(this);
391391
audio = new AudioOps(this);
392392
signal = new SignalOps(this);

tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/EagerOperationTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public class EagerOperationTest {
3535
public void failToCreateIfSessionIsClosed() {
3636
EagerSession session = EagerSession.create();
3737
session.close();
38-
try (TInt32 t = TInt32.tensorOf(Shape.of(2, 3))) {
38+
try (TensorScope scope = new TensorScope()) {
39+
TInt32 t = TInt32.tensorOf(scope, Shape.of(2, 3));
3940
EagerOperation op =
4041
opBuilder(session, "Const", "OutputAttrs")
4142
.setAttr("dtype", t.dataType())

tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/op/core/BooleanMaskTest.java

+21-20
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@
2222
import org.tensorflow.Graph;
2323
import org.tensorflow.Operand;
2424
import org.tensorflow.Session;
25+
import org.tensorflow.TensorScope;
2526
import org.tensorflow.ndarray.Shape;
2627
import org.tensorflow.op.Scope;
2728
import org.tensorflow.types.TBool;
2829
import org.tensorflow.types.TFloat32;
2930
import org.tensorflow.types.TInt32;
3031

3132
public class BooleanMaskTest {
33+
3234
@Test
33-
public void testBooleanMask(){
35+
public void testBooleanMask() {
3436
try (Graph g = new Graph();
35-
Session sess = new Session(g)) {
37+
Session sess = new Session(g);
38+
TensorScope tensorScope = new TensorScope()) {
3639
Scope scope = new Scope(g);
3740

3841
Operand<TInt32> input = Constant.arrayOf(scope, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
@@ -43,25 +46,23 @@ public void testBooleanMask(){
4346
Operand<TInt32> output1 = BooleanMask.create(scope, input, mask);
4447
Operand<TInt32> output2 = BooleanMask.create(scope, input2, mask, BooleanMask.axis(1));
4548

46-
try (TFloat32 result = (TFloat32) sess.runner().fetch(output1).run().get(0)) {
47-
// expected shape from Python tensorflow
48-
assertEquals(Shape.of(5), result.shape());
49-
assertEquals(0, result.getFloat(0));
50-
assertEquals(1, result.getFloat(1));
51-
assertEquals(4, result.getFloat(2));
52-
assertEquals(5, result.getFloat(3));
53-
assertEquals(6, result.getFloat(4));
54-
}
49+
TFloat32 result = (TFloat32) sess.runner().fetch(output1).run(tensorScope).get(0);
50+
// expected shape from Python tensorflow
51+
assertEquals(Shape.of(5), result.shape());
52+
assertEquals(0, result.getFloat(0));
53+
assertEquals(1, result.getFloat(1));
54+
assertEquals(4, result.getFloat(2));
55+
assertEquals(5, result.getFloat(3));
56+
assertEquals(6, result.getFloat(4));
5557

56-
try (TFloat32 result = (TFloat32) sess.runner().fetch(output2).run().get(0)) {
57-
// expected shape from Python tensorflow
58-
assertEquals(Shape.of(5), result.shape());
59-
assertEquals(0, result.getFloat(0));
60-
assertEquals(1, result.getFloat(1));
61-
assertEquals(4, result.getFloat(2));
62-
assertEquals(5, result.getFloat(3));
63-
assertEquals(6, result.getFloat(4));
64-
}
58+
TFloat32 result2 = (TFloat32) sess.runner().fetch(output2).run(tensorScope).get(0);
59+
// expected shape from Python tensorflow
60+
assertEquals(Shape.of(5), result2.shape());
61+
assertEquals(0, result2.getFloat(0));
62+
assertEquals(1, result2.getFloat(1));
63+
assertEquals(4, result2.getFloat(2));
64+
assertEquals(5, result2.getFloat(3));
65+
assertEquals(6, result2.getFloat(4));
6566
}
6667
}
6768
}

tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/op/core/BooleanMaskUpdateTest.java

+53-52
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.tensorflow.Operand;
2525
import org.tensorflow.Session;
2626
import org.tensorflow.Tensor;
27+
import org.tensorflow.TensorScope;
2728
import org.tensorflow.ndarray.Shape;
2829
import org.tensorflow.op.Scope;
2930
import org.tensorflow.types.TBool;
@@ -34,7 +35,8 @@ public class BooleanMaskUpdateTest {
3435
@Test
3536
public void testBooleanMaskUpdateSlice() {
3637
try (Graph g = new Graph();
37-
Session sess = new Session(g)) {
38+
Session sess = new Session(g);
39+
TensorScope tensorScope = new TensorScope()) {
3840
Scope scope = new Scope(g);
3941

4042
Operand<TInt32> input = Constant.tensorOf(scope, new int[][]{{0, 0, 0}, {1, 1, 1}, {2, 2, 2}});
@@ -47,31 +49,31 @@ public void testBooleanMaskUpdateSlice() {
4749

4850
Operand<TInt32> bcastOutput = BooleanMaskUpdate.create(scope, input, mask, Constant.scalarOf(scope, -1));
4951

50-
List<Tensor> results = sess.runner().fetch(output).fetch(bcastOutput).run();
51-
try (TInt32 result = (TInt32) results.get(0);
52-
TInt32 bcastResult = (TInt32) results.get(1)) {
52+
List<Tensor> results = sess.runner().fetch(output).fetch(bcastOutput).run(tensorScope);
53+
TInt32 result = (TInt32) results.get(0);
54+
TInt32 bcastResult = (TInt32) results.get(1);
5355

54-
assertEquals(Shape.of(3, 3), result.shape());
56+
assertEquals(Shape.of(3, 3), result.shape());
5557

56-
assertEquals(-1, result.getInt(0, 0));
57-
assertEquals(-1, result.getInt(0, 1));
58-
assertEquals(-1, result.getInt(0, 2));
59-
assertEquals(1, result.getInt(1, 0));
60-
assertEquals(1, result.getInt(1, 1));
61-
assertEquals(1, result.getInt(1, 2));
62-
assertEquals(2, result.getInt(2, 0));
63-
assertEquals(2, result.getInt(2, 1));
64-
assertEquals(2, result.getInt(2, 2));
58+
assertEquals(-1, result.getInt(0, 0));
59+
assertEquals(-1, result.getInt(0, 1));
60+
assertEquals(-1, result.getInt(0, 2));
61+
assertEquals(1, result.getInt(1, 0));
62+
assertEquals(1, result.getInt(1, 1));
63+
assertEquals(1, result.getInt(1, 2));
64+
assertEquals(2, result.getInt(2, 0));
65+
assertEquals(2, result.getInt(2, 1));
66+
assertEquals(2, result.getInt(2, 2));
6567

66-
assertEquals(result, bcastResult);
67-
}
68+
assertEquals(result, bcastResult);
6869
}
6970
}
7071

7172
@Test
7273
public void testBooleanMaskUpdateSliceWithBroadcast() {
7374
try (Graph g = new Graph();
74-
Session sess = new Session(g)) {
75+
Session sess = new Session(g);
76+
TensorScope tensorScope = new TensorScope()) {
7577
Scope scope = new Scope(g);
7678

7779
Operand<TInt32> input = Constant.tensorOf(scope, new int[][]{{0, 0, 0}, {1, 1, 1}, {2, 2, 2}});
@@ -84,31 +86,31 @@ public void testBooleanMaskUpdateSliceWithBroadcast() {
8486

8587
Operand<TInt32> bcastOutput = BooleanMaskUpdate.create(scope, input, mask, Constant.scalarOf(scope, -1));
8688

87-
List<Tensor> results = sess.runner().fetch(output).fetch(bcastOutput).run();
88-
try (TInt32 result = (TInt32) results.get(0);
89-
TInt32 bcastResult = (TInt32) results.get(1)) {
89+
List<Tensor> results = sess.runner().fetch(output).fetch(bcastOutput).run(tensorScope);
90+
TInt32 result = (TInt32) results.get(0);
91+
TInt32 bcastResult = (TInt32) results.get(1);
9092

91-
assertEquals(Shape.of(3, 3), result.shape());
93+
assertEquals(Shape.of(3, 3), result.shape());
9294

93-
assertEquals(-1, result.getInt(0, 0));
94-
assertEquals(-1, result.getInt(0, 1));
95-
assertEquals(-1, result.getInt(0, 2));
96-
assertEquals(1, result.getInt(1, 0));
97-
assertEquals(1, result.getInt(1, 1));
98-
assertEquals(1, result.getInt(1, 2));
99-
assertEquals(2, result.getInt(2, 0));
100-
assertEquals(2, result.getInt(2, 1));
101-
assertEquals(2, result.getInt(2, 2));
95+
assertEquals(-1, result.getInt(0, 0));
96+
assertEquals(-1, result.getInt(0, 1));
97+
assertEquals(-1, result.getInt(0, 2));
98+
assertEquals(1, result.getInt(1, 0));
99+
assertEquals(1, result.getInt(1, 1));
100+
assertEquals(1, result.getInt(1, 2));
101+
assertEquals(2, result.getInt(2, 0));
102+
assertEquals(2, result.getInt(2, 1));
103+
assertEquals(2, result.getInt(2, 2));
102104

103-
assertEquals(result, bcastResult);
104-
}
105+
assertEquals(result, bcastResult);
105106
}
106107
}
107108

108109
@Test
109110
public void testBooleanMaskUpdateAxis() {
110111
try (Graph g = new Graph();
111-
Session sess = new Session(g)) {
112+
Session sess = new Session(g);
113+
TensorScope tensorScope = new TensorScope()) {
112114
Scope scope = new Scope(g);
113115

114116
Operand<TInt32> input = Constant.tensorOf(scope, new int[][][]{{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}}});
@@ -122,25 +124,24 @@ public void testBooleanMaskUpdateAxis() {
122124
Operand<TInt32> bcastOutput = BooleanMaskUpdate
123125
.create(scope, input, mask, Constant.scalarOf(scope, -1), BooleanMaskUpdate.axis(2));
124126

125-
List<Tensor> results = sess.runner().fetch(output).fetch(bcastOutput).run();
126-
try (TInt32 result = (TInt32) results.get(0);
127-
TInt32 bcastResult = (TInt32) results.get(1)) {
128-
129-
assertEquals(Shape.of(1, 1, 10), result.shape());
130-
131-
assertEquals(-1, result.getInt(0, 0, 0));
132-
assertEquals(-1, result.getInt(0, 0, 1));
133-
assertEquals(2, result.getInt(0, 0, 2));
134-
assertEquals(3, result.getInt(0, 0, 3));
135-
assertEquals(-1, result.getInt(0, 0, 4));
136-
assertEquals(-1, result.getInt(0, 0, 5));
137-
assertEquals(-1, result.getInt(0, 0, 6));
138-
assertEquals(7, result.getInt(0, 0, 7));
139-
assertEquals(8, result.getInt(0, 0, 8));
140-
assertEquals(9, result.getInt(0, 0, 9));
141-
142-
assertEquals(result, bcastResult);
143-
}
127+
List<Tensor> results = sess.runner().fetch(output).fetch(bcastOutput).run(tensorScope);
128+
TInt32 result = (TInt32) results.get(0);
129+
TInt32 bcastResult = (TInt32) results.get(1);
130+
131+
assertEquals(Shape.of(1, 1, 10), result.shape());
132+
133+
assertEquals(-1, result.getInt(0, 0, 0));
134+
assertEquals(-1, result.getInt(0, 0, 1));
135+
assertEquals(2, result.getInt(0, 0, 2));
136+
assertEquals(3, result.getInt(0, 0, 3));
137+
assertEquals(-1, result.getInt(0, 0, 4));
138+
assertEquals(-1, result.getInt(0, 0, 5));
139+
assertEquals(-1, result.getInt(0, 0, 6));
140+
assertEquals(7, result.getInt(0, 0, 7));
141+
assertEquals(8, result.getInt(0, 0, 8));
142+
assertEquals(9, result.getInt(0, 0, 9));
143+
144+
assertEquals(result, bcastResult);
144145
}
145146
}
146147
}

tensorflow-framework/src/test/java/org/tensorflow/framework/constraints/MinMaxNormTest.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package org.tensorflow.framework.constraints;
22

3+
import java.util.Random;
4+
import java.util.concurrent.atomic.AtomicInteger;
35
import org.junit.jupiter.api.Test;
46
import org.tensorflow.Operand;
7+
import org.tensorflow.TensorScope;
58
import org.tensorflow.framework.utils.ND;
69
import org.tensorflow.framework.utils.TestSession;
710
import org.tensorflow.ndarray.FloatNdArray;
@@ -10,9 +13,6 @@
1013
import org.tensorflow.op.Ops;
1114
import org.tensorflow.types.TFloat32;
1215

13-
import java.util.Random;
14-
import java.util.concurrent.atomic.AtomicInteger;
15-
1616
class MinMaxNormTest {
1717

1818
private final TestSession.Mode[] tfModes = {TestSession.Mode.EAGER, TestSession.Mode.GRAPH};
@@ -27,12 +27,15 @@ private float[] getSampleArray() {
2727
return result;
2828
}
2929

30-
/** Test of call method, of class MinMaxNorm. */
30+
/**
31+
* Test of call method, of class MinMaxNorm.
32+
*/
3133
@Test
3234
public void testCall() {
3335
float[] testValues = {0.1f, 0.5f, 3f, 8f, 1e-7f};
34-
for (TestSession.Mode tfMode : tfModes)
35-
try (TestSession session = TestSession.createTestSession(tfMode)) {
36+
for (TestSession.Mode tfMode : tfModes) {
37+
try (TestSession session = TestSession.createTestSession(tfMode);
38+
TensorScope scope = new TensorScope()) {
3639
Ops tf = session.getTF();
3740
final float[] array = getSampleArray();
3841
Operand<TFloat32> weights = tf.reshape(tf.constant(array), tf.constant(Shape.of(100, 100)));
@@ -41,15 +44,17 @@ public void testCall() {
4144
i.getAndIncrement()) {
4245
MinMaxNorm instance = new MinMaxNorm(tf, testValues[i.get()], testValues[i.get()] * 2);
4346
Operand<TFloat32> result = instance.call(weights);
44-
if (tfMode == TestSession.Mode.EAGER)
45-
evaluate(session, result.asTensor(), testValues[i.get()]);
46-
else
47+
if (tfMode == TestSession.Mode.EAGER) {
48+
evaluate(session, result.asTensor(scope), testValues[i.get()]);
49+
} else {
4750
try (TFloat32 tensor =
48-
(TFloat32) session.getGraphSession().runner().fetch(result).run().get(0)) {
51+
(TFloat32) session.getGraphSession().runner().fetch(result).run(scope).get(0)) {
4952
evaluate(session, tensor, testValues[i.get()]);
5053
}
54+
}
5155
}
5256
}
57+
}
5358
}
5459

5560
private void evaluate(TestSession session, TFloat32 tensor, float m) {

0 commit comments

Comments
 (0)