Skip to content

Commit da8d3e0

Browse files
committed
style: changes according to clang-format
1 parent 814cc9a commit da8d3e0

File tree

4 files changed

+325
-325
lines changed

4 files changed

+325
-325
lines changed

include/regular_path_query.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
#include <cubool/cubool.h>
44

55
cuBool_Matrix regular_path_query_with_transposed(
6-
// vector of sparse graph matrices for each label
7-
const std::vector<cuBool_Matrix> &graph, const std::vector<cuBool_Index> &source_vertices,
8-
// vector of sparse automaton matrices for each label
9-
const std::vector<cuBool_Matrix> &automaton, const std::vector<cuBool_Index> &start_states,
10-
// transposed matrices for graph and automaton
11-
const std::vector<cuBool_Matrix> &graph_transposed,
12-
const std::vector<cuBool_Matrix> &automaton_transposed,
6+
// vector of sparse graph matrices for each label
7+
const std::vector<cuBool_Matrix>& graph, const std::vector<cuBool_Index>& source_vertices,
8+
// vector of sparse automaton matrices for each label
9+
const std::vector<cuBool_Matrix>& automaton, const std::vector<cuBool_Index>& start_states,
10+
// transposed matrices for graph and automaton
11+
const std::vector<cuBool_Matrix>& graph_transposed,
12+
const std::vector<cuBool_Matrix>& automaton_transposed,
1313

14-
const std::vector<bool> &inversed_labels = {}, bool all_labels_are_inversed = false);
14+
const std::vector<bool>& inversed_labels = {}, bool all_labels_are_inversed = false);
1515

1616
cuBool_Matrix regular_path_query(
17-
// vector of sparse graph matrices for each label
18-
const std::vector<cuBool_Matrix> &graph, const std::vector<cuBool_Index> &source_vertices,
19-
// vector of sparse automaton matrices for each label
20-
const std::vector<cuBool_Matrix> &automaton, const std::vector<cuBool_Index> &start_states,
17+
// vector of sparse graph matrices for each label
18+
const std::vector<cuBool_Matrix>& graph, const std::vector<cuBool_Index>& source_vertices,
19+
// vector of sparse automaton matrices for each label
20+
const std::vector<cuBool_Matrix>& automaton, const std::vector<cuBool_Index>& start_states,
2121

22-
const std::vector<bool> &inversed_labels = {}, bool all_labels_are_inversed = false);
22+
const std::vector<bool>& inversed_labels = {}, bool all_labels_are_inversed = false);

src/regular_path_query.cpp

Lines changed: 157 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -7,187 +7,187 @@
77
#include "regular_path_query.hpp"
88

