Created
June 11, 2020 18:38
-
-
Save michelp/35feaa712c225f04b4875813e94f4723 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pygraphblas import * | |
M = Matrix.random(FP32, 7, 7, 30, no_diagonal=True, make_pattern=True, seed=42) | |
def pagerank3f(A, damping, itermax): | |
n = A.nrows | |
r = Vector.sparse(FP32, n) | |
t = Vector.sparse(FP32, n) | |
d = A.reduce_vector() | |
with Accum(FP32.DIV): | |
d[:] = damping | |
r[:] = 1.0 / n | |
teleport = (1 - damping) / n | |
tol = 1e-4 | |
rdiff = 1.0 | |
for i in range(itermax): | |
if rdiff <= tol: | |
break | |
temp = t ; t = r ; r = temp | |
w = t / d | |
r[:] = teleport | |
A.mxv(w, | |
out=r, | |
accum=FP32.PLUS, | |
semiring=FP32.PLUS_SECOND, | |
desc=TransposeA) | |
t -= r | |
t = abs(t) | |
rdiff = t.reduce_float() | |
return r | |
pr = pagerank3f(M, 0.35, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment