如何将 boost::numeric::ublas::vector 复制到矩阵?
我在这里做错了什么?
// file main.cpp
#include <iostream>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
namespace ublas = boost::numeric::ublas;
int main()
{
ublas::vector<double> const v( 10 );
ublas::matrix<double> m( 1, v.size() );
ublas::matrix_row<ublas::matrix<double> > r( m, 1 );
r = v;
return 0;
}
这失败并显示消息:
Check failed in file /usr/local/include/boost/numeric/ublas/functional.hpp at line 1370:
i < size_i
terminate called after throwing an instance of 'boost::numeric::ublas::bad_index'
what(): bad index
Aborted
但是,是否有更简洁的方法将 v
转换为 main.cpp
处的 m
?
What am I doing wrong here?
// file main.cpp
#include <iostream>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
namespace ublas = boost::numeric::ublas;
int main()
{
ublas::vector<double> const v( 10 );
ublas::matrix<double> m( 1, v.size() );
ublas::matrix_row<ublas::matrix<double> > r( m, 1 );
r = v;
return 0;
}
This fails with message:
Check failed in file /usr/local/include/boost/numeric/ublas/functional.hpp at line 1370:
i < size_i
terminate called after throwing an instance of 'boost::numeric::ublas::bad_index'
what(): bad index
Aborted
However, is there more laconic way to v
into m
at main.cpp
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不起作用吗?
这将占用
m
的第一个v.size()
元素,其值为 v。以下代码在我的系统上编译并运行(boost 1.48 和 g++ 4.62)
Did this not work?
this will occupy the first
v.size()
elements ofm
with the value of v.The following code compiles and runs on my system (boost 1.48 and g++ 4.62)
当然,您正在尝试访问 1 xv,size() 矩阵中不存在的第一行。你应该写:
虽然你会更好
Of course, you're trying to access 1st row which just isn't there for 1 x v,size() matrix. You should write:
though you'd be better with