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

            Line data    Source code
       1              : // SPDX-License-Identifier: Apache-2.0
       2              : /**
       3              :  * Copyright (C) 2024 SeungBaek Hong <sb92.hong@samsung.com>
       4              :  *
       5              :  * @file   multiply_layer.h
       6              :  * @date   10 Oct 2024
       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 mul layer class (operation layer)
      11              :  *
      12              :  */
      13              : 
      14              : #ifndef __MULTIPLY_LAYER_H__
      15              : #define __MULTIPLY_LAYER_H__
      16              : #ifdef __cplusplus
      17              : 
      18              : #include <common_properties.h>
      19              : #include <layer_devel.h>
      20              : #include <operation_layer.h>
      21              : 
      22              : namespace nntrainer {
      23              : 
      24              : /**
      25              :  * @class Multiply Layer
      26              :  * @brief Multiply Layer
      27              :  */
      28              : class MultiplyLayer : public BinaryOperationLayer {
      29              : public:
      30              :   /**
      31              :    * @brief Constructor of Multiply Layer
      32              :    */
      33           41 :   MultiplyLayer() :
      34              :     BinaryOperationLayer(),
      35           41 :     multiply_props(props::Print(), props::InPlaceProp(),
      36           41 :                    props::InPlaceDirectionProp()),
      37           82 :     support_backwarding(true) {}
      38              : 
      39              :   /**
      40              :    * @brief Destructor of Multiply Layer
      41              :    */
      42           41 :   ~MultiplyLayer(){};
      43              : 
      44              :   /**
      45              :    *  @brief  Move constructor of Multiply Layer.
      46              :    *  @param[in] MultiplyLayer &&
      47              :    */
      48              :   MultiplyLayer(MultiplyLayer &&rhs) noexcept = default;
      49              : 
      50              :   /**
      51              :    * @brief  Move assignment operator.
      52              :    * @parma[in] rhs MultiplyLayer to be moved.
      53              :    */
      54              :   MultiplyLayer &operator=(MultiplyLayer &&rhs) = default;
      55              : 
      56              :   /**
      57              :    * @copydoc Layer::finalize(InitLayerContext &context)
      58              :    */
      59              :   void finalize(InitLayerContext &context) final;
      60              : 
      61              :   /**
      62              :    * @brief forwarding operation for add
      63              :    *
      64              :    * @param input0 input tensor 0
      65              :    * @param input1 input tensor 1
      66              :    * @param hidden tensor to store the result of addition
      67              :    */
      68              :   void forwarding_operation(const Tensor &input0, const Tensor &input1,
      69              :                             Tensor &hidden) final;
      70              : 
      71              :   /**
      72              :    * @copydoc Layer::calcDerivative(RunLayerContext &context)
      73              :    */
      74              :   void calcDerivative(RunLayerContext &context) final;
      75              : 
      76              :   /**
      77              :    * @copydoc bool supportBackwarding()
      78              :    */
      79           14 :   bool supportBackwarding() const final { return support_backwarding; };
      80              : 
      81              :   /**
      82              :    * @brief Get the inplace direction for the tensor operation layer
      83              :    *
      84              :    * @return InPlaceDirection
      85              :    */
      86            0 :   InPlaceDirection getInPlaceDirection() override {
      87            0 :     if (!supportInPlace())
      88              :       return InPlaceDirection::NONE;
      89            0 :     if (std::get<props::InPlaceDirectionProp>(multiply_props).empty() ||
      90            0 :         (std::get<props::InPlaceDirectionProp>(multiply_props).get() ==
      91              :          "left")) {
      92            0 :       return InPlaceDirection::LEFT;
      93              :     } else {
      94              :       return InPlaceDirection::RIGHT;
      95              :     }
      96              :   };
      97              : 
      98              :   /**
      99              :    * @brief Initialize the in-place settings of the layer
     100              :    * @return InPlaceType
     101              :    */
     102            2 :   InPlaceType initializeInPlace() final {
     103            2 :     if (std::get<props::InPlaceProp>(multiply_props).empty() ||
     104            0 :         !std::get<props::InPlaceProp>(multiply_props).get()) {
     105            2 :       is_inplace = false;
     106            2 :       support_backwarding = true;
     107              :     } else {
     108            0 :       is_inplace = true;
     109            0 :       support_backwarding = false;
     110              :     }
     111              : 
     112            2 :     if (!supportInPlace())
     113              :       return InPlaceType::NONE;
     114              :     else
     115            0 :       return InPlaceType::NON_RESTRICTING;
     116              :   }
     117              : 
     118              :   /**
     119              :    * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
     120              :    * method)
     121              :    */
     122            2 :   void exportTo(Exporter &exporter,
     123            2 :                 const ml::train::ExportMethods &method) const final {}
     124              : 
     125              :   /**
     126              :    * @copydoc Layer::setProperty(const std::vector<std::string> &values)
     127              :    */
     128              :   void setProperty(const std::vector<std::string> &values) final;
     129              : 
     130              :   /**
     131              :    * @copydoc Layer::getType()
     132              :    */
     133          133 :   const std::string getType() const final { return MultiplyLayer::type; };
     134              : 
     135              :   std::tuple<props::Print, props::InPlaceProp, props::InPlaceDirectionProp>
     136              :     multiply_props;
     137              :   bool support_backwarding; /**< support backwarding */
     138              : 
     139              :   static constexpr const char *type = "multiply";
     140              : };
     141              : 
     142              : } // namespace nntrainer
     143              : 
     144              : #endif /* __cplusplus */
     145              : #endif /* __MULTIPLY_LAYER_H__ */
        

Generated by: LCOV version 2.0-1