Add algorithms - #243
Add algorithms#243cat923 wants to merge 29 commits into
Conversation
| @@ -0,0 +1,16 @@ | |||
| # Install ruff to check your code style : | |||
| @@ -0,0 +1,21 @@ | |||
| from collections import deque | |||
|
|
|||
| INF = int(1e9) | |||
There was a problem hiding this comment.
Why you need distance and infinite in BFS?
| depth += 1 | ||
| count += front_size | ||
| v.assign(front, depth, op_assign=INT.SECOND, op_select=INT.NQZERO) | ||
| front = front.vxm(v, A, op_mult=INT.LAND, op_add=INT.LOR, op_select=INT.EQZERO) |
There was a problem hiding this comment.
How you prevent repeated visiting of vertices?
There was a problem hiding this comment.
I copypasted this code from __init__.py. It says there is a mask to prevent repeating. I think it is op_select=INT.EQZERO
| return graph, n | ||
|
|
||
|
|
||
| def read_mtx_weighted(filename): |
There was a problem hiding this comment.
Is it helper for MTX reading? Can we use standard functions to do it?
There was a problem hiding this comment.
Should i use mmread or is there a way to read MTX from SPLA ?
| from pyspla import FLOAT, INT, Matrix | ||
|
|
||
|
|
||
| def read_mtx_int(filename): |
There was a problem hiding this comment.
Too many helpers with duplicated code. There are standard functions for mtx reading.
| read_vectors_weighted, | ||
| ) | ||
| from pr_classic import pagerank_classic | ||
| from sssp_classic import INF as SSSP_INF |
| from tc_spla import cohen | ||
|
|
||
|
|
||
| def main(): |
| import math | ||
|
|
||
|
|
||
| def pagerank_classic(adj_in, out_degree, n, alpha, eps): |
There was a problem hiding this comment.
What is the reason to implement it again? can you use existing reference implementation?
There was a problem hiding this comment.
You told me to make a classic version for checking during one of our meetings .Could you please point out what exactly needs to be redone?
| @@ -0,0 +1,14 @@ | |||
| INF = 1e9 | |||
| @@ -0,0 +1,41 @@ | |||
| from pyspla import FLOAT, Matrix, Scalar, Vector | |||
|
|
|||
| INF = float(1e9) | |||
There was a problem hiding this comment.
infinity can be represented in floats.
|
|
||
| def is_converged(old, new, eps=EPS): | ||
| diff = old.eadd(FLOAT.MINUS_POW2, new) | ||
| error2 = diff.reduce(FLOAT.PLUS) |
There was a problem hiding this comment.
It is strange that in SSSP we need to check error with epsilon.
| std::cout << std::endl; | ||
| for (std::size_t k = 0; k < loader.get_n_values(); ++k) { | ||
| A->set_float(Ai[k], Aj[k], w); | ||
| A->set_float(Ai[k], Aj[k], Aw[k]); |
There was a problem hiding this comment.
To use the actual edge weights loaded from the mtx file instead of the constant weight w = 1.
|
|
||
| for (std::size_t k = 0; k < loader.get_n_values(); ++k) { | ||
| if (Ai[k] > Aj[k]) { | ||
| if (Ai[k] < Aj[k]) { |
There was a problem hiding this comment.
There is no difference in the results, but I like upper triangles more.
|
|
||
| [[nodiscard]] SPLA_API const std::vector<uint>& get_Ai() const; | ||
| [[nodiscard]] SPLA_API const std::vector<uint>& get_Aj() const; | ||
| [[nodiscard]] SPLA_API const std::vector<float>& get_Aw() const; |
There was a problem hiding this comment.
To use the actual edge weights loaded from the mtx file instead of the constant weight w = 1.
| std::size_t n_lines = 0; | ||
| std::size_t n_sort = 0; | ||
|
|
||
| std::string first_line; |
There was a problem hiding this comment.
What reasons of changes in this file?
There was a problem hiding this comment.
Previously, all matrices were made symmetric by default, and weights were set to 1.0 for SSSP. Now, reverse edges are added only for symmetric matrices, and 1 weight is set specifically for pattern matrices.
Implemented graph algorithms and test coverage for result comparison between Classic and SPLA versions.
Added project documentation with usage instructions and input format examples.
Added graph input readers for both vectors (.txt) and Matrix Market (.mtx) formats.