# HG changeset patch
# User Simon King <simon.king@unijena.de>
# Date 1315762581 7200
# Node ID 8a39d4c00ae744e28099cb98ef543e555d2e5682
# Parent 00f9c408bdc6b67ce026910dc042d9bb520e4e88
#11115: Pickling of cached functions
diff git a/sage/misc/cachefunc.pyx b/sage/misc/cachefunc.pyx
a

b


226  226  sage: print sage_getdoc(test_pfunc) 
227  227  Some documentation 
228  228  sage: print sage_getdoc(O.wrapped_method) 
229   File: ... 
230   (starting at line ...) some doc for a wrapped cython method 
 229  some doc for a wrapped cython method 
 230  <BLANKLINE> 
231  231  sage: print sage_getsource(O.wrapped_method) 
232  232  cpdef test_meth(self,x): 
233  233  "some doc for a wrapped cython method" 
… 
… 

262  262  ######################################################################## 
263  263  # Copyright (C) 2008 William Stein <wstein@gmail.com> 
264  264  # Mike Hansen <mhansen@gmail.com> 
 265  # 2011 Simon King <simon.king@unijena.de> 
265  266  # 
266  267  # Distributed under the terms of the GNU General Public License (GPL) 
267  268  # 
… 
… 

271  272  import os 
272  273  from sage.misc.sageinspect import sage_getfile, sage_getsourcelines 
273  274  
 275  def _cached_function_unpickle(module,name): 
 276  """ 
 277  Unpickling of cached functions. 
 278  
 279  NOTE: 
 280  
 281  Pickling and unpickling of cached functions is by importing 
 282  from the module in which the function is defined. 
 283  
 284  INPUT: 
 285  
 286   ``module``: A string, describing the module to import the 
 287  function from. 
 288   ``name``: A string, name of the tobeimported cached function. 
 289  
 290  EXAMPLE:: 
 291  
 292  sage: type(cunningham_prime_factors) 
 293  <type 'sage.misc.cachefunc.CachedFunction'> 
 294  sage: loads(dumps(cunningham_prime_factors)) is cunningham_prime_factors #indirect doctest 
 295  True 
 296  
 297  """ 
 298  return getattr(__import__(module, fromlist=['']),name) 
 299  
274  300  cdef class CachedFunction(object): 
275  301  """ 
276  302  Create a cached version of a function, which only recomputes 
… 
… 

391  417  self._argument_fixer = argument_fixer 
392  418  self._fix_to_pos = argument_fixer.fix_to_pos 
393  419  
 420  def __reduce__(self): 
 421  """ 
 422  Pickling of cached functions. 
 423  
 424  TEST:: 
 425  
 426  sage: type(cunningham_prime_factors) 
 427  <type 'sage.misc.cachefunc.CachedFunction'> 
 428  sage: loads(dumps(cunningham_prime_factors)) is cunningham_prime_factors #indirect doctest 
 429  True 
 430  
 431  """ 
 432  return _cached_function_unpickle, (self.__module__, self.__name__) 
 433  
394  434  ######### 
395  435  ## Introspection 
396  436  ## 
… 
… 

411  451  sage: I = P*[x,y] 
412  452  sage: from sage.misc.sageinspect import sage_getdoc 
413  453  sage: print sage_getdoc(I.groebner_basis) # indirect doctest 
414   File: sage/rings/polynomial/multi_polynomial_ideal.py (starting at 
415   line ...) 
 454  Return the reduced Groebner basis of this ideal. 
416  455  ... 
417  456  ALGORITHM: Uses Singular, Magma (if available), Macaulay2 (if 
418  457  available), or a toy implementation. 