diff --git a/include/xtensor/io/xio.hpp b/include/xtensor/io/xio.hpp index fbc0cd3a0..09ee4da58 100644 --- a/include/xtensor/io/xio.hpp +++ b/include/xtensor/io/xio.hpp @@ -20,6 +20,7 @@ #include "../core/xexpression.hpp" #include "../core/xmath.hpp" #include "../views/xstrided_view.hpp" +#include "xtl/xmasked_value_meta.hpp" namespace xt { @@ -646,7 +647,14 @@ namespace xt void update(const_reference val) { std::stringstream buf; - buf << val; + if constexpr (xtl::is_xmasked_value::value) + { + buf << +val; + } + else + { + buf << val; + } std::string s = buf.str(); if (int(s.size()) > m_width) { diff --git a/test/test_xmasked_view.cpp b/test/test_xmasked_view.cpp index 14613d169..1c7f9cb4d 100644 --- a/test/test_xmasked_view.cpp +++ b/test/test_xmasked_view.cpp @@ -7,6 +7,8 @@ * The full license is in the file LICENSE, distributed with this software. * ****************************************************************************/ +#include + #include "xtensor/io/xio.hpp" #include "xtensor/optional/xoptional_assembly.hpp" #include "xtensor/views/xmasked_view.hpp" @@ -210,6 +212,21 @@ namespace xt EXPECT_EQ(data, expected2); } + TEST(xmasked_view, non_optional_data_stream) + { + const xarray data = {{1., 5., 3.}, {4., 5., 6.}}; + const xarray mask = {{true, false, false}, {false, true, false}}; + + const auto masked_data = masked_view(data, mask); + + std::stringstream out; + out << masked_data; + + const std::string expected = "{{ 1, masked, masked},\n" + " {masked, 5, masked}}"; + EXPECT_EQ(out.str(), expected); + } + TEST(xmasked_view, assign) { xarray data = {{1., -2., 3.}, {4., 5., -6.}, {7., 8., -9.}};