From 39a4076456ef5e8f3d401066d3e8a9d97bd6c400 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20Boquien?=
Date: Sun, 1 May 2016 16:01:07 -0300
Subject: [PATCH] A significant fraction of the total run time is spent
computing integrals (e.g. fluxes in passbands). We can make the integration
faster by rewriting the trapezoidal rule in terms of np.dot(). This allows to
offload the computation to optimised libraries. The end result is that the
integration is twice as fast, with a gain of ~10-15% on the total run time.
---
CHANGELOG.md | 1 +
pcigale/sed/utils.py | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3a8a3943..ca182624 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
### Changed
### Fixed
### Optimised
+- A significant fraction of the total run time is spent computing integrals (e.g. fluxes in passbands). We can make the integration faster by rewriting the trapezoidal rule in terms of np.dot(). This allows to offload the computation to optimised libraries. The end result is that the integration is twice as fast, with a gain of ~10-15% on the total run time. (Médéric Boquien)
## 0.9.0 (2016-04-04)
### Added
diff --git a/pcigale/sed/utils.py b/pcigale/sed/utils.py
index d7f7c168..127fb1cb 100644
--- a/pcigale/sed/utils.py
+++ b/pcigale/sed/utils.py
@@ -409,4 +409,4 @@ def flux_trapz(y, x, key):
else:
dx = np.diff(x)
dx_cache[key] = dx
- return (dx*(y[1:]+y[:-1])).sum()/2.
+ return np.dot(dx, y[1:]+y[:-1]) * .5
--
2.22.2