如何正确使用boost :: numeric :: ublas :: matrix_vector_range与boost :: numeric :: ublas :: basic_range <int> </int>

时间:2014-08-21 20:20:10

标签: c++ c++11 boost ublas

我构造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更改为{ {1}}。新的源代码是:

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; } 编译源代码并运行可执行文件(gcc版本4.9.1)。出现以下错误:

g++ -std=c++11 -O2 -march=native -DNEBUG

然后我在第892行转到 /usr/include/boost/numeric/ublas/storage.hpp 并查看:

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

但在我看来,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_。所以我不知道为什么会出现这样的错误。有什么想法会导致它吗?

0 个答案:

没有答案