
I saw that boost already has a pretty impressive linear algebra suite, with many specialized types of matrices. Though these are all very useful, I was wondering if there might be room for one more type of matrix: one which makes each size of matrix a unique type (I did not see such a matrix in the docs, but please correct me if I overlooked it and it does already exist). Using such matrices, it would be possible to validate the legality of certain operations at compile time (for instance, only matrices of compatible sizes can be multiplied). A very stripped down version of the class might look like this: template < typename T, unsigned int X, unsigned int Y > class matrix { // maintains Y rows, each containing X Ts internally }; template < typename T, unsigned int X, unsigned int Y, unsigned int Z > matrix < T, Z, Y > operator * ( const Matrix < T, X, Y > & lhs, const Matrix < T, Z, X > & rhs ); // multiplication defined only for compatible matrices Is there any interest in such a class? -Jason

"Jason Hise" <chaos@ezequal.com> wrote in message news:422FC5B2.6070908@ezequal.com...
Is there any interest in such a class? I was planning such a class to be a sample usage of my Lazy library (see post "N-arity operators in C++...) in examples of usage.
-- Pavel Chikulaev

Jason Hise wrote:
I saw that boost already has a pretty impressive linear algebra suite, with many specialized types of matrices. Though these are all very useful, I was wondering if there might be room for one more type of matrix: one which makes each size of matrix a unique type (I did not see such a matrix in the docs, but please correct me if I overlooked it and it does already exist). Using such matrices, it would be possible to validate the legality of certain operations at compile time (for instance, only matrices of compatible sizes can be multiplied). A very stripped down version of the class might look like this:
template < typename T, unsigned int X, unsigned int Y > class matrix { // maintains Y rows, each containing X Ts internally };
template < typename T, unsigned int X, unsigned int Y, unsigned int Z > matrix < T, Z, Y > operator * ( const Matrix < T, X, Y > & lhs, const Matrix < T, Z, X > & rhs ); // multiplication defined only for compatible matrices
Is there any interest in such a class?
For what it's worth; If it turns out there is an interest in such a class, I have already written one (with that exact declaration in fact) I'd be more that willing to donate to boost. It can currently do addition, subtraction and multiplication of matrices, as well as provide functions for a lot of vector and matrix operations like generation of rotation matrices, taking the length of a vector and so on and so forth. Just wanted to let you know... - Erik

On 03/10/2005 01:31 AM, Erik Wien wrote: [snip]
For what it's worth; If it turns out there is an interest in such a class, I have already written one (with that exact declaration in fact) I'd be more that willing to donate to boost. It can currently do addition, subtraction and multiplication of matrices, as well as provide functions for a lot of vector and matrix operations like generation of rotation matrices, taking the length of a vector and so on and so forth.
Isn't a matrix a "rank 2". I'm using the term "rank" because that's an apl term, and I'm a fan ;) : http://www.aplusdev.org/APlusRefV2_4.html#17 Anyway, why not a template: template < typename T, typename Shape > class array { ... }; where Shape is a vector_c<unsigned, S1,S2,...,Sn> to create a rank n array with S1 is length (or dimension) of 1st axis, S2 the length of 2nd axis, ... ? The strides of such a "compile-time specified shape" array could also be calculated at compile time as shown in the test_partial_product function of fold_seq_test.cpp in fold_seq_test.zip in http://boost-sandbox.sourceforge.net/vault/.

On 03/10/2005 06:58 AM, Larry Evans wrote:
On 03/10/2005 01:31 AM, Erik Wien wrote: [snip] Anyway, why not a template:
template < typename T, typename Shape > class array { ... };
where Shape is a vector_c<unsigned, S1,S2,...,Sn>
I should have mentioned that vector_c<...> is an mpl template and I probably should have appended a ::type.
to create a rank n array with S1 is length (or dimension) of 1st axis, S2 the length of 2nd axis, ... ? The strides of such a "compile-time specified shape" array could also be calculated at compile time as shown in the test_partial_product function of fold_seq_test.cpp in fold_seq_test.zip in http://boost-sandbox.sourceforge.net/vault/.
I just uploaded another version which calculates the offset for a given fixed vector of indices and fixed shape for a hypothetical array. The test is in function test_array_index_offset in the aforementioned .zip file.

Jason Hise <chaos@ezequal.com> writes:
I saw that boost already has a pretty impressive linear algebra suite, with many specialized types of matrices. Though these are all very useful, I was wondering if there might be room for one more type of matrix: one which makes each size of matrix a unique type (I did not see such a matrix in the docs, but please correct me if I overlooked it and it does already exist). Using such matrices, it would be possible to validate the legality of certain operations at compile time (for instance, only matrices of compatible sizes can be multiplied). A very stripped down version of the class might look like this:
template < typename T, unsigned int X, unsigned int Y > class matrix { // maintains Y rows, each containing X Ts internally };
template < typename T, unsigned int X, unsigned int Y, unsigned int Z > matrix < T, Z, Y > operator * ( const Matrix < T, X, Y > & lhs, const Matrix < T, Z, X > & rhs ); // multiplication defined only for compatible matrices
Is there any interest in such a class?
The MTL project will certainly include a fixed-size matrix. http://www.boost-consulting.com/projects/mtl -- Dave Abrahams Boost Consulting www.boost-consulting.com

Jason Hise <chaos@ezequal.com> writes:
I saw that boost already has a pretty impressive linear algebra suite, with many specialized types of matrices. Though these are all very useful, I was wondering if there might be room for one more type of matrix: one which makes each size of matrix a unique type (I did not see such a matrix in the docs, but please correct me if I overlooked it and it does already exist). Using such matrices, it would be possible to validate the legality of certain operations at compile time (for instance, only matrices of compatible sizes can be multiplied). A very stripped down version of the class might look like this:
template < typename T, unsigned int X, unsigned int Y > class matrix { // maintains Y rows, each containing X Ts internally };
template < typename T, unsigned int X, unsigned int Y, unsigned int Z > matrix < T, Z, Y > operator * ( const Matrix < T, X, Y > & lhs, const Matrix < T, Z, X > & rhs ); // multiplication defined only for compatible matrices
Is there any interest in such a class?
You can take a look at ``Tiny Vector Matrix library using Expression Templates'': http://tvmet.sourceforge.net/ fres

Jason Hise <chaos@ezequal.com> writes:
I saw that boost already has a pretty impressive linear algebra suite, with many specialized types of matrices. Though these are all very useful, I was wondering if there might be room for one more type of matrix: one which makes each size of matrix a unique type (I did not see such a matrix in the docs, but please correct me if I overlooked it and it does already exist).
There are two fixed size matrix types, but unfortunately they are not documented: template<class T, std::size_t M, std::size_t N, class L = row_major> class bounded_matrix; template<class T, std::size_t M, std::size_t N> class c_matrix; Both are defined in matrix.hpp. bounded_matrix uses bounded_array for storage: template<class T, std::size_t M, std::size_t N, class L> class bounded_matrix: public matrix<T, L, bounded_array<T, M * N> > { /* ... */ }; Therefore it can have row major and column major storage. c_matrix wraps C array: template<class T, std::size_t N, std::size_t M> class c_matrix { // ... T data_ [N] [M]; }; Obviously, it must be row major. fres

On Thu, Mar 10, 2005 at 09:12:37AM -0500, David Abrahams <dave@boost-consulting.com> wrote:
The MTL project will certainly include a fixed-size matrix. http://www.boost-consulting.com/projects/mtl
I am interested in contributing to the expression template system, while working on my master thesis work. The topic is related to fast but accurate dot/scalar products in linear algebra expressions. I already posted some first ideas to the glas list, but I am not sure if the list is still working. So is it possible to contribute to that project? Regards Andreas Pokorny

Andreas Pokorny wrote:
On Thu, Mar 10, 2005 at 09:12:37AM -0500, David Abrahams <dave@boost-consulting.com> wrote:
The MTL project will certainly include a fixed-size matrix. http://www.boost-consulting.com/projects/mtl
I am interested in contributing to the expression template system, while working on my master thesis work. The topic is related to fast but accurate dot/scalar products in linear algebra expressions. I already posted some first ideas to the glas list, but I am not sure if the list is still working.
Oh yeah, it certainly is still active and soon will become much more active. The last few weeks were slow I admit but the intention was also to collect a bit of feedback on the 'goals' of the glas project. I will make an overview of this discussion RSN so that it is stated clearly what we actually want to accomplish with GLAS. OTOH we also need to bootstrap the design-implementation process. As suggested by Andrew and Harold, the best way to do this is to start with defining the basic concepts. Dave suggested to start from the concepts that are already defined in MTL3 and provided the MTL3-design-document of Jeremy. But I understood that there has been many changes already in respect to Jeremy's paper so would like to ask Dave if he has a documented update available? toon

Andreas Pokorny <andreas.pokorny@gmx.de> writes:
On Thu, Mar 10, 2005 at 09:12:37AM -0500, David Abrahams <dave@boost-consulting.com> wrote:
The MTL project will certainly include a fixed-size matrix. http://www.boost-consulting.com/projects/mtl
I am interested in contributing to the expression template system, while working on my master thesis work. The topic is related to fast but accurate dot/scalar products in linear algebra expressions. I already posted some first ideas to the glas list, but I am not sure if the list is still working.
So is it possible to contribute to that project?
GLAS or MTL? If you want to contribute to MTL, be in touch with me and Andrew Lumsdaine, who's Cc:'d here. We'll discuss it. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (8)
-
Andreas Pokorny
-
David Abrahams
-
Erik Wien
-
Jason Hise
-
Kresimir Fresl
-
Larry Evans
-
Pavel Chikulaev
-
Toon Knapen