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

Missing numpy functions #619

Merged
merged 14 commits into from
Feb 16, 2024
Merged

Missing numpy functions #619

merged 14 commits into from
Feb 16, 2024

Conversation

AngelEzquerra
Copy link
Contributor

@AngelEzquerra AngelEzquerra commented Jan 11, 2024

This PR adds a number of missing numpy functions:

  • tril, triu: These were already implemented but not exported nor tested
  • tri
  • geomspace
  • sinc
  • meshgrid
  • all / any
  • flatten / roll

I'd like to add more but I think this is a good first set.

Copy link
Owner

@mratsim mratsim left a comment

Choose a reason for hiding this comment

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

Thanks, excellent

@AngelEzquerra
Copy link
Contributor Author

I rebased this branch on top of the latest master branch.

@AngelEzquerra AngelEzquerra force-pushed the missing_numpy branch 3 times, most recently from 89ca2cc to e76e885 Compare February 7, 2024 18:57
@AngelEzquerra
Copy link
Contributor Author

Added missing flatten and roll functions.

@Vindaar
Copy link
Collaborator

Vindaar commented Feb 11, 2024

Also great work on this! 🥳

After merging the other two (and having dropped 1.4 support), CI should pass for this one too. Can never remember whether you'll need to rebase onto the then-master without 1.4 though.

Also tweaks the assert messages of the diagonal() proc a little to match similar messages in the new functions.
Tests have been added to test_diag.nim which will be renamed to test_special_matrices.nim.
Also adds messages to a couple of asserts on the linspace procedure.
Also adds a corresponding test.
`flatten` flattens a tensor, returning a rank-1 tensor with the same data as the input.

This is the same as `t.reshape([t.size.int])`. Therefore, if possible no data copy is done and the returned tensor shares data with the input.
If input is not contiguous, this is not possible and a copy will be made.
Support for higher rank tensors will be added later.
This adds two roll types (which are the same for rank 1 tensors, but different for higher rank tensors): "global" (axis-less) roll and "axis" roll. The former flattens the input tensor before rolling the elements and then reshapes the rolled tensor back to the original shape, while the latter rolls the positions of _slices_ of a tensor taken along a specific axis.
@Vindaar Vindaar merged commit 830197e into mratsim:master Feb 16, 2024
6 checks passed
@Vindaar
Copy link
Collaborator

Vindaar commented Feb 16, 2024

Thanks again! Great work. 🚀

@AngelEzquerra AngelEzquerra deleted the missing_numpy branch February 17, 2024 21:52
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.

3 participants