aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/java/src/main/java/org/tensorflow/Shape.java
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/java/src/main/java/org/tensorflow/Shape.java')
-rw-r--r--tensorflow/java/src/main/java/org/tensorflow/Shape.java42
1 files changed, 7 insertions, 35 deletions
diff --git a/tensorflow/java/src/main/java/org/tensorflow/Shape.java b/tensorflow/java/src/main/java/org/tensorflow/Shape.java
index d99b0078f6..d533c3d480 100644
--- a/tensorflow/java/src/main/java/org/tensorflow/Shape.java
+++ b/tensorflow/java/src/main/java/org/tensorflow/Shape.java
@@ -74,41 +74,7 @@ public final class Shape {
* @return The size of the requested dimension or -1 if it is unknown.
*/
public long size(int i) {
- return shape == null ? -1 : shape[i];
- }
-
- /**
- * The total number of elements found in a tensor of this shape.
- *
- * <p>If the size of some dimensions is unknown, the total number of elements cannot be calculated and -1 is returned.
- *
- * @return the number of elements or -1 if size of some dimension are unknown
- */
- public int numElements() {
- if (shape == null) {
- return -1;
- }
- int total = 1;
- for (int i = 0; i < shape.length; ++i) {
- // TODO (karllessard): There might be a lossy conversion here from 'long' sizes to 'int' total, but this issue
- // seems ubiquitous in the current Java client implementation. It should be adressed all at once.
- int size = (int) size(i);
- if (size < 0) {
- return -1;
- }
- total *= size;
- }
- return total;
- }
-
- /**
- * Returns the shape as an array.
- *
- * <p>Each element represent the size of the dimension at the given index. For example,
- * {@code shape.asArray()[2]} is equal to the size of the third dimension of this shape.
- */
- public long[] asArray() {
- return shape;
+ return shape[i];
}
@Override
@@ -143,6 +109,12 @@ public final class Shape {
this.shape = shape;
}
+ // Package-private accessor.
+ // The idea is that the public API does not expose the internal array.
+ long[] asArray() {
+ return shape;
+ }
+
private long[] shape;
private boolean hasUnknownDimension() {