Symengine序列化

发布于 2025-01-20 19:13:34 字数 409 浏览 2 评论 0原文

我正在开发一个项目,我需要创建一个函数数组,这些函数是数组中其他函数的偏导数的组合。这些函数需要进行羔羊化,然后尽可能快地连续评估,因为它是实时模拟器的一部分。我尝试过在 C++ 和 python 中使用 symengine,在 python 中使用 sympy。我需要使用 C++ 中的函数,并且我已经设法使用 symengine 来制作它们,但是它们变得非常毛茸茸并且评估速度很慢,而且我知道 symengine 中没有简化函数。我注意到,如果在进行羔羊化之前使用 sympy.simplify() 简化函数,则可以更快地评估函数。(这也适用于 python 中的 symengine 函数)。有没有办法从 python 序列化和存储函数数组(符号或 lamdified)并在 C++ 中加载它们?或者还有其他用于 C++ 的符号数学库吗?或者有没有办法简化 C++ 中的 symengine 函数?

Im working on a project where i need to create a an array of functions that are combinations of partial derivatives of other functions in the array. These functions needs to be lambdified, and then evaluated continuously, as quick as possible as it is part of a real-time simulator. I’ve experimented using symengine in c++ and python and sympy in python. I need to use the functions in c++ and i have managed to make them using symengine, but they get quite hairy and slow to evaluate, and i understand there is no simplify function in symengine. I’ve noticed that functions can be evaluated much quicker if they have been simplified using sympy.simplify() before being lambdified.(this also work with symengine functions i python). Is there a way to serialize and store the arrays of functions(symbolic or lamdified) from python and load them in c++? Or is there some other symbolic math library for c++? Or is there a way to simplify symengine functions in c++?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痞味浪人 2025-01-27 19:13:34

在Python中,您可以保存字节

expr.__reduce__()[1][0]

,然后在C ++中加载该字节

Basic::loads(str)

,请注意,这很脆弱,您需要使用相同的Symengine版本作为Python和C ++

In python you can save the bytes

expr.__reduce__()[1][0]

and then load that in C++

Basic::loads(str)

Note that this is fragile and you need to use the same symengine version for both python and C++

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文