views:

95

answers:

4

I have a lot of elements in a matrix and when I access them manually it takes a pretty long time to eliminate all the bugs arising from wrong indexing... Is there a suitable library that can keep track of e.g the neighbors,the numbering, if an element is in the outer edge or not and so on.

e.g.

VA=
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44

Now what I would like to do is write a function that says something like

for every Neighbor to element at index 12(which would be 41)
 do something

I would like this to only recognize the elements at index 8 (31) and 13 (42).

Right now I'm using vectors (vector<vector<int>>V;)but the code gets pretty difficult and clumsy both to write and read since I have these annoying if statements in every single function. example:

     for (int i=0;i<MatrixSIZE;i++)
        if ((i+1)%rowSize!=0){//check that it's not in the outer edge.
    //Do something
}

What approach would you suggest? Can boost::MultiArray help me here in some way? Are there any other similar?

UPDATE:: So i'm looking more for a template that can easily access the elements than a template that can do matrix arithmetichs.

A: 

There is this: http://osl.iu.edu/research/mtl/

or this: http://www.robertnz.net/nm_intro.htm

If you Google it a bit, there's quite a few matrix libraries out there for C++.

Tony
A: 

This might inspire you:

http://stackoverflow.com/questions/1280474/matrix-classes-in-c

Nubsis
A: 

Is it used in a larger program ? If not, it would be more adapted to use R to deal with matrices.

If it's in a larger program, you can use a lib such as MTL.

Guillaume Lebourgeois
+1  A: 

Try LAPACK, a linear algebra package.

George