Re: [eigen] Missing operator definition in Sparse? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Missing operator definition in Sparse?
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Thu, 24 Jun 2010 22:51:13 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=lF/QkEbnEvRZL8crHJtuMBty4ktANiSEWrHe5cdni2g=; b=MjUxSxITWhVG+0d++m/MBQlAM4iXX3+WR5QgXa/LOynhbLUOCFY337Fbg2ypmeO2Dr XDfbLnzBt4tVEYETSdcGIVgXn947WScm3/22KrvoJyBZ4lkpGlRd/Q3oH0FIxqIphywm VtD1sFHD64Kp5HcESEbNWlidjX9/vAmdZipzU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=tzHef/w8KRxPGJ9b/U1jnGU3CNS0Jd2XTl8gIpZZDaiHk/Qe+0Q/1sgyqK3I2Q+iAI 0Msoh3g3rO3aAm605vnHFi0OnyRlkkso0I8AX+f3GK10ufhB8W1jtUI3LtPLwixMdpPi i+eO6YK3ifevK3f4RexpvBeZdgLw0C7JYE2Gk=
On Thu, Jun 24, 2010 at 10:07 PM, Sameer Agarwal
<sameeragarwal@xxxxxxxxxx> wrote:
> Hi Guys,
>
> I am using the development branch. The following bit of code does not compile.
>
> #include "Eigen/Core"
> #include "Eigen/Sparse"
>
> typedef Eigen::SparseMatrix<double, Eigen::ColMajor> SparseCol;
> typedef Eigen::Matrix<double, Eigen::Dynamic, 1> Vector;
>
> int main() {
> int nrow = 5;
> int ncol = 5;
> SparseCol m(nrow,ncol);
> Vector x(ncol,1);
> SparseCol A = m.subcols(1, 4) - m.col(0)* x.transpose();
> return 0;
> }
>
> Compiled complains about a missing operator definition.
Indeed, there is no special handling for m.col(0)* x.transpose(). It
is treated as a standard sparse by dense product, and so it returns a
dense object...
To be honest I'm a bit surprised by such an expression, but if you
need it that's easily doable.
As a side note, the following works but fully evaluate the outer
product to a dense temporary matrix:
Vector x(4,1);
SparseCol A = m.subcols(1, 4) - (m.col(0)* x.transpose()).sparseView();
(you need to update your local copy to make it compile fine)
gael
>
>
> test_sparse.cc: In function ‘int main()’:
> test_sparse.cc:12: error: no match for ‘operator-’ in
> ‘m.Eigen::SparseMatrix<double, 0,
> int>::<anonymous>.Eigen::SparseMatrixBase<Derived>::subcols [with
> Derived = Eigen::SparseMatrix<double, 0, int>](1, 4) -
> Eigen::SparseMatrixBase<Derived>::operator*(const
> Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived =
> Eigen::Transpose<Eigen::Matrix<double, -0x00000000000000001, 1, 0,
> -0x00000000000000001, 1> >, Derived =
> Eigen::SparseInnerVectorSet<Eigen::SparseMatrix<double, 0, int>,
> 1>](((const Eigen::MatrixBase<Eigen::Transpose<Eigen::Matrix<double,
> -0x00000000000000001, 1, 0, -0x00000000000000001, 1> > >&)((const
> Eigen::MatrixBase<Eigen::Transpose<Eigen::Matrix<double,
> -0x00000000000000001, 1, 0, -0x00000000000000001, 1> >
>>*)(&((Eigen::DenseBase<Eigen::Matrix<double, -0x00000000000000001, 1,
> 0, -0x00000000000000001, 1> >*)(&
> x))->Eigen::DenseBase<Derived>::transpose [with Derived =
> Eigen::Matrix<double, -0x00000000000000001, 1, 0,
> -0x00000000000000001, 1>]()))))’
> Eigen/src/Sparse/../plugins/CommonCwiseUnaryOps.h:59: note: candidates
> are: const Eigen::CwiseUnaryOp<Eigen::ei_scalar_opposite_op<typename
> Eigen::ei_traits<Derived>::Scalar>, Derived>
> Eigen::SparseMatrixBase<Derived>::operator-() const [with Derived =
> Eigen::SparseInnerVectorSet<Eigen::SparseMatrix<double, 0, int>,
> -0x00000000000000001>]
>
> Thanks,
> Sameer
>
>
>