77****************************************************************************/
88
99#include < algorithm>
10+
1011#include " gtest/gtest.h"
12+
13+ #include " xtensor/xarray.hpp"
14+ #include " xtensor/xoptional_assembly.hpp"
15+
1116#include " test_fixture.hpp"
1217
1318namespace xf
@@ -278,7 +283,7 @@ namespace xf
278283
279284 EXPECT_EQ (fma (sa, sb, a.select (sel)), xf::fma (sa, sb, a).select (sel));
280285 }
281-
286+
282287 TEST (xvariable_math, fmax)
283288 {
284289 variable_type a = make_test_variable ();
@@ -657,11 +662,34 @@ namespace xf
657662 EXPECT_EQ (isnan (a.select (sel)), xf::isnan (a).select (sel));
658663 }
659664
665+ TEST (xvariable_math, where)
666+ {
667+ auto missing = xtl::missing<double >();
668+ using data_type = xt::xoptional_assembly<xt::xarray<double >, xt::xarray<bool >>;
669+
670+ variable_type a = make_test_variable ();
671+ variable_type b = make_test_variable2 ();
672+
673+ variable_type res = where (a < 6 , b, a);
674+
675+ data_type expected = {{{ 1 ., 2 ., missing},
676+ {missing, missing, missing}},
677+ {{ 7 ., 7 ., 7 .},
678+ { 9 ., 9 ., 9 .}}};
679+ EXPECT_EQ (res.data (), expected);
680+
681+ variable_type res2 = where (a < 6 , 0 ., a);
682+ data_type expected2 = {{ 0 , 0 , missing},
683+ {missing, 0 , 6 },
684+ { 7 , 8 , 9 }};
685+ EXPECT_EQ (res2.data (), expected2);
686+ }
687+
660688 // Needs a fix in xtensor
661689 /* TEST(xvariable_math, isclose)
662690 {
663691 variable_type a = make_test_variable();
664692 dict_type sel = make_selector_aa();
665693 EXPECT_TRUE(isclose(a, a).select(sel));
666694 }*/
667- }
695+ }
0 commit comments