Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document / simplify conversion to/from ndarray arrays (and other libraries) #37

Open
robertknight opened this issue Jan 7, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation usability

Comments

@robertknight
Copy link
Owner

robertknight commented Jan 7, 2024

To make using this library easier in downstream projects, it would help to have more documentation / examples etc. around converting to/from tensors/arrays in other libraries.

In the meantime, here are some useful resources:

Cheatsheet

For the case where the tensor/array is "contiguous" (RTen terminology) or "standard layout" (ndarray terminology):

ndarray -> RTen:

TensorView::from_data(array.shape(), array.as_slice().unwrap());

RTen -> ndarray:

ArrayViewD::from_shape(tensor.shape(), tensor.data().unwrap()).unwrap()

The unwraps above will fail if the layout is not contiguous.

Outputs from RTen model execution are always contiguous / in standard order. If it is not certain that a tensor is in standard order, then Tensor::to_contiguous (RTen) or ArrayView::as_standard_layout can be used to get a contiguous layout tensor, copying only if necessary.

@robertknight robertknight added the documentation Improvements or additions to documentation label Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation usability
Projects
None yet
Development

No branches or pull requests

1 participant