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 slice_layer.h
6 : * @date 07 April 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 slice layer class (operation layer)
11 : */
12 :
13 : #ifndef __SLICE_LAYER_H__
14 : #define __SLICE_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 Slice Layer
25 : * @brief Slice Layer
26 : */
27 : class SliceLayer : public UnaryOperationLayer {
28 : public:
29 : /**
30 : * @brief Constructor of Slice Layer
31 : */
32 0 : SliceLayer() :
33 : UnaryOperationLayer(),
34 0 : slice_props(props::Print(), props::StartIndex(), props::EndIndex(),
35 0 : props::Axis()),
36 0 : support_backwarding(true) {}
37 :
38 : /**
39 : * @brief Destructor of Slice Layer
40 : */
41 0 : ~SliceLayer(){};
42 :
43 : /**
44 : * @brief Move constructor of Slice Layer.
45 : * @param[in] SliceLayer &&
46 : */
47 : SliceLayer(SliceLayer &&rhs) noexcept = default;
48 :
49 : /**
50 : * @brief Move assignment operator.
51 : * @parma[in] rhs SliceLayer to be moved.
52 : */
53 : SliceLayer &operator=(SliceLayer &&rhs) = default;
54 :
55 : /**
56 : * @copydoc Layer::finalize(InitLayerContext &context)
57 : */
58 : void finalize(InitLayerContext &context) final;
59 :
60 : /**
61 : * @brief forwarding operation for slice
62 : *
63 : * @param input tensor to be sliced from
64 : * @param hidden tensor to store the result value
65 : */
66 : void forwarding_operation(const Tensor &input, Tensor &hidden) final;
67 :
68 : /**
69 : * @copydoc Layer::calcDerivative(RunLayerContext &context)
70 : */
71 : void calcDerivative(RunLayerContext &context) final;
72 :
73 : /**
74 : * @copydoc bool supportBackwarding() const
75 : */
76 0 : bool supportBackwarding() const final { return support_backwarding; };
77 :
78 : /**
79 : * @copydoc Layer::exportTo(Exporter &exporter, ml::train::ExportMethods
80 : * method)
81 : */
82 0 : void exportTo(Exporter &exporter,
83 0 : const ml::train::ExportMethods &method) const final {}
84 :
85 : /**
86 : * @copydoc Layer::setProperty(const std::vector<std::string> &values)
87 : */
88 : void setProperty(const std::vector<std::string> &values) final;
89 :
90 : /**
91 : * @copydoc Layer::getType()
92 : */
93 0 : const std::string getType() const final { return SliceLayer::type; };
94 :
95 : std::tuple<props::Print, props::StartIndex, props::EndIndex, props::Axis>
96 : slice_props;
97 :
98 : inline static const std::string type = "slice";
99 : bool support_backwarding;
100 : unsigned int axis;
101 : unsigned int start;
102 : // TensorDim starts;
103 : };
104 :
105 : } // namespace nntrainer
106 :
107 : #endif /* __cplusplus */
108 : #endif /* __SLICE_LAYER_H__ */
|