Class TensorInfo

  • All Implemented Interfaces:
    ValueInfo

    public class TensorInfo
    extends java.lang.Object
    implements ValueInfo
    Describes an OnnxTensor, including it's size, shape and element type.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  TensorInfo.OnnxTensorType
      The native element types supported by the ONNX runtime.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static TensorInfo constructFromBuffer​(java.nio.Buffer buffer, long[] shape, OnnxJavaType type)
      Constructs a TensorInfo from the supplied byte buffer.
      static TensorInfo constructFromJavaArray​(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.
      boolean isScalar()
      Returns true if the shape represents a scalar value (i.e.
      java.lang.Object makeCarrier()
      Constructs an array the right shape and type to hold this tensor.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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.
    • 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:
        toString in class java.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 OrtException
        Constructs 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.