arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1412.6395cs.MSphysics.comp-ph
收藏

SClib,Python中直接嵌入C函数的黑客

SClib, a hack for straightforward embedded C functions in Python

Esteban Fuentes, Hector E. Martinez

摘要:

我们介绍了SClib,这是一个简单的黑客,可以在Python代码中轻松简单地评估C函数,提高灵活性,以便在计算能力和功能可用性之间进行更好的权衡,例如SciPy中的可视化和现有计算例程。我们还介绍了两个案例,SClib已被使用。在第一组应用程序中,我们使用SClib编写了一个薛定谔方程求解器的Python端口,该求解器已被广泛使用的文献,生成的脚本相对于原始脚本的速度提高了约150倍。审查的情况下,加速脚本已被使用。我们还描述了解决一组耦合薛定谔方程的相关问题的解决方案,其中SClib用于实现代码的速度关键部分。我们认为,当在IPython中使用SClib时,我们可以使用NumPy和Matplotlib在交互式环境中对解决方案进行操作和可视化,而不会影响性能。第二种情况是工程应用。我们使用SClib来评估电动机的反馈控制回路中的控制和系统导数。有了这个和SciPy中可用的集成例程,我们可以在Simulink中运行控制回路的仿真。C代码的使用不仅提高了模拟的速度,而且还能够测试我们在测试台中使用的完全相同的代码以获得实验结果。同样,与IPython的集成为我们提供了分析和可视化数据的灵活性。

英文摘要:

We present SClib, a simple hack that allows easy and straightforward evaluation of C functions within Python code, boosting flexibility for better trade-off between computation power and feature availability, such as visualization and existing computation routines in SciPy. We also present two cases were SClib has been used. In the first set of applications we use SClib to write a port to Python of a Schrödinger equation solver that has been extensively used the literature, the resulting script presents a speed-up of about 150x with respect to the original one. A review of the situations where the speeded-up script has been used is presented. We also describe the solution to the related problem of solving a set of coupled Schrödinger-like equations where SClib is used to implement the speed-critical parts of the code. We argue that when using SClib within IPython we can use NumPy and Matplotlib for the manipulation and visualization of the solutions in an interactive environment with no performance compromise. The second case is an engineering application. We use SClib to evaluate the control and system derivatives in a feedback control loop for electrical motors. With this and the integration routines available in SciPy, we can run simulations of the control loop a la Simulink. The use of C code not only boosts the speed of the simulations, but also enables to test the exact same code that we use in the test rig to get experimental results. Again, integration with IPython gives us the flexibility to analyze and visualize the data.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