forcing the generator to be evaluated resulting in a real array?
Then, it would be really great to have xt::tile and xt::roll as well! Would you be willing to convert your efforts in one or two PRs?
As to the xt::roll, my intuition would be that it would be best to do it with minimal allocation. xt::pad has to allocate the full bigger matrix. In contrast, xt::roll could potentially get away with minimal temporary storage. Though you or others may have a different intuition.
@tort-dla-psa At the level of xt::pad you've reached the limitation of the current implementation (that can clearly be improved!). For the moment xt::pad is not recursive, i.e. all pad modes that are not constant fail when the pad width is bigger than the shape along the relevant axis (or in the case of reflect the shape minus one).
Upon enabling assertions:
#defineXTENSOR_ENABLE_ASSERT
#include<xtensor/xarray.hpp>
#include<xtensor/xpad.hpp>
#include<xtensor/xio.hpp>intmain()
{
xt::xarray<int> b = xt::arange<int>(2);
std::cout << b << std::endl;
b = xt::pad(b, {2, 2}, xt::pad_mode::reflect);
std::cout << b << std::endl;
return0;
}
You will indeed find
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: .../include/xtensor/xpad.hpp:138: assertion failed (nb <= out.shape()[axis] - 1)
To clarify, currently:
b = xt::pad(b, {2, 2}, xt::pad_mode::periodic); // works
b = xt::pad(b, {3, 3}, xt::pad_mode::periodic); // throws
b = xt::pad(b, {3, 3}, xt::pad_mode::constant); // works
I think that the quickest fix for this would be to make xt::pad recursive. Obviously with the disadvantage of re-allocation more often than needed.
We're very much open to improvements. In this regard I mention:
With respect to you original issue of implementing xt::tile, I think that its stand-alone implementation could be faster than a generalisation of xt::pad (though the latter would obviously much more welcome).
Activity
tdegeus commented on Nov 27, 2019
In terms of your problem, could you try with
forcing the generator to be evaluated resulting in a real array?
Then, it would be really great to have xt::tile and xt::roll as well! Would you be willing to convert your efforts in one or two PRs?
As to the xt::roll, my intuition would be that it would be best to do it with minimal allocation. xt::pad has to allocate the full bigger matrix. In contrast, xt::roll could potentially get away with minimal temporary storage. Though you or others may have a different intuition.
tort-dla-psa commented on Nov 27, 2019
It kinda works with real xarray/xtensor passing, but I have some strange results:
desired output:
real output:
tdegeus commented on Nov 28, 2019
@tort-dla-psa At the level of xt::pad you've reached the limitation of the current implementation (that can clearly be improved!). For the moment xt::pad is not recursive, i.e. all pad modes that are not constant fail when the pad width is bigger than the shape along the relevant axis (or in the case of reflect the shape minus one).
Upon enabling assertions:
You will indeed find
To clarify, currently:
b = xt::pad(b, {2, 2}, xt::pad_mode::periodic); // works b = xt::pad(b, {3, 3}, xt::pad_mode::periodic); // throws b = xt::pad(b, {3, 3}, xt::pad_mode::constant); // worksI think that the quickest fix for this would be to make xt::pad recursive. Obviously with the disadvantage of re-allocation more often than needed.
We're very much open to improvements. In this regard I mention:
With respect to you original issue of implementing xt::tile, I think that its stand-alone implementation could be faster than a generalisation of xt::pad (though the latter would obviously much more welcome).