Repository: dmlc/dgl
Pull request: [Bugfix] Update dgl function `random_walk_pe` to be compatible with latest scipy 
## Description
This is to fix https://github.com/dmlc/dgl/issues/5943.

Due to this PR: https://github.com/scipy/scipy/pull/18508, scipy changes the output of divide (sparse, dense) from dense to sparse format. As a result, it would break the function `random_walk_pe`, as follows:https://github.com/dmlc/dgl/blob/4b585ba068b67f10a25eada64532c09da6561d10/python/dgl/transforms/functional.py#L3592

Reference: 
Release note of scipy 1.11.0: https://github.com/scipy/scipy/releases/tag/v1.11.0
## Checklist
Please feel free to remove inapplicable items for your PR.
- [x] The PR title starts with [$CATEGORY] (such as [NN], [Model], [Doc], [Feature]])
- [x] I've leverage the [tools](https://docs.google.com/document/d/1iHyj7zlmygKSk5gBPsqIqL5ASPzJSPREaNT_QdsiYA4/edit) to beautify the python and c++ code.
- [x] The PR is complete and small, read the [Google eng practice (CL equals to PR)](https://google.github.io/eng-practices/review/developer/small-cls.html) to understand more about small PR. In DGL, we consider PRs with less than 200 lines of core code change are small (example, test and documentation could be exempted).
- [x] All changes have test coverage
- [x] Code is well-documented
- [ ] To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
- [ ] Related issue is referred in this PR
- [ ] If the PR is for a new model/paper, I've updated the example index [here](../examples/README.md).

## Changes
If scipy < 1.11.0, uses `np.array` to change the output to dense ndarray.
Otherwise, uses `.toarray()` to change the output to dense ndarray.



Problem statement:
[Bug] Unit test failed due to a recent update of scipy package (scipy >1.11.0)
## 🐛 Bug

DGL transform function `random_walk_pe` breaks due to recent update of scipy package, which results in an unit test failing (`python/common  -k "test_module_random_walk_pe"`).

## To Reproduce
Install scipy with later version `pip install scipy==1.11` and then `python3 -m pytest --durations=100 tests/python/common -k "test_module_random_walk_pe" `

Or,  run the following:
```
import dgl
import numpy as np
g = dgl.graph(([0, 1, 1], [1, 1, 0]))
A = g.adj_external(scipy_fmt="csr")
B = (A / (A.sum(1) + 1e-30))
# with scipy=1.10, B is a dense matrix in numpy.matrix type
# with scipy=1.11+, B is a sparse matrix in scipy coo format
RW = np.array(B)
print(RW.diagonal())
```
If using later scipy==1.11+, it would crash with err msg:```ValueError: diag requires an array of at least two dimensions```. It is fine with earlier scipy == 1.10.

## Additional context

I will create a PR to fix it.

Hints from issue discussion:

Commit message: Fix lint

Patch to review:
diff --git a/python/dgl/transforms/functional.py b/python/dgl/transforms/functional.py
index fafb2ed32afb..9d79e50aedfa 100644
--- a/python/dgl/transforms/functional.py
+++ b/python/dgl/transforms/functional.py
@@ -3589,7 +3589,12 @@ def random_walk_pe(g, k, eweight_name=None):
             shape=(N, N),
         )
         A = A.multiply(W)
-    RW = np.array(A / (A.sum(1) + 1e-30))  # 1-step transition probability
+    # 1-step transition probability
+    if scipy.__version__ < "1.11.0":
+        RW = np.array(A / (A.sum(1) + 1e-30))
+    else:
+        # sparse matrix divided by a dense array returns a sparse matrix in scipy since 1.11.0
+        RW = (A / (A.sum(1) + 1e-30)).toarray()
 
     # Iterate for k steps
     PE = [F.astype(F.tensor(RW.diagonal()), F.float32)]


Code review comments:
diff_hunk: @@ -3589,7 +3589,12 @@ def random_walk_pe(g, k, eweight_name=None):
             shape=(N, N),
         )
         A = A.multiply(W)
-    RW = np.array(A / (A.sum(1) + 1e-30))  # 1-step transition probability
+    # 1-step transition probability
+    if scipy.__version__ < "1.11.0":
+        RW = np.array(A / (A.sum(1) + 1e-30))
+    else:
+        # sparse matrix divided by a dense array returns a sparse matrix in scipy since 1.11.0
path: python/dgl/transforms/functional.py
text: @user1:
```suggestion
        # Sparse matrix divided by a dense array returns a sparse matrix in
        # scipy since 1.11.0.
```