Skip to content
Snippets Groups Projects
Commit 9e7da09f authored by Izzard, Robert Dr (Maths & Physics)'s avatar Izzard, Robert Dr (Maths & Physics)
Browse files

memoize (with functools' lru_cache) calls to spacing_functions

parent 8f194630
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ import sys ...@@ -14,7 +14,7 @@ import sys
from binarycpython.utils.grid import Population from binarycpython.utils.grid import Population
@functools.lru_cache(maxsize=128)
def const( def const(
min_bound: Union[int, float], max_bound: Union[int, float], steps: int min_bound: Union[int, float], max_bound: Union[int, float], steps: int
) -> list: ) -> list:
...@@ -34,6 +34,7 @@ def const( ...@@ -34,6 +34,7 @@ def const(
############################################################ ############################################################
@functools.lru_cache(maxsize=128)
def peak_normalized_gaussian_func( def peak_normalized_gaussian_func(
x: Union[int, float], mean: Union[int, float], sigma: Union[int, float] x: Union[int, float], mean: Union[int, float], sigma: Union[int, float]
) -> Union[int, float]: ) -> Union[int, float]:
...@@ -58,6 +59,7 @@ def peak_normalized_gaussian_func( ...@@ -58,6 +59,7 @@ def peak_normalized_gaussian_func(
############################################################ ############################################################
@functools.lru_cache(maxsize=128)
def gaussian_zoom( def gaussian_zoom(
min_bound: Union[int, float], min_bound: Union[int, float],
max_bound: Union[int, float], max_bound: Union[int, float],
...@@ -102,6 +104,7 @@ def gaussian_zoom( ...@@ -102,6 +104,7 @@ def gaussian_zoom(
return array return array
@functools.lru_cache(maxsize=128)
def const_dt(self, def const_dt(self,
dt=1000.0, dt=1000.0,
dlogt=0.1, dlogt=0.1,
...@@ -111,8 +114,8 @@ def const_dt(self, ...@@ -111,8 +114,8 @@ def const_dt(self,
logspacing=False, logspacing=False,
tmin=3.0, # start at 3Myr tmin=3.0, # start at 3Myr
tmax=None, # use max_evolution_time by default tmax=None, # use max_evolution_time by default
mindm=None, # list of tuples mindm=None, # tuple of tuples
maxdm=[(0.07,1.0,0.1),(1.0,300.0,1.0)], # list of tuples maxdm=((0.07,1.0,0.1),(1.0,300.0,1.0)), # tuple of tuples
fsample=1.0, fsample=1.0,
factor=1.0, factor=1.0,
showtable=False): showtable=False):
...@@ -128,7 +131,7 @@ def const_dt(self, ...@@ -128,7 +131,7 @@ def const_dt(self,
logspacing: whether to use log-spaced time, in which case dt is actually d(log10(t)) logspacing: whether to use log-spaced time, in which case dt is actually d(log10(t))
tmin: the minimum time to consider (Myr, default 3.0 Myr) tmin: the minimum time to consider (Myr, default 3.0 Myr)
tmax: the maximum time to consider (Myr, default None which means we use the grid option 'max_evolution_time') tmax: the maximum time to consider (Myr, default None which means we use the grid option 'max_evolution_time')
mindm: a list of tuples containing a mass range and minimum mass spacing in that range. The default is [(0.07,1.0,0.1),(1.0,300.0,1.0)] allocated a minimum dm of 0.1Msun in the mass range 0.07 to 1.0 Msun and 1.0Msun in the range 1.0 to 300.0 Msun. Anything you set overrides this. mindm: a tuple of tuples containing a mass range and minimum mass spacing in that range. The default is ((0.07,1.0,0.1),(1.0,300.0,1.0)) allocated a minimum dm of 0.1Msun in the mass range 0.07 to 1.0 Msun and 1.0Msun in the range 1.0 to 300.0 Msun. Anything you set overrides this.
maxdm: a list of tuples similar to mindm but specifying a maximum mass spacing. (None) maxdm: a list of tuples similar to mindm but specifying a maximum mass spacing. (None)
fsample: a global sampling (Shannon-like) factor (<1) to improve resolution (default 1.0, set to smaller to improve resolution) fsample: a global sampling (Shannon-like) factor (<1) to improve resolution (default 1.0, set to smaller to improve resolution)
factor: all masses generated are multiplied by this after generation factor: all masses generated are multiplied by this after generation
...@@ -145,7 +148,7 @@ def const_dt(self, ...@@ -145,7 +148,7 @@ def const_dt(self,
# logarithmic spacing in time, generally suitable for Galactic # logarithmic spacing in time, generally suitable for Galactic
# chemical evolution yield grids. # chemical evolution yield grids.
spacingfunc="const_dt(self,dlogt=0.1,nres=100,mmin=0.07,mmax=80.0,maxdm=[(0.07,1.0,0.1),(1.0,10.0,1.0),(10.0,80.0,2.0)],showtable=True,logspacing=True,fsample=1.0/4.0)" spacingfunc="const_dt(self,dlogt=0.1,nres=100,mmin=0.07,mmax=80.0,maxdm=((0.07,1.0,0.1),(1.0,10.0,1.0),(10.0,80.0,2.0)),showtable=True,logspacing=True,fsample=1.0/4.0)"
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment