Class Native
java.lang.Object
smile.torch.Native
Internal helpers for the FFM (Foreign Function and Memory API) binding to the
smile_torch native library. This class glues the idiomatic
smile.deep.tensor API to the raw smile_torch_h
downcall stubs generated by jextract.
It centralizes three concerns: converting native error sentinels into Java
exceptions, freeing native handles when their Java wrappers become
unreachable (via a shared Cleaner), and a handful of downcalls for
functions that are not yet covered by the generated bindings.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordFrees anST_TensorIndexhandle exactly once.static final recordFrees anST_Tensorhandle exactly once. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic MemorySegmentcheck(MemorySegment handle) Verifies that a native call returned a non-null handle, throwing the native error message otherwise.static StringReturns the message describing the most recent native failure, or an empty string if none.
-
Field Details
-
CLEANER
Shared cleaner that releases native handles owned by Java wrappers (tensors, indices, modules, …) once those wrappers are no longer reachable. It is a safety net; callers should still close resources deterministically via try-with-resources or anAutoScopewhere possible.
-
-
Method Details
-
lastError
Returns the message describing the most recent native failure, or an empty string if none.- Returns:
- the last native error message.
-
check
Verifies that a native call returned a non-null handle, throwing the native error message otherwise.- Parameters:
handle- the handle returned by a native call.- Returns:
- the validated handle.
-