code: def test_get_nondiag_weight(rndstate):
      """Test get_nondiag_weight"""
      n_conds, n_matrices, n_channels = 10, 20, 3
  
      # test a 2d array, ie a single square matrix
      w = get_nondiag_weight(rndstate.randn(n_channels, n_channels))
      assert np.isscalar(w)
      # test a 3d array, ie a group of square matrices
      w = get_nondiag_weight(
          rndstate.randn(n_matrices, n_channels, n_channels)
      )
      assert w.shape == (n_matrices,)
      # test a 4d array, ie a group of groups of square matrices
      shape = (n_conds, n_matrices, n_channels, n_channels)
      w = get_nondiag_weight(rndstate.randn(*shape))
      assert w.shape == (n_conds, n_matrices)
  
      # 2x2 constant matrices => non-diag weights equal to 1
      mats = rndstate.randn(n_matrices, 1, 1) * np.ones(
          (n_matrices, 2, 2)
      )
      w = get_nondiag_weight(mats)
      assert_array_almost_equal(w, np.ones(n_matrices))
      # diagonal matrices => non-diag weights equal to 0
      mats = rndstate.randn(n_matrices, 1, 1) * (
          [np.eye(n_channels)] * n_matrices
      )
      w = get_nondiag_weight(mats)
      assert_array_almost_equal(w, np.zeros(n_matrices))
  
      with pytest.raises(ValueError):  # not at least 2d
          get_nondiag_weight(rndstate.randn(n_channels))
      with pytest.raises(ValueError):  # not square
          shape = (n_matrices, n_channels, n_channels + 2)
          get_nondiag_weight(rndstate.randn(*shape))
  
imports: from numpy.testing import assert_array_almost_equal
  import numpy
  from scipy.linalg import block_diag
  from scipy.signal import welch, csd, coherence
  from sklearn.covariance import empirical_covariance
  import pytest
  from pyriemann.utils.covariance import covariances, covariances_EP, covariances_X, eegtocov, cross_spectrum, cospectrum, coherence, normalize, get_nondiag_weight, block_covariances, _complex_estimator
  from pyriemann.utils.test import is_real, is_hermitian, is_sym_pos_def, is_herm_pos_def
label_desc: Use image node_id 17 for calling a global function with example usage: test_get_nondiag_weight(rndstate) without return types