I construct boost::numeric::ublas::compressed_matrix<std::complex<double>,boost::numeric::ublas::row_major,0,boost::numeric::ublas::unbounded_array<std::size_t>>
and then extract the diagonal part via boost::numeric::ublas::matrix_vector_range
. The source is:
#include<boost/numeric/ublas/matrix_sparse.hpp>
#include<boost/numeric/ublas/matrix_proxy.hpp>
#include<boost/numeric/ublas/io.hpp>
int main()
{
namespace ublas=boost::numeric::ublas;
ublas::compressed_matrix<std::complex<double>,ublas::row_major,0,ublas::unbounded_array<std::size_t>>matrix(3,3);
matrix.push_back(0,0,{1,1});
matrix.push_back(0,1,{2,1});
matrix.push_back(1,1,{3,1});
matrix.push_back(2,2,{4,1});
std::cout<<ublas::matrix_vector_range<decltype(matrix)>(matrix,ublas::basic_range<std::size_t>(0,matrix.size1()),ublas::basic_range<std::size_t>(0,matrix.size2()))<<std::endl;
}
and it works fine.
And then, because I need to pass the compressed_matrix
to some FORTRAN function as well as the FORTRAN function requires the row and column indexes must be int
, I change std::size_t
to int
. The new source code is:
#include<boost/numeric/ublas/matrix_sparse.hpp>
#include<boost/numeric/ublas/matrix_proxy.hpp>
#include<boost/numeric/ublas/io.hpp>
int main()
{
namespace ublas=boost::numeric::ublas;
ublas::compressed_matrix<std::complex<double>,ublas::row_major,0,ublas::unbounded_array<int>>matrix(3,3);
matrix.push_back(0,0,{1,1});
matrix.push_back(0,1,{2,1});
matrix.push_back(1,1,{3,1});
matrix.push_back(2,2,{4,1});
std::cout<<ublas::matrix_vector_range<decltype(matrix)>(matrix,ublas::basic_range<int>(0,matrix.size1()),ublas::basic_range<int>(0,matrix.size2()))<<std::endl;
}
After that I use g++ -std=c++11 -O2 -march=native -DNEBUG
to compile the source code and run the executable file (gcc version 4.9.1). The following error appears:
Check failed in file /usr/include/boost/numeric/ublas/storage.hpp at line 892:
start_ <= stop
terminate called after throwing an instance of 'boost::numeric::ublas::bad_index'
what(): bad index
Aborted
Then I go to /usr/include/boost/numeric/ublas/storage.hpp at line 892 and see:
BOOST_UBLAS_INLINE
basic_range ():
start_ (0), size_ (0) {}
BOOST_UBLAS_INLINE
basic_range (size_type start, size_type stop):
start_ (start), size_ (stop - start) {
BOOST_UBLAS_CHECK (start_ <= stop, bad_index ());
}
But in my case start_
is less than stop
. So I have no idea why such error will appear. Any ideas what's causing it?