Repository: pyg-team/pytorch_geometric
Pull request #9027 (2024-03-07 16:18:28)

Fix MKL issue on Windows

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/9027?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 89.24%. Comparing base [(`af0f5f4`)](https://app.codecov.io/gh/pyg-team/pytorch_geometric/commit/af0f5f44d4dfa8accd898df3e8523d06b67940b0?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) to head [(`a4d9bec`)](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/9027?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team).

> :exclamation: Current head a4d9bec differs from pull request most recent head b7eb76b. Consider uploading reports for the commit b7eb76b to get more accurate results


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #9027      +/-   ##
==========================================
- Coverage   89.86%   89.24%   -0.63%     
==========================================
  Files         468      468              
  Lines       30039    30036       -3     
==========================================
- Hits        26995    26805     -190     
- Misses       3044     3231     +187     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/9027?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team).


Patch:
diff --git a/torch_geometric/edge_index.py b/torch_geometric/edge_index.py
index c9be09abd..90f77cb17 100644
--- a/torch_geometric/edge_index.py
+++ b/torch_geometric/edge_index.py
@@ -1823,7 +1823,7 @@ def matmul(
 
     transpose &= not input.is_undirected or input_value is not None
 
-    if not torch_geometric.typing.WITH_MKL:  # pragma: no cover
+    if torch_geometric.typing.NO_MKL:  # pragma: no cover
         sparse_input = input.to_sparse_coo(input_value)
     elif input.is_sorted_by_col:
         sparse_input = input.to_sparse_csc(input_value)
@@ -1833,7 +1833,7 @@ def matmul(
     if transpose:
         sparse_input = sparse_input.t()
 
-    if not torch_geometric.typing.WITH_MKL:  # pragma: no cover
+    if torch_geometric.typing.NO_MKL:  # pragma: no cover
         other = other.to_sparse_coo(other_value)
     elif other.is_sorted_by_col:
         other = other.to_sparse_csc(other_value)
diff --git a/torch_geometric/transforms/add_positional_encoding.py b/torch_geometric/transforms/add_positional_encoding.py
index f55c2030e..e4d43a032 100644
--- a/torch_geometric/transforms/add_positional_encoding.py
+++ b/torch_geometric/transforms/add_positional_encoding.py
@@ -153,10 +153,10 @@ class AddRandomWalkPE(BaseTransform):
             adj = torch.zeros((N, N), device=row.device)
             adj[row, col] = value
             loop_index = torch.arange(N, device=row.device)
-        elif torch_geometric.typing.WITH_MKL:
-            adj = to_torch_csr_tensor(data.edge_index, value, size=data.size())
-        else:
+        elif torch_geometric.typing.NO_MKL:  # pragma: no cover
             adj = to_torch_coo_tensor(data.edge_index, value, size=data.size())
+        else:
+            adj = to_torch_csr_tensor(data.edge_index, value, size=data.size())
 
         def get_pe(out: Tensor) -> Tensor:
             if is_torch_sparse_tensor(out):
diff --git a/torch_geometric/typing.py b/torch_geometric/typing.py
index 16a5fbd42..049c86bb8 100644
--- a/torch_geometric/typing.py
+++ b/torch_geometric/typing.py
@@ -17,7 +17,7 @@ WITH_PT112 = WITH_PT20 or int(torch.__version__.split('.')[1]) >= 12
 WITH_PT113 = WITH_PT20 or int(torch.__version__.split('.')[1]) >= 13
 
 WITH_WINDOWS = os.name == 'nt'
-WITH_MKL = 'USE_MKL=OFF' not in torch.__config__.show()
+NO_MKL = 'USE_MKL=OFF' in torch.__config__.show() or WITH_WINDOWS
 
 MAX_INT64 = torch.iinfo(torch.int64).max
 


Test patch:
diff --git a/test/test_edge_index.py b/test/test_edge_index.py
index b6680b6d5..8c732d2c1 100644
--- a/test/test_edge_index.py
+++ b/test/test_edge_index.py
@@ -952,7 +952,7 @@ def test_spspmm(device, reduce, transpose, is_undirected):
         assert isinstance(out, EdgeIndex)
         assert out.is_sorted_by_row
         assert out._sparse_size == (3, 3)
-        if torch_geometric.typing.WITH_MKL:
+        if not torch_geometric.typing.NO_MKL:
             assert out._indptr is not None
         assert torch.allclose(out.to_dense(value), adj1_dense @ adj2_dense)
     else: