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

SparseVector Transpose

Tags: None
(comma "," separated)
redimp
Registered Member
Posts
1
Karma
0

SparseVector Transpose

Mon Mar 04, 2013 8:51 am
Hi everybody,

i'm stuck on a problem and hope you can help me.

The multiplication of a transposed SparseVector does not work as expected:

Code: Select all
#include <iostream>

#include <Eigen/Sparse>
typedef Eigen::SparseMatrix<double,Eigen::RowMajor> matrix_type;
typedef Eigen::SparseVector<double> vector_type_sparse;
typedef Eigen::VectorXd vector_type;

int main(int argc, char *argv[]) {
  matrix_type A(2,2);

  A.coeffRef(0,0) = 1; A.coeffRef(0,1) = 2;
  A.coeffRef(1,0) = 3; A.coeffRef(1,1) = 4;

  // Dense Vector
  vector_type v(2);
  v.coeffRef(0) = -1;
  v.coeffRef(1) = 1;

  vector_type u = v.transpose() * A;
  std::cout << "v^T*A = u[" << u.rows() << "] = "  << std::endl<< u << std::endl;

  // SparseVector
  vector_type_sparse r(2);
  r.coeffRef(0) = -1;
  r.coeffRef(1) = 1;

  vector_type_sparse t = r.transpose() * A;
  std::cout << "r^T*A = t[" << t.rows() << "] = " << t;
}


The output is:
Code: Select all
v^T*A = u[2] =
2
2
r^T*A = t[2] = (2,0)


What did i wrong? Is this a Bug?

Thanks in advance, Ralph

P.S. I tested the current stable (eigen-eigen-5097c01bcdc4) and the current development branch (eigen-eigen-bdfde234c2f9)
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: SparseVector Transpose

Wed Mar 06, 2013 10:59 am
Fixed in the devel branch:

https://bitbucket.org/eigen/eigen/commits/fc34433a6beb/
changeset: fc34433a6beb
user: ggael
date: 2013-03-06 11:58:22
summary: fix sparse vector assignment from a sparse matrix

I'll backport the patch to 3.1 too.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]