Skip to content

Commit

Permalink
10x speed increase in CIB profile (#917)
Browse files Browse the repository at this point in the history
* optimization

* even faster

* corn-flaked

* check for M > Mmin

* Mmin in sat CIB profile
  • Loading branch information
nikfilippas committed Jun 22, 2022
1 parent 8a87eee commit b6823c2
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions pyccl/halos/profiles_cib.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,22 @@ def _Lumcen(self, M, a):
return Lumcen

def _Lumsat(self, M, a):
Lumsat = np.zeros_like(M)
# Loop over Mparent
# TODO: if this is too slow we could move it to C
# and parallelize
for iM, Mparent in enumerate(M):
if Mparent > self.Mmin:
# Array of Msubs (log-spaced with 10 samples per dex)
nm = max(2, int(np.log10(Mparent/1E10)*10))
msub = np.geomspace(1E10, Mparent, nm+1)
# Sample integrand
dnsubdlnm = self.dNsub_dlnM_TinkerWetzel10(msub, Mparent)
Lum = self._Lum(np.log10(msub), a)
integ = dnsubdlnm*Lum
Lumsat[iM] = simps(integ, x=np.log(msub))
return Lumsat
if not np.max(M) > self.Mmin:
return np.zeros_like(M)

res = np.zeros_like(M)
M_use = M[M >= self.Mmin, None]
logM = np.log10(M_use)
LOGM_MIN = np.log10(self.Mmin)
nm = max(2, 10*int(np.max(logM) - LOGM_MIN))
msub = np.linspace(LOGM_MIN, np.max(logM), nm+1)[None, :]

Lum = self._Lum(msub, a)
dnsubdlnm = self.dNsub_dlnM_TinkerWetzel10(10**msub, M_use)
integ = dnsubdlnm * Lum
Lumsat = simps(integ, x=np.log(10)*msub)
res[-len(Lumsat):] = Lumsat
return res

def _real(self, cosmo, r, M, a, mass_def):
M_use = np.atleast_1d(M)
Expand Down

0 comments on commit b6823c2

Please sign in to comment.