Skip to content
This repository was archived by the owner on Jul 22, 2026. It is now read-only.

Commit cebf82c

Browse files
author
NeiroYT
committed
Tidy
1 parent a0b4d7f commit cebf82c

6 files changed

Lines changed: 82 additions & 13 deletions

File tree

app/Graph/onnx_subgraphs.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ using namespace it_lab_ai;
1616

1717
void alexnet_inf_careless(Graph& graph, const RuntimeOptions& options,
1818
Tensor& input, Tensor& output) {
19-
Tensor* o = new Tensor(output);
20-
Tensor* i = new Tensor(input);
19+
auto* o = new Tensor(output);
20+
auto* i = new Tensor(input);
2121
graph.inference(options);
2222
graph.setOutput(*o);
2323
graph.setInput(*i);
@@ -28,7 +28,7 @@ void alexnet_comparison() {
2828
891, 957, 1027, 973, 1008};
2929
size_t sum = std::accumulate(counts.begin(), counts.end(), size_t{0});
3030
int count_pic = static_cast<int>(sum) + 10;
31-
std::vector<float> res(count_pic * 28 * 28, 1.0f);
31+
std::vector<float> res(count_pic * 28 * 28, 1.0F);
3232
Tensor input;
3333
Shape sh1({1, 5, 5, 3});
3434
std::vector<float> vec;
@@ -43,21 +43,21 @@ void alexnet_comparison() {
4343
input = t;
4444

4545
RuntimeOptions options;
46-
Graph graph1;
46+
Graph graph;
4747
Graph graph2;
48-
build_graph_linear(graph1, input, output, options, true);
48+
build_graph_linear(graph, input, output, options, true);
4949
Graph subgraph;
5050
std::shared_ptr<Layer> layer_0 = std::make_shared<ConvolutionalLayer>();
5151
std::shared_ptr<Layer> layer_1 = std::make_shared<EWLayer>("relu");
5252
subgraph.setInput(layer_0, input);
5353
subgraph.makeConnection(layer_0, layer_1);
5454
std::shared_ptr<Layer> layer_to = std::make_shared<ConvReluLayer>(
5555
std::dynamic_pointer_cast<ConvolutionalLayer>(layer_0));
56-
changed_subgraphs(graph1, subgraph, layer_to, graph2, input, options);
56+
changed_subgraphs(graph, subgraph, layer_to, graph2, input, options);
5757
Tensor input_c = input;
5858
Tensor output_c = output;
5959
double time1 = elapsed_time_avg<double, std::milli>(
60-
2, alexnet_inf_careless, graph1, options, input_c, output_c);
60+
2, alexnet_inf_careless, graph, options, input_c, output_c);
6161
double time2 = elapsed_time_avg<double, std::milli>(
6262
2, alexnet_inf_careless, graph2, options, input_c, output_c);
6363
std::cout << time1 << " for unchanged graph\n";
@@ -74,7 +74,7 @@ int main() {
7474
build_graph(graph1, input, input, MODEL_PATH_DENSENET_ONNX, options, false);
7575

7676
Graph subgraph;
77-
Tensor scale = make_tensor(std::vector<float>({1.0}));
77+
Tensor scale = make_tensor(std::vector<float>({1.0F}));
7878
std::shared_ptr<Layer> layer_0 =
7979
std::make_shared<BatchNormalizationLayer>(scale, scale, scale, scale);
8080
std::shared_ptr<Layer> layer_1 = std::make_shared<EWLayer>("relu");

include/layers/ConvLayer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ class ConvolutionalLayer : public Layer {
5959
useLegacyImpl_ = useLegacyImpl;
6060
}
6161

62-
std::vector<size_t> get_numeric_params() {
62+
std::vector<size_t> getNumericParams() const {
6363
std::vector<size_t> res = {stride_, pads_, dilations_, group_};
6464
return res;
6565
}
6666

67-
std::vector<std::shared_ptr<Tensor>> get_tensor_params() {
67+
std::vector<std::shared_ptr<Tensor>> getTensorParams() {
6868
std::vector<std::shared_ptr<Tensor>> res = {kernel_, bias_};
6969
return res;
7070
}
7171

72-
bool getLegacyImplBool() { return useLegacyImpl_; }
72+
bool getLegacyImplBool() const { return useLegacyImpl_; }
7373

7474
void run(const std::vector<Tensor>& input,
7575
std::vector<Tensor>& output) override;

include/layers_fused/ConvRelu.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ class ConvReluLayer : public Layer {
6161
}
6262
ConvReluLayer(const std::shared_ptr<ConvolutionalLayer>& conv)
6363
: Layer(kConvRelu) {
64-
auto numerics = conv->get_numeric_params();
65-
auto tensors = conv->get_tensor_params();
64+
auto numerics = conv->getNumericParams();
65+
auto tensors = conv->getTensorParams();
6666
stride_ = numerics[0];
6767
pads_ = numerics[1];
6868
dilations_ = numerics[2];

test/graph/test_graph.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,44 @@
3232

3333
using namespace it_lab_ai;
3434

35+
TEST(graph, test_new_setInput) {
36+
const std::vector<float> vec1 = {2.0F, 1.5F, 0.1F, 1.9F, 0.0F, 5.5F};
37+
Tensor weights = make_tensor<float>(vec1, {3, 2});
38+
Tensor bias = make_tensor<float>({0.5F, 0.5F, 1.0F});
39+
Tensor input = make_tensor<float>({1.0F, 2.0F}, {2});
40+
Tensor output;
41+
Graph graph;
42+
43+
auto fcLayer = std::make_shared<FCLayer>(weights, bias);
44+
auto inputLayer = std::make_shared<InputLayer>();
45+
auto ewLayer = std::make_shared<EWLayer>();
46+
47+
graph.addSingleLayer(inputLayer);
48+
graph.makeConnection(inputLayer, fcLayer);
49+
graph.makeConnection(fcLayer, ewLayer);
50+
51+
ASSERT_NO_THROW(graph.setInput(input));
52+
}
53+
54+
TEST(graph, test_new_setOutput) {
55+
const std::vector<float> vec1 = {2.0F, 1.5F, 0.1F, 1.9F, 0.0F, 5.5F};
56+
Tensor weights = make_tensor<float>(vec1, {3, 2});
57+
Tensor bias = make_tensor<float>({0.5F, 0.5F, 1.0F});
58+
Tensor input = make_tensor<float>({1.0F, 2.0F}, {2});
59+
Tensor output;
60+
Graph graph;
61+
62+
auto fcLayer = std::make_shared<FCLayer>(weights, bias);
63+
auto inputLayer = std::make_shared<InputLayer>();
64+
auto ewLayer = std::make_shared<EWLayer>();
65+
66+
graph.addSingleLayer(inputLayer);
67+
graph.makeConnection(inputLayer, fcLayer);
68+
graph.makeConnection(fcLayer, ewLayer);
69+
70+
ASSERT_NO_THROW(graph.setOutput(output));
71+
}
72+
3573
TEST(graph, test_deep_copy) {
3674
Graph graph;
3775
Graph graph2;

test/single_layer/test_convlayer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@ using namespace it_lab_ai;
77

88
class ConvTestFixture : public BaseTestFixture {};
99

10+
TEST(ConvolutionalLayerTest, Getters) {
11+
int step = 2;
12+
std::vector<float> kernelvec = {1, 0, 1, 0, 1, 0, 1, 0, 1};
13+
Shape sh2({3, 3});
14+
Tensor kernel = make_tensor(kernelvec, sh2);
15+
ConvolutionalLayer layer(step, 0, 1, kernel);
16+
std::vector<float> vec = {1, 2, 3, 4};
17+
Tensor input1 = make_tensor<float>(vec, {4});
18+
Tensor input2 = make_tensor<float>(vec, {2, 2});
19+
std::vector<Tensor> in{input1, input2};
20+
std::vector<Tensor> output{input1};
21+
EXPECT_NO_THROW(layer.getLegacyImplBool());
22+
EXPECT_NO_THROW(layer.getNumericParams());
23+
EXPECT_NO_THROW(layer.getTensorParams());
24+
}
25+
1026
TEST(ConvolutionalLayerTest, IncompatibleInput) {
1127
int step = 2;
1228
std::vector<float> kernelvec = {1, 0, 1, 0, 1, 0, 1, 0, 1};

test/single_layer_fused/test_convrelu.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55

66
using namespace it_lab_ai;
77

8+
TEST(ConvReluLayerTest, CopyFromConv) {
9+
int step = 2;
10+
std::vector<float> kernelvec = {1, 0, 1, 0, 1, 0, 1, 0, 1};
11+
Shape sh2({3, 3});
12+
Tensor kernel = make_tensor(kernelvec, sh2);
13+
std::shared_ptr<ConvolutionalLayer> layer =
14+
std::make_shared<ConvolutionalLayer>(step, 0, 1, kernel);
15+
std::vector<float> vec = {1, 2, 3, 4};
16+
Tensor input1 = make_tensor<float>(vec, {4});
17+
Tensor input2 = make_tensor<float>(vec, {2, 2});
18+
std::vector<Tensor> in{input1, input2};
19+
std::vector<Tensor> output{input1};
20+
EXPECT_NO_THROW(ConvReluLayer layer2(layer));
21+
}
22+
823
TEST(ConvReluLayerTest, IncompatibleInput) {
924
int step = 2;
1025
std::vector<float> kernelvec = {1, 0, 1, 0, 1, 0, 1, 0, 1};

0 commit comments

Comments
 (0)