<commit_before>/***************************************************************************
* Copyright (c) <NAME>, <NAME> and <NAME>          *
* Copyright (c) QuantStack                                                 *
*                                                                          *
* Distributed under the terms of the BSD 3-Clause License.                 *
*                                                                          *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XTENSOR_XMASKED_VIEW_HPP
#define XTENSOR_XMASKED_VIEW_HPP

#include "xtl/xmasked_value.hpp"

#include "xaccessible.hpp"
#include "xexpression.hpp"
#include "xiterable.hpp"
#include "xutils.hpp"
#include "xshape.hpp"
#include "xsemantic.hpp"
#include "xtensor_forward.hpp"

namespace xt
{
    /****************************
     * xmasked_view declaration  *
     *****************************/

    template <class CTD, class CTM>
    class xmasked_view;

    template <class D, bool is_const>
    class xmasked_view_stepper;

    template <class T>
    struct xcontainer_inner_types;

    template <class CTD, class CTM>
    struct xcontainer_inner_types<xmasked_view<CTD, CTM>>
    {   
        using data_type = std::decay_t<CTD>;
        using mask_type = std::decay_t<CTM>;
        using base_value_type = typename data_type::value_type;
        using flag_type = typename mask_type::value_type;
        using val_reference = inner_reference_t<CTD>;
        using mask_reference = inner_reference_t<CTM>;
        using value_type = xtl::xmasked_value<base_value_type, flag_type>;
        using reference = xtl::xmasked_value<val_reference, mask_reference>;
        using const_reference = xtl::xmasked_value<typename data_type::const_reference, typename mask_type::const_reference>;
        using size_type = typename data_type::size_type;
        using temporary_type = xarray<xtl::xmasked_value<base_value_type, flag_type>>;
    };

    template <class CTD, class CTM>
    struct xiterable_inner_types<xmasked_view<CTD, CTM>>
    {
        using masked_view_type = xmasked_view<CTD, CTM>;
        using inner_shape_type = typename std::decay_t<CTD>::inner_shape_type;
        using stepper = xmasked_view_stepper<masked_view_type, false>;
        using const_stepper = xmasked_view_stepper<masked_view_type, true>;
    };

    /**
     * @class xmasked_view
     * @brief View on an xoptional_assembly or xoptional_assembly_adaptor
     * hiding values depending on a given mask.
     *
     * The xmasked_view class implements a view on an xoptional_assembly or
     * xoptional_assembly_adaptor, it takes this xoptional_assembly and a
     * mask as input. The mask is an xexpression containing boolean values,
     * whenever the value of the mask is false, the optional value of
     * xmasked_view is considered missing, otherwise it depends on the
     * underlying xoptional_assembly.
     *
     * @tparam CTD The type of expression holding the values.
     * @tparam CTM The type of expression holding the mask.
     */
    template <class CTD, class CTM>
    class xmasked_view : public xview_semantic<xmasked_view<CTD, CTM>>,
                         private xaccessible<xmasked_view<CTD, CTM>>,
                         private xiterable<xmasked_view<CTD, CTM>>
    {
    public:

        using self_type = xmasked_view<CTD, CTM>;
        using semantic_base = xview_semantic<xmasked_view<CTD, CTM>>;
        using accessible_base = xaccessible<self_type>;
        using inner_types = xcontainer_inner_types<self_type>;
        using temporary_type = typename inner_types::temporary_type;

        using data_type = typename inner_types::data_type;
        using mask_type = typename inner_types::mask_type;
        using value_expression = CTD;
        using mask_expression = CTM;

        static constexpr bool is_data_const = std::is_const<std::remove_reference_t<value_expression>>::value;

        using base_value_type = typename inner_types::base_value_type;
        using base_reference = typename data_type::reference;
        using base_const_reference = typename data_type::const_reference;

        using flag_type = typename inner_types::flag_type;
        using flag_reference = typename mask_type::reference;
        using flag_const_reference = typename mask_type::const_reference;

        using val_reference = typename inner_types::val_reference;
        using mask_reference = typename inner_types::mask_reference;

        using value_type = typename inner_types::value_type;
        using reference = typename inner_types::reference;
        using const_reference = typename inner_types::const_reference;

        using pointer = xtl::xclosure_pointer<reference>;
        using const_pointer = xtl::xclosure_pointer<const_reference>;

        using size_type = typename inner_types::size_type;
        using difference_type = typename data_type::difference_type;

        using bool_load_type = xtl::xmasked_value<typename data_type::bool_load_type, mask_type>;

        using shape_type = typename data_type::shape_type;
        using strides_type = typename data_type::strides_type;

        static constexpr layout_type static_layout = data_type::static_layout;
        static constexpr bool contiguous_layout = false;

        using inner_shape_type = typename data_type::inner_shape_type;
        using inner_strides_type = typename data_type::inner_strides_type;
        using inner_backstrides_type = typename data_type::inner_backstrides_type;

        using expression_tag = xtensor_expression_tag;

        using iterable_base = xiterable<xmasked_view<CTD, CTM>>;
        using stepper = typename iterable_base::stepper;
        using const_stepper = typename iterable_base::const_stepper;

        template <layout_type L>
        using layout_iterator = typename iterable_base::template layout_iterator<L>;
        template <layout_type L>
        using const_layout_iterator = typename iterable_base::template const_layout_iterator<L>;
        template <layout_type L>
        using reverse_layout_iterator = typename iterable_base::template reverse_layout_iterator<L>;
        template <layout_type L>
        using const_reverse_layout_iterator = typename iterable_base::template const_reverse_layout_iterator<L>;

        template <class S, layout_type L>
        using broadcast_iterator = typename iterable_base::template broadcast_iterator<S, L>;
        template <class S, layout_type L>
        using const_broadcast_iterator = typename iterable_base::template const_broadcast_iterator<S, L>;
        template <class S, layout_type L>
        using reverse_broadcast_iterator = typename iterable_base::template reverse_broadcast_iterator<S, L>;
        template <class S, layout_type L>
        using const_reverse_broadcast_iterator = typename iterable_base::template const_reverse_broadcast_iterator<S, L>;

        using iterator = typename iterable_base::iterator;
        using const_iterator = typename iterable_base::const_iterator;
        using reverse_iterator = typename iterable_base::reverse_iterator;
        using const_reverse_iterator = typename iterable_base::const_reverse_iterator;

        template <class D, class M>
        xmasked_view(D&& data, M&& mask);

        size_type size() const noexcept;
        const inner_shape_type& shape() const noexcept;
        const inner_strides_type& strides() const noexcept;
        const inner_backstrides_type& backstrides() const noexcept;
        using accessible_base::dimension;
        using accessible_base::shape;

        layout_type layout() const noexcept;
        bool is_contiguous() const noexcept;

        template <class T>
        void fill(const T& value);

        template <class... Args>
        reference operator()(Args... args);

        template <class... Args>
        const_reference operator()(Args... args) const;

        template <class... Args>
        reference unchecked(Args... args);

        template <class... Args>
        const_reference unchecked(Args... args) const;

        using accessible_base::at;<commit_msg>Make xmasked_view copy constructor default<commit_after>/***************************************************************************
* Copyright (c) <NAME>, <NAME> and <NAME>          *
* Copyright (c) QuantStack                                                 *
*                                                                          *
* Distributed under the terms of the BSD 3-Clause License.                 *
*                                                                          *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XTENSOR_XMASKED_VIEW_HPP
#define XTENSOR_XMASKED_VIEW_HPP

#include "xtl/xmasked_value.hpp"

#include "xaccessible.hpp"
#include "xexpression.hpp"
#include "xiterable.hpp"
#include "xutils.hpp"
#include "xshape.hpp"
#include "xsemantic.hpp"
#include "xtensor_forward.hpp"

namespace xt
{
    /****************************
     * xmasked_view declaration  *
     *****************************/

    template <class CTD, class CTM>
    class xmasked_view;

    template <class D, bool is_const>
    class xmasked_view_stepper;

    template <class T>
    struct xcontainer_inner_types;

    template <class CTD, class CTM>
    struct xcontainer_inner_types<xmasked_view<CTD, CTM>>
    {   
        using data_type = std::decay_t<CTD>;
        using mask_type = std::decay_t<CTM>;
        using base_value_type = typename data_type::value_type;
        using flag_type = typename mask_type::value_type;
        using val_reference = inner_reference_t<CTD>;
        using mask_reference = inner_reference_t<CTM>;
        using value_type = xtl::xmasked_value<base_value_type, flag_type>;
        using reference = xtl::xmasked_value<val_reference, mask_reference>;
        using const_reference = xtl::xmasked_value<typename data_type::const_reference, typename mask_type::const_reference>;
        using size_type = typename data_type::size_type;
        using temporary_type = xarray<xtl::xmasked_value<base_value_type, flag_type>>;
    };

    template <class CTD, class CTM>
    struct xiterable_inner_types<xmasked_view<CTD, CTM>>
    {
        using masked_view_type = xmasked_view<CTD, CTM>;
        using inner_shape_type = typename std::decay_t<CTD>::inner_shape_type;
        using stepper = xmasked_view_stepper<masked_view_type, false>;
        using const_stepper = xmasked_view_stepper<masked_view_type, true>;
    };

    /**
     * @class xmasked_view
     * @brief View on an xoptional_assembly or xoptional_assembly_adaptor
     * hiding values depending on a given mask.
     *
     * The xmasked_view class implements a view on an xoptional_assembly or
     * xoptional_assembly_adaptor, it takes this xoptional_assembly and a
     * mask as input. The mask is an xexpression containing boolean values,
     * whenever the value of the mask is false, the optional value of
     * xmasked_view is considered missing, otherwise it depends on the
     * underlying xoptional_assembly.
     *
     * @tparam CTD The type of expression holding the values.
     * @tparam CTM The type of expression holding the mask.
     */
    template <class CTD, class CTM>
    class xmasked_view : public xview_semantic<xmasked_view<CTD, CTM>>,
                         private xaccessible<xmasked_view<CTD, CTM>>,
                         private xiterable<xmasked_view<CTD, CTM>>
    {
    public:

        using self_type = xmasked_view<CTD, CTM>;
        using semantic_base = xview_semantic<xmasked_view<CTD, CTM>>;
        using accessible_base = xaccessible<self_type>;
        using inner_types = xcontainer_inner_types<self_type>;
        using temporary_type = typename inner_types::temporary_type;

        using data_type = typename inner_types::data_type;
        using mask_type = typename inner_types::mask_type;
        using value_expression = CTD;
        using mask_expression = CTM;

        static constexpr bool is_data_const = std::is_const<std::remove_reference_t<value_expression>>::value;

        using base_value_type = typename inner_types::base_value_type;
        using base_reference = typename data_type::reference;
        using base_const_reference = typename data_type::const_reference;

        using flag_type = typename inner_types::flag_type;
        using flag_reference = typename mask_type::reference;
        using flag_const_reference = typename mask_type::const_reference;

        using val_reference = typename inner_types::val_reference;
        using mask_reference = typename inner_types::mask_reference;

        using value_type = typename inner_types::value_type;
        using reference = typename inner_types::reference;
        using const_reference = typename inner_types::const_reference;

        using pointer = xtl::xclosure_pointer<reference>;
        using const_pointer = xtl::xclosure_pointer<const_reference>;

        using size_type = typename inner_types::size_type;
        using difference_type = typename data_type::difference_type;

        using bool_load_type = xtl::xmasked_value<typename data_type::bool_load_type, mask_type>;

        using shape_type = typename data_type::shape_type;
        using strides_type = typename data_type::strides_type;

        static constexpr layout_type static_layout = data_type::static_layout;
        static constexpr bool contiguous_layout = false;

        using inner_shape_type = typename data_type::inner_shape_type;
        using inner_strides_type = typename data_type::inner_strides_type;
        using inner_backstrides_type = typename data_type::inner_backstrides_type;

        using expression_tag = xtensor_expression_tag;

        using iterable_base = xiterable<xmasked_view<CTD, CTM>>;
        using stepper = typename iterable_base::stepper;
        using const_stepper = typename iterable_base::const_stepper;

        template <layout_type L>
        using layout_iterator = typename iterable_base::template layout_iterator<L>;
        template <layout_type L>
        using const_layout_iterator = typename iterable_base::template const_layout_iterator<L>;
        template <layout_type L>
        using reverse_layout_iterator = typename iterable_base::template reverse_layout_iterator<L>;
        template <layout_type L>
        using const_reverse_layout_iterator = typename iterable_base::template const_reverse_layout_iterator<L>;

        template <class S, layout_type L>
        using broadcast_iterator = typename iterable_base::template broadcast_iterator<S, L>;
        template <class S, layout_type L>
        using const_broadcast_iterator = typename iterable_base::template const_broadcast_iterator<S, L>;
        template <class S, layout_type L>
        using reverse_broadcast_iterator = typename iterable_base::template reverse_broadcast_iterator<S, L>;
        template <class S, layout_type L>
        using const_reverse_broadcast_iterator = typename iterable_base::template const_reverse_broadcast_iterator<S, L>;

        using iterator = typename iterable_base::iterator;
        using const_iterator = typename iterable_base::const_iterator;
        using reverse_iterator = typename iterable_base::reverse_iterator;
        using const_reverse_iterator = typename iterable_base::const_reverse_iterator;

        template <class D, class M>
        xmasked_view(D&& data, M&& mask);

        xmasked_view(xmasked_view const&) = default;

        size_type size() const noexcept;
        const inner_shape_type& shape() const noexcept;
        const inner_strides_type& strides() const noexcept;
        const inner_backstrides_type& backstrides() const noexcept;
        using accessible_base::dimension;
        using accessible_base::shape;

        layout_type layout() const noexcept;
        bool is_contiguous() const noexcept;

        template <class T>
        void fill(const T& value);

        template <class... Args>
        reference operator()(Args... args);

        template <class... Args>
        const_reference operator()(Args... args) const;

        template <class... Args>
        reference unchecked(Args... args);

        template <class... Args>
        const_reference unchecked(Args... args) const;

        using accessible_base::at;
{'fraction_non_alphanumeric': 0.09772520473157416, 'fraction_numerical': 0.0001213224143160449, 'mean_word_length': 3.2621509824198553, 'pattern_counts': {'":': 0, '<': 135, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7198874', 'n_tokens_mistral': 4667, 'n_tokens_neox': 4468, 'n_words': 1130}