|
1 | 1 | #include <vector>
|
2 | 2 |
|
3 | 3 | #include "graph/graph.hpp"
|
4 |
| -#include "graph/graph_transformations.hpp" |
| 4 | +#include "graph_transformations/graph_transformations.hpp" |
5 | 5 | #include "gtest/gtest.h"
|
6 | 6 | #include "layers/EWLayer.hpp"
|
7 | 7 | #include "layers/FCLayer.hpp"
|
@@ -141,5 +141,117 @@ TEST(graph_transformations, check_subgraphs_search) {
|
141 | 141 | subgraph.setInput(fcLayer, input);
|
142 | 142 | subgraph.makeConnection(fcLayer, fcLayer2);
|
143 | 143 |
|
144 |
| - ASSERT_EQ(find_subgraphs(graph, subgraph), std::vector<int>(1, 1)); |
| 144 | + ASSERT_EQ(find_subgraphs(graph, subgraph), std::vector<int>({1})); |
| 145 | +} |
| 146 | + |
| 147 | +TEST(graph_transformations, check_subgraphs_search1) { |
| 148 | + const std::vector<float> vec1 = {2.0F, 1.5F, 0.1F, 1.9F, 0.0F, 5.5F}; |
| 149 | + Tensor weights = make_tensor<float>(vec1, {3, 2}); |
| 150 | + Tensor bias = make_tensor<float>({0.5F, 0.5F, 1.0F}); |
| 151 | + Tensor input = make_tensor<float>({1.0F, 2.0F}, {2}); |
| 152 | + Tensor output; |
| 153 | + |
| 154 | + Graph graph(5); |
| 155 | + Graph subgraph(2); |
| 156 | + FCLayer fcLayer(weights, bias); |
| 157 | + FCLayer fcLayer2(weights, bias); |
| 158 | + FCLayer fcLayer3(weights, bias); |
| 159 | + FCLayer fcLayer4(weights, bias); |
| 160 | + FCLayer fcLayer5(weights, bias); |
| 161 | + |
| 162 | + graph.setInput(fcLayer, input); |
| 163 | + graph.makeConnection(fcLayer, fcLayer2); |
| 164 | + graph.makeConnection(fcLayer2, fcLayer3); |
| 165 | + graph.makeConnection(fcLayer, fcLayer4); |
| 166 | + graph.makeConnection(fcLayer4, fcLayer5); |
| 167 | + graph.setOutput(fcLayer5, output); |
| 168 | + |
| 169 | + subgraph.setInput(fcLayer, input); |
| 170 | + subgraph.makeConnection(fcLayer, fcLayer2); |
| 171 | + |
| 172 | + ASSERT_EQ(find_subgraphs(graph, subgraph), std::vector<int>({1, 3})); |
| 173 | +} |
| 174 | + |
| 175 | +TEST(graph_transformations, check_subgraphs_search2) { |
| 176 | + const std::vector<float> vec1 = {2.0F, 1.5F, 0.1F, 1.9F, 0.0F, 5.5F}; |
| 177 | + Tensor weights = make_tensor<float>(vec1, {3, 2}); |
| 178 | + Tensor bias = make_tensor<float>({0.5F, 0.5F, 1.0F}); |
| 179 | + Tensor input = make_tensor<float>({1.0F, 2.0F}, {2}); |
| 180 | + Tensor output; |
| 181 | + |
| 182 | + Graph graph(5); |
| 183 | + Graph subgraph(2); |
| 184 | + FCLayer fcLayer(weights, bias); |
| 185 | + FCLayer fcLayer2(weights, bias); |
| 186 | + FCLayer fcLayer3(weights, bias); |
| 187 | + FCLayer fcLayer4(weights, bias); |
| 188 | + |
| 189 | + graph.setInput(fcLayer, input); |
| 190 | + graph.makeConnection(fcLayer, fcLayer2); |
| 191 | + graph.makeConnection(fcLayer2, fcLayer3); |
| 192 | + graph.makeConnection(fcLayer3, fcLayer); |
| 193 | + graph.makeConnection(fcLayer3, fcLayer4); |
| 194 | + graph.setOutput(fcLayer4, output); |
| 195 | + |
| 196 | + subgraph.setInput(fcLayer, input); |
| 197 | + subgraph.makeConnection(fcLayer, fcLayer2); |
| 198 | + subgraph.makeConnection(fcLayer2, fcLayer3); |
| 199 | + |
| 200 | + ASSERT_EQ(find_subgraphs(graph, subgraph), std::vector<int>({0})); |
| 201 | +} |
| 202 | + |
| 203 | +TEST(graph_transformations, check_subgraphs_search3) { |
| 204 | + const std::vector<float> vec1 = {2.0F, 1.5F, 0.1F, 1.9F, 0.0F, 5.5F}; |
| 205 | + Tensor weights = make_tensor<float>(vec1, {3, 2}); |
| 206 | + Tensor bias = make_tensor<float>({0.5F, 0.5F, 1.0F}); |
| 207 | + Tensor input = make_tensor<float>({1.0F, 2.0F}, {2}); |
| 208 | + Tensor output; |
| 209 | + |
| 210 | + Graph graph(5); |
| 211 | + Graph subgraph(2); |
| 212 | + FCLayer fcLayer(weights, bias); |
| 213 | + FCLayer fcLayer2(weights, bias); |
| 214 | + FCLayer fcLayer3(weights, bias); |
| 215 | + FCLayer fcLayer4(weights, bias); |
| 216 | + |
| 217 | + graph.setInput(fcLayer, input); |
| 218 | + graph.makeConnection(fcLayer, fcLayer2); |
| 219 | + graph.makeConnection(fcLayer2, fcLayer3); |
| 220 | + graph.makeConnection(fcLayer3, fcLayer); |
| 221 | + graph.makeConnection(fcLayer2, fcLayer4); |
| 222 | + graph.setOutput(fcLayer4, output); |
| 223 | + |
| 224 | + subgraph.setInput(fcLayer, input); |
| 225 | + subgraph.makeConnection(fcLayer, fcLayer2); |
| 226 | + subgraph.makeConnection(fcLayer2, fcLayer3); |
| 227 | + |
| 228 | + ASSERT_EQ(find_subgraphs(graph, subgraph), std::vector<int>({2})); |
| 229 | +} |
| 230 | + |
| 231 | +TEST(graph_transformations, check_subgraphs_search4) { |
| 232 | + const std::vector<float> vec1 = {2.0F, 1.5F, 0.1F, 1.9F, 0.0F, 5.5F}; |
| 233 | + Tensor weights = make_tensor<float>(vec1, {3, 2}); |
| 234 | + Tensor bias = make_tensor<float>({0.5F, 0.5F, 1.0F}); |
| 235 | + Tensor input = make_tensor<float>({1.0F, 2.0F}, {2}); |
| 236 | + Tensor output; |
| 237 | + |
| 238 | + Graph graph(5); |
| 239 | + Graph subgraph(2); |
| 240 | + FCLayer fcLayer(weights, bias); |
| 241 | + FCLayer fcLayer2(weights, bias); |
| 242 | + FCLayer fcLayer3(weights, bias); |
| 243 | + FCLayer fcLayer4(weights, bias); |
| 244 | + |
| 245 | + graph.setInput(fcLayer, input); |
| 246 | + graph.makeConnection(fcLayer, fcLayer2); |
| 247 | + graph.makeConnection(fcLayer2, fcLayer3); |
| 248 | + graph.makeConnection(fcLayer3, fcLayer); |
| 249 | + graph.makeConnection(fcLayer, fcLayer4); |
| 250 | + graph.setOutput(fcLayer4, output); |
| 251 | + |
| 252 | + subgraph.setInput(fcLayer, input); |
| 253 | + subgraph.makeConnection(fcLayer, fcLayer2); |
| 254 | + subgraph.makeConnection(fcLayer2, fcLayer3); |
| 255 | + |
| 256 | + ASSERT_EQ(find_subgraphs(graph, subgraph), std::vector<int>({1})); |
145 | 257 | }
|
0 commit comments