[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
scalar.
E.g.
a=array(1,dtype='int32')
results in an array scalar (which cannot be indexed), while
a=array([1,2],dtype='int32')
a[0]
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.
Cheers,
Ger
>>> 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
between
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
types,
called numpy_matrix and numpy_vector. These hold their internal data in
Numpy
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
same
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
in
Python. An add-on module called PyUblasExt supplies additional
functionality
for these types, such as solvers for linear systems and eigenvalue
problems.
There's much more material available here:
http://mathema.tician.de/software/pyublas
Enjoy,
Andreas
PS: PyUblas also automatically converts Numpy "array scalars" from
Python to
C++. Ger, you listening? :)
More information about the Cplusplus-sig
mailing list