Nathann Cohen wrote:
Yoooooooooo !!

 > Perhaps not the most elegant solution ;-), but I guess you could use an
 > auxiliary cached function that throws its result instead of returning it
 > in cases where you don't want to cache it...

Hmmm... Well, the only way I see to do that is :

def my_main_function_which_caches_nothing(n,cache_it=False):
     if cache_it:
         return auxiliary_function(n)
     [do your job]

@cached_function
def auxiliary_function(n):
     return my_main_function_which_caches_nothing(n,cache_it=False)

But yeah, the main function would call itself through an auxiliary
function.... Well, I would like to avoid that :-/

Perhaps only slightly better (but omitting the additional 'cache_it' parameter):

def a(n):
    if n.is_prime_power():
        return _a_noncached(n)
    else:
        return _a_cached(n)

@cached_function
def _a_cached(n):
    return a_noncached(n)


(_a_noncached() is your original function a(), just renamed.)


Of course also depends on whether (here) n.is_prime_power() probably gets called twice [without caching the result], and in general on how expensive that is.


-leif

--
() The ASCII Ribbon Campaign
/\   Help Cure HTML E-Mail

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to