我构造boost::numeric::ublas::compressed_matrix<std::complex<double>,boost::numeric::ublas::row_major,0,boost::numeric::ublas::unbounded_array<std::size_t>>
然后通过 提取对角线部分boost::numeric::ublas::matrix_vector_range
。来源是:
#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;
}
它工作正常。
然后,因为我需要将 传递compressed_matrix
给一些 FORTRAN 函数以及 FORTRAN 函数要求行和列索引必须是int
,所以我更改std::size_t
为int
. 新的源代码是:
#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;
}
之后,我使用g++ -std=c++11 -O2 -march=native -DNEBUG
编译源代码并运行可执行文件(gcc 版本 4.9.1)。出现以下错误:
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
然后我转到第 892 行的/usr/include/boost/numeric/ublas/storage.hpp并查看:
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 ());
}
但在我的情况下start_
小于stop
. 所以我不知道为什么会出现这样的错误。任何想法是什么原因造成的?