boost ublas 矩阵乘积的问题
我正在尝试使用 Boost 的 ublas 部分,但由于某种原因,我无法将矩阵相乘并将结果分配给其他矩阵。
这有效:
#include <boost/numeric/ublas/symmetric.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace boost::numeric::ublas;
typedef symmetric_matrix<int,lower> symatrix;
int main() {
int N = 10;
symatrix foo(N,N);
for (int i = 0; i < N; i++)
for(int j = 0; j <= i; j++) {
foo(i,j) = i - j + 1;
}
symatrix goo(foo);
//goo = prod(foo,foo);
std::cout << prod(foo,foo)<< std::endl;
}
但是如果我取消注释行 goo = prod(foo,foo);
或尝试类似的操作:
symatrix goo = prod(foo,foo);
我收到运行时错误,我无法破译。
Check failed in file /usr/include/boost/numeric/ublas/detail/matrix_assign.hpp at line 761:
detail::expression_type_check (m, cm)
terminate called after throwing an instance of 'boost::numeric::ublas::external_logic'
what(): external logic
Aborted
如何将矩阵相乘并分配结果?
I'm trying to use the ublas part of Boost but I'm not able to multiply matrices and assign the result to other matrices for some reason.
This works:
#include <boost/numeric/ublas/symmetric.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace boost::numeric::ublas;
typedef symmetric_matrix<int,lower> symatrix;
int main() {
int N = 10;
symatrix foo(N,N);
for (int i = 0; i < N; i++)
for(int j = 0; j <= i; j++) {
foo(i,j) = i - j + 1;
}
symatrix goo(foo);
//goo = prod(foo,foo);
std::cout << prod(foo,foo)<< std::endl;
}
But if I uncomment the line goo = prod(foo,foo);
or try something like:
symatrix goo = prod(foo,foo);
I get a runtime error I can't decipher.
Check failed in file /usr/include/boost/numeric/ublas/detail/matrix_assign.hpp at line 761:
detail::expression_type_check (m, cm)
terminate called after throwing an instance of 'boost::numeric::ublas::external_logic'
what(): external logic
Aborted
How do I multiply matrices and assign the result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您将两个对称矩阵相乘时,不保证总是得到一个对称矩阵。所以这个错误可能与此相关,尽管我不知道为什么当我将类型更改为 symmetry_matrix 类型为 double 时代码会起作用。
You are not guaranteed to always get a symmetric matrix back when you multiply two symmetric matrices. So this error might be related to that, although I have no idea why the code works when I change your type to a symmetric_matrix type to a double.