RE: [eigen] operator== (and probably others) for 0-sized Eigen-types |
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
Hi Gael,
> I cannot reproduce the compilation issue with both gcc and clang. Here is what I tested:
I swapped rows and columns: The following example doesn't compile for me in the 2nd version:
#include <stdio.h>
#include <Eigen/Dense>
int main (int argc, char const *argv[])
{
Eigen::Matrix<double, 1, 0> a;
Eigen::Matrix<double, 1, 0> b;
Eigen::Matrix<double, 0, 1> c;
Eigen::Matrix<double, 0, 1> d;
// works
printf("%i\n", (int)(a == b));
// broken
printf("%i\n", (int)(c == d));
return 0;
}
Best regards Daniel Vollmer -------------------------- Deutsches Zentrum für Luft- und Raumfahrt e.V. (DLR) German Aerospace Center Institute of Aerodynamics and Flow Technology | Lilienthalplatz 7 | 38108 Braunschweig | Germany From: Gael Guennebaud [gael.guennebaud@xxxxxxxxx]
Sent: Monday, November 11, 2013 23:59 To: eigen Subject: Re: [eigen] operator== (and probably others) for 0-sized Eigen-types Hi,
#include <Eigen/Core>
#include <iostream>
int main() {
Eigen::Matrix<double, 1, 0> A, B;
std::cout << (A == B) << "\n";
};
However, it currently returns false, while returning true seems to be more appropriate. Actually the problem might be more general because it raises the question of what should be the result of .all() and .any() on an empty matrix of bool? Currently both
returns false, that is why operator== returns false too since A==B on Matrices is implemented as:
(A.array()==B.array()).all()
One option could be to make .all() and .any() returns the identity element of the operators && and || respectively, i.e., true and false. This choice would even be compatible with the following identities:
(A.array()==B.array()).all() <=> (A==B)
(A.array()!=B.array()).any() <=> (A!=B)
However it would break a more fundamental identity that is:
_expression_.all() => _expression_.any()
Moreover, it seems to me that an 'ideal' result of all() and any() on zero-sized objects depend on the context, e.g:
(A.array()==B.array()).all() == (A.array()==B.array()).any() == true
(A.array()!=B.array()).all() == (A.array()!=B.array()).any() == false
Therefore, perhaps it would be safer to disallow 'all' and 'any' on zero-sized object, and specialize operator== and operator!= on matrices for them?
(I'm very tired, so maybe I've missed something obvious here)
cheers,
gael
On Mon, Nov 11, 2013 at 6:30 PM, <Daniel.Vollmer@xxxxxx> wrote:
Hello, |
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |