Skip to content

Commit 8f2d557

Browse files
authored
Merge pull request #221 from martinRenou/min_max
Add support for minimum/maximum
2 parents b6c6dea + 1916030 commit 8f2d557

2 files changed

Lines changed: 24 additions & 20 deletions

File tree

include/xframe/xaxis_math.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ namespace xf
6262
using xt::fmax;
6363
using xt::fmin;
6464
using xt::fdim;
65-
// Needs a fix in xtensor
66-
//using xt::maximum;
67-
//using xt::minimum;
65+
using xt::maximum;
66+
using xt::minimum;
6867
using xt::clip;
6968
using xt::sign;
7069

test/test_xvariable_math.cpp

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -323,32 +323,37 @@ namespace xf
323323
EXPECT_EQ(fdim(sa, a.select(sel)), fdim(sa, a).select(sel));
324324
}
325325

326-
// TODO: enable this when xoptional is fixed
327-
/*TEST(xvariable_math, maximum)
326+
TEST(xvariable_math, maximum)
328327
{
329-
variable_type a = make_test_variable();
330-
dict_type sel = make_selector_aa();
331-
EXPECT_EQ(std::max(a.select(sel), a.select(sel)), maximum(a, a).select(sel));
328+
auto missing = xtl::missing<double>();
329+
using data_type = xt::xoptional_assembly<xt::xarray<double>, xt::xarray<bool>>;
332330

333-
double sb = 1.2;
334-
EXPECT_EQ(std::max(a.select(sel), sb), maximum(a, sb).select(sel));
331+
variable_type a = make_test_variable();
332+
variable_type b = make_test_variable2();
335333

336-
double sa = 1.2;
337-
EXPECT_EQ(std::max(sa, a.select(sel)), maximum(sa, a).select(sel));
334+
variable_type res = maximum(a, b);
335+
data_type expected = {{{ 1, 2, missing},
336+
{missing, missing, missing}},
337+
{{ 11, 12, 13},
338+
{missing, 15, 16}}};
339+
EXPECT_EQ(res.data(), expected);
338340
}
339341

340342
TEST(xvariable_math, minimum)
341343
{
342-
variable_type a = make_test_variable();
343-
dict_type sel = make_selector_aa();
344-
EXPECT_EQ(std::min(a.select(sel), a.select(sel)), minimum(a, a).select(sel));
344+
auto missing = xtl::missing<double>();
345+
using data_type = xt::xoptional_assembly<xt::xarray<double>, xt::xarray<bool>>;
345346

346-
double sb = 1.2;
347-
EXPECT_EQ(std::min(a.select(sel), sb), minimum(a, sb).select(sel));
347+
variable_type a = make_test_variable();
348+
variable_type b = make_test_variable2();
348349

349-
double sa = 1.2;
350-
EXPECT_EQ(std::min(sa, a.select(sel)), minimum(sa, a).select(sel));
351-
}*/
350+
variable_type res = minimum(a, b);
351+
data_type expected = {{{ 1, 1, missing},
352+
{missing, missing, missing}},
353+
{{ 7, 7, 7},
354+
{missing, 9, 9}}};
355+
EXPECT_EQ(res.data(), expected);
356+
}
352357

353358
TEST(xvariable_math, clip)
354359
{

0 commit comments

Comments
 (0)