code: def test_matrix_rank():
      # Full rank matrix
      assert 4 == matrix_rank(np.eye(4))
      I = np.eye(4)
      I[-1, -1] = 0.0  # rank deficient matrix
      assert matrix_rank(I) == 3
      # All zeros - zero rank
      assert matrix_rank(np.zeros((4, 4))) == 0
      # 1 dimension - rank 1 unless all 0
      assert matrix_rank(np.ones((4,))) == 1
      assert matrix_rank(np.zeros((4,))) == 0
      # accepts array-like
      assert matrix_rank([1]) == 1
      # Make rank deficient matrix
      rng = np.random.RandomState(20120613)
      X = rng.normal(size=(40, 10))
      X[:, 0] = X[:, 1] + X[:, 2]
      S = spl.svd(X, compute_uv=False)
      eps = np.finfo(X.dtype).eps
      assert matrix_rank(X, tol=0) == 10
      assert matrix_rank(X, tol=S.min() - eps) == 10
      assert matrix_rank(X, tol=S.min() + eps) == 9
  
file_path: nipy/nipy/algorithms/utils/tests/test_matrices.py
imports: import numpy
  import scipy.linalg
  from numpy.testing import assert_almost_equal, assert_array_almost_equal
  from ..matrices import full_rank, matrix_rank, pos_recipr, recipr0
label_desc: Use image node_id 1 for calling a global function with example usage: test_matrix_rank() without return types