Closed tdegeus closed 6 years ago
I've opened a PR with a test-case that compares to a NumPy result, to avoid future bugs in this function.
(Like the example I gave the PR fails, as it currently should)
The PR now contains a PARTIAL bugfix. The case that I presented above is evaluated correctly. However if we evaluate a very simple other test-case (by comparing to NumPy):
#include "xtensor/xarray.hpp"
#include "xtensor/xtensor.hpp"
#include "xtensor/xhistogram.hpp"
#include "xtensor/xmath.hpp"
#include "xtensor/xview.hpp"
#include "xtensor/xio.hpp"
int main()
{
// py_a
xt::xarray<double> py_a = {{{0.,1.},
{2.,3.}},
{{4.,5.},
{6.,7.}}};
// py_w
xt::xarray<double> py_w = {{{0.,1.},
{2.,3.}},
{{4.,5.},
{6.,7.}}};
// py_av
xt::xarray<double> py_av = {4.666666666666667,5.25 };
auto av = xt::average(py_a, py_w, {0,1});
std::cout << av << std::endl;
std::cout << py_av << std::endl;
std::cout << ( av - py_av ) << std::endl;
}
Result:
{ 4.666667, 7. }
{ 4.666667, 5.25 }
{ 0. , 1.75}
I.e. we find that one axis is correct, while one is incorrect.
Closed by #1118
Consider this simple example:
Since the data is homogeneous and all weight factor are the same the answer is trivial to compute:
However (with the current xtensor master) I get:
?!?!?