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

improve image tensor conversions #151

Merged
merged 1 commit into from
Sep 28, 2024
Merged

improve image tensor conversions #151

merged 1 commit into from
Sep 28, 2024

Conversation

edgarriba
Copy link
Member

@edgarriba edgarriba commented Sep 28, 2024

  • use builtin Buffer::from_slice_ref in TensorStorage creation
  • add method from_size_slice in Image
  • implement TryFrom for Image/Tensor conversion
  • added tests

///
/// Returns a `TensorAllocatorError` if the allocation fails.
pub fn from_slice(data: &[T], alloc: A) -> Self {
let buffer = Buffer::from_slice_ref(data);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emilmgeorge discovered this function, i thinks it still makes copy but we can explore later more safer ways to achieve zero copies. Another alternative could be to explore from_bytes https://docs.rs/arrow-buffer/latest/arrow_buffer/buffer/struct.Buffer.html#method.from_bytes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 (also: need to check how to handle custom allocations for non-CPU allocators?).

@edgarriba edgarriba merged commit 563ee3e into main Sep 28, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants