-
-
Notifications
You must be signed in to change notification settings - Fork 894
Description
Description
This RFC proposes achieving ndarray API parity with built-in JavaScript arrays. Built-in JavaScript Array
and TypedArray
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
, and ndarray/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/*
-
Array.prototype.at
ndarray/at
-
Array.prototype.entries
ndarray/iter/entries
-
Array.prototype.every
ndarray/every
-
Array.prototype.forEach
ndarray/for-each
-
Array.prototype.map
ndarray/map
-
Array.prototype.filter
ndarray/filter
-
Array.prototype.slice
ndarray/slice
-
Array.prototype.keys
ndarray/iter/indices
-
Array.prototype.values
ndarray/iter/values
-
Array.prototype.includes
ndarray/includes
-
Array.prototype.indexOf
blas/ext/index-of
-
Array.prototype.find
- reduction; specify one or more axes (WIP)
-
Array.prototype.findIndex
blas/ext/find-index
-
Array.prototype.lastIndexOf
blas/ext/last-index-of
-
Array.prototype.some
ndarray/any
-
Array.prototype.findLast
- reduction; specify one or more axes
-
Array.prototype.findLastIndex
blas/ext/find-last-index
-
Array.prototype.reverse
ndarray/reverse
-
Array.prototype.toReversed
(WIP)- data copy
- can potentially wrap "base"
-
Array.prototype.sort
- multiple functions for different sorting algorithms.
blas/ext/sorthp
.
-
Array.prototype.toSorted
- specify one or more axes
- data copy
- multiple functions for different sorting algorithms.
-
Array.prototype.fill
ndarray/fill
andndarray/fill-by
ndarray/fill-slice
-
Array.prototype.flat
ndarray/flatten
-
Array.prototype.reduce
- reduction; specify one or more axes
-
Array.prototype.concat
(WIP) -
Array.prototype.copyWithin
- specify axis
- how would this work for strided arrays?
- for ideal case, would prefer delegating to array prototype method, as likely faster; for non-ideal case, would need to take special care to avoid overwriting accessed values.
- Slice + assign?
- Temporary buffer for when there is overlap.
-
Array.prototype.reduceRight
- reduction; specify one or more axes
- iterate in reverse direction
-
Array.prototype.flatMap
ndarray/flatten-by
-
Array.prototype.join
- needs R&D
- how would dimension separators work? a different separator for each dimension? configurable?
-
Array.prototype.pop
ndarray/pop
-
Array.prototype.push (???)
- this would essentially be concat along an axis
- support for broadcasting?
- would require a data copy, no mutation
-
Array.prototype.shift
ndarray/shift
-
Array.prototype.splice
- needs R&D
- would involving slicing, concatenation, and data copy
-
Array.prototype.toLocaleString
- needs R&D
-
Array.prototype.toSpliced
- needs R&D
-
Array.prototype.toString
- just call
ndarray.toString()
?
- just call
-
Array.prototype.unshift
- this would essentially be concat along an axis
- support for broadcasting?
- would require a data copy, no mutation
-
Array.prototype.with
ndarray/with
Base: ndarray/base/*
-
Array.prototype.fill
ndarray/base/fill
-
Array.prototype.forEach
ndarray/base/for-each
-
Array.prototype.map
ndarray/base/map
-
Array.prototype.reverse
ndarray/base/reverse
-
Array.prototype.slice
ndarray/base/slice
-
Array.prototype.toReversed
ndarray/base/to-reversed
-
Array.prototype.every
ndarray/base/every-by
-
Array.prototype.some
ndarray/base/any
-
Array.prototype.find
ndarray/base/find
-
Array.prototype.pop
ndarray/base/pop
-
Array.prototype.shift
ndarray/base/shift
Related Issues
None.
Questions
No.
Other
No.
Checklist
- I have read and understood the Code of Conduct.
- Searched for existing issues and pull requests.
- The issue name begins with
RFC:
.