Skip to content

[RFC]: add blas/ext/base/dcircshift #162

@kgryte

Description

@kgryte

This is similar to MATLAB's circshift and NumPy's roll, but targeted to a strided array.

function dcircshift( N, k, x, strideX )

where k is the number of elements to shift. If >0, shift elements to right. If <0, shift elements to left.

The input array x should be mutated.

To minimize the number of swaps, one needs to determine whether to perform a left or right shift. Meaning, for every positive k, there is an equivalent negative k which achieves the same result. So, one needs to determine whether a positive or negative shift is more efficient. (i.e., min(k, N-k))

The implementation should be in-place and only use O(1) memory (i.e., no allocation of temporary workspaces).

Later, we can add a separate package for performing a circular shift and assigning to a separate output array (e.g., dcircshift-assign or similar). The assignment implementation will likely be more performant, as one can do bulk read/writes, but the in-place version is still useful.

There is the question as to whether we would want a separate in-place implementation which supports providing an explicit workspace buffer, but I am less keen on this as it effectively requires users to determine the optimum shift strategy in order to know the size of the workspace buffer. And an implementation which dynamically allocates a workspace buffer is not great, as it forces us into the memory management game in C. Not opposed, but also not sure what we'd name such as package (maybe dcircshiftw, where the w suffix indicates workspace?). Dunno. We can revisit this question later once the other packages are implemented.

Metadata

Metadata

Assignees

Labels

FeatureTask to add a new feature.difficulty: 3Likely to be challenging but manageable.estimate: 2-4hrsTask which should take between 2 to 4 hours.🤖 AIAllowed to use AI.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions