LCOV - code coverage report
Current view: top level - nntrainer/layers - cosine_layer.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 85.7 % 14 12
Test Date: 2025-12-14 20:38:17 Functions: 83.3 % 6 5

            Line data    Source code
       1              : // SPDX-License-Identifier: Apache-2.0
       2              : /**
       3              :  * Copyright (C) 2025 SeungBaek Hong <sb92.hong@samsung.com>
       4              :  *
       5              :  * @file   cosine_layer.h
       6              :  * @date   19 March 2025
       7              :  * @see    https://github.com/nnstreamer/nntrainer
       8              :  * @author SeungBaek Hong <sb92.hong@samsung.com>
       9              :  * @bug    No known bugs except for NYI items
      10              :  * @brief  This is cosine layer class (operation layer)
      11              :  */
      12              : 
      13              : #ifndef __COSINE_LAYER_H__
      14              : #define __COSINE_LAYER_H__
      15              : #ifdef __cplusplus
      16              : 
      17              : #include <common_properties.h>
      18              : #include <layer_devel.h>
      19              : #include <operation_layer.h>
      20              : 
      21              : namespace nntrainer {
      22              : 
      23              : /**
      24              :  * @class Cosine Layer
      25              :  * @brief Cosine Layer
      26              :  */
      27              : class CosineLayer : public UnaryOperationLayer {
      28              : public:
      29              :   /**
      30              :    * @brief Constructor of Cosine Layer
      31              :    */
      32           40 :   CosineLayer() :
      33              :     UnaryOperationLayer(),
      34           80 :     cosine_props(props::Print(), props::InPlaceProp()),
      35           40 :     support_backwarding(true) {}
      36              : 
      37              :   /**
      38              :    * @brief Destructor of Cosine Layer
      39              :    */
      40           40 :   ~CosineLayer(){};
      41              : 
      42              :   /**
      43              :    *  @brief  Move constructor of Cosine Layer.
      44              :    *  @param[in] CosineLayer &&
      45              :    */
      46              :   CosineLayer(CosineLayer &&rhs) noexcept = default;
      47              : 
      48              :   /**
      49              :    * @brief  Move assignment operator.
      50              :    * @parma[in] rhs CosineLayer to be moved.
      51              :    */
      52              :   CosineLayer &operator=(CosineLayer &&rhs) = default;
      53              : 
      54              :   /**
      55              :    * @copydoc Layer::finalize(InitLayerContext &context)
      56              :    */
      57              :   void finalize(InitLayerContext &context) final;
      58              : 
      59              :   /**
      60              :    * @brief forwarding operation for cosine
      61              :    *
      62              :    * @param input input tensor
      63              :    * @param hidden tensor to store the result value
      64              :    */
      65              :   void forwarding_operation(const Tensor &input, Tensor &hidden) final;
      66              : 
      67              :   /**
      68              :    * @copydoc Layer::calcDerivative(RunLayerContext &context)
      69              :    */
      70              :   void calcDerivative(RunLayerContext &context) final;
      71              : 
      72              :   /**
      73              :    * @copydoc bool supportBackwarding() const
      74              :    */
      75           14 :   bool supportBackwarding() const final { return support_backwarding; };
      76              : 
      77              :   /**
      78              :    * @brief Initialize the in-place settings of the layer
      79              :    * @return InPlaceType
      80              :    */
      81            2 :   InPlaceType initializeInPlace() final {
      82            2 :     is_inplace = !std::get<props::InPlaceProp>(cosine_props).empty() &&
      83            0 :                  std::get<props::InPlaceProp>(cosine_props).get();
      84            2 :     support_backwarding = !is_inplace;
      85              : 
      86            2 :     if (!supportInPlace())
      87              :       return InPlaceType::NONE;
      88              :     else
      89            0 :       return InPlaceType::NON_RESTRICTING;
      90              :   }
      91              : 
      92              :   /**
      93              :    * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
      94              :    * method)
      95              :    */
      96            2 :   void exportTo(Exporter &exporter,
      97            2 :                 const ml::train::ExportMethods &method) const final {}
      98              : 
      99              :   /**
     100              :    * @copydoc Layer::setProperty(const std::vector<std::string> &values)
     101              :    */
     102              :   void setProperty(const std::vector<std::string> &values) final;
     103              : 
     104              :   /**
     105              :    * @copydoc Layer::getType()
     106              :    */
     107          130 :   const std::string getType() const final { return CosineLayer::type; };
     108              : 
     109              :   std::tuple<props::Print, props::InPlaceProp> cosine_props;
     110              :   bool support_backwarding; /**< support backwarding */
     111              : 
     112              :   inline static const std::string type = "cos";
     113              : };
     114              : 
     115              : } // namespace nntrainer
     116              : 
     117              : #endif /* __cplusplus */
     118              : #endif /* __COSINE_LAYER_H__ */
        

Generated by: LCOV version 2.0-1