-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Py_hash_t Py_HashDouble(double, PyObject *obj)
function
#10
Comments
As I said before in the other issue, I have soured on "fixing" this. I'd rather keep the status quo. If we have to do something (but I don't think we do), the proposed API looks like it's just removing the leading |
IMO, this API is too tightly tied to one specific use in NumPy (and to CPython's internal use). It trades one implementation detail (NaN handling) for another (using a I'd be OK with exposing it as |
I'm taking an executive decision and closing this issue for lack of progress. |
Does that mean we should revert to 3.12 ( |
Revert to 3.12. |
API:
Py_hash_t PyHash_Double(double value, PyObject *obj)
inf
or-inf
, return the hash of value. Similar toPyObject_Hash(PyFloat_FromDouble(value))
.Py_HashPointer(obj)
-- other Python implementation can use a different implementation for this case.PyHASH_NAN
(0
).Pull request: python/cpython#112095
Differences with the existing private API
Py_hash_t _Py_HashDouble(PyObject *inst, double v)
:PyObject*
pointer can beNULL
in the proposed public API.Accepting
NULL
is a trade off with alternative APIs which have noPyObject*
argument, proposed previously:int Py_HashDouble(double value, Py_hash_t *result)
Py_hash_t Py_HashDouble(double value)
The
PyObject*
parameter avoids asking the caller to implement their own code for the not-a-number case usingPy_HashPointer()
, PyObject_GenericHash(), or something else. Python 3.10 changedhash(float)
to returnhash(id(obj))
if the float is not-a-number. Writing such code working on all Python implementation can be tricky. ProposedPy_hash_t PyHash_Double(double value, PyObject *obj)
API hides the implementation details, so using this proposed API is more portable.Main user of the existing private
_Py_HashDouble()
function: numpy, link to code.More background on the
Py_HashDouble()
API in the previous issue: #2Alternative: give up trying to add a public C API and comes back to Python 3.12 status quo with the private API
Py_hash_t _Py_HashDouble(PyObject *inst, double v)
.Votes:
The text was updated successfully, but these errors were encountered: