Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions test/test_pyvectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,9 @@ namespace xt
using complex_t = std::complex<double>;
shape_type shape = { 3, 2 };
pyarray<complex_t> a(shape, complex_t(1.2, 2.5));
auto f = [](const pyarray<complex_t>& t) {
return std::make_tuple(pyvectorize([](complex_t x) { return std::abs(x); })(t),
pyvectorize([](complex_t x) { return std::arg(x); })(t));
};

auto res = f(a);
double expected_abs = std::abs(a(1, 1));
double expected_arg = std::arg(a(1, 1));
EXPECT_EQ(expected_abs, std::get<0>(res)(1, 1));
EXPECT_EQ(expected_arg, std::get<1>(res)(1, 1));
}

TEST(pyvectorize, complex_pybind)
{
using complex_t = std::complex<double>;
shape_type shape = { 3, 2 };
pyarray<complex_t> a(shape, complex_t(1.2, 2.5));
auto f = [](const pyarray<complex_t>& t) {
return pybind11::make_tuple(pyvectorize([](complex_t x) { return std::abs(x); })(t),
pyvectorize([](complex_t x) { return std::arg(x); })(t));
};

auto f = pyvectorize([](complex_t x) { return std::abs(x); });
auto res = f(a);
double expected_abs = std::abs(a(1, 1));
double expected_arg = std::arg(a(1, 1));

EXPECT_EQ(expected_abs, res[0].cast<pyarray<double>>()(1, 1));
EXPECT_EQ(expected_arg, res[1].cast<pyarray<double>>()(1, 1));
double exp = std::abs(a(1, 1));
EXPECT_EQ(exp, res(1, 1));
}
}