sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.46k stars 482 forks source link

Cartesian product of Combinations fails #39004

Open tye-singwa opened 2 days ago

tye-singwa commented 2 days ago

Steps To Reproduce

Try to compute cartesian product of Combinations

a = Combinations([1,2,3], 2)
cartesian_product([a, a])

Expected Behavior

Returns cartesian product of Combinations

Actual Behavior

Fails with stacktrace

File ~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/misc/cachefunc.pyx:610, in sage.misc.cachefunc.cache_key_unhashable (build/cythonized/sage/misc/cachefunc.c:6105)()
    [608](~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/misc/cachefunc.pyx:610,%20in%20sage.misc.cachefunc.cache_key_unhashable%20(build/cythonized/sage/misc/cachefunc.c:608)     return tuple(cache_key(item) for item in o)
    [609](~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/misc/cachefunc.pyx:610,%20in%20sage.misc.cachefunc.cache_key_unhashable%20(build/cythonized/sage/misc/cachefunc.c:609) try:
--> [610](~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/misc/cachefunc.pyx:610,%20in%20sage.misc.cachefunc.cache_key_unhashable%20(build/cythonized/sage/misc/cachefunc.c:610)     k = o._cache_key()
    [611](~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/misc/cachefunc.pyx:610,%20in%20sage.misc.cachefunc.cache_key_unhashable%20(build/cythonized/sage/misc/cachefunc.c:611) except AttributeError:
    [612](~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/misc/cachefunc.pyx:610,%20in%20sage.misc.cachefunc.cache_key_unhashable%20(build/cythonized/sage/misc/cachefunc.c:612)     raise TypeError("unhashable type: {!r}".format(type(o).__name__))

File ~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/structure/sage_object.pyx:439, in sage.structure.sage_object.SageObject._cache_key (build/cythonized/sage/structure/sage_object.c:5084)()
    [437](~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/structure/sage_object.pyx:439,%20in%20sage.structure.sage_object.SageObject._cache_key%20(build/cythonized/sage/structure/sage_object.c:437)     hash(self)
    [438](~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/structure/sage_object.pyx:439,%20in%20sage.structure.sage_object.SageObject._cache_key%20(build/cythonized/sage/structure/sage_object.c:438) except TypeError:
--> [439](~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/structure/sage_object.pyx:439,%20in%20sage.structure.sage_object.SageObject._cache_key%20(build/cythonized/sage/structure/sage_object.c:439)     raise TypeError("{} is not hashable and does not implement _cache_key()".format(type(self)))
    [440](~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/structure/sage_object.pyx:439,%20in%20sage.structure.sage_object.SageObject._cache_key%20(build/cythonized/sage/structure/sage_object.c:440) else:
    [441](~/miniconda3/envs/sage/lib/python3.12/site-packages/sage/structure/sage_object.pyx:439,%20in%20sage.structure.sage_object.SageObject._cache_key%20(build/cythonized/sage/structure/sage_object.c:441)     assert False, "_cache_key() must not be called for hashable elements"

TypeError: <class 'sage.combinat.combination.Combinations_setk_with_category'> is not hashable and does not implement _cache_key()

Additional Information

I think _cache_key for Combinations_setk_with_category should be implemented

Environment

Checklist

maxale commented 2 days ago

Tuples(a,2) fails as well, but with a different error:

TypeError: unhashable type: 'list'