sandbox: implemented sin
[sympy.git] / sympy / sandbox / core / utils.py
blobd603e9e3dfb659a00bbfc7819ba31110a2391c10
1 all_caches = {}
3 def memoizer_immutable_args(name):
4 def make_memoized(func):
5 return func
6 func._cache_it_cache = func_cache_it_cache = {}
7 def wrapper(*args):
8 try:
9 return func_cache_it_cache[args]
10 except KeyError:
11 pass
12 except TypeError, msg:
13 if 'dict objects are unhashable'==str(msg):
14 return func(*args)
15 raise
16 func_cache_it_cache[args] = r = func(*args)
17 return r
18 all_caches[name] = func_cache_it_cache
19 return wrapper
20 return make_memoized
22 def memoizer_Symbol_new(func):
23 func._cache_it_cache = func_cache_it_cache = {}
24 def wrapper(cls, name, dummy=False, **options):
25 if dummy:
26 return func(cls, name, dummy=dummy, **options)
27 try:
28 return func_cache_it_cache[name]
29 except KeyError:
30 pass
31 func_cache_it_cache[name] = r = func(cls, name, dummy=dummy, **options)
32 return r
33 all_caches['Symbol.__new__'] = func_cache_it_cache
34 return wrapper
36 def memoizer_Interval_new(func):
37 func._cache_it_cache = func_cache_it_cache = {}
38 def wrapper(cls, a, b=None, **options):
39 if b is None:
40 # to ensure that Interval(a) is Interval(a,a)
41 args = (a,a)
42 else:
43 args = (a,b)
44 try:
45 return func_cache_it_cache[args]
46 except KeyError:
47 pass
48 func_cache_it_cache[args] = r = func(cls, a, b, **options)
49 return r
50 all_caches['Interval.__new__'] = func_cache_it_cache
51 return wrapper
53 def memoizer_Float_new(func):
54 func._cache_it_cache = func_cache_it_cache = {}
55 def wrapper(cls, x=0, prec=None, mode=None, **options):
56 if prec is None: prec = cls._prec
57 if mode is None: mode = cls._mode
58 args = (x, prec, mode)
59 try:
60 return func_cache_it_cache[args]
61 except KeyError:
62 pass
63 func_cache_it_cache[args] = r = func(cls, *args, **options)
64 return r
65 all_caches['Float.__new__'] = func_cache_it_cache
66 return wrapper
68 def clear_cache():
69 """Clear all cached objects."""
70 for cache in all_caches.values():
71 cache.clear()