crystal-data / num.cr

Scientific computing in pure Crystal
MIT License
151 stars 12 forks source link

feat: add functionality for advanced indexing operation using Tensors #89

Closed LucianBuzzo closed 1 year ago

LucianBuzzo commented 1 year ago

This commit introduces an advanced indexing operation that allows a tensor to be indexed by another tensor. This feature enhances the flexibility and expressiveness of tensor manipulation, enabling complex selection patterns that cannot be achieved with simple slicing.

Key changes include:

  1. The '[]' operator is now overloaded to support a Tensor as an argument.
  2. The resulting tensor's shape is determined by concatenating the shape of the 'indices' tensor and the remaining dimensions of the original tensor.
  3. Tests for 1D and 2D indexing have been added to ensure correctness and expected behavior of this feature.

This feature brings us closer to parity with other established tensor libraries such as PyTorch and TensorFlow, and enhances the usability of our library for complex tensor operations.

LucianBuzzo commented 1 year ago

@christopherzimmerman What do you think of this feature?

christopherzimmerman commented 1 year ago

Hey! Thanks for the PR, looks like a great feature, eventually I'd love to see fully fleshed out advanced indexing, similar to numpy, where this can be combined where standard types of slices, I've just never had a chance to dig into it!

LucianBuzzo commented 1 year ago

@christopherzimmerman Yep, definitely! I've already come across a few places where I'd really like to have access to that kind of functionality, so I may send a PR for that as well 😅