boost-ublas

why has uBLAS no `operator*(matrix, vector)`?

一世执手 提交于 2020-04-10 22:39:11
问题 In the doc, they say We decided to use no operator overloading for ... They provide prod instead for these. But why? Is there any good reason? I like to do matrix * vector (as in most other languages). I like to understand why they did not overloaded this operator to understand why it might be a bad idea to just do it myself. Or aren't they any drawbacks if I overload it myself? 回答1: Probably, because op* in other languages, e.g. with Numpy in Python, will always be element-wise. In case that

How to create a nonempty boost ublas::vector inside an initializer list?

馋奶兔 提交于 2019-12-13 04:44:59
问题 I'm trying to do something like this #include <boost/numeric/ublas/vector.hpp> using namespace boost::numeric::ublas; class A{ protected: vector< double > a_; public: A( vector< double > a ) : a_( a ) {}; }; class B : public A{ public: B() : A( vector< double >( { 1.25, 2.75, 3.34 } ) ){}; }; The result should be, that the vector a_ gets declared as a three-vector containing a_[0]=1.25, a_[1]=2.75, a_[2]=3.34 . This code is not working because boost::numeric::ublas::vector does not have a

Writing a Boost ublas matrix to a text file

陌路散爱 提交于 2019-12-11 02:40:09
问题 I have a Boost ublas matrix, and I want to print its contents to a text file. I have the following implementation, and it works. #include <iostream> using namespace std; #include "boost\numeric\ublas\matrix.hpp" typedef boost::numeric::ublas::matrix<float> matrix; #include <algorithm> #include <iterator> #include <fstream> int main() { fill(m1.begin2(), m1.begin2() + 400 * 500, 3.3); ofstream dat("file.txt"); for (auto i = 0; i < 400 ; i++) { for (auto j = 0; j < 500; j++) { dat << m1(i, j) <

BOOST uBLAS matrix product extremely slow

时光怂恿深爱的人放手 提交于 2019-12-01 07:31:07
Is there a way to improve the boost ublas product performance? I have two matrices A,B which i want to mulitply/add/sub/... In MATLAB vs. C++ i get the following times [s] for a 2000x2000 matrix Operations OPERATION | MATLAB | C++ (MSVC10) A + B | 0.04 | 0.04 A - B | 0.04 | 0.04 AB | 1.0 | 62.66 A'B' | 1.0 | 54.35 Why there is such a huge performance loss here? The matrices are only real doubles. But i also need positive definites,symmetric,rectangular products. EDIT: The code is trivial matrix<double> A( 2000 , 2000 ); // Fill Matrix A matrix<double> B = A; C = A + B; D = A - B; E = prod(A,B)

Why is boosts matrix multiplication slower than mine?

丶灬走出姿态 提交于 2019-11-28 16:58:30
I have implemented one matrix multiplication with boost::numeric::ublas::matrix (see my full, working boost code ) Result result = read (); boost::numeric::ublas::matrix<int> C; C = boost::numeric::ublas::prod(result.A, result.B); and another one with the standard algorithm (see full standard code ): 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] += A[i][k] * B

Why is boosts matrix multiplication slower than mine?

与世无争的帅哥 提交于 2019-11-28 16:38:43
问题 I have implemented one matrix multiplication with boost::numeric::ublas::matrix (see my full, working boost code) Result result = read (); boost::numeric::ublas::matrix<int> C; C = boost::numeric::ublas::prod(result.A, result.B); and another one with the standard algorithm (see full standard code): 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 =