-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_object_factory.cpp
190 lines (126 loc) · 6.53 KB
/
function_object_factory.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "function_object_factory.h"
#include "function_object.h"
#include "computational_graph_map.h"
#include "tensor.h"
#include <optional>
namespace NeuralNetwork {
namespace Computation {
namespace Graph {
// std::optional<FunctionObject> DereferenceRegistry::from(RegisteredOperation _op) {
// if (_op.get_tensor_id() == TensorID(0)) return {};
// ComputationalGraphMap& map = ComputationalGraphMap::get();
// return map._get_tensor(_op.get_tensor_id());
// }
// void OperationFactory::create(
// const Matrix::Operations::Code _typ, T _res,
// TensorID _op, TensorID _op2) {
// ComputationalGraphMap& map = ComputationalGraphMap::get();
// auto op = RegisteredOperation(
// _typ,
// _res->get_tensor_id(),
// _op,
// _op2
// );
// TensorID tensor_id = map._register_operation(_res, op);
// op.result = tensor_id;
// }
/*
Creates a Function Object signifying NOP expression.
*/
FunctionObject FunctionObjectFactory::create(T _res) {
ComputationalGraphMap& map = ComputationalGraphMap::get();
auto tensor_identification = _res->get_tensor_id();
auto fn_object = FunctionObject(
RegisteredTensor(tensor_identification)
);
map._register_operation(_res, fn_object);
return fn_object;
}
/*
1) access _res NOP
2) create Instantiate based on operation
3) fill step 2 with TensorID of operands
4)
*/
template <Matrix::Operations::BinaryMatrixOperatable RegisteryType>
FunctionObject FunctionObjectFactory::create(
RegisteryType operation, T _res,
TensorID _operand_id, TensorID _operand_id_two) {
ComputationalGraphMap& map = ComputationalGraphMap::get();
auto res_tensor_id = _res->get_tensor_id();
auto fn_object = FunctionObject();
auto binaryRegistry = States::BinaryRegistered(
RegisteredBinaryOperation(res_tensor_id,
_operand_id, _operand_id_two)
);
auto instantiate_event = Events::Instantiate(operation, binaryRegistry);
fn_object.process_event(instantiate_event);
fn_object.stringify_type();
// transition _res default NOP state to unary-state
// update computational graph OP state
map._register_operation(_res, fn_object);
return fn_object;
}
template <Matrix::Operations::UnaryMatrixOperatable RegisteryType>
FunctionObject FunctionObjectFactory::create(
RegisteryType operation, T _res, TensorID _operand_id) {
ComputationalGraphMap& map = ComputationalGraphMap::get();
auto res_tensor_id = _res->get_tensor_id();
auto fn_object = FunctionObject();
auto unaryRegistry = States::UnaryRegistered(
RegisteredUnaryOperation(res_tensor_id, _operand_id)
);
auto instantiate_event = Events::Instantiate(operation, unaryRegistry);
fn_object.process_event(instantiate_event);
fn_object.stringify_type();
// transition _res default NOP state to unary-state
// update computational ~graph OP state
map._register_operation(_res, fn_object);
return fn_object;
}
template FunctionObject FunctionObjectFactory::create<Matrix::Operations::Unary::ReLU>(
Matrix::Operations::Unary::ReLU operation,
T _res,
TensorID _operand_id);
template FunctionObject FunctionObjectFactory::create<Matrix::Operations::Unary::SoftMax>(
Matrix::Operations::Unary::SoftMax operation,
T _res,
TensorID _operand_id);
template FunctionObject FunctionObjectFactory::create<Matrix::Operations::Binary::HadamardProduct::Std>(
Matrix::Operations::Binary::HadamardProduct::Std operation,
T _res,
TensorID _operand_id,
TensorID _operand_id_two);
template FunctionObject FunctionObjectFactory::create<Matrix::Operations::Binary::Multiplication::ParallelDNC>(
Matrix::Operations::Binary::Multiplication::ParallelDNC operation,
T _res,
TensorID _operand_id,
TensorID _operand_id_two);
template FunctionObject FunctionObjectFactory::create<Matrix::Operations::Binary::Multiplication::Naive>(
Matrix::Operations::Binary::Multiplication::Naive operation,
T _res,
TensorID _operand_id,
TensorID _operand_id_two);
template FunctionObject FunctionObjectFactory::create<Matrix::Operations::Binary::Multiplication::Square>(
Matrix::Operations::Binary::Multiplication::Square operation,
T _res,
TensorID _operand_id,
TensorID _operand_id_two);
template FunctionObject FunctionObjectFactory::create<Matrix::Operations::Binary::Addition::Std>(
Matrix::Operations::Binary::Addition::Std operation,
T _res,
TensorID _operand_id,
TensorID _operand_id_two);
template FunctionObject FunctionObjectFactory::create<Matrix::Operations::Binary::OuterProduct::Naive>(
Matrix::Operations::Binary::OuterProduct::Naive operation,
T _res,
TensorID _operand_id,
TensorID _operand_id_two);
template FunctionObject FunctionObjectFactory::create<Matrix::Operations::Metric::CrossEntropy>(
Matrix::Operations::Metric::CrossEntropy operation,
T _res,
TensorID _operand_id,
TensorID _operand_id_two);
}
}
}