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 sqrt_layer.cpp
6 : * @date 18 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 sqrt layer class (operation layer)
11 : *
12 : */
13 :
14 : #include "common_properties.h"
15 : #include <nntrainer_error.h>
16 : #include <nntrainer_log.h>
17 : #include <node_exporter.h>
18 : #include <sqrt_layer.h>
19 : #include <util_func.h>
20 :
21 : #include <layer_context.h>
22 :
23 : namespace nntrainer {
24 :
25 12 : void SQRTLayer::finalize(InitLayerContext &context) {
26 12 : context.setOutputDimensions({context.getInputDimensions()[0]});
27 12 : }
28 :
29 6 : void SQRTLayer::forwarding_operation(const Tensor &input, Tensor &hidden) {
30 6 : input.sqrt(hidden);
31 6 : }
32 :
33 3 : void SQRTLayer::calcDerivative(RunLayerContext &context) {
34 3 : context.getIncomingDerivative(SINGLE_INOUT_IDX)
35 6 : .multiply(0.5)
36 6 : .multiply(context.getInput(SINGLE_INOUT_IDX)
37 6 : .inv_sqrt(context.getOutgoingDerivative(SINGLE_INOUT_IDX)));
38 3 : }
39 :
40 88 : void SQRTLayer::setProperty(const std::vector<std::string> &values) {
41 88 : auto remain_props = loadProperties(values, sqrt_props);
42 86 : if (!remain_props.empty()) {
43 : std::string msg = "[SQRTLayer] Unknown Layer Properties count " +
44 4 : std::to_string(values.size());
45 8 : throw exception::not_supported(msg);
46 : }
47 86 : }
48 : } /* namespace nntrainer */
|