Skip to content

Commit 0ccf225

Browse files
committed
FIX: correct compose operation.
1 parent efc1c9f commit 0ccf225

File tree

1 file changed

+5
-46
lines changed

1 file changed

+5
-46
lines changed

rocketpy/Function.py

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,20 +2230,16 @@ def findInput(self, val):
22302230
lambda x: np.abs(self.getValue(x) - val), 0, ftol=1e-6, disp=False
22312231
)
22322232

2233-
def compose(self, func, lower=None, upper=None, datapoints=100):
2233+
def compose(self, func):
22342234
"""
2235-
Returns a Function object which is the result of inputing a function into a
2236-
function (i.e. f(g(x))). The domain will become the domain of the input function
2237-
and the range will become the range of the original function.
2235+
Returns a Function object which is the result of inputing a function into a function
2236+
(i.e. f(g(x))). The domain will become the domain of the input function and the range
2237+
will become the range of the original function.
22382238
22392239
Parameters
22402240
----------
22412241
func : Function
22422242
The function to be inputed into the function.
2243-
lower : float
2244-
Lower limit of the new domain.
2245-
upper : float
2246-
Upper limit of the new domain.
22472243
22482244
Returns
22492245
-------
@@ -2254,45 +2250,8 @@ def compose(self, func, lower=None, upper=None, datapoints=100):
22542250
if not isinstance(func, Function):
22552251
raise TypeError("Input must be a Function object.")
22562252

2257-
# Checks to make sure lower bound is given
2258-
# If not it will start at the higher of the two lower bounds
2259-
if lower is None:
2260-
if isinstance(self.source, np.ndarray):
2261-
lower = self.source[0, 0]
2262-
if isinstance(func.source, np.ndarray):
2263-
lower = (
2264-
func.source[0, 0]
2265-
if lower is None
2266-
else max(lower, func.source[0, 0])
2267-
)
2268-
if lower is None:
2269-
raise ValueError(
2270-
"If Functions.source is a <class 'function'>, must provide bounds"
2271-
)
2272-
2273-
# Checks to make sure upper bound is given
2274-
# If not it will end at the lower of the two upper bounds
2275-
if upper is None:
2276-
if isinstance(self.source, np.ndarray):
2277-
upper = self.source[-1, 0]
2278-
if isinstance(func.source, np.ndarray):
2279-
upper = (
2280-
func.source[-1, 0]
2281-
if upper is None
2282-
else min(upper, func.source[-1, 0])
2283-
)
2284-
if upper is None:
2285-
raise ValueError(
2286-
"If Functions.source is a <class 'function'>, must provide bounds"
2287-
)
2288-
2289-
# Create a new Function object
2290-
xData = np.linspace(lower, upper, datapoints)
2291-
yData = np.zeros(datapoints)
2292-
for i in range(datapoints):
2293-
yData[i] = self.getValue(func.getValue(xData[i]))
22942253
return Function(
2295-
np.concatenate(([xData], [yData])).T,
2254+
lambda x: self(func(x)),
22962255
inputs=func.__inputs__,
22972256
outputs=self.__outputs__,
22982257
interpolation=self.__interpolation__,

0 commit comments

Comments
 (0)