[eigen] Assigning row vector expression to VectorXd |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] Assigning row vector expression to VectorXd
- From: "Jean-Claude Monnin" <jc_monnin@xxxxxxxxxxxxx>
- Date: Wed, 14 Aug 2019 11:30:11 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emailplus.org; h=mime-version:message-id:date:from:to:subject:content-type; s= fm1; bh=TpEkNqsB6OVz1tjA3DiAzg8dcekceW7k266hvJMMDhg=; b=pcV03MQh oijFPTl6yhzhpQs06CZ6CwWZhQNLjnXF0soLsdW2Vs5nG3lMJYoXFK+1SMRYDS6/ wsstTICi2HiafWnYFcsMLZmPGFHFpQDXYhjSjFkG6Fbciu5Z9J/+lJgoZV3EJ/Rb ZG/uvKK6Q4Y/E/+nm7V4Ui+PIthhiwQgB7nxb2ikG/MMD6HJIwh/6qvES6ur56c4 B8+DAZusq5eAw2kgWWfWcpEKNGShkXlzzUOkWv7P8tXhf26BI/QmMWp5DZMtwHdb MaGaraHvN0roR/vMy4d1j6d8rD0wZBRz9NZjMW/9pFPeQpqpt+uWUftm2q41oSEU MNN/pDQtUpo2Ng==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=TpEkNqsB6OVz1tjA3DiAzg8dcekce W7k266hvJMMDhg=; b=L5fNhe/T/euXbERJToUjpsyHGFO3z94rITOYsc+quUIo0 6SJklDGeKpeoYtoIv+1kHHeVCKfF3sY3wmrNNyyKgQ7XBz5NXGjr3z3DLIIZC6uG D/F1KZWtALsIgl/+w1D7y8kYBK1i6btcs7vG9y0fgGubbDi7cpO/K4sa/ZIZqMxa ncsL/bi0Z7SS+T0qHY/mcB5dzx5jkCnsI8DuOoPHmhq2krbDdUEqxf+LovqBtJUM tmww/h5apziM21GwJrICZHBkLXOMO+s1HEUjHKGy6Z+FinqRbQd2xerYoTKb6HIj NdNUMV/w/2289kQIUauLEuA+y+d77M+3VfyKuOX4Q==
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