I wrote some physics modeling code in C ++, and parsing input text files is a bottleneck. As one of the input parameters, the user must specify a mathematical function that will be evaluated many times at runtime. C ++ code has some predefined function classes for this (they are actually quite complicated on the mathematical side) and some limited parsing capabilities, but I am not satisfied with this construction at all.
I need both the algorithm and the function evaluation to remain fast, so it is advisable to save them as compiled code (and, preferably, mathematical functions as objects of C ++ functions). However, I was thinking of gluing the whole simulation together with Python: the user could specify the input parameters in the Python script, as well as implement storage, visualization of the results (matplotlib) and the GUI in Python too.
I know that most of the time you can expose C ++ classes, for example. with SWIG, but I still have a question regarding parsing a user-defined math function in Python:
Is it possible to somehow build a C ++ function object in Python and pass it to the C ++ algorithm? For example. when i call
f = WrappedCPPGaussianFunctionClass(sigma=0.5) WrappedCPPAlgorithm(f)
in Python, it will return a pointer to a C ++ object, which will then be passed to a C ++ routine that requires such a pointer, or something like that ... (don't ask me about memory management in this case: S)
The thing is, no callback is required in the algorithm for Python . Later, I would like to expand this example to also do simple parsing on the Python side, such as a sum or a product of functions, and return some kind of parsing, such as a C ++ object, but now stay on the basics.
Sorry for the long post and thanks for the suggestions in advance.
c ++ python functor wrapping
cornail
source share