From 9c7da174a320fe0c1eb3422fd6c361394dc7c2f9 Mon Sep 17 00:00:00 2001 From: Per A Brodtkorb Date: Thu, 1 Jun 2017 18:25:00 +0200 Subject: [PATCH] Replaced dict().setdefault with use of defaultdict. --- wafo/integrate.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wafo/integrate.py b/wafo/integrate.py index d773912..57f2789 100644 --- a/wafo/integrate.py +++ b/wafo/integrate.py @@ -10,11 +10,12 @@ from scipy.integrate import simps, trapz from wafo.plotbackend import plotbackend as plt from wafo.demos import humps from wafo.misc import dea3 -from wafo.dctpack import dct +# from wafo.dctpack import dct +from collections import defaultdict # from pychebfun import Chebfun _EPS = np.finfo(float).eps -_NODES_AND_WEIGHTS = {} +_NODES_AND_WEIGHTS = defaultdict(list) __all__ = ['dea3', 'clencurt', 'romberg', 'h_roots', 'j_roots', 'la_roots', 'p_roots', 'qrule', @@ -939,7 +940,7 @@ class _Gaussq(object): def _nodes_and_weights(num_nodes, wfun, alpha, beta): global _NODES_AND_WEIGHTS name = 'wfun{:d}_{:d}_{:g}_{:g}'.format(wfun, num_nodes, alpha, beta) - nodes_and_weights = _NODES_AND_WEIGHTS.setdefault(name, []) + nodes_and_weights = _NODES_AND_WEIGHTS[name] if len(nodes_and_weights) == 0: nodes_and_weights.extend(qrule(num_nodes, wfun, alpha, beta)) nodes, weights = nodes_and_weights