|
19 | 19 | except ImportError: |
20 | 20 | from ..tools import cached_property |
21 | 21 |
|
| 22 | +NUMERICAL_TYPES = (float, int, complex, np.ndarray, np.integer, np.floating) |
| 23 | + |
22 | 24 |
|
23 | 25 | class Function: |
24 | 26 | """Class converts a python function or a data sequence into an object |
@@ -1937,9 +1939,7 @@ def __add__(self, other): |
1937 | 1939 | return Function(lambda x: (self.get_value(x) + other(x))) |
1938 | 1940 | # If other is Float except... |
1939 | 1941 | except AttributeError: |
1940 | | - if isinstance( |
1941 | | - other, (float, int, complex, np.ndarray, np.integer, np.floating) |
1942 | | - ): |
| 1942 | + if isinstance(other, NUMERICAL_TYPES): |
1943 | 1943 | # Check if Function object source is array or callable |
1944 | 1944 | if isinstance(self.source, np.ndarray): |
1945 | 1945 | # Operate on grid values |
@@ -2069,9 +2069,7 @@ def __mul__(self, other): |
2069 | 2069 | return Function(lambda x: (self.get_value(x) * other(x))) |
2070 | 2070 | # If other is Float except... |
2071 | 2071 | except AttributeError: |
2072 | | - if isinstance( |
2073 | | - other, (float, int, complex, np.ndarray, np.integer, np.floating) |
2074 | | - ): |
| 2072 | + if isinstance(other, NUMERICAL_TYPES): |
2075 | 2073 | # Check if Function object source is array or callable |
2076 | 2074 | if isinstance(self.source, np.ndarray): |
2077 | 2075 | # Operate on grid values |
@@ -2160,9 +2158,7 @@ def __truediv__(self, other): |
2160 | 2158 | return Function(lambda x: (self.get_value_opt(x) / other(x))) |
2161 | 2159 | # If other is Float except... |
2162 | 2160 | except AttributeError: |
2163 | | - if isinstance( |
2164 | | - other, (float, int, complex, np.ndarray, np.integer, np.floating) |
2165 | | - ): |
| 2161 | + if isinstance(other, NUMERICAL_TYPES): |
2166 | 2162 | # Check if Function object source is array or callable |
2167 | 2163 | if isinstance(self.source, np.ndarray): |
2168 | 2164 | # Operate on grid values |
@@ -2201,9 +2197,7 @@ def __rtruediv__(self, other): |
2201 | 2197 | A Function object which gives the result of other(x)/self(x). |
2202 | 2198 | """ |
2203 | 2199 | # Check if Function object source is array and other is float |
2204 | | - if isinstance( |
2205 | | - other, (float, int, complex, np.ndarray, np.integer, np.floating) |
2206 | | - ): |
| 2200 | + if isinstance(other, NUMERICAL_TYPES): |
2207 | 2201 | if isinstance(self.source, np.ndarray): |
2208 | 2202 | # Operate on grid values |
2209 | 2203 | ys = other / self.y_array |
@@ -2271,9 +2265,7 @@ def __pow__(self, other): |
2271 | 2265 | return Function(lambda x: (self.get_value_opt(x) ** other(x))) |
2272 | 2266 | # If other is Float except... |
2273 | 2267 | except AttributeError: |
2274 | | - if isinstance( |
2275 | | - other, (float, int, complex, np.ndarray, np.integer, np.floating) |
2276 | | - ): |
| 2268 | + if isinstance(other, NUMERICAL_TYPES): |
2277 | 2269 | # Check if Function object source is array or callable |
2278 | 2270 | if isinstance(self.source, np.ndarray): |
2279 | 2271 | # Operate on grid values |
@@ -2312,9 +2304,7 @@ def __rpow__(self, other): |
2312 | 2304 | A Function object which gives the result of other(x)**self(x). |
2313 | 2305 | """ |
2314 | 2306 | # Check if Function object source is array and other is float |
2315 | | - if isinstance( |
2316 | | - other, (float, int, complex, np.ndarray, np.integer, np.floating) |
2317 | | - ): |
| 2307 | + if isinstance(other, NUMERICAL_TYPES): |
2318 | 2308 | if isinstance(self.source, np.ndarray): |
2319 | 2309 | # Operate on grid values |
2320 | 2310 | ys = other**self.y_array |
|
0 commit comments