Comments (5)
Sorting is also not well defined for complex dtypes (potentially for other advanced dtypes as well if those were ever added). See #102 (comment). I'm not clear what the final resolution of that is, but it sounds like the sort
function and friends require additional complexity to properly handle complex numbers (e.g., a key
parameter). So it would probably be a good idea to omit sorted
from any non-sorting API functions, as they would also have to support those additional parameters to be usable with complex dtypes.
from array-api.
Most relevant comment from gh-25:
Regarding sorting, that's an annoying one. Even if TensorFlow would add a sorting option, it probably couldn't easily default to sorted=True
. The tf.experimental.numpy
namespace doesn't have unique yet, maybe that would have sorted return values for compatibility?
@agarwal-ashish or @edloper do you have an opinion on this one?
from array-api.
Unless we believe sorted order is almost always desired, it will be better to not enforce sorting and leave the API simpler. We could expect frameworks to perform operator fusion if this becomes a common performance bottleneck.
from array-api.
Unless we believe sorted order is almost always desired
I don't think it is. Just wanting to know the number of unique values for example is common enough that pandas offers a separate nunique
method. And I've heard requests for an unsorted (and hence faster) version in NumPy before.
So then to write portable code, users should explicitly write sort(unique(x))
. Which if unique
already sorts is cheap, so it shouldn't matter much performance-wise.
So the right resolution then is probably:
- Document that element order in output array is unspecified.
- Remove the
sorted
keyword from https://data-apis.github.io/array-api/latest/API_specification/set_functions.html
However, as discussed in the OP, combining unique/sort may allow implementation perf optimizations which cannot be replicated when performed as two separate steps.
In practice this is probably not so relevant. NumPy sorts anyway, and most other libraries have the ability (at least in principle) to do operator fusion.
from array-api.
Makes sense, thanks @asmeurer. There are no other sorted
keywords at the moment other than in unique
(which gh-104 removes).
from array-api.
Related Issues (20)
- result_type() for mixed arrays/Python scalars HOT 11
- Python scalars in elementwise functions HOT 15
- RFC: add `take_along_axis` to take values along a specified dimension HOT 3
- RFC: add bincount HOT 5
- RFC: `item()` to return scalar for arrays with exactly 1 element. HOT 8
- Disallowed typing in `linalg.vector_norm` HOT 2
- Iteration on 1-D arrays HOT 10
- Comparing arrays of different dtype kinds HOT 2
- `unique_inverse` diverges from NumPy HOT 1
- ``broadcast_to`` semantics HOT 7
- Revisit requirement that inputs to `real`, `imag`, and `conj` be complex-valued HOT 19
- Specify correct rounding for sqrt HOT 3
- Wording in default_dtypes does not leave room for unsupported data types HOT 3
- Clarification for non-portable behavior for in-place Python operations HOT 1
- Support for DLPack exchange of hot buffers
- Minor clarification on allowed rounding mode HOT 1
- Minor clarification for conflicting information in `__dlpack__`
- Data type objects for libraries with multiple backends HOT 11
- indexing: require `[()]` to be a no-op for all ranks? HOT 7
- Calculate number of unique values in a lazy array HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from array-api.