Line data Source code
1 : // SPDX-License-Identifier: Apache-2.0
2 : /**
3 : * Copyright (C) 2021 Jihoon Lee <jhoon.it.lee@samsung.com>
4 : *
5 : * @file identity.cpp
6 : * @date 16 Dec 2021
7 : * @brief This is identity layer flows everything as it is
8 : * @see https://github.com/nnstreamer/nntrainer
9 : * @author Jihoon Lee <jhoon.it.lee@samsung.com>
10 : * @bug No known bugs except for NYI items
11 : *
12 : */
13 : #include <identity_layer.h>
14 : #include <layer_context.h>
15 : #include <nntrainer_error.h>
16 : #include <stdexcept>
17 : #include <tensor.h>
18 :
19 : namespace nntrainer {
20 144 : IdentityLayer::IdentityLayer() {}
21 :
22 288 : IdentityLayer::~IdentityLayer() {}
23 :
24 103 : void IdentityLayer::finalize(InitLayerContext &context) {
25 103 : context.setOutputDimensions(context.getInputDimensions());
26 103 : }
27 :
28 150 : void IdentityLayer::forwarding(RunLayerContext &context, bool training) {
29 150 : if (!context.getInPlace()) {
30 300 : for (unsigned int i = 0, sz = context.getNumInputs(); i < sz; ++i) {
31 150 : Tensor &input_ = context.getInput(i);
32 150 : Tensor &hidden_ = context.getOutput(i);
33 150 : hidden_.copyData(input_);
34 : }
35 : }
36 150 : }
37 :
38 75 : void IdentityLayer::calcDerivative(RunLayerContext &context) {
39 75 : if (!context.getInPlace()) {
40 150 : for (unsigned int i = 0, sz = context.getNumInputs(); i < sz; ++i) {
41 75 : const Tensor &d_hidden = context.getIncomingDerivative(i);
42 75 : Tensor &d_input = context.getOutgoingDerivative(i);
43 75 : d_input.copyData(d_hidden);
44 75 : }
45 : }
46 75 : }
47 :
48 647 : void IdentityLayer::setProperty(const std::vector<std::string> &values) {
49 647 : NNTR_THROW_IF(values.size(), std::invalid_argument)
50 : << "Identity layer has left unparsed properties";
51 647 : }
52 : } // namespace nntrainer
|