computational science and engineering

Archive for the ‘Python’ Category

A lookup table for fast Python math

Thursday, December 11th, 2008 Posted in Python, Scientific computing | 2 Comments »

EDIT: the UnivariateSpline class from Scipy is much faster! Numerical programming frequently requires the use of look-up tables. A look-up table is a collection of pre-computed values. When given an "x" value, the table returns a pre-computed "y" value. ...

Update 2: building 64-bit Numpy with Intel compilers and MKL

Tuesday, December 9th, 2008 Posted in Linux, Python, Scientific computing | 1 Comment »

NOTE: these instructions are obsolete.  Please see Building NumPy on a 64-bit Red Hat Cluster with Intel MKL. In a previous post I described how I built Numpy with Intel compilers and the Math Kernel Library on a 64-bit cluster. Today I ...

Using Python to generate XML files for visualization in Paraview

Thursday, November 13th, 2008 Posted in Linux, Python, Software development | No Comments »

VTK is an open-source software system for "3D computer graphics, image processing, and visualization" developed by by Kitware. VTK is the foundation of Paraview, an industrial-strength CFD visualization tool that I have found to be very useful. I ...

Unexpected integer/float math behavior in Python

Thursday, November 6th, 2008 Posted in Python, Software development | No Comments »

I wasted some time today tracking down a bug in one of my programs.  It turned out to be "unexpected behavior" rather than a bug.  I was aware of this aspect of the language, but I made an assumption and ...

Profiling Python code

Friday, October 24th, 2008 Posted in Python | 1 Comment »

"Speed" is a complicated term when used in the context of software.  Does it mean raw speed of execution, or reducing the amount of time until a correct result is obtained?  Python is not the first language that comes to ...

Updated: building 64-bit Numpy with Intel compilers (icc)

Friday, October 17th, 2008 Posted in Linux, Python | 1 Comment »

I had to re-build Numpy because our cluster was upgraded and the Intel compilers and libraries were moved to a different directory.  This turned out to be a half-day affair of trial-and-error.  I learned a few important things, which I ...

Even faster collision detection in Python using Numpy

Thursday, October 16th, 2008 Posted in Python, Scientific computing, Software development | No Comments »

Last night, in the shower, I realized that my collision detection routine could be even faster. Here is a representative snippet of code from my previous post: d2 = (x-self.x[0:i])*(x-self.x[0:i]) + (y-self.y[0:i])*(y-self.y[0:i]) + (z-self.z[0:i])*(z-self.z[0:i]) For some reason, I ...

Speeding up Python math with Numpy: collision detection example

Sunday, October 12th, 2008 Posted in Python, Software development | 1 Comment »

Python is a very-high-level language.  That makes it easy to write code quickly, but the program may not be as fast as a program compiled from a lower-level language.  For this reason, many scientific programs are written in Fortran or ...

Python Pickle: Painless binary storage for Python objects

Monday, September 15th, 2008 Posted in Python, Software development | 2 Comments »

The pickle module provided with Python is so useful that I'm surprised I haven't used it before. Pickle allows you to save an entire data structure (such as an object) to disk as a binary file in a effortless ...