Boost uBlas の疎行列で値がセットされているか判定

Boost uBlas で、mapped_matrix に値が入っているかどうかは find_element メソッドでわかる。

    typedef boost::numeric::ublas::mapped_matrix<int> Matrix;

    const int N=3;
    Matrix m(N,N);
    m(0,2) = 0;
    m(1,0) = 2;
    m(2,1) = 1;
    std::cout << m << std::endl;

    for(int i=0;i<N;++i) for(int j=0;j<N;++j) {
        std::cout << i << " " << j << " " << (m.find_element(i, j)?1:0) << std::endl;
    }
[3,3]((0,0,0),(2,0,0),(0,1,0))
0 0 0
0 1 0
0 2 1 <- 0 がセットされている項もちゃんとわかる
1 0 1
1 1 0
1 2 0
2 0 0
2 1 1
2 2 0

ただし undocumented なので、この仕様が保たれるかは不明。


#もう uBlas のソースは読みたくない……Expression Template なんか大っきらいだー。