Skip to content
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

py3: hashing of cartesian product elements #26145

Closed
dkrenn opened this issue Aug 28, 2018 · 15 comments
Closed

py3: hashing of cartesian product elements #26145

dkrenn opened this issue Aug 28, 2018 · 15 comments

Comments

@dkrenn
Copy link
Contributor

dkrenn commented Aug 28, 2018

part of #24551

sage: C = cartesian_product([ZZ,ZZ])
sage: b = C((1,1))
sage: hash(b)
---------------------------
TypeError      Traceback (most recent call last)
<ipython-input-1-b09cf2f9caf6> in <module>()
      1 C = cartesian_product([ZZ,ZZ])
      2 b = C((Integer(1),Integer(1)))
----> 3 hash(b)

TypeError: unhashable type: 'CartesianProduct_with_category.element_class'

Component: python3

Author: Frédéric Chapoton

Branch/Commit: bc571fd

Reviewer: Travis Scrimshaw

Issue created by migration from https://trac.sagemath.org/ticket/26145

@dkrenn dkrenn added this to the sage-8.4 milestone Aug 28, 2018
@fchapoton

This comment has been minimized.

@fchapoton
Copy link
Contributor

comment:2

indeed, hash does not exist, even if it appears in the tab completion:

sage: A = cartesian_product([ZZ, ZZ])
sage: elt = A((1,1))
sage: elt.__eq__
<method-wrapper '__eq__' of CartesianProduct_with_category.element_class object at 0x7f289e0953b8>
sage: elt.__hash__

@fchapoton

This comment has been minimized.

@fchapoton
Copy link
Contributor

comment:4

Looks similar to the problem here:

sage:  w = Word([0,1,1,0])
sage: type(w)
<class 'sage.combinat.words.word.FiniteWord_list'>
sage: w.__eq__
<method-wrapper '__eq__' of FiniteWord_list object at 0x7f840419ec78>
sage: w.__hash__

Maybe there is something to change in the way cython handles the __richcmp__ methods ?

@fchapoton
Copy link
Contributor

Author: Frédéric Chapoton

@fchapoton
Copy link
Contributor

Commit: dc1d704

@fchapoton
Copy link
Contributor

New commits:

dc1d704py3: hash for Cartesian product elements

@fchapoton
Copy link
Contributor

Branch: u/chapoton/hash_cartesian

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2018

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

bc571fdpy3: hash for Cartesian product elements

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Aug 31, 2018

Changed commit from dc1d704 to bc571fd

@tscrim
Copy link
Collaborator

tscrim commented Sep 1, 2018

Reviewer: Travis Scrimshaw

@tscrim
Copy link
Collaborator

tscrim commented Sep 1, 2018

comment:9

LGTM.

@dkrenn
Copy link
Contributor Author

dkrenn commented Sep 1, 2018

comment:10

Replying to @fchapoton:

indeed, hash does not exist, even if it appears in the tab completion: [...]

Fix LGTM, but can someone explain what is going on: The class ElementWrapper has a __hash__ defined; the class ElementWrapperCheckWrappedClass is derived from ElementWrapper, so there should be the same __hash__ used. Why does this not work (with Py3)?

@fchapoton
Copy link
Contributor

comment:11

Probably because it redefines comparison __richcmp__, which itself is used by Cython to redefine __eq__.. just a guess..

@vbraun
Copy link
Member

vbraun commented Sep 2, 2018

Changed branch from u/chapoton/hash_cartesian to bc571fd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants