Re: [eigen] Re: mixing Matrix types in expressions containing reductions |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Re: mixing Matrix types in expressions containing reductions
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Sun, 31 Oct 2010 11:29:03 -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=xt9L8q4RmHgR3H1IZ3nkz1pKmmcDOrl3fC356HsnaWU=; b=PcL9RMWWfNCRNsCmU4gFfslFg/ZNx160Xqkbk77mdKtC44uUczJmB3+fCu8GW0g0kL R8mYanN99iA1vd6zqn9prlkTbsBZyoKxngq7QlbXW2cKhlUs0b8/pQqVKEY1CILUmh/Y L8I0I50y7NaghcFl2bR28csYBUrot5gc/yGLU=
- 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=SkFoygZJODRfIuZVVgKy7O9zts8WoCqedi56ZQPAUJk18zVK76cFJwzOqWS2UfYVIJ Yi2ztRPc4tOyBbfzh2raWZLZpcHasSksdErc7WiA/m442heIYIOQjky32/wlTTPRHD2H pSi0K+LzuVB3J4393lHE22xfpFuceidaIHcLk=
2010/10/31 Patrick Sauer <pat05.mlst@xxxxxxxxx>:
> Hi,
>
> I'm trying to compute the variance of data vectors contained in the rows of
> an Eigen3 matrix, i.e.:
>
> MatrixXd Y = MatrixXd::Random(2,3);
> VectorXd mean = Y.colwise().mean();
> MatrixXd variance = (Y.colwise().squaredNorm()/Y.rows()).array() -
> mean.array()*mean.array();
>
> Strangely, with this code the variance vector contains only the variance
> over the first column. However, changing the "VectorXd mean" declaration to
> "MatrixXd mean" solves this problem and the code yields the correct result.
Looks like you found a bug.
What happens with "RowVectorXd mean" ?
Benoit
> Is this behaviour expected? Could the compiler provide the user with a hint
> here, or does the user need to remember to use equivalent types in
> expressions containing reduction operations?
>
> Thanks.
>
> Kind regards,
>
> Patrick
>