-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathModule.cpp
More file actions
62 lines (54 loc) · 1.51 KB
/
Module.cpp
File metadata and controls
62 lines (54 loc) · 1.51 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************
* Copyright (c) 2017, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <af/nn/Modules/Module.hpp>
namespace af
{
namespace nn
{
using autograd::Variable;
Module::Module() :
m_parameters()
{
m_train = false;
}
Module::Module(const std::vector<Variable> ¶meters) :
m_parameters(parameters.begin(), parameters.end())
{
}
void Module::setParams(const std::vector<Variable> ¶meters)
{
m_parameters.clear();
for(auto parameter : parameters) {
m_parameters.push_back(parameter);
}
}
void Module::train()
{
m_train = true;
for (auto ¶meter : m_parameters) {
parameter.setCalcGrad(true);
}
}
void Module::eval()
{
m_train = false;
for (auto ¶meter : m_parameters) {
parameter.setCalcGrad(false);
}
}
std::vector<Variable> Module::parameters()
{
return m_parameters;
}
Variable Module::operator()(const Variable &input)
{
return this->forward(input);
}
}
}