//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************

#pragma once

#include <memory>

#include "ngraph/op/op.hpp"

namespace ngraph
{
    namespace op
    {
        /// \brief GenerateMask
        ///
        class GenerateMask : public op::Op
        {
        public:
            NGRAPH_API
            static const std::string type_name;
            const std::string& description() const override { return type_name; }
            /// \brief Constructs a GenerateMask node with a given shape, seed,
            /// probability and training/inference mode
            GenerateMask() = default;

#if 0
            /// Switch to dynamic arguments when all transformers have switched to using the node values
            /// \brief Constructs a GenerateMask node with a given shape, seed,
            /// probability and training/inference mode
            GenerateMask(const Output<Node>& training,
                         const Output<Node>& shape,
                         const Output<Node>& probability,
                         const Output<Node>& seed,
                         const Output<Node>& use_seed,
                         const element::Type& element_type);
#endif
            /// \brief Constructs a GenerateMask node with a given shape, seed,
            /// probability and training/inference mode
            GenerateMask(const Output<Node>& training,
                         const Shape& shape,
                         const element::Type& element_type,
                         uint64_t seed,
                         double prob,
                         bool use_seed = false);

            virtual std::shared_ptr<Node>
                copy_with_new_args(const NodeVector& new_args) const override;

            const element::Type& get_element_type() const { return m_element_type; }
            void set_element_type(const element::Type& element_type)
            {
                m_element_type = element_type;
            }

            /// Deprecated accessor for transitional attributes
            const Shape& get_mask_shape() const { return m_shape; }
            /// \brief Returns the probability of a trial generating 1 (i.e. an element being kept)
            double get_probability() const { return m_probability; }
            /// \brief Returns the seed value supplied to a random generator
            uint64_t get_seed() const { return m_seed; }
            bool get_use_seed() const { return m_use_seed; }
            /// GenerateMask has state.
            bool has_state() const override { return true; }
            void validate_and_infer_types() override;

        protected:
            virtual void generate_adjoints(autodiff::Adjoints& adjoints,
                                           const NodeVector& deltas) override
            {
            }

            element::Type m_element_type;
            // These will be deprecated
            Shape m_shape;
            bool m_use_seed{false};
            uint64_t m_seed{0};
            double m_probability{0.0};
        };
    }
}
