Re: [eigen] How does toDenseMatrix() work? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] How does toDenseMatrix() work?
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Fri, 23 Jul 2010 19:00:36 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=auakzW770sNt73x5Gb4zD8aVgrU7a200WpTNGXkQ144=; b=BdwlEYxD/ZKyTBLz1qB3mJZlpTqzZ1I4A/194hyrsj49gHMAO3CGOX0pPe6ZRS4Vbe uGxxCLiYN0c/ew85Kxt1eX+ml80cWcCC6phr6ORC0RLyw63HwqTJVPlgju0MxHOagCiC +oowpSwJx7tZSwWt933g4Y260eSI5b3q4voTU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=K192uE+IcvHEwj1Sy/JWM6PeuWnb3SRRXq9MgtKM18e3p6SrpyQm4+HyWdPw6huHzx J5RdGv5tPILEKIKYCtbxTJtfp9joqOuLQVco9mYoyQB8nZvYbCeYONLAAtcpcRWSwOA5 ikDUb3Fk+T+AyENy0Y/fF4gpC6d2P5FVWv3pI=
2010/7/23 Manoj Rajagopalan <rmanoj@xxxxxxxxx>:
> Hi eigen developers,
>
> In some specialized classes like DiagonalMatrix,
It should be in _all_ special matrix classes. If we still have special
matrix classes without toDenseMatrix(), or with the old name
toDense(), we should fix that.
> I see the following member:
>
> DenseMatrixType toDenseMatrix() const { return derived(); }
>
> where DenseMatrixType is a typedef for the full MxN container whereas
> derived() returns the "sparse" derived instance. Somewhere, the Eigen3
> machinery is ensuring an element-by-element "translation" from the derived
> matrix expression to the full MxN matrix. What is this mechanism?
>
> Is this happening because the lvalue's EigenBase<> copy CTOR and copy
> assignment operator call the rvalue's evalTo() method? So if I write a custom
> matrix class for compact representation, I only need to inherit EigenBase<>
> and override the evalTo() method for this translation to work?
Yes, this is happening in DenseBase::operator=(EigenBase) which is
defined in Eigen/src/Core/EigenBase.h:
template<typename Derived>
template<typename OtherDerived>
Derived& DenseBase<Derived>::operator=(const EigenBase<OtherDerived> &other)
{
other.derived().evalTo(derived());
return derived();
}
So yes, you got it right, see e.g. in Eigen/src/Core/DiagonalMatrix.h
for an example of a special matrix class implementation. Indeed evalTo
is implemented there as:
template<typename Derived>
template<typename DenseDerived>
void DiagonalBase<Derived>::evalTo(MatrixBase<DenseDerived> &other) const
{
other.setZero();
other.diagonal() = diagonal();
}
By the way... we have a discrepancy there, evalTo should be taking a
DenseBase not a MatrixBase, otherwise code trying to do that on an
Array will compile but will enter an infinite recursive call of
DenseBase::evalTo at runtime, let me fix this now :-)
Benoit
>
> thanks,
> Manoj
>
>
>