Roll array along an axis

Open
#281 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
numpy, rust
Domain
data

Research direction

Start by reviewing the crate's existing array-axis and view/indexing APIs, using the np.roll examples as the behavioral reference. Determine how rolling by an axis and signed shift should behave, including wraparound and the central-difference example. Done means the crate exposes equivalent rolling behavior with coverage for the shown two-dimensional cases.

Written by the indexing model from the issue text.

Description

In numpy you can roll an array along an axis. Which is an index shift with wrap around, meaning, that given an array

a = np.arange(1, 10).reshape(3, 3)
[[1, 2, 3],
 [4, 5, 6],
 [7, 8, 9]]

rolling along the 2nd axis by 1 results in

np.roll(a, 1, 1)
[[3, 1, 2],
 [6, 4, 5],
 [9, 7, 8]]

I wonder if this can be cheaply implemented in this crate, since it is basically just a remapping of indices? It would be useful to calculate a gradient with periodic boundaries (wrap around). For example, a central difference (modulo prefactors) in y direction can be implemented like

np.roll(a, -1, 1) - np.roll(a, 1, 1)
[[-1,  2, -1],
 [-1,  2, -1],
 [-1,  2, -1]
Dominant language
Rust
Stars
4.3k
Forks
391
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-ndarray/ndarray

All issues in rust-ndarray/ndarray

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.