-
-
Notifications
You must be signed in to change notification settings - Fork 0
[RFC]: add blas/ext/base/dcircshift #162
Copy link
Copy link
Closed
stdlib-js/stdlib
#10977Labels
FeatureTask to add a new feature.Task to add a new feature.difficulty: 3Likely to be challenging but manageable.Likely to be challenging but manageable.estimate: 2-4hrsTask which should take between 2 to 4 hours.Task which should take between 2 to 4 hours.🤖 AIAllowed to use AI.Allowed to use AI.
Metadata
Metadata
Assignees
Labels
FeatureTask to add a new feature.Task to add a new feature.difficulty: 3Likely to be challenging but manageable.Likely to be challenging but manageable.estimate: 2-4hrsTask which should take between 2 to 4 hours.Task which should take between 2 to 4 hours.🤖 AIAllowed to use AI.Allowed to use AI.
This is similar to MATLAB's
circshiftand NumPy'sroll, but targeted to a strided array.where
kis the number of elements to shift. If>0, shift elements to right. If<0, shift elements to left.The input array
xshould 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 negativekwhich 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-assignor 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 thewsuffix indicates workspace?). Dunno. We can revisit this question later once the other packages are implemented.