GithubHelp home page GithubHelp logo

Comments (5)

asmeurer avatar asmeurer commented on August 20, 2024 2

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.

rgommers avatar rgommers commented on August 20, 2024

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.

agarwal-ashish avatar agarwal-ashish commented on August 20, 2024

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.

rgommers avatar rgommers commented on August 20, 2024

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:

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.

rgommers avatar rgommers commented on August 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.