Skip to content

Commit 3649959

Browse files
committed
Update TF integration example
1 parent c613cce commit 3649959

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,31 +91,30 @@ assertEquals(3, slice.getInt(1, 0)); // (1, 1, 0) in the original matrix
9191

9292
The NdArray library is independent of the TensorFlow runtime library, making it a good choice for
9393
manipulating multi-dimensional data structures from anywhere. But as an example, here
94-
is how it is actually being used by the [TensorFlow Core API](https://github.com/tensorflow/java/tree/master/tensorflow-core/tensorflow-core-api):
94+
is how it is actually being used by the [TensorFlow Java API](https://github.com/tensorflow/java/):
9595

9696
```java
9797
// Allocate a tensor of 32-bits integer of the shape (2, 3, 2)
98-
Tensor<TInt32> tensor = TInt32.ofShape(2, 3, 2);
98+
TInt32 tensor = TInt32.ofShape(2, 3, 2);
9999

100100
// Access tensor memory directly
101-
IntNdArray tensorData = tensor.data();
102-
assertEquals(3, tensorData.rank());
103-
assertEquals(12, tensorData.size());
101+
assertEquals(3, tensor.rank());
102+
assertEquals(12, tensor.size());
104103

105104
try (EagerSession session = EagerSession.create()) {
106105
Ops tf = Ops.create(session);
107106

108107
// Initialize tensor memory with zeros and take a snapshot
109-
tensorData.scalars().forEach(scalar -> scalar.setInt(0));
108+
tensor.scalars().forEach(scalar -> scalar.setInt(0));
110109
Constant<T> x = tf.constant(tensor);
111110

112111
// Initialize the same tensor memory with ones and take a snapshot
113-
tensorData.scalars().forEach(scalar -> scalar.setInt(1));
112+
tensor.scalars().forEach(scalar -> scalar.setInt(1));
114113
Constant<T> y = tf.constant(tensor);
115114

116115
// Subtract y from x and validate the result
117116
Sub<T> sub = tf.math.sub(x, y);
118-
sub.data().scalars().forEach(scalar ->
117+
sub.asTensor().scalars().forEach(scalar ->
119118
assertEquals(-1, scalar.getInt())
120119
);
121120
}

0 commit comments

Comments
 (0)