class_docstr: Tests for the _sparse_expand_matrix function.
class_docstr_tok: ["Tests","for","the","_sparse_expand_matrix","function","."]
docstr: Test the swap matrix generated is as expected.
docstr_tok: ["Test","the","swap","matrix","generated","is","as","expected","."]
code: def test_sparse_swap_mat(self):
      """Test the swap matrix generated is as expected."""
      # pylint: disable=protected-access
      n = 4
      for i in range(n):
          for j in range(n):
              if i != j:
                  expected_mat = qml.SWAP(wires=[i, j]).matrix()
                  expected_mat = qml.math.expand_matrix(
                      expected_mat, [i, j], wire_order=range(n)
                  )
                  computed_mat = (
                      qml.math.matrix_manipulation._sparse_swap_mat(
                          i, j, n
                      ).toarray()
                  )
                  assert np.allclose(expected_mat, computed_mat)
  
imports: from functools import reduce
  import numpy
  import pytest
  from gate_data import CNOT, II, SWAP, I, Toffoli
  from scipy.sparse import csr_matrix
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 12 for calling the TestExpandMatrixSparse obj's underlying member method code with example usage: obj.test_sparse_swap_mat() without return types