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.
    • 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.
      • getDimensionNames

        public java.lang.String[] getDimensionNames()
        Get a copy of the tensor's named dimensions.
        Returns:
        A copof the tensor's named dimensions.
      • 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.
      • getNumElements

        public long getNumElements()
        Returns the number of elements in this tensor.

        If the returned value is negative, then this tensor info refers to an input or output placeholder which has symbolic dimensions, and the element count cannot be computed without specifying the symbolic dimensions.

        Returns:
        The number of elements.
      • 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 its 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.