-
Notifications
You must be signed in to change notification settings - Fork 432
Closed
Labels
Description
hello , I'm newer to xtensor, I really like it. yesterday, I made a test, found it is somewhat slow, below is consuming time of same code written in numpy, eigen and xtensor:
numpy 1.5ms
eigen 0.7ms
xtensor 5.5ms
here is my code and test dada, I want to know if I made something wrong? thanks.
#include <iostream>
#include "xtensor/xarray.hpp"
#include "xtensor/xio.hpp"
#include "xtensor/xview.hpp"
#include "xtensor/xnpy.hpp"
#include <omp.h>
using namespace xt::placeholders;
void test()
{
auto loc = xt::load_npy<float>("c:/temp/loc.npy");
auto anchor = xt::load_npy<float>("c:/temp/anchor.npy");
auto fg_score = xt::load_npy<float>("c:/temp/fg_score.npy");
xt::xarray<float> result(loc.shape(), 0);
int loop = 500;
float ts = omp_get_wtime();
for (int i = 0; i < loop; i++)
{
auto anc0 = xt::view(anchor, xt::all(), 0);
auto anc1 = xt::view(anchor, xt::all(), 1);
auto h = xt::view(anchor, xt::all(), 2) - anc0;
auto w = xt::view(anchor, xt::all(), 3) - anc1;
auto cy = anc0 + h / 2;
auto cx = anc1 + w / 2;
auto ty = h * xt::view(loc, xt::all(), 0) + cy;
auto tx = w * xt::view(loc, xt::all(), 1) + cx;
auto th = xt::exp(xt::view(loc, xt::all(), 2)) * h;
auto tw = xt::exp(xt::view(loc, xt::all(), 3)) * w;
xt::view(result, xt::all(), 0) = ty - th / 2;
xt::view(result, xt::all(), 1) = tx - tw / 2;
xt::view(result, xt::all(), 2) = ty + th / 2;
xt::view(result, xt::all(), 3) = tx + tw / 2;
}
ts = omp_get_wtime() - ts;
std::cout << ts/loop << std::endl;
}
int main()
{
test();
return 0;
}