Skip to content

Commit

Permalink
Merge pull request #69 from mscheltienne/assert_allclose
Browse files Browse the repository at this point in the history
Use assert_allclose from numpy.testing instead of np.allclose
  • Loading branch information
smoia authored Aug 16, 2023
2 parents 8d55f01 + aef8391 commit ec717a9
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions nigsp/tests/test_laplacian.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from copy import deepcopy as dc

import numpy as np
from pytest import mark, raises
from numpy.testing import assert_allclose
from pytest import raises

from nigsp.operations import laplacian

Expand All @@ -24,29 +25,29 @@ def glap(mtx):
L, deg = glap(adj)
lapl, degree = laplacian.compute_laplacian(mtx)

assert np.allclose(lapl, L)
assert np.allclose(degree, deg)
assert_allclose(lapl, L)
assert_allclose(degree, deg)

lapl, degree = laplacian.compute_laplacian(mtx, selfloops=True)
L, deg = glap(mtx)
assert np.allclose(lapl, L)
assert np.allclose(degree, deg)
assert_allclose(lapl, L)
assert_allclose(degree, deg)

rn_deg = np.random.rand(4)
lapl, degree = laplacian.compute_laplacian(mtx, selfloops=rn_deg)
adj = dc(mtx)
adj[np.diag_indices(mtx.shape[0])] = rn_deg
L, deg = glap(adj)
assert np.allclose(lapl, L)
assert np.allclose(degree, deg)
assert_allclose(lapl, L)
assert_allclose(degree, deg)

lapl, degree = laplacian.compute_laplacian(mtx, selfloops="degree")
adj[np.diag_indices(mtx.shape[0])] = 0
_, deg = glap(adj)
adj[np.diag_indices(mtx.shape[0])] = deg
L, deg = glap(adj)
assert np.allclose(lapl, L)
assert np.allclose(degree, deg)
assert_allclose(lapl, L)
assert_allclose(degree, deg)

mtx = mtx - mtx.mean()

Expand All @@ -57,18 +58,18 @@ def glap(mtx):

L, deg = glap(mtx_abs)
lapl, degree = laplacian.compute_laplacian(mtx, negval="absolute", selfloops=True)
assert np.allclose(lapl, L)
assert np.allclose(degree, deg)
assert_allclose(lapl, L)
assert_allclose(degree, deg)

L, deg = glap(mtx_rem)
lapl, degree = laplacian.compute_laplacian(mtx, negval="remove", selfloops=True)
assert np.allclose(lapl, L)
assert np.allclose(degree, deg)
assert_allclose(lapl, L)
assert_allclose(degree, deg)

L, deg = glap(mtx_res)
lapl, degree = laplacian.compute_laplacian(mtx, negval="rescale", selfloops=True)
assert np.allclose(lapl, L)
assert np.allclose(degree, deg)
assert_allclose(lapl, L)
assert_allclose(degree, deg)


def test_normalisation():
Expand Down

0 comments on commit ec717a9

Please sign in to comment.