aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/java/src/test/java/org/tensorflow/TestUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/java/src/test/java/org/tensorflow/TestUtil.java')
-rw-r--r--tensorflow/java/src/test/java/org/tensorflow/TestUtil.java24
1 files changed, 14 insertions, 10 deletions
diff --git a/tensorflow/java/src/test/java/org/tensorflow/TestUtil.java b/tensorflow/java/src/test/java/org/tensorflow/TestUtil.java
index 265e21203b..6a3a16c2e1 100644
--- a/tensorflow/java/src/test/java/org/tensorflow/TestUtil.java
+++ b/tensorflow/java/src/test/java/org/tensorflow/TestUtil.java
@@ -54,6 +54,7 @@ public class TestUtil {
/**
* Counts the total number of elements in an ND array.
+ *
* @param array the array to count the elements of
* @return the number of elements
*/
@@ -61,10 +62,9 @@ public class TestUtil {
int count = 0;
for (int i = 0; i < Array.getLength(array); i++) {
Object e = Array.get(array, i);
- if(!e.getClass().isArray()) {
+ if (!e.getClass().isArray()) {
count += 1;
- }
- else {
+ } else {
count += flattenedNumElements(e);
}
}
@@ -73,6 +73,7 @@ public class TestUtil {
/**
* Flattens an ND-array into a 1D-array with the same elements.
+ *
* @param array the array to flatten
* @param elementType the element class (e.g. {@code Integer.TYPE} for an {@code int[]})
* @return a flattened array
@@ -86,10 +87,9 @@ public class TestUtil {
private static int flatten(Object array, Object out, int next) {
for (int i = 0; i < Array.getLength(array); i++) {
Object e = Array.get(array, i);
- if(!e.getClass().isArray()) {
+ if (!e.getClass().isArray()) {
Array.set(out, next++, e);
- }
- else {
+ } else {
next = flatten(e, out, next);
}
}
@@ -99,11 +99,12 @@ public class TestUtil {
/**
* Converts a {@code boolean[]} to a {@code byte[]}.
*
- * <p>Suitable for creating tensors of type {@link DataType#BOOL} using {@link java.nio.ByteBuffer}.
+ * <p>Suitable for creating tensors of type {@link DataType#BOOL} using {@link
+ * java.nio.ByteBuffer}.
*/
public static byte[] bool2byte(boolean[] array) {
byte[] out = new byte[array.length];
- for(int i = 0; i< array.length; i++) {
+ for (int i = 0; i < array.length; i++) {
out[i] = array[i] ? (byte) 1 : (byte) 0;
}
return out;
@@ -112,13 +113,16 @@ public class TestUtil {
/**
* Converts a {@code byte[]} to a {@code boolean[]}.
*
- * <p>Suitable for reading tensors of type {@link DataType#BOOL} using {@link java.nio.ByteBuffer}.
+ * <p>Suitable for reading tensors of type {@link DataType#BOOL} using {@link
+ * java.nio.ByteBuffer}.
*/
public static boolean[] byte2bool(byte[] array) {
boolean[] out = new boolean[array.length];
- for(int i = 0; i< array.length; i++) {
+ for (int i = 0; i < array.length; i++) {
out[i] = array[i] != 0;
}
return out;
}
+
+ private TestUtil() {}
}