Skip to content

Commit

Permalink
FIX: include numpy numeric types in Function arithmetic.
Browse files Browse the repository at this point in the history
  • Loading branch information
phmbressan committed Nov 28, 2023
1 parent b82810f commit 63881c4
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions rocketpy/mathutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,9 @@ def __add__(self, other):
return Function(lambda x: (self.get_value(x) + other(x)))
# If other is Float except...
except AttributeError:
if isinstance(other, (float, int, complex, np.ndarray)):
if isinstance(
other, (float, int, complex, np.ndarray, np.integer, np.floating)
):
# Check if Function object source is array or callable
if isinstance(self.source, np.ndarray):
# Operate on grid values
Expand Down Expand Up @@ -1970,7 +1972,9 @@ def __mul__(self, other):
return Function(lambda x: (self.get_value(x) * other(x)))
# If other is Float except...
except AttributeError:
if isinstance(other, (float, int, complex, np.ndarray)):
if isinstance(
other, (float, int, complex, np.ndarray, np.integer, np.floating)
):
# Check if Function object source is array or callable
if isinstance(self.source, np.ndarray):
# Operate on grid values
Expand Down Expand Up @@ -2059,7 +2063,9 @@ def __truediv__(self, other):
return Function(lambda x: (self.get_value_opt(x) / other(x)))
# If other is Float except...
except AttributeError:
if isinstance(other, (float, int, complex, np.ndarray)):
if isinstance(
other, (float, int, complex, np.ndarray, np.integer, np.floating)
):
# Check if Function object source is array or callable
if isinstance(self.source, np.ndarray):
# Operate on grid values
Expand Down Expand Up @@ -2098,7 +2104,9 @@ def __rtruediv__(self, other):
A Function object which gives the result of other(x)/self(x).
"""
# Check if Function object source is array and other is float
if isinstance(other, (float, int, complex, np.ndarray)):
if isinstance(
other, (float, int, complex, np.ndarray, np.integer, np.floating)
):
if isinstance(self.source, np.ndarray):
# Operate on grid values
ys = other / self.y_array
Expand Down Expand Up @@ -2166,7 +2174,9 @@ def __pow__(self, other):
return Function(lambda x: (self.get_value_opt(x) ** other(x)))
# If other is Float except...
except AttributeError:
if isinstance(other, (float, int, complex, np.ndarray)):
if isinstance(
other, (float, int, complex, np.ndarray, np.integer, np.floating)
):
# Check if Function object source is array or callable
if isinstance(self.source, np.ndarray):
# Operate on grid values
Expand Down Expand Up @@ -2205,7 +2215,9 @@ def __rpow__(self, other):
A Function object which gives the result of other(x)**self(x).
"""
# Check if Function object source is array and other is float
if isinstance(other, (float, int, complex, np.ndarray)):
if isinstance(
other, (float, int, complex, np.ndarray, np.integer, np.floating)
):
if isinstance(self.source, np.ndarray):
# Operate on grid values
ys = other**self.y_array
Expand Down

0 comments on commit 63881c4

Please sign in to comment.