@@ -2206,47 +2206,56 @@ def funcify_method(*args, **kwargs):
22062206
22072207 Examples
22082208 --------
2209- >>> class Test():
2210- ... @Funcify(inputs=['x'], outputs=['y'])
2211- ... def func(x):
2212- ... return x**2
2213- >>> t = Test()
2214- ... t.func
2209+ There are 3 types of methods that this decorator supports:
2210+
2211+ 1. Method which returns a valid rocketpy.Function source argument.
2212+
2213+ >>> from rocketpy.Function import funcify_method
2214+ >>> class Example():
2215+ ... @funcify_method(inputs=['x'], outputs=['y'])
2216+ ... def f(self):
2217+ ... return lambda x: x**2
2218+ >>> example = Example()
2219+ >>> example.f
22152220 Function from R1 to R1 : (x) → (y)
2216- >>> g = 2*t.func + 3
2221+
2222+ Normal algebra can be performed afterwards:
2223+
2224+ >>> g = 2*example.f + 3
22172225 >>> g(2)
22182226 11
22192227
2220- Can also be used without any arguments:
2228+ 2. Method which returns a rocketpy.Function instance. An interesting use is to reset
2229+ input and output names after algebraic operations.
2230+
2231+ >>> class Example():
2232+ ... @funcify_method(inputs=['x'], outputs=['x**3'])
2233+ ... def cube(self):
2234+ ... f = Function(lambda x: x**2)
2235+ ... g = Function(lambda x: x**5)
2236+ ... return g / f
2237+ >>> example = Example()
2238+ >>> example.cube
2239+ Function from R1 to R1 : (x) → (x**3)
22212240
2222- >>> class Test():
2223- ... @Funcify
2224- ... def func(x):
2241+ 3. Method which is itself a valid rocketpy.Function source argument.
2242+
2243+ >>> class Example():
2244+ ... @funcify_method('x', 'f(x)')
2245+ ... def f(self, x):
22252246 ... return x**2
2226- >>> t = Test()
2227- ... t.func
2228- Function from R1 to R1 : (Scalar) → (Scalar)
2229-
2230- Can also be used when the method already returns a Function instance. In such case
2231- it is interesting to use the `inputs` and `outputs` arguments to overwrite the
2232- inputs and outputs of the method.
2233-
2234- >>> class Test():
2235- ... @Funcify(inputs='x', outputs='y')
2236- ... def func(x):
2237- ... return Function(lambda x: x**2)
2238- >>> t = Test()
2239- ... t.func
2240- Function from R1 to R1 : (x) → (y)
2247+ >>> example = Example()
2248+ >>> example.f
2249+ Function from R1 to R1 : (x) → (f(x))
22412250
22422251 In order to reset the cache, just delete de attribute from the instance:
22432252
2244- >>> del t.func
2253+ >>> del example.f
22452254
22462255 Once it is requested again, it will be re-created as a new Function object:
22472256
2248- >>> t.func
2249- Function from R1 to R1 : (Scalar ) → (Scalar )
2257+ >>> example.f
2258+ Function from R1 to R1 : (x ) → (f(x) )
22502259 """
22512260 func = None
22522261 if len (args ) == 1 and callable (args [0 ]):
0 commit comments