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:31:30 -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=VAxNyjLbqOveyJLVOSZ41DGBeYFo032wAp9dIBB/jFo=; b=dqwE7ikHiwDfiujml734XnqH3vwQV390TH65Qe0X+uLDTy09pBgUH51YvlP8Q8ze2w rQi9yJ597w59A9HMTY4ipC7x4P8KitGCiArKp1daAVMWB87EMaTzRz1TLAi9I3rg7lyr qdCfzuqcJDqZ5J+leqiQy+ywCVIBhR2WrnQyA=
- 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=lH5LBJS13kMwNXG5J8xHrXmhHcKeJ436p0ceWbEKukGOmI5OkAhqA+8s7Rs+gxlIce oD+hxV4AuIdyOWdgi3iVCahUMN5vkvvKC9WVu+8MIAzNaMhRoUC1ARtYemPg16ybtiBd NHnv/Mwceg5hh1aVos4z081aAutsTRDOr6Dx8=
2010/7/23 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
> 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 :-)
Ah no, here we are actually safe because the template evalTo()
declaration in the derived class overrides the evalTo() from
DenseBase. ok. So no crash.
That said, since we normally allow assigning a matrix to an array, I
think we should allow it too for special matrices. So I'll still fix
it.
Benoit
>
> Benoit
>
>>
>> thanks,
>> Manoj
>>
>>
>>
>