The function document method uses sympy to generate a latex expression for the fit function and returns None if it fails to generate the expression.
See also from lsqfitgui.util.function import parse_function_expression.
Unfortunately, parsing functions using numpy fail. This is due to
from sympy import S
import numpy as np
x = S("x")
np.exp(x)
fails.
A workaround is overloading the Symbol class
from sympy import Symbol, exp
import numpy as np
class MySymbol(Symbol):
def exp(self):
return exp(self)
x = MySymbol("x")
np.exp(x)
which may also work for other functions (maybe there is a more elegant way by looking up matching module attributes).
The main issue, I have however encountered is that, for example
x = MySymbol("x")
y = MySymbol("y")
np.exp(x + y)
fails again because this is now not a MySymbol but rather an Add class.
So, I believe, if it is somehow possible, it would be more effective to replace all the numpy expressions by sympy expressions within the function call. Maybe this possible in the spirit of unittest.mock.
The function document method uses sympy to generate a latex expression for the fit function and returns
Noneif it fails to generate the expression.See also
from lsqfitgui.util.function import parse_function_expression.Unfortunately, parsing functions using numpy fail. This is due to
fails.
A workaround is overloading the
Symbolclasswhich may also work for other functions (maybe there is a more elegant way by looking up matching module attributes).
The main issue, I have however encountered is that, for example
fails again because this is now not a
MySymbolbut rather anAddclass.So, I believe, if it is somehow possible, it would be more effective to replace all the numpy expressions by sympy expressions within the function call. Maybe this possible in the spirit of unittest.mock.