Package ai.onnxruntime
Class TensorInfo
- java.lang.Object
-
- ai.onnxruntime.TensorInfo
-
- All Implemented Interfaces:
ValueInfo
public class TensorInfo extends java.lang.Object implements ValueInfo
Describes anOnnxTensor, including it's size, shape and element type.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTensorInfo.OnnxTensorTypeThe native element types supported by the ONNX runtime.
-
Field Summary
Fields Modifier and Type Field Description static intMAX_DIMENSIONSMaximum number of dimensions supported by the Java interface methods.TensorInfo.OnnxTensorTypeonnxTypeThe native type of this tensor.OnnxJavaTypetypeThe Java type of this tensor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TensorInfoconstructFromBuffer(java.nio.Buffer buffer, long[] shape, OnnxJavaType type)Constructs a TensorInfo from the supplied byte buffer.static TensorInfoconstructFromJavaArray(java.lang.Object obj)Constructs a TensorInfo from the supplied multidimensional Java array, used to allocate the appropriate amount of native memory.long[]getShape()Get a copy of the tensor's shape.booleanisScalar()Returns true if the shape represents a scalar value (i.e.java.lang.ObjectmakeCarrier()Constructs an array the right shape and type to hold this tensor.java.lang.StringtoString()
-
-
-
Field Detail
-
MAX_DIMENSIONS
public static final int MAX_DIMENSIONS
Maximum number of dimensions supported by the Java interface methods.- See Also:
- Constant Field Values
-
type
public final OnnxJavaType type
The Java type of this tensor.
-
onnxType
public final TensorInfo.OnnxTensorType onnxType
The native type of this tensor.
-
-
Method Detail
-
getShape
public long[] getShape()
Get a copy of the tensor's shape.- Returns:
- A copy of the tensor's shape.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isScalar
public boolean isScalar()
Returns true if the shape represents a scalar value (i.e. it has zero dimensions).- Returns:
- True if the shape is a scalar.
-
makeCarrier
public java.lang.Object makeCarrier() throws OrtExceptionConstructs an array the right shape and type to hold this tensor.Note for String tensors, this carrier is a single dimensional array with enough space for all elements as that's the expected format of the native code. It can be reshaped to the correct shape using
OrtUtil.reshape(String[],long[]).- Returns:
- A multidimensional array of the appropriate primitive type (or String).
- Throws:
OrtException- If the shape isn't representable in Java (i.e. if one of it's indices is greater than an int).
-
constructFromJavaArray
public static TensorInfo constructFromJavaArray(java.lang.Object obj) throws OrtException
Constructs a TensorInfo from the supplied multidimensional Java array, used to allocate the appropriate amount of native memory.- Parameters:
obj- The object to inspect.- Returns:
- A TensorInfo which can be used to make the right size Tensor.
- Throws:
OrtException- If the supplied Object isn't an array, or is an invalid type.
-
constructFromBuffer
public static TensorInfo constructFromBuffer(java.nio.Buffer buffer, long[] shape, OnnxJavaType type) throws OrtException
Constructs a TensorInfo from the supplied byte buffer.- Parameters:
buffer- The buffer to inspect.shape- The shape of the tensor.type- The Java type.- Returns:
- A TensorInfo for a tensor.
- Throws:
OrtException- If the supplied buffer doesn't match the shape.
-
-