Opened 15 months ago
Closed 13 months ago
#31676 closed defect (fixed)
Hash of mpmath complex numbers produces OverFlowError
Reported by: | soehms | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-9.4 |
Component: | python3 | Keywords: | mpmath complex hash |
Cc: | malb, vdelecroix | Merged in: | |
Authors: | Sebastian Oehms | Reviewers: | Dima Pasechnik, Travis Scrimshaw |
Report Upstream: | N/A | Work issues: | |
Branch: | 3e82038 (Commits, GitHub, GitLab) | Commit: | 3e8203807cfee4f0951820b1f6bfc82a0561d33e |
Dependencies: | Stopgaps: |
Description
The issue is decribed by the following example:
sage: from mpmath import mpc sage: hash(mpc(1, -1)) --------------------------------------------------------------------------- OverflowError Traceback (most recent call last) <ipython-input-2-ff647837f542> in <module> ----> 1 hash(mpc(Integer(1), -Integer(1))) ~/devel/sage/local/lib/python3.9/site-packages/sage/libs/mpmath/ext_main.pyx in sage.libs.mpmath.ext_main.mpc.__hash__ (build/cythonized/sage/libs/mpmath/ext_main.c:27881)() 2496 True 2497 """ -> 2498 return libmp.mpc_hash(self._mpc_) 2499 2500 def __neg__(s): OverflowError: Python int too large to convert to C ssize_t
Change History (7)
comment:1 Changed 15 months ago by
- Branch set to u/soehms/mpmath_hash
comment:2 Changed 15 months ago by
- Commit set to 3e8203807cfee4f0951820b1f6bfc82a0561d33e
- Status changed from new to needs_review
comment:3 Changed 15 months ago by
- Reviewers set to Dima Pasechnik
comment:4 Changed 15 months ago by
- Cc malb vdelecroix added
Can someone who knows something about hash functions comment on the quality of the resulting hash function? We don't want too many collisions....
comment:5 Changed 15 months ago by
- Reviewers changed from Dima Pasechnik to Dima Pasechnik, Travis Scrimshaw
- Status changed from needs_review to positive_review
All it is doing is using Python's hashing of a long int
into a ssize_t
sized int, which has to be a good hash function (at least, I highly doubt we could do better than the Python developers for this).
comment:6 Changed 15 months ago by
Thanks!
comment:7 Changed 13 months ago by
- Branch changed from u/soehms/mpmath_hash to 3e8203807cfee4f0951820b1f6bfc82a0561d33e
- Resolution set to fixed
- Status changed from positive_review to closed
Note: See
TracTickets for help on using
tickets.
Its seems that
__hash__
cannot return a Python3int
which is not anint
in Python2. Therefore, my solution is to take thehash
of the result oflibmp.mpc_hash
.New commits:
31676: initial version