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

asDiagonal function error for sparse matrix

Tags: None
(comma "," separated)
changyan
Registered Member
Posts
6
Karma
0
I want to get the diagonal part of a sparse matrix as follows:
Code: Select all
typedef Eigen::SparseMatrix<std::complex<double>> SpMatcd;
SpMatcd A(4,4);
   A.insert(0,0)=1;
   A.insert(1,0)=1;
   A.insert(1,1)=-3;
   A.insert(2,2)=2;
SpMatcd  B=A.diagonal().asDiagonal();


but a compiler error occurs:
error: conversion from ‘const Eigen::DiagonalWrapper<const Eigen::Diagonal<const Eigen::SparseMatrix<std::complex<double> >, 0> >’ to non-scalar type ‘Eigen::Diagonal<Eigen::SparseMatrix<std::complex<double> >, 0>’

So how to fix it? o)


Bookmarks



Who is online

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