Vector type in C anythere?

hinsen at cnrs-orleans.fr hinsen at cnrs-orleans.fr
Sun May 23 15:21:34 EDT 1999


Marco Bubke <bubke at monet.cs.uni-magdeburg.de> writes:

> Ich need a vector class of the length three (for 3D calculations). The
> speed of this class in python is to slow so I have tried to program it
> as C extension. But I have two problems. The first one are the types

You can save yourself a lot of work by using the array type from the
NumPy extension. Your new 3D vector type would store its data as an
array of shape (3,) and pass all method calls etc. on to the NumPy
code with just minor parameter changes. The price to pay is memory
overhead (the bookkeeping data structures of arrays are of a
significant size compared to three numbers), but you save a lot of
work (plus some features you'd probably never implement yourself,
such as the ability to use all C data types as vector elements),
and you get interoperability with NumPy arrays.

I have a 3D vector class in my scientific collection
(http://starship.python.net/crew/hinsen/scientific.html), which is
written in Python (and thus probably too slow for you), and uses NumPy
arrays internally. I found the interoperability an important feature;
it allows me to store lists of points in an (N, 3) array for easy
access from C extension modules, and at them same time access each
point as a vector object from Python code, all that without any data
duplication that holds the risk of incompatibility.

In fact, I have planned to replace this Python class by a C type for
efficiency, keeping it 100% compatible (and thus requiring data storage in
array form). It's not a high-priority project for me, but if anybody wants to
work on it, I can provide some help. --
-----------------------------------------------------------------------------
-- Konrad Hinsen  | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique
Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69 Rue Charles Sadron  | Fax: 
+33-2.38.63.15.17 45071 Orleans Cedex 2  | Deutsch/Esperanto/English/ France 
| Nederlands/Francais
-----------------------------------------------------------------------------
--


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---




More information about the Python-list mailing list