Interested in a generic safe n-dimensional matrix/vector library?

c++0x features allow us to implement some nice stuff: - Safe variadic functions with parameter count checking. For example consider a constructor of the N dimensional vector of T takes only N farameters that are convertable to T and fails othervise: vector<T, N> v(/*...N parameters convertable to T...*/); vector<float, 3> v(1,2,3); // good vector<float, 4> v(1.f,2.f); //fails vector<int, 3> v(1,2,3,4); //fails vector<int, 4> v(1,2,3,4); //good or an N dimensional cross product function that takes exactly N-1 vectors of dimension N: cross(v1,v2,v3,/*...*/, vn-1); Please note that N is arbitrary positive integer and is only restricted by compiler's template recursion depth. - Same type comversion as for fundamental types. This means that char multiplied by int gives int result and int multiplied by float gives float result. vectors work exactly the same: vector<float, 3> vf; vector<int, 3> vl; vector<short, 3> vs; vector<double, 3> vd; vi*vf; //returns vector<float, 3> vf*vd; //returns vector<double, 3> vs*vi; //returns vector<int, 3> Among other notable features are matrix matrix and vector matrix multiplications, component vise addition/substraction/multiplication/division, dot product, matrix inversion, matrix determinant calculation, etc. I want to know if there is any interest in such a library in boost community, and if so to make it available for public inspecion and criticism.

Cool! :-) Have you looked at Blitz++? You might find it easier to start with the code that they have there and modify it to take advantage of c++0x features than to start from scratch. Cheers, Greg On 2/21/11 12:19 PM, Тимофей Игнатьич wrote:
c++0x features allow us to implement some nice stuff:
- Safe variadic functions with parameter count checking. For example consider a constructor of the N dimensional vector of T takes only N farameters that are convertable to T and fails othervise:
vector<T, N> v(/*...N parameters convertable to T...*/); vector<float, 3> v(1,2,3); // good vector<float, 4> v(1.f,2.f); //fails vector<int, 3> v(1,2,3,4); //fails vector<int, 4> v(1,2,3,4); //good
or an N dimensional cross product function that takes exactly N-1 vectors of dimension N:
cross(v1,v2,v3,/*...*/, vn-1);
Please note that N is arbitrary positive integer and is only restricted by compiler's template recursion depth.
- Same type comversion as for fundamental types. This means that char multiplied by int gives int result and int multiplied by float gives float result. vectors work exactly the same:
vector<float, 3> vf; vector<int, 3> vl; vector<short, 3> vs; vector<double, 3> vd;
vi*vf; //returns vector<float, 3> vf*vd; //returns vector<double, 3> vs*vi; //returns vector<int, 3>
Among other notable features are matrix matrix and vector matrix multiplications, component vise addition/substraction/multiplication/division, dot product, matrix inversion, matrix determinant calculation, etc. I want to know if there is any interest in such a library in boost community, and if so to make it available for public inspecion and criticism.
_______________________________________________ Unsubscribe& other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Hi. I am working on a tensor library (in the spirit of FTensor). Perhaps you are interested as well? http://code.google.com/p/asadchev/source/browse/#svn%2Ftrunk%2Fprojects%2Fbo... example: tensor::tensor<3> A(10,10,10); size_t size[] = { 10, 10, 10, 10 }; tensor::tensor<4> B(size), C(size); tensor::index<'a'> a; tensor::index<'b'> b; tensor::index<'c'> c; tensor::index<'d'> d; tensor::index<'e'> e; // using dgemm underneath contract(1, B(b,0,a,0), C(a,c,d,0), 0, A(b,c,d)); A(b,c,d) = contract(B(b,0,a,0), C(a,c,d,0)); A(b,c,d) = 5.0*contract(B(b,0,a,0), C(a,c,d,0)); A(b,c,d) -= 5*contract(B(b,0,a,0), C(a,c,d,0)); A(b,c,d) += 4*contract(B(b,0,a,0), C(a,c,d,0)); int i = 9; // arbitrary tensor ops using templates A(c,d,i) = C(b,c,a,i)*A(a,b,i); A(i,i,i) = C(b,c,a,i)*(A(a,b,c) + B(a,b,i,c));

On Tue, Feb 22, 2011 at 4:11 AM, Andrey Asadchev <asadchev@gmail.com> wrote:
Hi.
I am working on a tensor library (in the spirit of FTensor). Perhaps you are interested as well? http://code.google.com/p/asadchev/source/browse/#svn%2Ftrunk%2Fprojects%2Fbo...
example:
tensor::tensor<3> A(10,10,10); size_t size[] = { 10, 10, 10, 10 }; tensor::tensor<4> B(size), C(size);
tensor::index<'a'> a; tensor::index<'b'> b; tensor::index<'c'> c; tensor::index<'d'> d; tensor::index<'e'> e;
// using dgemm underneath contract(1, B(b,0,a,0), C(a,c,d,0), 0, A(b,c,d)); A(b,c,d) = contract(B(b,0,a,0), C(a,c,d,0)); A(b,c,d) = 5.0*contract(B(b,0,a,0), C(a,c,d,0)); A(b,c,d) -= 5*contract(B(b,0,a,0), C(a,c,d,0)); A(b,c,d) += 4*contract(B(b,0,a,0), C(a,c,d,0));
int i = 9;
// arbitrary tensor ops using templates A(c,d,i) = C(b,c,a,i)*A(a,b,i); A(i,i,i) = C(b,c,a,i)*(A(a,b,c) + B(a,b,i,c));
Hi, while not extending the Boost.uBLAS library? http://www.boost.org/doc/libs/1_45_0/libs/numeric/ublas/doc/index.htm It works very well with matrix and vector. It uses expression templates. It handles special matrices (like sparse matricies). It easly integrates with LAPACK/UBLAS thanks to Boost.Numeric-Bindings. Best, -- Marco

