code: def test_random_sample_with_replacement(
      weights,
      num_samples,
      tolerance,
      raises_exception,
      device_id,
      precision,
  ):
      weights = AA(weights, precision)
      expected_relative_frequency = weights / np.sum(weights)
      num_calls = 10
      identity = np.identity(weights.size)
      allow_duplicates = True  # sample with replacement
  
      if raises_exception:
          with pytest.raises(ValueError):
              result = random_sample(
                  weights, num_samples, allow_duplicates
              )
              result.eval()
      else:
          observed_frequency = np.empty_like(weights)
          for i in range(0, num_calls):
              result = random_sample(
                  weights, num_samples, allow_duplicates
              )
              denseResult = times(result, identity)
              observed_frequency += np.sum(denseResult.eval(), 0)
          observed_relative_frequency = observed_frequency / (
              num_calls * num_samples
          )
          assert np.allclose(
              observed_relative_frequency,
              expected_relative_frequency,
              atol=tolerance,
          )
  
file_path: CNTK/bindings/python/cntk/ops/tests/random_sample_test.py
imports: from __future__ import division
  import numpy
  import pytest
  from .ops_test_utils import AA, precision
  from cntk import random_sample_inclusion_frequency, random_sample, times
label_desc: Use image node_id 2 for calling a global function with example usage: test_random_sample_with_replacement(weights, num_samples, tolerance, raises_exception, device_id, precision) without return types