LCOV - code coverage report
Current view: top level - nntrainer/layers - rnn.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 3 3
Test Date: 2025-12-14 20:38:17 Functions: 100.0 % 4 4

            Line data    Source code
       1              : // SPDX-License-Identifier: Apache-2.0
       2              : /**
       3              :  * Copyright (C) 2021 Jijoong Moon <jijoong.moon@samsung.com>
       4              :  *
       5              :  * @file   rnn.h
       6              :  * @date   17 March 2021
       7              :  * @brief  This is Recurrent Layer Class of Neural Network
       8              :  * @see    https://github.com/nnstreamer/nntrainer
       9              :  * @author Jijoong Moon <jijoong.moon@samsung.com>
      10              :  * @bug    No known bugs except for NYI items
      11              :  *
      12              :  */
      13              : 
      14              : #ifndef __RNN_H__
      15              : #define __RNN_H__
      16              : #ifdef __cplusplus
      17              : 
      18              : #include <acti_func.h>
      19              : #include <common_properties.h>
      20              : #include <layer_impl.h>
      21              : 
      22              : namespace nntrainer {
      23              : 
      24              : /**
      25              :  * @class   RNNLayer
      26              :  * @brief   RNNLayer
      27              :  */
      28              : class RNNLayer : public LayerImpl {
      29              : public:
      30              :   /**
      31              :    * @brief     Constructor of RNNLayer
      32              :    */
      33              :   RNNLayer();
      34              : 
      35              :   /**
      36              :    * @brief     Destructor of RNNLayer
      37              :    */
      38           94 :   ~RNNLayer() = default;
      39              : 
      40              :   /**
      41              :    *  @brief  Move constructor.
      42              :    *  @param[in] RNNLayer &&
      43              :    */
      44              :   RNNLayer(RNNLayer &&rhs) noexcept = default;
      45              : 
      46              :   /**
      47              :    * @brief  Move assignment operator.
      48              :    * @parma[in] rhs RNNLayer to be moved.
      49              :    */
      50              :   RNNLayer &operator=(RNNLayer &&rhs) = default;
      51              : 
      52              :   /**
      53              :    * @copydoc Layer::finalize(InitLayerContext &context)
      54              :    */
      55              :   void finalize(InitLayerContext &context) override;
      56              : 
      57              :   /**
      58              :    * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
      59              :    */
      60              :   void forwarding(RunLayerContext &context, bool training) override;
      61              : 
      62              :   /**
      63              :    * @copydoc Layer::calcDerivative(RunLayerContext &context)
      64              :    */
      65              :   void calcDerivative(RunLayerContext &context) override;
      66              : 
      67              :   /**
      68              :    * @copydoc Layer::calcGradient(RunLayerContext &context)
      69              :    */
      70              :   void calcGradient(RunLayerContext &context) override;
      71              : 
      72              :   /**
      73              :    * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
      74              :    * method)
      75              :    */
      76              :   void exportTo(Exporter &exporter,
      77              :                 const ml::train::ExportMethods &method) const override;
      78              : 
      79              :   /**
      80              :    * @copydoc Layer::getType()
      81              :    */
      82         1191 :   const std::string getType() const override { return RNNLayer::type; };
      83              : 
      84              :   /**
      85              :    * @copydoc Layer::supportBackwarding()
      86              :    */
      87           52 :   bool supportBackwarding() const override { return true; }
      88              : 
      89              :   /**
      90              :    * @copydoc Layer::setProperty(const PropertyType type, const std::string
      91              :    * &value)
      92              :    */
      93              :   void setProperty(const std::vector<std::string> &values) override;
      94              : 
      95              :   /**
      96              :    * @copydoc Layer::setBatch(RunLayerContext &context, unsigned int batch)
      97              :    */
      98              :   void setBatch(RunLayerContext &context, unsigned int batch) override;
      99              : 
     100              :   static constexpr const char *type = "rnn";
     101              : 
     102              : private:
     103              :   /**
     104              :    * Unit: number of output neurons
     105              :    * HiddenStateActivation: activation type for hidden state. default is tanh
     106              :    * ReturnSequence: option for return sequence
     107              :    * DropOutRate: dropout rate
     108              :    * IntegrateBias: Integrate bias_ih, bias_hh to bias_h
     109              :    *
     110              :    * */
     111              :   std::tuple<props::Unit, props::HiddenStateActivation, props::ReturnSequences,
     112              :              props::DropOutRate, props::IntegrateBias>
     113              :     rnn_props;
     114              :   std::array<unsigned int, 7> wt_idx; /**< indices of the weights */
     115              : 
     116              :   /**
     117              :    * @brief     activation function for h_t : default is tanh
     118              :    */
     119              :   ActiFunc acti_func;
     120              : 
     121              :   /**
     122              :    * @brief     to pretect overflow
     123              :    */
     124              :   float epsilon;
     125              : };
     126              : } // namespace nntrainer
     127              : 
     128              : #endif /* __cplusplus */
     129              : #endif /* __RNN_H__ */
        

Generated by: LCOV version 2.0-1