[C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy

Ger van Diepen diepen at astron.nl
Mon Apr 21 09:19:45 CEST 2008

Hi Andreas,

I'm listening and it looks very nice.
Are you internally using the numpy code to acces the arrays so that it
also deals with numpy array slices without copying?
I'm wondering what you are doing with the axes order. Blas is Fortran,
while numpy is basically C. Although numpy supports axes in Fortran
order, an array gets converted to C order as soon as you do operations
on it. (e.g. when doing a=b+1 where b is in Fortran order, a will be in
C order). Note that numpy is double as fast for arrays in C order
compared to Fortran order.

I think there is a difference between a numpy array scalar and a numpy
results in an array scalar (which cannot be indexed), while
results in an integer scalar of type numpy.int32

It is the latter that causes us problems in passing it via Boost.Python
to a function expecting a normal integer. We have no problem handling a
numpy array scalar to a function expecting an array.


>>> Andreas Klöckner <lists at informa.tiker.net> 04/21/08 1:36 AM >>>
Hi all,

I'm pleased to announce the availability of PyUblas, a software bridge
Numpy and Boost.Ublas, for use with Boost.Python.

PyUblas lets you use the "native" matrix library on either side of the 
language "fence". This is achieved without any copying at the language 
boundary. The end result is a very fast and convenient environment for 
writing hybrid numerical codes.

To do its magic, PyUblas defines new Ublas-derived matrix and vector
called numpy_matrix and numpy_vector. These hold their internal data in
arrays, and can therefore be passed to and from Python without penalty. 
Variables of these types can be used directly in Ublas's C++ vector and 
matrix expressions, without any copying or conversion, and achieve the
speed as Ublas's native types. In addition, PyUblas exposes (copying) 
converters for many of Ublas's own types.

The package also (optionally) wraps Ublas's sparse matrix types for use
Python. An add-on module called PyUblasExt supplies additional
for these types, such as solvers for linear systems and eigenvalue

There's much more material available here:



PS: PyUblas also automatically converts Numpy "array scalars" from
Python to 
C++. Ger, you listening? :)

More information about the Cplusplus-sig mailing list