99
cuBool_Matrix regular_path_query_with_transposed(
10-
// vector of sparse graph matrices for each label
11-
const std::vector<cuBool_Matrix> &graph, const std::vector<cuBool_Index> &source_vertices,
12-
// vector of sparse automaton matrices for each label
13-
const std::vector<cuBool_Matrix> &automaton, const std::vector<cuBool_Index> &start_states,
14-
// transposed matrices for graph and automaton
15-
const std::vector<cuBool_Matrix> &graph_transposed,
16-
const std::vector<cuBool_Matrix> &automaton_transposed,
17-
18-
const std::vector<bool> &inversed_labels_input, bool all_labels_are_inversed) {
19-
cuBool_Status status;
20-
21-
auto inversed_labels = inversed_labels_input;
22-
inversed_labels.resize(std::max(graph.size(), automaton.size()));
23-
24-
for (uint32_t i = 0; i < inversed_labels.size(); i++) {
25-
bool is_inverse = inversed_labels[i];
26-
is_inverse ^= all_labels_are_inversed;
27-
inversed_labels[i] = is_inverse;
28-
}
29-
30-
cuBool_Index graph_nodes_number = 0;
31-
cuBool_Index automaton_nodes_number = 0;
32-
33-
// get number of graph nodes
34-
for (auto label_matrix : graph) {
35-
if (label_matrix != nullptr) {
36-
cuBool_Matrix_Nrows(label_matrix, &graph_nodes_number);
37-
break;
10+
// vector of sparse graph matrices for each label
11+
const std::vector<cuBool_Matrix>& graph, const std::vector<cuBool_Index>& source_vertices,
12+
// vector of sparse automaton matrices for each label
13+
const std::vector<cuBool_Matrix>& automaton, const std::vector<cuBool_Index>& start_states,
14+
// transposed matrices for graph and automaton
15+
const std::vector<cuBool_Matrix>& graph_transposed,
16+
const std::vector<cuBool_Matrix>& automaton_transposed,
17+
18+
const std::vector<bool>& inversed_labels_input, bool all_labels_are_inversed) {
19+
cuBool_Status status;
20+
21+
auto inversed_labels = inversed_labels_input;
22+
inversed_labels.resize(std::max(graph.size(), automaton.size()));
23+
24+
for (uint32_t i = 0; i < inversed_labels.size(); i++) {
25+
bool is_inverse = inversed_labels[i];
26+
is_inverse ^= all_labels_are_inversed;
27+
inversed_labels[i] = is_inverse;
3828
}
39-
}
4029

41-
// get number of automaton nodes
42-
for (auto label_matrix : automaton) {
43-
if (label_matrix != nullptr) {
44-
cuBool_Matrix_Nrows(label_matrix, &automaton_nodes_number);
45-
break;
46-
}
47-
}
48-
49-
// this will be answer
50-
cuBool_Matrix reacheble {};
51-
status = cuBool_Matrix_New(&reacheble, automaton_nodes_number, graph_nodes_number);
52-
assert(status == CUBOOL_STATUS_SUCCESS);
53-
54-
// allocate neccessary for algorithm matrices
55-
cuBool_Matrix frontier {}, symbol_frontier {}, next_frontier {};
56-
status = cuBool_Matrix_New(&next_frontier, automaton_nodes_number, graph_nodes_number);
57-
assert(status == CUBOOL_STATUS_SUCCESS);
58-
status = cuBool_Matrix_New(&frontier, automaton_nodes_number, graph_nodes_number);
59-
assert(status == CUBOOL_STATUS_SUCCESS);
60-
status = cuBool_Matrix_New(&symbol_frontier, automaton_nodes_number, graph_nodes_number);
61-
assert(status == CUBOOL_STATUS_SUCCESS);
62-
63-
// init start values of algorithm matricies
64-
for (const auto state : start_states) {
65-
for (const auto vert : source_vertices) {
66-
assert(state < automaton_nodes_number);
67-
assert(vert < graph_nodes_number);
68-
cuBool_Matrix_SetElement(next_frontier, state, vert);
69-
cuBool_Matrix_SetElement(reacheble, state, vert);
70-
}
71-
}
30+
cuBool_Index graph_nodes_number = 0;
31+
cuBool_Index automaton_nodes_number = 0;
7232

73-
cuBool_Index states = source_vertices.size();
33+
// get number of graph nodes
34+
for (auto label_matrix : graph) {
35+
if (label_matrix != nullptr) {
36+
cuBool_Matrix_Nrows(label_matrix, &graph_nodes_number);
37+
break;
38+
}
39+
}
7440

75-
// temporary matrix for write result of cubool functions
76-
cuBool_Matrix result;
77-
status = cuBool_Matrix_New(&result, automaton_nodes_number, graph_nodes_number);
78-
assert(status == CUBOOL_STATUS_SUCCESS);
41+
// get number of automaton nodes
42+
for (auto label_matrix : automaton) {
43+
if (label_matrix != nullptr) {
44+
cuBool_Matrix_Nrows(label_matrix, &automaton_nodes_number);
45+
break;
46+
}
47+
}
7948

80-
const auto label_number = std::min(graph.size(), automaton.size());
81-
while (states > 0) {
82-
std::swap(frontier, next_frontier);
49+
// this will be answer
50+
cuBool_Matrix reacheble{};
51+
status = cuBool_Matrix_New(&reacheble, automaton_nodes_number, graph_nodes_number);
52+
assert(status == CUBOOL_STATUS_SUCCESS);
8353

84-
// clear next_frontier
85-
status = cuBool_Matrix_Build(next_frontier, nullptr, nullptr, 0, CUBOOL_HINT_NO);
54+
// allocate neccessary for algorithm matrices
55+
cuBool_Matrix frontier{}, symbol_frontier{}, next_frontier{};
56+
status = cuBool_Matrix_New(&next_frontier, automaton_nodes_number, graph_nodes_number);
57+
assert(status == CUBOOL_STATUS_SUCCESS);
58+
status = cuBool_Matrix_New(&frontier, automaton_nodes_number, graph_nodes_number);
59+
assert(status == CUBOOL_STATUS_SUCCESS);
60+
status = cuBool_Matrix_New(&symbol_frontier, automaton_nodes_number, graph_nodes_number);
8661
assert(status == CUBOOL_STATUS_SUCCESS);
8762

88-
for (int i = 0; i < label_number; i++) {
89-
if (graph[i] == nullptr || automaton[i] == nullptr) {
90-
continue;
91-
}
92-
93-
cuBool_Matrix automaton_matrix = all_labels_are_inversed ? automaton[i] : automaton_transposed[i];
94-
status = cuBool_MxM(symbol_frontier, automaton_matrix, frontier, CUBOOL_HINT_NO);
95-
assert(status == CUBOOL_STATUS_SUCCESS);
96-
97-
// next_frontier += (symbol_frontier * graph[i]) & (!reachible)
98-
// multiply 2 matrices
99-
cuBool_Matrix graph_matrix = inversed_labels[i] ? graph_transposed[i] : graph[i];
100-
status = cuBool_MxM(next_frontier, symbol_frontier, graph_matrix, CUBOOL_HINT_ACCUMULATE);
101-
assert(status == CUBOOL_STATUS_SUCCESS);
102-
// apply invert mask
103-
status = cuBool_Matrix_EWiseMulInverted(result, next_frontier, reacheble, CUBOOL_HINT_NO);
104-
assert(status == CUBOOL_STATUS_SUCCESS);
105-
std::swap(result, next_frontier);
63+
// init start values of algorithm matricies
64+
for (const auto state : start_states) {
65+
for (const auto vert : source_vertices) {
66+
assert(state < automaton_nodes_number);
67+
assert(vert < graph_nodes_number);
68+
cuBool_Matrix_SetElement(next_frontier, state, vert);
69+
cuBool_Matrix_SetElement(reacheble, state, vert);
70+
}
10671
}
10772

108-
// this must be accumulate with mask and save old value: reacheble += next_frontier & reacheble
109-
status = cuBool_Matrix_EWiseAdd(result, reacheble, next_frontier, CUBOOL_HINT_NO);
73+
cuBool_Index states = source_vertices.size();
74+
75+
// temporary matrix for write result of cubool functions
76+
cuBool_Matrix result;
77+
status = cuBool_Matrix_New(&result, automaton_nodes_number, graph_nodes_number);
11078
assert(status == CUBOOL_STATUS_SUCCESS);
111-
std::swap(result, reacheble);
11279

113-
cuBool_Matrix_Nvals(next_frontier, &states);
114-
}
80+
const auto label_number = std::min(graph.size(), automaton.size());
81+
while (states > 0) {
82+
std::swap(frontier, next_frontier);
83+
84+
// clear next_frontier
85+
status = cuBool_Matrix_Build(next_frontier, nullptr, nullptr, 0, CUBOOL_HINT_NO);
86+
assert(status == CUBOOL_STATUS_SUCCESS);
87+
88+
for (int i = 0; i < label_number; i++) {
89+
if (graph[i] == nullptr || automaton[i] == nullptr) {
90+
continue;
91+
}
92+
93+
cuBool_Matrix automaton_matrix = all_labels_are_inversed ? automaton[i] : automaton_transposed[i];
94+
status = cuBool_MxM(symbol_frontier, automaton_matrix, frontier, CUBOOL_HINT_NO);
95+
assert(status == CUBOOL_STATUS_SUCCESS);
96+
97+
// next_frontier += (symbol_frontier * graph[i]) & (!reachible)
98+
// multiply 2 matrices
99+
cuBool_Matrix graph_matrix = inversed_labels[i] ? graph_transposed[i] : graph[i];
100+
status = cuBool_MxM(next_frontier, symbol_frontier, graph_matrix, CUBOOL_HINT_ACCUMULATE);
101+
assert(status == CUBOOL_STATUS_SUCCESS);
102+
// apply invert mask
103+
status = cuBool_Matrix_EWiseMulInverted(result, next_frontier, reacheble, CUBOOL_HINT_NO);
104+
assert(status == CUBOOL_STATUS_SUCCESS);
105+
std::swap(result, next_frontier);
106+
}
107+
108+
// this must be accumulate with mask and save old value: reacheble += next_frontier & reacheble
109+
status = cuBool_Matrix_EWiseAdd(result, reacheble, next_frontier, CUBOOL_HINT_NO);
110+
assert(status == CUBOOL_STATUS_SUCCESS);
111+
std::swap(result, reacheble);
112+
113+
cuBool_Matrix_Nvals(next_frontier, &states);
114+
}
115115

116-
// free matrix necessary for algorithm
117-
cuBool_Matrix_Free(next_frontier);
118-
cuBool_Matrix_Free(frontier);
119-
cuBool_Matrix_Free(symbol_frontier);
120-
cuBool_Matrix_Free(result);
116+
// free matrix necessary for algorithm
117+
cuBool_Matrix_Free(next_frontier);
118+
cuBool_Matrix_Free(frontier);
119+
cuBool_Matrix_Free(symbol_frontier);
120+
cuBool_Matrix_Free(result);
121121

122-
return reacheble;
122+
return reacheble;
123123
}
124124

125125

126126
cuBool_Matrix regular_path_query(
127-
// vector of sparse graph matrices for each label
128-
const std::vector<cuBool_Matrix> &graph, const std::vector<cuBool_Index> &source_vertices,
129-
// vector of sparse automaton matrices for each label
130-
const std::vector<cuBool_Matrix> &automaton, const std::vector<cuBool_Index> &start_states,
131-
// work with inverted labels
132-
const std::vector<bool> &inversed_labels_input, bool all_labels_are_inversed) {
133-
cuBool_Status status;
134-
135-
// transpose graph matrices
136-
std::vector<cuBool_Matrix> graph_transposed;
137-
graph_transposed.reserve(graph.size());
138-
for (uint32_t i = 0; i < graph.size(); i++) {
139-
graph_transposed.emplace_back();
140-
141-
auto label_matrix = graph[i];
142-
if (label_matrix == nullptr) {
143-
continue;
127+
// vector of sparse graph matrices for each label
128+
const std::vector<cuBool_Matrix>& graph, const std::vector<cuBool_Index>& source_vertices,
129+
// vector of sparse automaton matrices for each label
130+
const std::vector<cuBool_Matrix>& automaton, const std::vector<cuBool_Index>& start_states,
131+
// work with inverted labels
132+
const std::vector<bool>& inversed_labels_input, bool all_labels_are_inversed) {
133+
cuBool_Status status;
134+
135+
// transpose graph matrices
136+
std::vector<cuBool_Matrix> graph_transposed;
137+
graph_transposed.reserve(graph.size());
138+
for (uint32_t i = 0; i < graph.size(); i++) {
139+
graph_transposed.emplace_back();
140+
141+
auto label_matrix = graph[i];
142+
if (label_matrix == nullptr) {
143+
continue;
144+
}
145+
146+
cuBool_Index nrows, ncols;
147+
cuBool_Matrix_Nrows(label_matrix, &nrows);
148+
cuBool_Matrix_Ncols(label_matrix, &ncols);
149+
150+
status = cuBool_Matrix_New(&graph_transposed.back(), ncols, nrows);
151+
assert(status == CUBOOL_STATUS_SUCCESS);
152+
status = cuBool_Matrix_Transpose(graph_transposed.back(), label_matrix, CUBOOL_HINT_NO);
153+
assert(status == CUBOOL_STATUS_SUCCESS);
144154
}
145155

146-
cuBool_Index nrows, ncols;
147-
cuBool_Matrix_Nrows(label_matrix, &nrows);
148-
cuBool_Matrix_Ncols(label_matrix, &ncols);
149-
150-
status = cuBool_Matrix_New(&graph_transposed.back(), ncols, nrows);
151-
assert(status == CUBOOL_STATUS_SUCCESS);
152-
status = cuBool_Matrix_Transpose(graph_transposed.back(), label_matrix, CUBOOL_HINT_NO);
153-
assert(status == CUBOOL_STATUS_SUCCESS);
154-
}
155-
156-
// transpose automaton matrices
157-
std::vector<cuBool_Matrix> automaton_transposed;
158-
automaton_transposed.reserve(automaton.size());
159-
for (auto label_matrix : automaton) {
160-
automaton_transposed.emplace_back();
161-
if (label_matrix == nullptr) {
162-
continue;
156+
// transpose automaton matrices
157+
std::vector<cuBool_Matrix> automaton_transposed;
158+
automaton_transposed.reserve(automaton.size());
159+
for (auto label_matrix : automaton) {
160+
automaton_transposed.emplace_back();
161+
if (label_matrix == nullptr) {
162+
continue;
163+
}
164+
165+
cuBool_Index nrows, ncols;
166+
cuBool_Matrix_Nrows(label_matrix, &nrows);
167+
cuBool_Matrix_Ncols(label_matrix, &ncols);
168+
169+
status = cuBool_Matrix_New(&automaton_transposed.back(), ncols, nrows);
170+
assert(status == CUBOOL_STATUS_SUCCESS);
171+
status = cuBool_Matrix_Transpose(automaton_transposed.back(), label_matrix, CUBOOL_HINT_NO);
172+
assert(status == CUBOOL_STATUS_SUCCESS);
163173
}
164174

165-
cuBool_Index nrows, ncols;
166-
cuBool_Matrix_Nrows(label_matrix, &nrows);
167-
cuBool_Matrix_Ncols(label_matrix, &ncols);
168-
169-
status = cuBool_Matrix_New(&automaton_transposed.back(), ncols, nrows);
170-
assert(status == CUBOOL_STATUS_SUCCESS);
171-
status = cuBool_Matrix_Transpose(automaton_transposed.back(), label_matrix, CUBOOL_HINT_NO);
172-
assert(status == CUBOOL_STATUS_SUCCESS);
173-
}
174-
175-
auto result = regular_path_query_with_transposed(
176-
graph, source_vertices,
177-
automaton, start_states,
178-
graph_transposed, automaton_transposed,
179-
inversed_labels_input, all_labels_are_inversed);
175+
auto result = regular_path_query_with_transposed(
176+
graph, source_vertices,
177+
automaton, start_states,
178+
graph_transposed, automaton_transposed,
179+
inversed_labels_input, all_labels_are_inversed);
180180

181-
for (cuBool_Matrix matrix : graph_transposed) {
182-
if (matrix != nullptr) {
183-
cuBool_Matrix_Free(matrix);
181+
for (cuBool_Matrix matrix : graph_transposed) {
182+
if (matrix != nullptr) {
183+
cuBool_Matrix_Free(matrix);
184+
}
184185
}
185-
}
186-
for (cuBool_Matrix matrix : automaton_transposed) {
187-
if (matrix != nullptr) {
188-
cuBool_Matrix_Free(matrix);
186+
for (cuBool_Matrix matrix : automaton_transposed) {
187+
if (matrix != nullptr) {
188+
cuBool_Matrix_Free(matrix);
189+
}
189190
}
190-
}
191191

192-
return result;
192+
return result;
193193
}

tests/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <gtest/gtest.h>
22

3-
int main(int argc, char **argv) {
3+
int main(int argc, char** argv) {
44
::testing::InitGoogleTest(&argc, argv);
55
return RUN_ALL_TESTS();
66
}

0 commit comments

Comments
 (0)