Consider the following code
#include <xtensor/xtensor.hpp>
#include <xtensor/xarray.hpp>
#include <xtensor/xrandom.hpp>
#include <xtensor/xadapt.hpp>
#include <xtensor/xview.hpp>
#include <xtensor/xsort.hpp>
#include <xtensor/xnoalias.hpp>
#include <xtensor/xio.hpp>
#include <cstdlib>
#include <ctime>
int main(int argc, const char** argv)
{
xt::random::seed(time(NULL));
size_t N = 1e3;
xt::xtensor<int,1> h = 0 * xt::ones<int>({N});
h(0) = 1;
xt::xtensor<bool,1> s = xt::equal(h, 1);
xt::xtensor<double,1> p = 0.01 * xt::ones<double>({N});
xt::view(p, xt::range(0, 500)) = 0.0;
xt::xtensor<double,1> r = xt::random::rand<double>(p.shape());
xt::xtensor<bool,1> t = r <= p;
std::cout << t << std::endl;
std::cout << h << std::endl;
h = xt::where(r <= p, 1, h);
std::cout << h << std::endl;
return 0;
}
The test r <= p evaluates true for only a few items, so the result of xt::where(r <= p, 1, h) should contain mostly zeros (which is does when I print just this command). However, h contains only ones, when using xsimd (the behaviour is correct without xsimd). Note that for compilation I use
cmake_minimum_required(VERSION 3.1)
project(main)
set(CMAKE_BUILD_TYPE Release)
find_package(xtensor REQUIRED)
find_package(xsimd REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE
xtensor xtensor::optimize xtensor::use_xsimd)
with the latests commits on conda-forge.
Strangely the more minimal code
#include <xtensor/xtensor.hpp>
#include <xtensor/xarray.hpp>
#include <xtensor/xrandom.hpp>
#include <xtensor/xadapt.hpp>
#include <xtensor/xview.hpp>
#include <xtensor/xsort.hpp>
#include <xtensor/xnoalias.hpp>
#include <xtensor/xio.hpp>
#include <cstdlib>
#include <ctime>
int main(int argc, const char** argv)
{
xt::random::seed(time(NULL));
size_t N = 1e3;
xt::xtensor<int,1> h = 0 * xt::ones<int>({N});
h(0) = 1;
xt::xtensor<bool,1> t = xt::zeros<bool>({N});
t(1) = 1;
h = xt::where(t, 1, h);
std::cout << h << std::endl;
return 0;
}
does work fine?!?
Consider the following code
The test
r <= pevaluatestruefor only a few items, so the result ofxt::where(r <= p, 1, h)should contain mostly zeros (which is does when I print just this command). However,hcontains only ones, when using xsimd (the behaviour is correct without xsimd). Note that for compilation I usewith the latests commits on conda-forge.
Strangely the more minimal code
does work fine?!?