Open kgryte opened 1 month ago
cc @headlessNode
I want to work on this issue @kgryte and could you elaborate on the specific goals of aligning ndarray APIs with JavaScript arrays? How will this benefit users and developers?
How will this benefit users and developers?
This is already addressed in the OP. Second paragraph.
Yup! Starting work on this!
@SarthakPaandey Before you begin, it would be best to communicate what you're planning to work on. Some of the above routines are easier than others and should be addressed first. Reductions require R&D and should only be worked on once we've determined the best approach.
"Understood, @kgryte. I'll prioritize the routines that are comparatively easier and communicate my plan before starting. I'll defer work on reductions until we've established the best approach. Thanks for the guidance!
@kgryte I have started to work on the map
method. I plan to submit PR for it when I've implemented the kernels for it up to 3d
. This way, it would be possible to get feedback from you earlier and it would be easier for me to work on the feedback. Does that seem reasonable?
@headlessNode That makes sense. I am currently working on for-each
, which is related.
@headlessNode I suggest working a "base" implementation of map
first. For @stdlib/ndarray/base/map
, we can assume that an output array is provided, similar to ndarray/base/unary
. In fact, unary
is a good reference for map
. The main difference being the support of a thisArg
and no C implementation.
@kgryte The thisArg
in our case would be similar to how it is handled in the Array.prototype.map
right? e.g.
//Array.prototype.map
let numbers = [1, 2, 3];
let obj = { multiplier: 2 };
numbers.map(function(num) {
return num * this.multiplier;
}, obj);```
@headlessNode Yes. As an example, see https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/any-by.
@headlessNode Pushed up a POC implementation of for-each
: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/for-each
Thanks!
Heads up. I have started to work on ndarray/base/fill
Sounds good, @headlessNode! Thanks for the heads up!
Description
This RFC proposes achieving ndarray API parity with built-in JavaScript arrays. Built-in JavaScript
Array
andTypedArray
objects have a number of methods for searching, manipulating, sorting, and transforming array data.The goal of this RFC is to add functional APIs providing equivalent functionality for ndarrays. By providing these APIs, stdlib can offer a powerful toolset using a similar vocabulary and interface design as existing art for working with ndarrays. This should help reduce the barrier to ndarray adoption and encourage their more widespread use.
Note, however, that ndarrays have considerable additional complexity due to their multi-dimensional nature, and, in particular, element-wise iteration requires specialized kernels for handling non-contiguous underlying data.
There does exist precedent in stdlib for such kernels (e.g.,
ndarray/base/assign
,ndarray/base/nullary
, andndarray/base/unary
). Those packages also provide C APIs which may or may not be relevant to the functional APIs proposed in this RFC.What follows is an initial list of
Array.prototype.*
methods and notes regarding whether an equivalent already exists or what constraints we need to consider when designing ndarray equivalent packages.Top-level:
ndarray/*
[x]
Array.prototype.at
ndarray/at
[ ]
Array.prototype.concat
[ ]
Array.prototype.copyWithin
[x]
Array.prototype.entries
ndarray/iter/entries
[ ]
Array.prototype.every
[ ]
Array.prototype.fill
ndarray/base/assign
[ ]
Array.prototype.filter
[ ]
Array.prototype.find
[ ]
Array.prototype.findIndex
[ ]
Array.prototype.findLast
[ ]
Array.prototype.findLastIndex
[ ]
Array.prototype.flat
flatten
[ ]
Array.prototype.flatMap
flatten-by
[ ]
Array.prototype.forEach
(in-progress)[ ]
Array.prototype.includes
[ ]
Array.prototype.indexOf
[ ]
Array.prototype.join
[x]
Array.prototype.keys
ndarray/iter/indices
[ ]
Array.prototype.lastIndexOf
[ ]
Array.prototype.map
(in progress)[ ]
Array.prototype.pop
slice(0,axis.length-1)
[ ]
Array.prototype.push (???)
[ ]
Array.prototype.reduce
[ ]
Array.prototype.reduceRight
[ ]
Array.prototype.reverse
[ ]
Array.prototype.shift
slice(1)
[x]
Array.prototype.slice
ndarray/slice
[ ]
Array.prototype.some
[ ]
Array.prototype.sort
to-sorted
by the copy version.[ ]
Array.prototype.splice
[ ]
Array.prototype.toLocaleString
[ ]
Array.prototype.toReversed
[ ]
Array.prototype.toSorted
[ ]
Array.prototype.toSpliced
[ ]
Array.prototype.toString
ndarray.toString()
?[ ]
Array.prototype.unshift
[x]
Array.prototype.values
ndarray/iter/values
[ ]
Array.prototype.with
assign
in order to copy, and then set the individual elementndarray/base/assign
for acceleration in Node.jsBase:
ndarray/base/*
[x]
Array.prototype.fill
ndarray/base/fill
[x]
Array.prototype.forEach
ndarray/base/for-each
[x]
Array.prototype.map
ndarray/base/map
[x]
Array.prototype.reverse
ndarray/base/reverse
[x]
Array.prototype.slice
ndarray/base/slice
[x]
Array.prototype.toReversed
ndarray/base/to-reversed
Related Issues
None.
Questions
No.
Other
No.
Checklist
RFC:
.