Skip to main content

impl_ndarray_interop

Macro impl_ndarray_interop 

Source
macro_rules! impl_ndarray_interop {
    () => { ... };
    ($($nd:ident)::+) => { ... };
}
Expand description

Generate ndarray interop for tract_proxy::Tensor using the caller crate’s own ndarray version.

tract-proxy itself has no public ndarray dependency: the tensor interface deals only in shapes, slices, bytes and primitive datums. If your application wants the ergonomics of ndarray, invoke this macro once at the root of your crate. The macro expands in your crate’s scope, so the ndarray::* types referenced in the generated code resolve against your ndarray dependency.

The generated surface mirrors tract::impl_ndarray_interop! exactly: a Tract trait with fn tract(self) -> anyhow::Result<tract_proxy::Tensor> for ndarray::ArrayBase, and an Ndarray trait with ndarray::<T>() / ndarray0..ndarray6::<T>() on tract_proxy::Tensor.

§Invocation

Zero-argument form uses the ndarray crate from your crate’s dependencies:

tract_proxy::impl_ndarray_interop!();

Explicit form takes the ndarray root as a path — useful if your Cargo.toml renames the crate or pins multiple versions side by side:

tract_proxy::impl_ndarray_interop!(ndarray_017);