Package ai.onnxruntime
Class OnnxSparseTensor
java.lang.Object
ai.onnxruntime.OnnxTensorLike
ai.onnxruntime.OnnxSparseTensor
- All Implemented Interfaces:
OnnxValue,AutoCloseable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe Java side representation of a block sparse tensor.static final classThe Java side representation of a COO sparse tensor.static final classThe Java side representation of a CSRC sparse tensor.static classOnnxSparseTensor.SparseTensor<T extends Buffer>Abstract base class for Java sparse tensorsstatic enumThe type of the sparse tensor.Nested classes/interfaces inherited from interface ai.onnxruntime.OnnxValue
OnnxValue.OnnxValueType -
Field Summary
Fields inherited from class ai.onnxruntime.OnnxTensorLike
allocatorHandle, closed, info, nativeHandle -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the OnnxValue, freeing its native memory.static <T extends Buffer>
OnnxSparseTensorcreateSparseTensor(OrtEnvironment env, OnnxSparseTensor.SparseTensor<T> tensor) Creates a Sparse Tensor in ORT from the Java side representation.Gets a copy of the indices.long[]Gets the shape of the (outer) indices.Gets a copy of the inner indices in a CSRC sparse tensor.long[]Gets the shape of the inner indices in a CSRC sparse tensor.Returns the type of this OnnxSparseTensor.getType()Gets the type of this OnnxValue.OnnxSparseTensor.SparseTensor<? extends Buffer>getValue()Returns the value as a Java object copying it out of the native heap.Gets a copy of the data buffer.long[]Gets the shape of the values.Methods inherited from class ai.onnxruntime.OnnxTensorLike
checkClosed, getInfo, isClosed
-
Method Details
-
createSparseTensor
public static <T extends 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.- Parameters:
env- The OrtEnvironment.tensor- The Java side representation.- Returns:
- The sparse tensor in ORT.
- Throws:
OrtException- If the tensor could not be created or was invalid.
-
getType
Description copied from interface:OnnxValueGets the type of this OnnxValue.- Returns:
- The value type.
-
getValue
Description copied from interface:OnnxValueReturns 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 preferOnnxTensor.getByteBuffer()etc.Overridden by the subclasses with a more specific type if available.
- Returns:
- The value.
- Throws:
OrtException- If an error occurred reading the value.
-
close
public void close()Description copied from interface:OnnxValueCloses the OnnxValue, freeing its native memory. -
getSparseTensorType
Returns the type of this OnnxSparseTensor.- Returns:
- The sparsity type.
-
getIndicesBuffer
Gets a copy of the indices.These are the outer indices if it's a CSRC sparse tensor.
It's a
LongBufferif COO or CSRC, andIntBufferif Block Sparse.- Returns:
- The indices.
-
getInnerIndicesBuffer
Gets a copy of the inner indices in a CSRC sparse tensor.Throws
IllegalStateExceptionif called on a different sparse tensor type.- Returns:
- The inner indices.
-
getValuesBuffer
Gets a copy of the data buffer.As with
OnnxTensorfp16 values are upcast into fp32 and returned as aFloatBuffer.- Returns:
- The data buffer.
-
getIndicesShape
public long[] getIndicesShape()Gets the shape of the (outer) indices.- Returns:
- The indices shape.
-
getInnerIndicesShape
public long[] getInnerIndicesShape()Gets the shape of the inner indices in a CSRC sparse tensor.- Returns:
- The indices shape.
-
getValuesShape
public long[] getValuesShape()Gets the shape of the values.- Returns:
- The values shape.
-