简体   繁体   中英

library for matrices in c++

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 eg the neighbors,the numbering, if an element is in the outer edge or not and so on.

eg

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.

尝试使用LAPACK ,一个线性代数包。

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++.

This might inspire you:

Matrix classes in c++

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM