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

            Line data    Source code
       1              : 
       2              : // SPDX-License-Identifier: Apache-2.0
       3              : /**
       4              :  * Copyright (C) 2021 Jihoon Lee <jhoon.it.lee@samsung.com>
       5              :  *
       6              :  * @file   permute_layer.h
       7              :  * @date   06 May 2021
       8              :  * @brief  Permute layer to support transpose
       9              :  * @see    https://github.com/nnstreamer/nntrainer
      10              :  * @author Jihoon Lee <jhoon.it.lee@samsung.com>
      11              :  * @bug    No known bugs except for NYI items
      12              :  */
      13              : 
      14              : #ifndef __PERMUTE_LAYER_H__
      15              : #define __PERMUTE_LAYER_H__
      16              : 
      17              : #include <array>
      18              : #include <string>
      19              : 
      20              : #include <base_properties.h>
      21              : #include <layer_devel.h>
      22              : 
      23              : namespace nntrainer {
      24              : 
      25              : namespace props {
      26              : /**
      27              :  * @brief PermuteDims property, direction property describes the axis to be
      28              :  * transposed. to be used with array
      29              :  *
      30              :  */
      31          232 : class PermuteDims : public nntrainer::Property<unsigned int> {
      32              : public:
      33              :   static constexpr const char *key = "direction"; /**< unique key to access */
      34              :   using prop_tag = uint_prop_tag;                 /**< property type */
      35              : 
      36              :   /**
      37              :    * @brief check if given value is valid
      38              :    *
      39              :    * @return true if valid
      40              :    * @return false if not valid
      41              :    */
      42              :   bool isValid(const unsigned int &) const override;
      43              : };
      44              : } // namespace props
      45              : 
      46              : /**
      47              :  * @class   PermuteLayer
      48              :  * @brief   Permute layer to transpose a tensor
      49              :  */
      50              : class PermuteLayer : public Layer {
      51              : public:
      52              :   /**
      53              :    * @brief     Constructor of Permute Layer
      54              :    * @param     direction direction to permute
      55              :    */
      56           66 :   PermuteLayer() : Layer(), direction(), reverse_direction() {}
      57              : 
      58              :   /**
      59              :    * @brief     Destructor of Permute Layer
      60              :    */
      61           99 :   ~PermuteLayer() = default;
      62              : 
      63              :   /**
      64              :    *  @brief  Move constructor.
      65              :    *  @param[in] PermuteLayer &&
      66              :    */
      67              :   PermuteLayer(PermuteLayer &&rhs) noexcept = default;
      68              : 
      69              :   /**
      70              :    * @brief  Move assignment operator.
      71              :    * @param[in] rhs PermuteLayer to be moved.
      72              :    */
      73              :   PermuteLayer &operator=(PermuteLayer &&rhs) = default;
      74              : 
      75              :   /**
      76              :    * @copydoc Layer::finalize(InitLayerContext &context)
      77              :    */
      78              :   void finalize(InitLayerContext &context) override;
      79              : 
      80              :   /**
      81              :    * @copydoc Layer::forwarding(RunLayerContext &context, bool training)
      82              :    */
      83              :   void forwarding(RunLayerContext &context, bool training) override;
      84              : 
      85              :   /**
      86              :    * @copydoc Layer::calcDerivative(RunLayerContext &context)
      87              :    */
      88              :   void calcDerivative(RunLayerContext &context) override;
      89              : 
      90              :   /**
      91              :    * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
      92              :    * method)
      93              :    */
      94              :   void exportTo(Exporter &exporter,
      95              :                 const ml::train::ExportMethods &method) const override;
      96              : 
      97              :   /**
      98              :    * @copydoc Layer::getType()
      99              :    */
     100           31 :   const std::string getType() const override { return PermuteLayer::type; };
     101              : 
     102              :   /**
     103              :    * @copydoc Layer::supportBackwarding()
     104              :    */
     105            2 :   bool supportBackwarding() const override { return true; }
     106              : 
     107              :   /**
     108              :    * @copydoc Layer::setProperty(const std::vector<std::string> &values)
     109              :    */
     110              :   void setProperty(const std::vector<std::string> &values) override;
     111              : 
     112              :   static constexpr const char *type = "permute";
     113              : 
     114              : private:
     115              :   std::string
     116              :     direction_str; /**< transpose representation, @todo deprecate this */
     117              :   std::string rdirection_str; /**< transpose representation, @todo
     118              :                                         deprecate this */
     119              : 
     120              :   std::array<props::PermuteDims, 3> direction;
     121              :   std::array<props::PermuteDims, 3> reverse_direction;
     122              : };
     123              : 
     124              : } // namespace nntrainer
     125              : #endif // __PERMUTE_LAYER_H__
        

Generated by: LCOV version 2.0-1