This forum has been archived. All content is frozen. Please use KDE Discuss instead.

it is wrong a sparse vector adds a common vector

Tags: None
(comma "," separated)
cuixue
Registered Member
Posts
2
Karma
0
I want to add a sparse vector with a common vector,like the following " vxd= vec + vxd ",However,the error is "no match for 'operator +' in 'vec + vxd' ".I would like to know how should i do can deal with the situation like this.Thank you!

Code: Select all
#include <iostream>
#include <vector>
#include <eigen3/Eigen/SparseCore>
#include <eigen3/Eigen/Sparse>

using namespace Eigen;
using namespace std;
typedef Matrix< double, 1, 4 > rowVec;

int main()
{   
    std :: vector<Triplet<double>> triplets1;
    int r[3] = {0,1,2};
    int c[3] = {1,2,2};
    double val[3] = {8,1,8};
   // double va2[3] = {5,7,8};
    for (int i = 0 ; i < 3; i++)
       triplets1.emplace_back (r[i],c[i],val[i]);
   SparseMatrix<double,RowMajor> A(4,4);
    A.setFromTriplets(triplets1.begin(),triplets1.end());
    cout << "A = "  <<A<<endl;
   SparseVector<double,RowMajor> vec(4),s(4);
   vec.insert(2) = 7;
   
   rowVec vxd;
   vxd(0) = 1; vxd(3) = 100;   vxd(1) = 1; vxd(2) = 100;
   
   vec = A.row(1) + vec;
   vxd=  vec  + vxd ;
}
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Only compound assignment from sparse to dense is allowed, like:

vxd += vec;


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar