Re: [eigen] Assigning row vector expression to VectorXd |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Assigning row vector expression to VectorXd
- From: Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Aug 2019 14:04:56 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=uni-bremen.de; s=dkim; t=1565784297; i=@uni-bremen.de; bh=CBZc2m+v6oLzFT/qba2WPEQzD+RUZfpNxSd/ANJpH6k=; h=To:References:From:Date:In-Reply-To; b=uFd/Ah+CgsDNH6emqJJDBSkeuiP7wv62RykmDRecXYKfC0LqWge7Sw24sWcxnaOkp qmlrNVBBfRjepveHltmjCSgf8OHgksm3iqT1OE+1cLdfOHS4dZ4bbyamA9Sh097D2d XqTbUOnz08FersUjBk34CipNfZtpNwO5mRjYyhLQ=
Hi!
This is not a problem of implicitly converting a row-vector to a column
vector, but that you are mixing a column and a row-vector in the same
expression. I.e., expressions like
row.cwiseQuotient(col); row + col;
much more likely are user-errors, so they are prohibited (this has
nothing to do with assigning them). Also, for `row+col` what should be
the dimensions of the result (should it result in a row or column)?
If one of the dimensions is Dynamic, it is only possible to check this
at run-time, since Dynamic could be 1 at runtime. And runtime checks are
disabled when compiled with `-DNDEBUG` (or `-DEIGEN_NO_DEBUG`).
Allowing to assign row-expressions to VectorXd was an early
design-decision which can't be changed without breaking a lot of
existing code. I would generally suggest to always make sure that
dimensions match exactly. Adding a `.transpose()` does not add any
runtime overhead (when compiled with optimizations enabled).
I can't find the exact point where (or if) this behavior (the implicit
transposition) is documented.
Related: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1218
Cheers,
Christoph
On 14/08/2019 11.30, Jean-Claude Monnin wrote:
Hi,
When assigning a row vector into VectorXd (eg. a column vector), it does an implicit transpose in most cases (like in the line `VectorXd tmp = m.row(i) - m.row(j);` below).
I'm wondering why it doesn't behave the same way in line `VectorXd v3 = (m.row(i) - m.row(j)).cwiseQuotient(q);`. This gives the the wrong result in release mode (but calls`abort` in debug mode due to size mismatch).
Why does the assignment of `v3` behaves differently than the assignment of `tmp` in the example below? Is this documented behavior?
Cheers,
Jean-Claude
{
using namespace Eigen;
MatrixXd m = MatrixXd::Random(10, 4);
VectorXd q = VectorXd::Random(m.cols());
Index i = 3;
Index j = 8;
VectorXd tmp = m.row(i) - m.row(j);
VectorXd v1 = tmp.cwiseQuotient(q);
VectorXd v2 = (m.row(i) - m.row(j)).transpose().cwiseQuotient(q);
VectorXd v3 = (m.row(i) - m.row(j)).cwiseQuotient(q);
std::cout << "v1 rows:" << v1.rows() << ", cols:" << v1.cols() << std::endl;
std::cout << "v2 rows:" << v2.rows() << ", cols:" << v2.cols() << std::endl;
std::cout << "v3 rows:" << v3.rows() << ", cols:" << v3.cols() << std::endl;
std::cout << "v1 = " << v1.transpose() << std::endl;
std::cout << "v2 = " << v2.transpose() << std::endl;
std::cout << "v3 = " << v3.transpose() << std::endl;
}
Output in release mode:
v1 rows:4, cols:1
v2 rows:4, cols:1
v3 rows:1, cols:1
v1 = -0.0375015 1.61562 -1.3097 -0.394064
v2 = -0.0375015 1.61562 -1.3097 -0.394064
v3 = -0.0375015
--
Dr.-Ing. Christoph Hertzberg
Besuchsadresse der Nebengeschäftsstelle:
DFKI GmbH
Robotics Innovation Center
Robert-Hooke-Straße 5
28359 Bremen, Germany
Postadresse der Hauptgeschäftsstelle Standort Bremen:
DFKI GmbH
Robotics Innovation Center
Robert-Hooke-Straße 1
28359 Bremen, Germany
Tel.: +49 421 178 45-4021
Zentrale: +49 421 178 45-0
E-Mail: christoph.hertzberg@xxxxxxx
Weitere Informationen: http://www.dfki.de/robotik
-------------------------------------------------------------
Deutsches Forschungszentrum für Künstliche Intelligenz GmbH
Trippstadter Strasse 122, D-67663 Kaiserslautern, Germany
Geschäftsführung:
Prof. Dr. Jana Koehler (Vorsitzende)
Dr. Walter Olthoff
Vorsitzender des Aufsichtsrats:
Prof. Dr. h.c. Hans A. Aukes
Amtsgericht Kaiserslautern, HRB 2313
-------------------------------------------------------------