Boost MultiArray and Boost uBLAS - Designed to be used together?

Hi all, Were Boost MultiArray and Boost uBLAS designed to be used together? I.e. can I apply linear algebra operations to Boost MultiArrays and get Boost MultiArrays back? If this is impossible / impractical / inefficient, what's the right approach (conversion?). I would be very keen to know your thoughts on this. Many thanks for your help. Best wishes, Paul Paul Bilokon, Vice President Citigroup | FX - Options Trading | Quants 33 Canada Square | Canary Wharf | Floor 3 London, E14 5LB Phone: +44 20 798-62191 paul.bilokon@citi.commailto:paul.bilokon@citi.com

On Jan 14, 7:40 am, "Bilokon, Paul "
Hi all,
Were Boost MultiArray and Boost uBLAS designed to be used together? I.e. can I apply linear algebra operations to Boost MultiArrays and get Boost MultiArrays back? If this is impossible / impractical / inefficient, what's the right approach (conversion?).
If this is a one-off problem, you could order the dimensions of the multi_array (fortran vs. C ordering) so that the matrix data you need is contiguous, get the underlying data pointer, go to the right offset by looking at the extents() variable, then use ublas data adaptors to turn the pointer into. Of course, this is a horrible hack and not generally useful. As far as I can tell, the right way to do this is: Create ublas adaptors for multi_array references of dimension 1 and 2. I am not entirely sure how to do this, but I was told before that looking at the undocumented ublas::shallow_array_adaptor in \boost\numeric\ublas \storage.hpp might give a template for the 1d version at least. The other thing I thought about was that the matrix_range class and equivalent for vectors (which is returned from subrange, and is in matrix_proxy.cpp) would provide a great template for the iterators, typedefs, etc. necessary for the adaptor. I imagine most of the code will just be proxying iterators to the underlying multi_array iterators, etc. I haven't had a pressing need for this, so might never get around to playing with it. But if you write it, I am sure everyone on the ublas list would love to have it.

Dear Jesse,
Thank you very much for your reply!
I'll let you know how far I get with this!
Best wishes,
Paul
-----Original Message-----
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Jesse Perla
Sent: 14 January 2010 19:08
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] Boost MultiArray and Boost uBLAS - Designed to be used together?
On Jan 14, 7:40 am, "Bilokon, Paul "
Hi all,
Were Boost MultiArray and Boost uBLAS designed to be used together? I.e. can I apply linear algebra operations to Boost MultiArrays and get Boost MultiArrays back? If this is impossible / impractical / inefficient, what's the right approach (conversion?).
If this is a one-off problem, you could order the dimensions of the multi_array (fortran vs. C ordering) so that the matrix data you need is contiguous, get the underlying data pointer, go to the right offset by looking at the extents() variable, then use ublas data adaptors to turn the pointer into. Of course, this is a horrible hack and not generally useful. As far as I can tell, the right way to do this is: Create ublas adaptors for multi_array references of dimension 1 and 2. I am not entirely sure how to do this, but I was told before that looking at the undocumented ublas::shallow_array_adaptor in \boost\numeric\ublas \storage.hpp might give a template for the 1d version at least. The other thing I thought about was that the matrix_range class and equivalent for vectors (which is returned from subrange, and is in matrix_proxy.cpp) would provide a great template for the iterators, typedefs, etc. necessary for the adaptor. I imagine most of the code will just be proxying iterators to the underlying multi_array iterators, etc. I haven't had a pressing need for this, so might never get around to playing with it. But if you write it, I am sure everyone on the ublas list would love to have it. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Dear Jesse, All,
I'll certainly have a look and if I come up with something useful will let you know.
However, this leads to another question: if MultiArray and Boost uBLAS were not designed to work together, is there a reason for this?
Is it perhaps the case that Boost MultiArray wasn't designed (or optimised) for numerical calculations?
Best wishes,
Paul
-----Original Message-----
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Jesse Perla
Sent: 14 January 2010 19:08
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] Boost MultiArray and Boost uBLAS - Designed to be used together?
On Jan 14, 7:40 am, "Bilokon, Paul "
Hi all,
Were Boost MultiArray and Boost uBLAS designed to be used together? I.e. can I apply linear algebra operations to Boost MultiArrays and get Boost MultiArrays back? If this is impossible / impractical / inefficient, what's the right approach (conversion?).
If this is a one-off problem, you could order the dimensions of the multi_array (fortran vs. C ordering) so that the matrix data you need is contiguous, get the underlying data pointer, go to the right offset by looking at the extents() variable, then use ublas data adaptors to turn the pointer into. Of course, this is a horrible hack and not generally useful. As far as I can tell, the right way to do this is: Create ublas adaptors for multi_array references of dimension 1 and 2. I am not entirely sure how to do this, but I was told before that looking at the undocumented ublas::shallow_array_adaptor in \boost\numeric\ublas \storage.hpp might give a template for the 1d version at least. The other thing I thought about was that the matrix_range class and equivalent for vectors (which is returned from subrange, and is in matrix_proxy.cpp) would provide a great template for the iterators, typedefs, etc. necessary for the adaptor. I imagine most of the code will just be proxying iterators to the underlying multi_array iterators, etc. I haven't had a pressing need for this, so might never get around to playing with it. But if you write it, I am sure everyone on the ublas list would love to have it. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Jan 18, 5:10 am, "Bilokon, Paul "
Dear Jesse, All, Is it perhaps the case that Boost MultiArray wasn't designed (or optimised) for numerical calculations?
I think that multi_array is optimized as a numerical library for its feature set. It certainly in the spirit of blitz++, though it doesn't have stencils, tensor reductions, etc. My guess is that the lack of integration with ublas is the usual problem of libraries working in silos, and a (relative) lack of new ublas features in the last few years. Also, you might want to consider discussing this on the ublas mailing list as well. -Jesse

Is it perhaps the case that Boost MultiArray wasn't designed (or optimised) for numerical calculations?
...
My guess is that the lack of integration with ublas is the usual problem of libraries working in silos, and a (relative) lack of new ublas features in the last few years.
There are probably some stride-related gotchas involved in using shallow_array_adaptors to wrap 1 and 2 dimensional MultiArray implementations. I believe MultiArray concepts/views can handle a more general stride specification than uBlas matrix and vector types may be able to. In particular, the MultiArray 2D storage ordering semantics are not encoded in types the way that uBlas has them. Not insurmountable, just something to be aware of. - Rhys

Many thanks, Rhys, I'll also forward this email to the ublas mailing list. (The question, of course, is the effect of these adapters on performance. However, I trust most of the overhead is compile-time?) Best wishes, Paul -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Rhys Ulerich Sent: 18 January 2010 15:20 To: boost-users@lists.boost.org Subject: Re: [Boost-users] Boost MultiArray and Boost uBLAS - Designed to be used together?
Is it perhaps the case that Boost MultiArray wasn't designed (or optimised) for numerical calculations?
...
My guess is that the lack of integration with ublas is the usual problem of libraries working in silos, and a (relative) lack of new ublas features in the last few years.
There are probably some stride-related gotchas involved in using shallow_array_adaptors to wrap 1 and 2 dimensional MultiArray implementations. I believe MultiArray concepts/views can handle a more general stride specification than uBlas matrix and vector types may be able to. In particular, the MultiArray 2D storage ordering semantics are not encoded in types the way that uBlas has them. Not insurmountable, just something to be aware of. - Rhys _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Bilokon, Paul
-
Jesse Perla
-
Rhys Ulerich