class_docstr: Tests for the _sparse_expand_matrix function.
class_docstr_tok: ["Tests","for","the","_sparse_expand_matrix","function","."]
docstr: Test that a 3 qubit gate on consecutive
  wires correctly expands to 4 qubits.
docstr_tok: ["Test","that","a","3","qubit","gate","on","consecutive","wires","correctly","expands","to","4","qubits","."]
code: def test_expand_three_consecutive_wires(self):
      """Test that a 3 qubit gate on consecutive
      wires correctly expands to 4 qubits."""
      # test applied to wire 0,1,2
      res = qml.math.expand_matrix(
          csr_matrix(Toffoli), [0, 1, 2], [0, 1, 2, 3]
      )
      res.sort_indices()
      expected = csr_matrix(np.kron(Toffoli, I))
      expected.sort_indices()
  
      assert isinstance(res, type(expected))
      assert all(res.data == expected.data)
      assert all(res.indices == expected.indices)
  
      # test applied to wire 1,2,3
      res = qml.math.expand_matrix(
          csr_matrix(Toffoli), [1, 2, 3], [0, 1, 2, 3]
      )
      res.sort_indices()
      expected = csr_matrix(np.kron(I, Toffoli))
      expected.sort_indices()
  
      assert isinstance(res, type(expected))
      assert all(res.data == expected.data)
      assert all(res.indices == expected.indices)
  
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 9 for calling the TestExpandMatrixSparse obj's underlying member method code with example usage: obj.test_expand_three_consecutive_wires() without return types