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\"odinger 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\"odinger-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.
翻译:我们展示了 Slib, 这是一种简单的黑客, 便于在 Python 代码中简单和直截了当地评估 C 函数, 提高了在 SciPy 中计算能力和功能可用性之间进行更佳权衡的灵活性, 例如 SciPy 的视觉化和现有计算程序。 我们还展示了两个案例 。 在第一个应用程序中, 我们使用 Slib 将一个 Schr\\" 调味方程式解析器的端口写到 Python 的 Python 端口, 并广泛使用文献, 由此产生的脚本比原始版本快150x 。 第二个是工程应用程序, 已经使用加速脚本, 并展示了使用加速脚本的状态。 我们还用 Slib SClib 来评估一套连接的 Schr\" odg- 类似方程式, 用于执行该代码的速检部分。 我们说, 当使用 SClip 和 Matplotlibliblip 来操作和 快速化系统, 我们用 Sral 的精度控制, 我们用 S tral 的缩缩化码 和S 。