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