Sorry for not responding without prompting. A PR is indeed a better venue
to ask questions about a proposed code change than a mailing list post.

Adding a keyword argument to trigger a fast path seems like a bad python
API to me, since most users won’t notice it. “kind” seems nicer in that
it’s more general, but it would be even better to have some kind of
heuristic to choose the fast path when appropriate, although it sounds like
that’s not possible? Are there cases where the int path is a pessimisation?

It seems to me like it would be more natural to alter the C code as you’re
implying, but I think there’s some confusion about which C function you
need. You probably shouldn’t touch the public C API (PyArray_LexSort is in
the public API). The function that is actually being called in that python
file is a wrapper for the C API function:

https://github.com/numpy/numpy/blob/1e5386334b6f9508964fcd2e1c30293a9d82f026/numpy/_core/src/multiarray/multiarraymodule.c#L3446

So, rather than putting your int fast path in python, you’d implement in C
in that file, adding the new “kind” keyword or some sort of heuristic to
trigger it to array_lexsort in C.

If it’s possible to use a heuristic rather than requiring users to opt in,
then it could make sense to update PyArray_LexSort, but changing public C
APIs is much more disruptive in C than in python, so we generally don’t do
it and make python-level optimizations possible in C by adding new
non-public C functions that python can call using private APIs like
_multiarray_umath.

Obviously writing CPython C API code is a lot less straightforward than
Python, but the numpy code reviewers have a lot of experience spotting C
API issues and we can point you to resources for learning.

Hope that helps,

Nathan

On Sat, May 11, 2024 at 4:35 PM <m...@pietrobattiston.it> wrote:

> Any feedback, even just on where to locate the Python code I wrote?
>
> Otherwise I will try to just open a PR and see how it goes.
>
> Thanks,
>
> Pietro
> _______________________________________________
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: nathan12...@gmail.com
>
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to