@@ -91,31 +91,30 @@ assertEquals(3, slice.getInt(1, 0)); // (1, 1, 0) in the original matrix
91
91
92
92
The NdArray library is independent of the TensorFlow runtime library, making it a good choice for
93
93
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/ ) :
95
95
96
96
``` java
97
97
// 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 );
99
99
100
100
// 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());
104
103
105
104
try (EagerSession session = EagerSession . create()) {
106
105
Ops tf = Ops . create(session);
107
106
108
107
// 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 ));
110
109
Constant<T > x = tf. constant(tensor);
111
110
112
111
// 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 ));
114
113
Constant<T > y = tf. constant(tensor);
115
114
116
115
// Subtract y from x and validate the result
117
116
Sub<T > sub = tf. math. sub(x, y);
118
- sub. data (). scalars(). forEach(scalar - >
117
+ sub. asTensor (). scalars(). forEach(scalar - >
119
118
assertEquals(- 1 , scalar. getInt())
120
119
);
121
120
}
0 commit comments