Skip to content

Commit d748cc7

Browse files
committed
use cached_property is available
1 parent 5be5a66 commit d748cc7

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

adaptive/learner/integrator_coeffs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Based on an adaptive quadrature algorithm by Pedro Gonnet
22

3-
import functools
43
from collections import defaultdict
54
from fractions import Fraction
65

76
import numpy as np
87
import scipy.linalg
98

9+
try:
10+
from functools import cached_property
11+
except ImportError:
12+
from adaptive.utils import cached_property
13+
1014

1115
def legendre(n):
1216
"""Return the first n Legendre polynomials.
@@ -142,10 +146,6 @@ def calc_V(x, n):
142146
return np.array(V).T
143147

144148

145-
def cached_property(f):
146-
return property(functools.lru_cache(None)(f))
147-
148-
149149
class Coefficients:
150150
def __init__(self) -> None:
151151
self.is_set = False

adaptive/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ def __call__(self, *args, **kwargs):
8383
msg = f"The attribute '{name}' should be of type {type_}, not {type(x)}."
8484
raise TypeError(msg)
8585
return obj
86+
87+
88+
def cached_property(f):
89+
return property(functools.lru_cache(None)(f))

0 commit comments

Comments
 (0)