我已经实现了一个矩阵乘法boost::numeric::ublas::matrix(参见我的完整工作增强代码)
Result result = read ();
boost::numeric::ublas::matrix<int> C;
C = boost::numeric::ublas::prod(result.A, result.B);
Run Code Online (Sandbox Code Playgroud)
另一个使用标准算法(参见完整的标准代码):
vector< vector<int> > ijkalgorithm(vector< vector<int> > A,
vector< vector<int> > B) {
int n = A.size();
// initialise C with 0s
vector<int> tmp(n, 0);
vector< vector<int> > C(n, tmp);
for (int i = 0; i < n; i++) {
for (int k = 0; k < n; k++) {
for (int j = 0; j < n; j++) {
C[i][j] += …Run Code Online (Sandbox Code Playgroud) 我有一个使用Boost实现uBLAS matricies的成功编译程序.唉,使用gdb进行调试证明是有问题的,因为在调试时我无法看到我的矩阵的内容.当我试图看到矩阵V的元素(确实存在并且充满了数据)时,我得到:
(gdb) print V(1,1)
Invalid data type for function to be called.
Run Code Online (Sandbox Code Playgroud)
有没有解决的办法?
谢谢!
我正在使用ublas作为我的矩阵代码,但我希望它可以交换,所以我这样做:
typedef boost::numeric::ublas::matrix<double> cMatrix;
Run Code Online (Sandbox Code Playgroud)
今天,我需要将一些矩阵更改为有界大小,所以我也会这样:
typedef boost::numeric::ublas::bounded_matrix<double, 3, 3> Matrix3d;
Run Code Online (Sandbox Code Playgroud)
问题是我的旧函数声明:
void cClass::function(int param1,
int param2,
cMatrix ¶m3,
int param4);
Run Code Online (Sandbox Code Playgroud)
不再有效.它给了我:
error : a reference of type "cMatrix &" (not const-qualified) cannot be initialized with a value of type "Matrix3d"
Run Code Online (Sandbox Code Playgroud)
我设法通过将声明更改为:
template <class A>
void cClass::function(int param1,
int param2,
boost::numeric::ublas::matrix<double, boost::numeric::ublas::row_major, A> ¶m3,
int param4);
Run Code Online (Sandbox Code Playgroud)
问题是我的定义是一个cpp文件,所以我必须在cpp中做这样的事情:
void dummyFunc()
{
cClass dummy(NULL, NULL);
cMatrix c;
Matrix12d d12;
dummy.function(-1, -1, c, -1);
dummy.function(-1, -1, d12, -1);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法避免使用dummyFunc或以其他方式概括函数?
为什么这样做?它不在任何地方的文档中......
#include <iostream>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
int main()
{
boost::numeric::ublas::matrix<double> twoByTwoMat(2,2,-2);
std::cout << "This is the matrix: " << twoByTwoMat << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
This is the matrix: [2,2]((-2,-2),(-2,-2))
Run Code Online (Sandbox Code Playgroud) 我想定义一个带有 boost 的常量 3x3 矩阵,它在执行过程中永远不会改变:
[1 2 3
4 5 6
7 8 9]
Run Code Online (Sandbox Code Playgroud)
该矩阵将是一个类的成员。那么,我可以像原始类型一样将常量矩阵变量定义并初始化为类成员吗?当我尝试为 someMatrix 变量输入 const 时,我无法在构造函数中分配矩阵数据并收到此错误:
error: assignment of read-only location '((Test*)this)->Test::someMatrix.boost::numeric::ublas::matrix<double>::operator()(0, 0)'
Run Code Online (Sandbox Code Playgroud)
以下是代码:
测试.h
#ifndef TEST_H_
#define TEST_H_
#include <boost/numeric/ublas/matrix.hpp>
namespace bnu = boost::numeric::ublas;
class Test {
private:
const double a = 1;
const double b = 2;
const double c = 3;
const double d = 4;
const double e = 5;
const double f = 6;
const double g = 7;
const double h …Run Code Online (Sandbox Code Playgroud) boost-ublas ×5
c++ ×5
boost ×3
constants ×1
gdb ×1
matrix ×1
performance ×1
templates ×1
typedef ×1
ublas ×1