class_docstr: Tests for the expand_matrix helper function.
class_docstr_tok: ["Tests","for","the","expand_matrix","helper","function","."]
docstr: Tests that the method is used correctly with a broadcasted matrix by defining
  a dummy operator and checking the permutation/expansion.
docstr_tok: ["Tests","that","the","method","is","used","correctly","with","a","broadcasted","matrix","by","defining","a","dummy","operator","and","checking","the","permutation\/expansion","."]
code: def test_expand_matrix_usage_in_operator_class_broadcasted(self, tol):
      """Tests that the method is used correctly with a broadcasted matrix by defining
      a dummy operator and checking the permutation/expansion."""
  
      perm = [0, 2, 1, 3]
      permuted_matrix = self.base_matrix_2_broadcasted[:, perm][
          :, :, perm
      ]
  
      expanded_matrix = np.tensordot(
          np.tensordot(
              np.kron(SWAP, I),
              np.kron(I_broadcasted, self.base_matrix_2_broadcasted),
              axes=[[1], [1]],
          ),
          np.kron(SWAP, I),
          axes=[[2], [0]],
      )
      expanded_matrix = np.moveaxis(expanded_matrix, 0, -2)
  
      class DummyOp(qml.operation.Operator):
          num_wires = 2
  
          @staticmethod
          def compute_matrix():
              return self.base_matrix_2_broadcasted
  
      op = DummyOp(wires=[0, 2])
      assert np.allclose(
          op.matrix(), self.base_matrix_2_broadcasted, atol=tol
      )
      assert np.allclose(
          op.matrix(wire_order=[2, 0]), permuted_matrix, atol=tol
      )
      assert np.allclose(
          op.matrix(wire_order=[0, 1, 2]), expanded_matrix, atol=tol
      )
  
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 26 for calling the TestExpandMatrix obj's underlying member method code with example usage: obj.test_expand_matrix_usage_in_operator_class_broadcasted(tol) and returns: self