Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Pickle caches of dirichlet characters
Browse files Browse the repository at this point in the history
  • Loading branch information
saraedum committed Jun 30, 2016
1 parent aaebb01 commit a152dc4
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/sage/modular/dirichlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ def __init__(self, parent, x, check=True):
if R.is_exact() and any(map(lambda u, v: u**v != 1, x, orders)):
raise ValueError("values (= {}) must have multiplicative orders dividing {}, respectively"
.format(x, orders))
self.__values_on_gens = x
self.values_on_gens.set_cache(x)
else:
if free_module_element.is_FreeModuleElement(x):
self.element.set_cache(x)
else:
self.__values_on_gens = x
self.values_on_gens.set_cache(x)

@cached_method
def __eval_at_minus_one(self):
Expand Down Expand Up @@ -1687,6 +1687,7 @@ def values(self):
exponents[i] = 0
i += 1

@cached_method(do_pickle=True)
def values_on_gens(self):
r"""
Return a tuple of the values of ``self`` on the standard
Expand All @@ -1697,16 +1698,19 @@ def values_on_gens(self):
sage: e = DirichletGroup(16)([-1, 1])
sage: e.values_on_gens ()
(-1, 1)
.. NOTE::
The constructor of :class:`DirichletCharacter` sets the
cache of :meth:`element` or of :meth:`values_on_gens`. The cache of
one of these methods needs to be set for the other method to work properly,
these caches have to be stored when pickling an instance of
:class:`DirichletCharacter`.
"""
try:
return self.__values_on_gens
except AttributeError:
pows = self.parent()._zeta_powers
v = tuple([pows[i] for i in self.element()])
self.__values_on_gens = v
return v
pows = self.parent()._zeta_powers
return tuple([pows[i] for i in self.element()])

@cached_method
@cached_method(do_pickle=True)
def element(self):
r"""
Return the underlying `\ZZ/n\ZZ`-module
Expand All @@ -1716,7 +1720,7 @@ def element(self):
Please do not change the entries of the returned vector;
this vector is mutable *only* because immutable vectors are
implemented yet.
not implemented yet.
EXAMPLES::
Expand All @@ -1725,6 +1729,14 @@ def element(self):
(2, 0)
sage: b.element()
(0, 1)
.. NOTE::
The constructor of :class:`DirichletCharacter` sets the
cache of :meth:`element` or of :meth:`values_on_gens`. The cache of
one of these methods needs to be set for the other method to work properly,
these caches have to be stored when pickling an instance of
:class:`DirichletCharacter`.
"""
P = self.parent()
M = P._module
Expand Down

0 comments on commit a152dc4

Please sign in to comment.