Hi, while not extending the Boost.uBLAS library? http://www.boost.org/doc/libs/1_45_0/libs/numeric/ublas/doc/index.htm
It works very well with matrix and vector. It uses expression templates. It handles special matrices (like sparse matricies). It easly integrates with LAPACK/UBLAS thanks to Boost.Numeric-Bindings.
Best,
Hi Marco. I considered doing it as such - but it was too difficult imo. I do use ublas/blas indirectly - where tensor can be treated as a matrix. but I didnt find it easy to reuse either containers or algorithms as they are stricly 2D. For my purposes multi array is much more useful (thats what I use as backend).

On 02/22/11 02:35, Andrey Asadchev wrote: [snip]
For my purposes multi array is much more useful (thats what I use as backend). By "multi array" do you mean:
http://www.boost.org/doc/libs/1_46_0/libs/multi_array/doc/user.html ?

On 21-2-2011 21:19, Тимофей Игнатьич wrote:
(...)
Among other notable features are matrix matrix and vector matrix multiplications, component vise addition/substraction/multiplication/division, dot product, matrix inversion, matrix determinant calculation, etc. I want to know if there is any interest in such a library in boost community, and if so to make it available for public inspecion and criticism.
Note there is already a matrix/vector/quaternion library in the Review Queue: http://www.boost.org/community/review_schedule.html http://www.revergestudios.com/boost-qvm/ Regards, Barend

Tue, 22 Feb 2011 11:13:52 +0100 Barend Gehrels:
Note there is already a matrix/vector/quaternion library in the Review Queue: http://www.boost.org/community/review_schedule.html http://www.revergestudios.com/boost-qvm/
Regards, Barend
thanks for the info, i wasn't aware of that. This lib however is limited to 4 dimensions and doesn't use c++0x feautures thus making code quite verbose.

On 21/02/2011 21:19, Тимофей Игнатьич wrote:
c++0x features allow us to implement some nice stuff:
- Safe variadic functions with parameter count checking. For example consider a constructor of the N dimensional vector of T takes only N farameters that are convertable to T and fails othervise:
[...]
- Same type comversion as for fundamental types. This means that char multiplied by int gives int result and int multiplied by float gives float result. vectors work exactly the same:
[...]
I don't see how C++0x adds anything new here.
Among other notable features are matrix matrix and vector matrix multiplications, component vise addition/substraction/multiplication/division, dot product, matrix inversion, matrix determinant calculation, etc. I want to know if there is any interest in such a library in boost community, and if so to make it available for public inspecion and criticism.
There could be interest, but be aware there is already quite a lot of competition in the domain of array programming, linear algebra or numerical computation in general.

On 21/02/2011 20:19, Тимофей Игнатьич wrote:
Safe variadic functions with parameter count checking. For example consider a constructor of the N dimensional vector of T takes only N farameters that are convertable to T and fails othervise: Are you sure this is right? It seems that the N parameters are dimensions and should be convertable to an integer like size_t. T is the value_type and could be anything?

Tue, 22 Feb 2011 10:32:45 +0000 Alex Hagen-Zanker On 21/02/2011 20:19, Тимофей Игнатьич wrote:
Safe variadic functions with parameter count checking. For example consider a constructor of the N dimensional vector of T takes only N farameters that are convertable to T and fails othervise: Are you sure this is right? It seems that the N parameters are dimensions and should be convertable to an integer like size_t. T is the value_type and could be anything?
Sorry, i guess i want. clear enough. vector template is defined like this: template <class T, size_t N> class vector; Where T is arbitrary type (supposedly arithmetic, or it woult be meaningless otherwise) and N is an amount of components in a vector (aka vector dimension or size) and not an amount of dimensions in an array (vector is a one dimensional array of elements). So vector is statically sized, and parameters passed to constructor are values to be stored in it and not sizes of corresponding array dimensions.

On 02/22/11 05:02, Тимофей Игнатьич wrote: [snip]
Sorry, i guess i want. clear enough. vector template is defined like this:
template <class T, size_t N> class vector;
Where T is arbitrary type (supposedly arithmetic, or it woult be meaningless otherwise) and N is an amount of components in a vector (aka vector dimension or size) and not an amount of dimensions in an array (vector is a one dimensional array of elements). So vector is statically sized, and parameters passed to constructor are values to be stored in it and not sizes of corresponding array dimensions.
This sounds like boost::array: http://www.boost.org/doc/libs/1_46_0/doc/html/array/reference.html

Tue, 22 Feb 2011 05:11:00 -0600 Larry Evans
Sorry, i guess i want. clear enough. vector template is defined like this:
template <class T, size_t N> class vector;
Where T is arbitrary type (supposedly arithmetic, or it woult be meaningless otherwise) and N is an amount of components in a vector (aka vector dimension or size) and not an amount of dimensions in an array (vector is a one dimensional array of elements). So vector is statically sized, and parameters passed to constructor are values to be stored in it and not sizes of corresponding array dimensions.
This sounds like boost::array:
except boost::array is a generic container, whereas i suggest an algebraic vector and matrix with related operations (blame those who named standart array class std::vector D:)
participants (8)
-
Alex Hagen-Zanker
-
Andrey Asadchev
-
Barend Gehrels
-
Gregory Crosswhite
-
Larry Evans
-
Mathias Gaunard
-
sguazt
-
Тимофей Игнатьич