class_docstr: Test the Rademacher distribution sampler.
class_docstr_tok: ["Test","the","Rademacher","distribution","sampler","."]
docstr: Test that the sampled output has the right entries to be non-zero
  and attains the right values.
docstr_tok: ["Test","that","the","sampled","output","has","the","right","entries","to","be","non-zero","and","attains","the","right","values","."]
code: def test_output_structure(self, ids, num):
      """Test that the sampled output has the right entries to be non-zero
      and attains the right values."""
      ids_mask = np.zeros(num, dtype=bool)
      ids_mask[ids] = True
      rng = np.random.default_rng()
  
      for _ in range(5):
          direction = _rademacher_sampler(ids, num, rng=rng)
          assert direction.shape == (num,)
          assert set(direction).issubset({0, -1, 1})
          assert np.allclose(np.abs(direction)[ids_mask], 1)
          assert np.allclose(direction[~ids_mask], 0)
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.devices import DefaultQubitLegacy
  from pennylane.gradients import spsa_grad
  from pennylane.gradients.spsa_gradient import _rademacher_sampler
  from pennylane.operation import AnyWires, Observable
label_desc: Use image node_id 1 for calling the TestRademacherSampler obj's underlying member method code with example usage: obj.test_output_structure(ids, num) without return types