Registered Member
|
The documentation's example (Tutorial page 7) implies that the mean() method returns real numbers from integer matrix, but when I apply it to partial reduction of integer matrix, the return type appears to be integer vectors.
The following code prints integers throughout,
while this
won't compile. Could someone enlighten me as to what is going on and update the documentation accordingly? Spending 2 hours discovering this was very unpleasant. |
Moderator
|
hm, the example of the tutorial uses a matrix of double.
In general in Eigen we never automatically promote integer to floating point numbers. Use .cast<double>() to switch to doubles. |
Registered Member
|
Well, I stand corrected.
But perhaps it would be better to populate the example with real numbers and not integers to accentuate the type of the matrix. I would also argue that it doesn't make sense to force mean() to return the same type since that is contrary to mathematical custom. Not a big deal, just a nasty surprise. |
Moderator
|
ok, but to what type? double? float? rational numbers?
That said we could certainly add some warnings in the documentation about this fact. |
Registered Member
|
Perhaps mean() on integers should yield a compile-time error, just like the entry-wise sqrt().
|
Registered Member
|
Mathematically, it makes sense to me for a mean's codomain to agree with its domain, mean : T -> T.
So, if mean takes ints, then mean returns ints. This is consistent* with the behavior of operator+ and operator/ in terms of which (mathematically) mean is defined (by function composition, map-reduce style) -- just as integer addition and integer division produce integer results, so does their composition. Seems perfectly correct and natural, just as no one acquainted with the types of operations would expect the result of 5.0/2.0==2.5 to agree with 5/2==2. * - http://en.wikipedia.org/wiki/Principle_of_compositionality |
Moderator
|
Just to add that I agree with mattd on this.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]