Package ai.onnxruntime
Class OrtUtil
java.lang.Object
ai.onnxruntime.OrtUtil
Util code for interacting with Java arrays.
-
Method Summary
Modifier and TypeMethodDescriptionstatic longelementCount(long[] shape) Counts the number of elements stored in a Tensor of this shape.static String[]Flatten a multidimensional String array into a single dimensional String array, reading it in a multidimensional row-major order.static ObjectnewBooleanArray(long[] shape) Creates a new primitive boolean array of up to 8 dimensions, using the supplied shape.static ObjectnewByteArray(long[] shape) Creates a new primitive byte array of up to 8 dimensions, using the supplied shape.static ObjectnewDoubleArray(long[] shape) Creates a new primitive double array of up to 8 dimensions, using the supplied shape.static ObjectnewFloatArray(long[] shape) Creates a new primitive float array of up to 8 dimensions, using the supplied shape.static ObjectnewIntArray(long[] shape) Creates a new primitive int array of up to 8 dimensions, using the supplied shape.static ObjectnewLongArray(long[] shape) Creates a new primitive long array of up to 8 dimensions, using the supplied shape.static ObjectnewShortArray(long[] shape) Creates a new primitive short array of up to 8 dimensions, using the supplied shape.static ObjectnewStringArray(long[] shape) Creates a new String array of up to 8 dimensions, using the supplied shape.static Objectreshape(boolean[] input, long[] shape) Reshapes a boolean array into the desired n-dimensional array assuming the boolean array is stored in n-dimensional row-major order.static Objectreshape(byte[] input, long[] shape) Reshapes a byte array into the desired n-dimensional array assuming the byte array is stored in n-dimensional row-major order.static Objectreshape(double[] input, long[] shape) Reshapes a double array into the desired n-dimensional array assuming the double array is stored in n-dimensional row-major order.static Objectreshape(float[] input, long[] shape) Reshapes a float array into the desired n-dimensional array assuming the float array is stored in n-dimensional row-major order.static Objectreshape(int[] input, long[] shape) Reshapes an int array into the desired n-dimensional array, assuming the int array is stored in n-dimensional row-major order.static Objectreshape(long[] input, long[] shape) Reshapes a long array into the desired n-dimensional array, assuming the long array is stored in n-dimensional row-major order.static Objectreshape(short[] input, long[] shape) Reshapes a short array into the desired n-dimensional array assuming the short array is stored in n-dimensional row-major order.static ObjectReshapes a String array into the desired n-dimensional array assuming the String array is stored in n-dimensional row-major order.static long[]transformShape(int[] shape) Converts an int shape into a long shape.static int[]transformShape(long[] shape) Converts a long shape into an int shape.static booleanvalidateShape(long[] shape) Checks that the shape is a valid shape for a Java array (i.e.
-
Method Details
-
transformShape
public static int[] transformShape(long[] shape) Converts a long shape into an int shape.Validates that the shape has more than 1 element, less than 9 elements, each element is less than
Integer.MAX_VALUEand that each entry is non-negative.- Parameters:
shape- The long shape.- Returns:
- The int shape.
-
transformShape
public static long[] transformShape(int[] shape) Converts an int shape into a long shape.Validates that the shape has more than 1 element, less than 9 elements and that each entry is non-negative.
- Parameters:
shape- The int shape.- Returns:
- The long shape.
-
newBooleanArray
Creates a new primitive boolean array of up to 8 dimensions, using the supplied shape.- Parameters:
shape- The shape of array to create.- Returns:
- A boolean array.
-
newByteArray
Creates a new primitive byte array of up to 8 dimensions, using the supplied shape.- Parameters:
shape- The shape of array to create.- Returns:
- A byte array.
-
newShortArray
Creates a new primitive short array of up to 8 dimensions, using the supplied shape.- Parameters:
shape- The shape of array to create.- Returns:
- A short array.
-
newIntArray
Creates a new primitive int array of up to 8 dimensions, using the supplied shape.- Parameters:
shape- The shape of array to create.- Returns:
- A int array.
-
newLongArray
Creates a new primitive long array of up to 8 dimensions, using the supplied shape.- Parameters:
shape- The shape of array to create.- Returns:
- A long array.
-
newFloatArray
Creates a new primitive float array of up to 8 dimensions, using the supplied shape.- Parameters:
shape- The shape of array to create.- Returns:
- A float array.
-
newDoubleArray
Creates a new primitive double array of up to 8 dimensions, using the supplied shape.- Parameters:
shape- The shape of array to create.- Returns:
- A double array.
-
newStringArray
Creates a new String array of up to 8 dimensions, using the supplied shape.- Parameters:
shape- The shape of array to create.- Returns:
- A double array.
-
reshape
Reshapes a boolean array into the desired n-dimensional array assuming the boolean array is stored in n-dimensional row-major order. ThrowsIllegalArgumentExceptionif the number of elements doesn't match between the shape and the input or the shape is invalid.- Parameters:
input- The boolean array.shape- The desired shape.- Returns:
- An n-dimensional boolean array.
-
reshape
Reshapes a byte array into the desired n-dimensional array assuming the byte array is stored in n-dimensional row-major order. ThrowsIllegalArgumentExceptionif the number of elements doesn't match between the shape and the input or the shape is invalid.- Parameters:
input- The byte array.shape- The desired shape.- Returns:
- An n-dimensional byte array.
-
reshape
Reshapes a short array into the desired n-dimensional array assuming the short array is stored in n-dimensional row-major order. ThrowsIllegalArgumentExceptionif the number of elements doesn't match between the shape and the input or the shape is invalid.- Parameters:
input- The short array.shape- The desired shape.- Returns:
- An n-dimensional short array.
-
reshape
Reshapes an int array into the desired n-dimensional array, assuming the int array is stored in n-dimensional row-major order. ThrowsIllegalArgumentExceptionif the number of elements doesn't match between the shape and the input or the shape is invalid.- Parameters:
input- The int array.shape- The desired shape.- Returns:
- An n-dimensional int array.
-
reshape
Reshapes a long array into the desired n-dimensional array, assuming the long array is stored in n-dimensional row-major order. ThrowsIllegalArgumentExceptionif the number of elements doesn't match between the shape and the input or the shape is invalid.- Parameters:
input- The long array.shape- The desired shape.- Returns:
- An n-dimensional long array.
-
reshape
Reshapes a float array into the desired n-dimensional array assuming the float array is stored in n-dimensional row-major order. ThrowsIllegalArgumentExceptionif the number of elements doesn't match between the shape and the input or the shape is invalid.- Parameters:
input- The float array.shape- The desired shape.- Returns:
- An n-dimensional float array.
-
reshape
Reshapes a double array into the desired n-dimensional array assuming the double array is stored in n-dimensional row-major order. ThrowsIllegalArgumentExceptionif the number of elements doesn't match between the shape and the input or the shape is invalid.- Parameters:
input- The double array.shape- The desired shape.- Returns:
- An n-dimensional double array.
-
reshape
Reshapes a String array into the desired n-dimensional array assuming the String array is stored in n-dimensional row-major order. ThrowsIllegalArgumentExceptionif the number of elements doesn't match between the shape and the input or the shape is invalid.- Parameters:
input- The double array.shape- The desired shape.- Returns:
- An n-dimensional String array.
-
elementCount
public static long elementCount(long[] shape) Counts the number of elements stored in a Tensor of this shape.Multiplies all the elements together if they are non-negative, throws an
IllegalArgumentExceptionotherwise.- Parameters:
shape- The shape to use.- Returns:
- The number of elements.
-
validateShape
public static boolean validateShape(long[] shape) Checks that the shape is a valid shape for a Java array (i.e. that the values are all positive and representable by an int).- Parameters:
shape- The shape to check.- Returns:
- True if the shape is valid.
-
flattenString
Flatten a multidimensional String array into a single dimensional String array, reading it in a multidimensional row-major order.- Parameters:
o- A multidimensional String array.- Returns:
- A single dimensional String array.
-