You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
xt::variance / xt::mean with axis returns different dimension #2005
Ok so actually it's not a bug, for the variance the axes must be specified as containers or initializer list:
auto variance = xt::variance(channels, {1});
Otherwise the integer is interpreted as the degree of freedom and the call is equivalent to computing the variance on the while expression.
I agree that this API is counter-intuitive and error-prone, we need to improve it but that will require a backward incompatible change.
@serge-sans-paille@zhujun98 do you think that having a dedicated type for the degree of freedom would be an acceptable solution? This would give code like the following:
auto variance = xt::variance(channels, 1, DDOF(1));
I think DDOF can be implicitly converted to an integer type, the SFINAE will avoid to get it selected for the axis argument.
Actually the syntax is well described in the doc xt::xarray<int> r0 = xt::variance(a, {1}); : and also in this issue : #1684 where there is no report of issues with dimensions.
Activity
JohanMabille commentedon Mar 30, 2020
That's a bug ;)
JohanMabille commentedon Apr 1, 2020
Ok so actually it's not a bug, for the variance the axes must be specified as containers or initializer list:
Otherwise the integer is interpreted as the degree of freedom and the call is equivalent to computing the variance on the while expression.
I agree that this API is counter-intuitive and error-prone, we need to improve it but that will require a backward incompatible change.
@serge-sans-paille @zhujun98 do you think that having a dedicated type for the degree of freedom would be an acceptable solution? This would give code like the following:
I think DDOF can be implicitly converted to an integer type, the SFINAE will avoid to get it selected for the axis argument.
Comeylo commentedon Apr 1, 2020
Actually the syntax is well described in the doc
xt::xarray<int> r0 = xt::variance(a, {1});: and also in this issue : #1684 where there is no report of issues with dimensions.Is there somewhere in the doc, a place where we can have a description of the reduction functions signature ? Because I can find this : https://xtensor.readthedocs.io/en/latest/api/reducing_functions.html#_CPPv4I000_N3xtl13check_conceptI18is_reducer_optionsI3EVSEEEEN2xt8varianceEDaRR1E3EVS. But it seems that there are some other signatures.
Thank you for the explanation nonetheless, it's clearly not a priority.
JohanMabille commentedon Apr 1, 2020
It looks like we forgot to update the documentation, all the overloads should be listed. I will also add this example as common pitfall in the doc.
zhujun98 commentedon Apr 3, 2020
@JohanMabille Sorry for the late response. I did not expect to be '@' here :-)
Having a dedicated type for
DDOFis of course a solution.Another possible solution just came to me, which is removing the following overload
since the use case of requiring a
DDOFis less frequent. After removing the above overload, given, the only case which requires extra typing is
Of course, some extra efforts are needed to make the following two cases compile