The aim of this project is to create a simple and easy to use wrapper class for the GNU Scientific Library (GSL). GSL, like many other GNU projects, is written in C. Once you have written and used your own matrix and vector classes in C++, it is difficult to switch back to C. This is because C++ (unlike Java) allows you to override the arithmetic operators such as addition, subtraction, multiplication and so on. This in turn allows the manipulation of matrix and vectors much as you would perform manipulation of basic data types such as floats. A C++ program that includes a matrix and vector library therefore creates an environment rather like Matlab, except you have to compile your C++ source files. Since GSL is built on BLAS this can result in code that is fast, easily readable, and very powerful.
This project was started by Ramin Nakisa, but then completely rewritten, and greatly improved, by Marcel Bosc and Torbjorn Vik at ULP Strasbourg.
To use the library to create two matrices, and to multiply those matrices together and take a look at the output do the following:
#include <iostream.h> #include<gslwrap/matrix_float.h> main() { gsl::matrix a( 3, 3 ); gsl::matrix b( 3, 3 ); srand48(10); int i, j; for( i = 0; i < a.size1(); i++ ) for(j = 0; j < a.size2(); j++ ) a( i, j ) = drand48(); for( i = 0; i < b.size1(); i++ ) for( j = 0; j < b.size2(); j++ ) b( i, j ) = drand48(); cout << "a + b:" << endl << a + b << endl; cout << "a - b:" << endl << a - b << endl; cout << "a + 1.0:" << endl << a + 1.0 << endl; cout << "1.0 - a:" << endl << 1.0 - a << endl; cout << "a * 10.0:" << endl << a * 10.0 << endl; cout << "10.0 * a:" << endl << 10.0 * a << endl; cout << "a / 10.0:" << endl << a / 10.0 << endl; cout << "a * b:" << endl << a * b << endl; cout << "a.LU_decomp():" << endl << a.LU_decomp() << endl; cout << "a.LU_invert():" << endl << a.LU_invert() << endl; cout << "a.LU_invert() * a:" << endl << a.LU_invert() * a << endl; }