Skip to content

Commit d1ca784

Browse files
committed
changes after review
1 parent e9c1a9c commit d1ca784

28 files changed

+61
-56
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# cuBoolGraph
22
cuBool based graph analysis algorithms
33

4+
## List of algorithms
5+
6+
regular_path_query - Single-Source Regular Path Query Algorithm in Terms of Linear Algebra
7+
48
# Run tests
59
```
10+
git submodule update --init --recursive
611
cmake -B build -DCUBOOL_GRAPH_ENABLE_TESTING=ON
712
cmake --build build
813
./build/tests/cuboolgraph_tests

include/regular_path_query.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ cuBool_Matrix regular_path_query_with_transposed(
66
// vector of sparse graph matrices for each label
77
const std::vector<cuBool_Matrix> &graph, const std::vector<cuBool_Index> &source_vertices,
88
// vector of sparse automat matrices for each label
9-
const std::vector<cuBool_Matrix> &automat, const std::vector<cuBool_Index> &start_states,
9+
const std::vector<cuBool_Matrix> &automaton, const std::vector<cuBool_Index> &start_states,
1010
// transposed matrices for graph and automat
1111
const std::vector<cuBool_Matrix> &graph_transposed,
12-
const std::vector<cuBool_Matrix> &automat_transposed,
12+
const std::vector<cuBool_Matrix> &automaton_transposed,
1313

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

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

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

src/regular_path_query.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@
99
cuBool_Matrix regular_path_query_with_transposed(
1010
// vector of sparse graph matrices for each label
1111
const std::vector<cuBool_Matrix> &graph, const std::vector<cuBool_Index> &source_vertices,
12-
// vector of sparse automat matrices for each label
13-
const std::vector<cuBool_Matrix> &automat, const std::vector<cuBool_Index> &start_states,
14-
// transposed matrices for graph and automat
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
1515
const std::vector<cuBool_Matrix> &graph_transposed,
16-
const std::vector<cuBool_Matrix> &automat_transposed,
16+
const std::vector<cuBool_Matrix> &automaton_transposed,
1717

1818
const std::vector<bool> &inversed_labels_input, bool all_labels_are_inversed) {
1919
cuBool_Status status;
2020

2121
auto inversed_labels = inversed_labels_input;
22-
inversed_labels.resize(std::max(graph.size(), automat.size()));
22+
inversed_labels.resize(std::max(graph.size(), automaton.size()));
2323

2424
for (uint32_t i = 0; i < inversed_labels.size(); i++) {
2525
bool is_inverse = inversed_labels[i];
@@ -28,7 +28,7 @@ cuBool_Matrix regular_path_query_with_transposed(
2828
}
2929

3030
cuBool_Index graph_nodes_number = 0;
31-
cuBool_Index automat_nodes_number = 0;
31+
cuBool_Index automaton_nodes_number = 0;
3232

3333
// get number of graph nodes
3434
for (auto label_matrix : graph) {
@@ -39,31 +39,31 @@ cuBool_Matrix regular_path_query_with_transposed(
3939
}
4040

4141
// get number of automat nodes
42-
for (auto label_matrix : automat) {
42+
for (auto label_matrix : automaton) {
4343
if (label_matrix != nullptr) {
44-
cuBool_Matrix_Nrows(label_matrix, &automat_nodes_number);
44+
cuBool_Matrix_Nrows(label_matrix, &automaton_nodes_number);
4545
break;
4646
}
4747
}
4848

4949
// this will be answer
5050
cuBool_Matrix reacheble {};
51-
status = cuBool_Matrix_New(&reacheble, automat_nodes_number, graph_nodes_number);
51+
status = cuBool_Matrix_New(&reacheble, automaton_nodes_number, graph_nodes_number);
5252
assert(status == CUBOOL_STATUS_SUCCESS);
5353

5454
// allocate neccessary for algorithm matrices
5555
cuBool_Matrix frontier {}, symbol_frontier {}, next_frontier {};
56-
status = cuBool_Matrix_New(&next_frontier, automat_nodes_number, graph_nodes_number);
56+
status = cuBool_Matrix_New(&next_frontier, automaton_nodes_number, graph_nodes_number);
5757
assert(status == CUBOOL_STATUS_SUCCESS);
58-
status = cuBool_Matrix_New(&frontier, automat_nodes_number, graph_nodes_number);
58+
status = cuBool_Matrix_New(&frontier, automaton_nodes_number, graph_nodes_number);
5959
assert(status == CUBOOL_STATUS_SUCCESS);
60-
status = cuBool_Matrix_New(&symbol_frontier, automat_nodes_number, graph_nodes_number);
60+
status = cuBool_Matrix_New(&symbol_frontier, automaton_nodes_number, graph_nodes_number);
6161
assert(status == CUBOOL_STATUS_SUCCESS);
6262

6363
// init start values of algorithm matricies
6464
for (const auto state : start_states) {
6565
for (const auto vert : source_vertices) {
66-
assert(state < automat_nodes_number);
66+
assert(state < automaton_nodes_number);
6767
assert(vert < graph_nodes_number);
6868
cuBool_Matrix_SetElement(next_frontier, state, vert);
6969
cuBool_Matrix_SetElement(reacheble, state, vert);
@@ -74,10 +74,10 @@ cuBool_Matrix regular_path_query_with_transposed(
7474

7575
// temporary matrix for write result of cubool functions
7676
cuBool_Matrix result;
77-
status = cuBool_Matrix_New(&result, automat_nodes_number, graph_nodes_number);
77+
status = cuBool_Matrix_New(&result, automaton_nodes_number, graph_nodes_number);
7878
assert(status == CUBOOL_STATUS_SUCCESS);
7979

80-
const auto label_number = std::min(graph.size(), automat.size());
80+
const auto label_number = std::min(graph.size(), automaton.size());
8181
while (states > 0) {
8282
std::swap(frontier, next_frontier);
8383

@@ -86,12 +86,12 @@ cuBool_Matrix regular_path_query_with_transposed(
8686
assert(status == CUBOOL_STATUS_SUCCESS);
8787

8888
for (int i = 0; i < label_number; i++) {
89-
if (graph[i] == nullptr || automat[i] == nullptr) {
89+
if (graph[i] == nullptr || automaton[i] == nullptr) {
9090
continue;
9191
}
9292

93-
cuBool_Matrix automat_matrix = all_labels_are_inversed ? automat[i] : automat_transposed[i];
94-
status = cuBool_MxM(symbol_frontier, automat_matrix, frontier, CUBOOL_HINT_NO);
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);
9595
assert(status == CUBOOL_STATUS_SUCCESS);
9696

9797
// next_frontier += (symbol_frontier * graph[i]) & (!reachible)
@@ -127,7 +127,7 @@ cuBool_Matrix regular_path_query(
127127
// vector of sparse graph matrices for each label
128128
const std::vector<cuBool_Matrix> &graph, const std::vector<cuBool_Index> &source_vertices,
129129
// vector of sparse automat matrices for each label
130-
const std::vector<cuBool_Matrix> &automat, const std::vector<cuBool_Index> &start_states,
130+
const std::vector<cuBool_Matrix> &automaton, const std::vector<cuBool_Index> &start_states,
131131
// work with inverted labels
132132
const std::vector<bool> &inversed_labels_input, bool all_labels_are_inversed) {
133133
cuBool_Status status;
@@ -154,10 +154,10 @@ cuBool_Matrix regular_path_query(
154154
}
155155

156156
// transpose automat matrices
157-
std::vector<cuBool_Matrix> automat_transposed;
158-
automat_transposed.reserve(automat.size());
159-
for (auto label_matrix : automat) {
160-
automat_transposed.emplace_back();
157+
std::vector<cuBool_Matrix> automaton_transposed;
158+
automaton_transposed.reserve(automaton.size());
159+
for (auto label_matrix : automaton) {
160+
automaton_transposed.emplace_back();
161161
if (label_matrix == nullptr) {
162162
continue;
163163
}
@@ -166,24 +166,24 @@ cuBool_Matrix regular_path_query(
166166
cuBool_Matrix_Nrows(label_matrix, &nrows);
167167
cuBool_Matrix_Ncols(label_matrix, &ncols);
168168

169-
status = cuBool_Matrix_New(&automat_transposed.back(), ncols, nrows);
169+
status = cuBool_Matrix_New(&automaton_transposed.back(), ncols, nrows);
170170
assert(status == CUBOOL_STATUS_SUCCESS);
171-
status = cuBool_Matrix_Transpose(automat_transposed.back(), label_matrix, CUBOOL_HINT_NO);
171+
status = cuBool_Matrix_Transpose(automaton_transposed.back(), label_matrix, CUBOOL_HINT_NO);
172172
assert(status == CUBOOL_STATUS_SUCCESS);
173173
}
174174

175175
auto result = regular_path_query_with_transposed(
176176
graph, source_vertices,
177-
automat, start_states,
178-
graph_transposed, automat_transposed,
177+
automaton, start_states,
178+
graph_transposed, automaton_transposed,
179179
inversed_labels_input, all_labels_are_inversed);
180180

181181
for (cuBool_Matrix matrix : graph_transposed) {
182182
if (matrix != nullptr) {
183183
cuBool_Matrix_Free(matrix);
184184
}
185185
}
186-
for (cuBool_Matrix matrix : automat_transposed) {
186+
for (cuBool_Matrix matrix : automaton_transposed) {
187187
if (matrix != nullptr) {
188188
cuBool_Matrix_Free(matrix);
189189
}

tests/rpq_tests.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
struct Config {
1717
std::vector<std::string> graph_data;
18-
std::vector<std::string> automat_data;
18+
std::vector<std::string> automaton_data;
1919
std::vector<uint32_t> sources;
2020
std::string expexted;
2121
std::string meta_data;
@@ -27,7 +27,7 @@ static bool test_on_config(const Config &config) {
2727

2828
std::vector<cuBool_Matrix> graph;
2929
std::vector<cuBool_Index> source_vertices;
30-
std::vector<cuBool_Matrix> automat;
30+
std::vector<cuBool_Matrix> automaton;
3131
std::vector<cuBool_Index> start_states;
3232

3333
int64_t nrows = 0, ncols = 0;
@@ -56,11 +56,11 @@ static bool test_on_config(const Config &config) {
5656
graph_rows = std::max(graph_rows, (cuBool_Index)nrows);
5757
}
5858

59-
cuBool_Index automat_rows = 0;
60-
// load automat
61-
automat.reserve(config.automat_data.size());
62-
for (const auto &data : config.automat_data) {
63-
automat.emplace_back();
59+
cuBool_Index automaton_rows = 0;
60+
// load automaton
61+
automaton.reserve(config.automaton_data.size());
62+
for (const auto &data : config.automaton_data) {
63+
automaton.emplace_back();
6464
if (data.empty()) {
6565
continue;
6666
}
@@ -71,10 +71,10 @@ static bool test_on_config(const Config &config) {
7171
}
7272
fast_matrix_market::read_matrix_market_triplet(file, nrows, ncols, rows, cols, vals);
7373

74-
cuBool_Matrix_New(&automat.back(), nrows, ncols);
75-
cuBool_Matrix_Build(automat.back(), rows.data(), cols.data(), vals.size(), CUBOOL_HINT_NO);
74+
cuBool_Matrix_New(&automaton.back(), nrows, ncols);
75+
cuBool_Matrix_Build(automaton.back(), rows.data(), cols.data(), vals.size(), CUBOOL_HINT_NO);
7676

77-
automat_rows = std::max(automat_rows, (cuBool_Index)nrows);
77+
automaton_rows = std::max(automaton_rows, (cuBool_Index)nrows);
7878
}
7979

8080
// temporary hardcoded
@@ -86,13 +86,13 @@ static bool test_on_config(const Config &config) {
8686
s--;
8787
}
8888

89-
auto answer = regular_path_query(graph, source_vertices, automat, start_states);
89+
auto answer = regular_path_query(graph, source_vertices, automaton, start_states);
9090

9191
cuBool_Vector P, F;
9292
cuBool_Vector_New(&P, graph_rows);
93-
cuBool_Vector_New(&F, automat_rows);
93+
cuBool_Vector_New(&F, automaton_rows);
9494

95-
std::vector<cuBool_Index> final_states(automat_rows);
95+
std::vector<cuBool_Index> final_states(automaton_rows);
9696
std::iota(final_states.begin(), final_states.end(), 0);
9797

9898
cuBool_Vector_Build(F, final_states.data(), final_states.size(), CUBOOL_HINT_NO);
@@ -140,7 +140,7 @@ static bool test_on_config(const Config &config) {
140140
cuBool_Matrix_Free(matrix);
141141
}
142142
}
143-
for (auto matrix : automat) {
143+
for (auto matrix : automaton) {
144144
if (matrix != nullptr) {
145145
cuBool_Matrix_Free(matrix);
146146
}
@@ -158,34 +158,34 @@ static std::string get_path(std::string_view file) {
158158
TEST(RPQ, Tests) {
159159
std::vector<Config> configs {
160160
{
161-
.graph_data = {get_path("example/graph_a.mtx"), get_path("example/graph_b.mtx")},
162-
.automat_data = {get_path("example/automat_a.mtx"), get_path("example/automat_b.mtx")},
161+
.graph_data = {get_path("5/graph_a.mtx"), get_path("5/graph_b.mtx")},
162+
.automaton_data = {get_path("5/automat_a.mtx"), get_path("5/automat_b.mtx")},
163163
.sources = {1},
164-
.expexted = get_path("example/expected.txt"),
164+
.expexted = get_path("5/expected.txt"),
165165
},
166166
{
167167
.graph_data = {get_path("a.mtx"), get_path("b.mtx")},
168-
.automat_data {get_path("1_a.mtx"), ""},
168+
.automaton_data {get_path("1/a.mtx"), ""},
169169
.sources = {1},
170-
.expexted = get_path("1_expected.txt"),
170+
.expexted = get_path("1/expected.txt"),
171171
},
172172
{
173173
.graph_data = {get_path("a.mtx"), get_path("b.mtx")},
174-
.automat_data {get_path("2_a.mtx"), get_path("2_b.mtx")},
174+
.automaton_data {get_path("2/a.mtx"), get_path("2/b.mtx")},
175175
.sources = {2},
176-
.expexted = get_path("2_expected.txt"),
176+
.expexted = get_path("2/expected.txt"),
177177
},
178178
{
179179
.graph_data = {get_path("a.mtx"), get_path("b.mtx")},
180-
.automat_data {get_path("3_a.mtx"), get_path("3_b.mtx")},
180+
.automaton_data {get_path("3/a.mtx"), get_path("3/b.mtx")},
181181
.sources = {3, 6},
182-
.expexted = get_path("3_expected.txt"),
182+
.expexted = get_path("3/expected.txt"),
183183
},
184184
{
185185
.graph_data = {get_path("a.mtx"), get_path("b.mtx")},
186-
.automat_data {"", get_path("4_b.mtx")},
186+
.automaton_data {"", get_path("4/b.mtx")},
187187
.sources = {4},
188-
.expexted = get_path("4_expected.txt"),
188+
.expexted = get_path("4/expected.txt"),
189189
},
190190
};
191191

0 commit comments

Comments
 (0)