Skip to content

Commit a4bda8d

Browse files
committed
ENH: maintain extrapolation in other operations
1 parent 8eae5d2 commit a4bda8d

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

rocketpy/mathutils/function.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,8 +1716,9 @@ def __add__(self, other):
17161716
outputs = self.__outputs__[0] + " + " + other.__outputs__[0]
17171717
outputs = "(" + outputs + ")"
17181718
interpolation = self.__interpolation__
1719+
extrapolation = self.__extrapolation__
17191720
# Create new Function object
1720-
return Function(source, inputs, outputs, interpolation)
1721+
return Function(source, inputs, outputs, interpolation, extrapolation)
17211722
else:
17221723
return Function(lambda x: (self.get_value(x) + other(x)))
17231724
# If other is Float except...
@@ -1845,8 +1846,9 @@ def __mul__(self, other):
18451846
outputs = self.__outputs__[0] + "*" + other.__outputs__[0]
18461847
outputs = "(" + outputs + ")"
18471848
interpolation = self.__interpolation__
1849+
extrapolation = self.__extrapolation__
18481850
# Create new Function object
1849-
return Function(source, inputs, outputs, interpolation)
1851+
return Function(source, inputs, outputs, interpolation, extrapolation)
18501852
else:
18511853
return Function(lambda x: (self.get_value(x) * other(x)))
18521854
# If other is Float except...
@@ -1863,8 +1865,9 @@ def __mul__(self, other):
18631865
outputs = self.__outputs__[0] + "*" + str(other)
18641866
outputs = "(" + outputs + ")"
18651867
interpolation = self.__interpolation__
1868+
extrapolation = self.__extrapolation__
18661869
# Create new Function object
1867-
return Function(source, inputs, outputs, interpolation)
1870+
return Function(source, inputs, outputs, interpolation, extrapolation)
18681871
else:
18691872
return Function(lambda x: (self.get_value(x) * other))
18701873
# Or if it is just a callable
@@ -1930,8 +1933,9 @@ def __truediv__(self, other):
19301933
outputs = self.__outputs__[0] + "/" + other.__outputs__[0]
19311934
outputs = "(" + outputs + ")"
19321935
interpolation = self.__interpolation__
1936+
extrapolation = self.__extrapolation__
19331937
# Create new Function object
1934-
return Function(source, inputs, outputs, interpolation)
1938+
return Function(source, inputs, outputs, interpolation, extrapolation)
19351939
else:
19361940
return Function(lambda x: (self.get_value_opt(x) / other(x)))
19371941
# If other is Float except...
@@ -1948,8 +1952,9 @@ def __truediv__(self, other):
19481952
outputs = self.__outputs__[0] + "/" + str(other)
19491953
outputs = "(" + outputs + ")"
19501954
interpolation = self.__interpolation__
1955+
extrapolation = self.__extrapolation__
19511956
# Create new Function object
1952-
return Function(source, inputs, outputs, interpolation)
1957+
return Function(source, inputs, outputs, interpolation, extrapolation)
19531958
else:
19541959
return Function(lambda x: (self.get_value_opt(x) / other))
19551960
# Or if it is just a callable
@@ -1983,8 +1988,9 @@ def __rtruediv__(self, other):
19831988
outputs = str(other) + "/" + self.__outputs__[0]
19841989
outputs = "(" + outputs + ")"
19851990
interpolation = self.__interpolation__
1991+
extrapolation = self.__extrapolation__
19861992
# Create new Function object
1987-
return Function(source, inputs, outputs, interpolation)
1993+
return Function(source, inputs, outputs, interpolation, extrapolation)
19881994
else:
19891995
return Function(lambda x: (other / self.get_value_opt(x)))
19901996
# Or if it is just a callable
@@ -2032,8 +2038,9 @@ def __pow__(self, other):
20322038
outputs = self.__outputs__[0] + "**" + other.__outputs__[0]
20332039
outputs = "(" + outputs + ")"
20342040
interpolation = self.__interpolation__
2041+
extrapolation = self.__extrapolation__
20352042
# Create new Function object
2036-
return Function(source, inputs, outputs, interpolation)
2043+
return Function(source, inputs, outputs, interpolation, extrapolation)
20372044
else:
20382045
return Function(lambda x: (self.get_value_opt(x) ** other(x)))
20392046
# If other is Float except...
@@ -2050,8 +2057,9 @@ def __pow__(self, other):
20502057
outputs = self.__outputs__[0] + "**" + str(other)
20512058
outputs = "(" + outputs + ")"
20522059
interpolation = self.__interpolation__
2060+
extrapolation = self.__extrapolation__
20532061
# Create new Function object
2054-
return Function(source, inputs, outputs, interpolation)
2062+
return Function(source, inputs, outputs, interpolation, extrapolation)
20552063
else:
20562064
return Function(lambda x: (self.get_value(x) ** other))
20572065
# Or if it is just a callable
@@ -2085,8 +2093,9 @@ def __rpow__(self, other):
20852093
outputs = str(other) + "**" + self.__outputs__[0]
20862094
outputs = "(" + outputs + ")"
20872095
interpolation = self.__interpolation__
2096+
extrapolation = self.__extrapolation__
20882097
# Create new Function object
2089-
return Function(source, inputs, outputs, interpolation)
2098+
return Function(source, inputs, outputs, interpolation, extrapolation)
20902099
else:
20912100
return Function(lambda x: (other ** self.get_value(x)))
20922101
# Or if it is just a callable
@@ -2326,7 +2335,7 @@ def derivative_function(self):
23262335
outputs = f"d({self.__outputs__[0]})/d({inputs[0]})"
23272336

23282337
# Create new Function object
2329-
return Function(source, inputs, outputs, self.__interpolation__)
2338+
return Function(source, inputs, outputs, self.__interpolation__, self.__extrapolation__)
23302339

23312340
def integral_function(self, lower=None, upper=None, datapoints=100):
23322341
"""Returns a Function object representing the integral of the Function
@@ -2494,6 +2503,7 @@ def inverse_function(self, approx_func=None, tol=1e-4):
24942503
inputs=self.__outputs__,
24952504
outputs=self.__inputs__,
24962505
interpolation=self.__interpolation__,
2506+
extrapolation=self.__extrapolation__,
24972507
)
24982508

24992509
def find_input(self, val, start, tol=1e-4):

0 commit comments

Comments
 (0)