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