-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivation_layer.cpp
51 lines (26 loc) · 1.25 KB
/
activation_layer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <memory>
#include <assert.h>
#include "tensor_forward_wrapper.h"
#include "activation_layer.h"
#include "m_algorithms.h"
// #include "matrix_printer.h"
#include "matrix_benchmark.h"
#include "config.h"
namespace NeuralNetwork {
std::shared_ptr<Computation::Graph::Tensor> NeuralNetwork::ActivationFunctions::ReLU::doForward(std::shared_ptr<Computation::Graph::Tensor> input) noexcept{
assert(input != nullptr && "Matrix has no data (pointing to null).");
Computation::Graph::TensorOp relu(Matrix::Operations::Unary::ReLU{});
std::shared_ptr<Computation::Graph::Tensor> output = relu(input);
// #if DEBUG
// Matrix::Printer m_printer;
// output = m_printer(std::move(output));
// #endif
return output;
}
std::shared_ptr<Computation::Graph::Tensor> NeuralNetwork::ActivationFunctions::SoftMax::doForward(std::shared_ptr<Computation::Graph::Tensor> input) noexcept{
assert(input != nullptr && "Matrix has no data (pointing to null).");
Computation::Graph::TensorOp softmax(Matrix::Operations::Unary::SoftMax{});
std::shared_ptr<Computation::Graph::Tensor> output = softmax(input);
return output;
}
}