@@ -91,31 +91,30 @@ assertEquals(3, slice.getInt(1, 0)); // (1, 1, 0) in the original matrix
9191
9292The NdArray library is independent of the TensorFlow runtime library, making it a good choice for
9393manipulating 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
105104try (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