Skip to content

Commit 69874f3

Browse files
committed
sparse_mkl backend integration
1 parent adc7180 commit 69874f3

File tree

8 files changed

+26
-12
lines changed

8 files changed

+26
-12
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip
25-
sudo apt install intel-basekit
2625
pip install sklearn
2726
pip install scipy
2827
pip install numpy

documentation/measures.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ Graph conductance (information flow) of scores.
372372
Assumes a fuzzy set of subgraphs whose nodes are included with probability proportional to their scores,
373373
as per the formulation of [krasanakis2019linkauc] and calculates E[outgoing edges] / E[internal edges] of
374374
the fuzzy rank subgraph. To avoid potential optimization towards filling the whole graph, the measure is
375-
evaluated to infinity if either denomator *or* the nominator is zero (this means that whole connected components
375+
evaluated to infinity if either denominator *or* the nominator is zero (this means that whole connected components
376376
should not be extracted).
377377
If scores assume binary values, E[.] becomes set size and this calculates the induced subgraph Conductance. The constructor initializes the Conductance measure.
378378

documentation/tips.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ algorithms.
4848
### My graph is already a scipy sparse matrix.
4949
Note that node ranking algorithms and graph signals
5050
typically require graphs. However, sometimes
51-
it is more computationally efficient to constuct
51+
it is more computationally efficient to construct
5252
and move around sparse scipy adjacency matrices,
5353
for example to avoid additional memory allocations.
5454

@@ -61,8 +61,8 @@ import pygrank as pg
6161
adj = ... # a square sparse scipy array
6262
graph = pg.AdjacencyWrapper(adj, directed=True)
6363
```
64-
In this case, the graph's nodes are consider to be
64+
In this case, the graph's nodes are considered to be
6565
the numerical values *0,1,..,adj.shape[0]-1*.
6666
The *directed* argument in the constructor only
6767
affects the type of *"auto"* normalization in
68-
preprocessors.
68+
preprocessors.

examples/playground/compare_filter_tuning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pygrank as pg
22

3-
pg.load_backend("numpy")
3+
pg.load_backend("sparse_dot_mkl")
44

55
datasets = ["amazon", "citeseer", "maven"]
66
datasets = ["citeseer"]

pygrank/core/backend/sparse_dot_mkl.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22
from numpy import abs, sum, exp, log, copy, repeat, min, max, dot, mean, diag, ones
33
from scipy.sparse import eye
4+
import warnings
45
import os
56
if "MKL_NUM_THREADS" not in os.environ:
67
os.environ["MKL_NUM_THREADS"] = str(os.cpu_count())
@@ -12,7 +13,7 @@ def backend_init():
1213

1314

1415
def graph_dropout(M, _):
15-
return M.to_csr()
16+
return M
1617

1718

1819
def separate_cols(x):
@@ -24,7 +25,7 @@ def combine_cols(cols):
2425

2526

2627
def backend_name():
27-
return "numpy"
28+
return "sparse_dot_mkl"
2829

2930

3031
def scipy_sparse_to_backend(M):
@@ -60,9 +61,23 @@ def self_normalize(obj):
6061
obj = obj / np_sum
6162
return obj
6263

64+
__pygrank_sparse_dot_mkl_warning = False
65+
6366

6467
def conv(signal, M):
65-
return sparse_dot_mkl.dot_product_mkl(signal, M)
68+
global __pygrank_sparse_dot_mkl_warning
69+
if __pygrank_sparse_dot_mkl_warning:
70+
return signal * M
71+
try:
72+
return sparse_dot_mkl.dot_product_mkl(signal, M)
73+
except Exception as e:
74+
if not __pygrank_sparse_dot_mkl_warning:
75+
__pygrank_sparse_dot_mkl_warning = True
76+
warnings.warn("sparse_dot_mkl failed to link for sparse matrix multiplication.\n"
77+
"Please check your environment setup."
78+
"Falling back to numpy implementation for this backend.")
79+
warnings.warn(str(e))
80+
return signal * M
6681

6782

6883
def length(x):

pygrank/core/utils/preprocessing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def to_sparse_matrix(G,
119119
elif normalization != "none":
120120
raise Exception("Supported normalizations: none, col, symmetric, both, laplacian, auto")
121121
M = transform_adjacency(M)
122-
ret = M if backend.backend_name() == "numpy" else backend.scipy_sparse_to_backend(M)
122+
ret = M if backend.backend_name() == "numpy" or backend.backend_name() == "sparse_dot_mkl" else backend.scipy_sparse_to_backend(M)
123123
ret._pygrank_node2id = {v: i for i, v in enumerate(G)}
124124
if cors:
125125
ret.__pygrank_preprocessed = {backend.backend_name(): ret, "numpy": M}

pygrank/measures/unsupervised.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Conductance(Unsupervised):
5555
Assumes a fuzzy set of subgraphs whose nodes are included with probability proportional to their scores,
5656
as per the formulation of [krasanakis2019linkauc] and calculates E[outgoing edges] / E[internal edges] of
5757
the fuzzy rank subgraph. To avoid potential optimization towards filling the whole graph, the measure is
58-
evaluated to infinity if either denomator *or* the nominator is zero (this means that whole connected components
58+
evaluated to infinity if either denominator *or* the nominator is zero (this means that whole connected components
5959
should not be extracted).
6060
If scores assume binary values, E[.] becomes set size and this calculates the induced subgraph Conductance.
6161
"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setuptools.setup(
1414
name='pygrank',
15-
version='0.2.9',
15+
version='0.2.10',
1616
author="Emmanouil (Manios) Krasanakis",
1717
author_email="[email protected]",
1818
description="Recommendation algorithms for large graphs",

0 commit comments

Comments
 (0)