Class OnnxSparseTensor

  • All Implemented Interfaces:
    OnnxValue, java.lang.AutoCloseable

    public final class OnnxSparseTensor
    extends OnnxTensorLike
    A Java object wrapping an OnnxSparseTensor.

    Sparse tensors support a variety of formats, and the getValue() method returns a different static inner class representing each type.

    • Method Detail

      • createSparseTensor

        public static <T extends java.nio.Buffer> OnnxSparseTensor createSparseTensor​(OrtEnvironment env,
                                                                                      OnnxSparseTensor.SparseTensor<T> tensor)
                                                                               throws OrtException
        Creates a Sparse Tensor in ORT from the Java side representation.
        Type Parameters:
        T - The buffer type.
        env - The OrtEnvironment.
        tensor - The Java side representation.
        The sparse tensor in ORT.
        OrtException - If the tensor could not be created or was invalid.
      • getValue

        public OnnxSparseTensor.SparseTensor<? extends java.nio.Buffer> getValue()
                                                                          throws OrtException
        Description copied from interface: OnnxValue
        Returns the value as a Java object copying it out of the native heap. This operation can be quite slow for high dimensional tensors, where you should prefer OnnxTensor.getByteBuffer() etc.

        Overridden by the subclasses with a more specific type if available.

        The value.
        OrtException - If an error occurred reading the value.
      • close

        public void close()
        Description copied from interface: OnnxValue
        Closes the OnnxValue, freeing its native memory.
      • getIndicesBuffer

        public java.nio.Buffer getIndicesBuffer()
        Gets a copy of the indices.

        These are the outer indices if it's a CSRC sparse tensor.

        It's a LongBuffer if COO or CSRC, and IntBuffer if Block Sparse.

        The indices.
      • getInnerIndicesBuffer

        public java.nio.LongBuffer getInnerIndicesBuffer()
        Gets a copy of the inner indices in a CSRC sparse tensor.

        Throws IllegalStateException if called on a different sparse tensor type.

        The inner indices.
      • getValuesBuffer

        public java.nio.Buffer getValuesBuffer()
        Gets a copy of the data buffer.

        As with OnnxTensor fp16 values are upcast into fp32 and returned as a FloatBuffer.

        The data buffer.
      • getIndicesShape

        public long[] getIndicesShape()
        Gets the shape of the (outer) indices.
        The indices shape.
      • getInnerIndicesShape

        public long[] getInnerIndicesShape()
        Gets the shape of the inner indices in a CSRC sparse tensor.
        The indices shape.
      • getValuesShape

        public long[] getValuesShape()
        Gets the shape of the values.
        The values shape.