Package ai.onnxruntime
Class OnnxSparseTensor
- java.lang.Object
-
- ai.onnxruntime.OnnxTensorLike
-
- ai.onnxruntime.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classOnnxSparseTensor.BlockSparseTensorThe Java side representation of a block sparse tensor.static classOnnxSparseTensor.COOTensorThe Java side representation of a COO sparse tensor.static classOnnxSparseTensor.CSRCTensorThe Java side representation of a CSRC sparse tensor.static classOnnxSparseTensor.SparseTensor<T extends java.nio.Buffer>Abstract base class for Java sparse tensorsstatic classOnnxSparseTensor.SparseTensorTypeThe 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the OnnxValue, freeing its native memory.static <T extends java.nio.Buffer>
OnnxSparseTensorcreateSparseTensor(OrtEnvironment env, OnnxSparseTensor.SparseTensor<T> tensor)Creates a Sparse Tensor in ORT from the Java side representation.java.nio.BuffergetIndicesBuffer()Gets a copy of the indices.long[]getIndicesShape()Gets the shape of the (outer) indices.java.nio.LongBuffergetInnerIndicesBuffer()Gets a copy of the inner indices in a CSRC sparse tensor.long[]getInnerIndicesShape()Gets the shape of the inner indices in a CSRC sparse tensor.OnnxSparseTensor.SparseTensorTypegetSparseTensorType()Returns the type of this OnnxSparseTensor.OnnxValue.OnnxValueTypegetType()Gets the type of this OnnxValue.OnnxSparseTensor.SparseTensor<? extends java.nio.Buffer>getValue()Returns the value as a Java object copying it out of the native heap.java.nio.BuffergetValuesBuffer()Gets a copy of the data buffer.long[]getValuesShape()Gets the shape of the values.-
Methods inherited from class ai.onnxruntime.OnnxTensorLike
checkClosed, getInfo, isClosed
-
-
-
-
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.- 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
public OnnxValue.OnnxValueType getType()
Description copied from interface:OnnxValueGets the type of this OnnxValue.- Returns:
- The value type.
-
getValue
public OnnxSparseTensor.SparseTensor<? extends java.nio.Buffer> getValue() throws OrtException
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
public OnnxSparseTensor.SparseTensorType getSparseTensorType()
Returns the type of this OnnxSparseTensor.- Returns:
- The sparsity type.
-
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
LongBufferif COO or CSRC, andIntBufferif Block Sparse.- Returns:
- The indices.
-
getInnerIndicesBuffer
public java.nio.LongBuffer 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
public java.nio.Buffer 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.
-
-