code: def sample(
      dim: int,
      num_results: types.IntTensor,
      skip: types.IntTensor = 0,
      validate_args: bool = False,
      dtype: tf.dtypes.DType = None,
      name: Optional[str] = None,
  ) -> types.RealTensor:
      """Returns num_results samples from the Sobol sequence of dimension dim.
  
      Uses the original ordering of points, not the more commonly used Gray code
      ordering. Derived from notes by Joe & Kuo[1].
  
      [1] describes bitwise operations on binary floats. The implementation below
      achieves this by transforming the floats into ints, being careful to align
      the digits so the bitwise operations are correct, then transforming back to
      floats.
  
      Args:
        dim: Positive Python `int` representing each sample's `event_size.`
        num_results: Positive scalar `Tensor` of dtype int32. The number of Sobol
          points to return in the output.
        skip: Positive scalar `Tensor` of dtype int32. The number of initial points
          of the Sobol sequence to skip.
        validate_args: Python `bool`. When `True`, input `Tensor's` are checked for
          validity despite possibly degrading runtime performance. The checks verify
          that `dim >= 1`, `num_results >= 1`, `skip >= 0` and whether
          `num_results + skip < 2**31 - 1`. When `False` invalid inputs may silently
          render incorrect outputs.
          Default value: False.
        dtype: Optional `dtype`. The dtype of the output `Tensor` (either `float32`
          or `float64`).
          Default value: `None` which maps to the `float32`.
        name: Python `str` name prefixed to ops created by this function.
  
      Returns:
        `Tensor` of samples from Sobol sequence with `shape` [n, dim].
  
      #### References
  
      [1]: S. Joe and F. Y. Kuo. Notes on generating Sobol sequences. August 2008.
           https://web.maths.unsw.edu.au/~fkuo/sobol/joe-kuo-notes.pdf
      """
      with tf.name_scope(name or "sobol_sample"):
          num_results = tf.convert_to_tensor(
              num_results, dtype=tf.int32, name="num_results"
          )
          skip = tf.convert_to_tensor(skip, dtype=tf.int32, name="skip")
          control_dependencies = []
          if validate_args:
              if dim < 1:
                  raise ValueError(
                      "Dimension must be greater than zero. Supplied {}".format(
                          dim
                      )
                  )
              control_dependencies.append(
                  tf.debugging.assert_greater(
                      num_results,
                      0,
                      message="Number of results `num_results` must be greater "
                      "than zero.",
                  )
              )
              control_dependencies.append(
                  tf.debugging.assert_greater(
                      skip, 0, message="`skip` must be non-negative."
                  )
              )
              # Need to check that skip + num_results < largest positive int32.
              control_dependencies.append(
                  tf.debugging.assert_greater(
                      _MAX_POSITIVE - num_results,
                      skip,
                      message="Skip too large. Should be smaller than "
                      f"{_MAX_POSITIVE} - num_results",
                  )
              )
  
          with tf.control_dependencies(control_dependencies):
              if validate_args:
                  # The following tf.maximum ensures that the graph can be executed
                  # even with ignored control dependencies
                  num_results = tf.math.maximum(
                      num_results, 1, name="fix_num_results"
                  )
                  skip = tf.math.maximum(skip, 0, name="fix_skip")
              direction_numbers = tf.convert_to_tensor(
                  _compute_direction_numbers(dim),
                  name="direction_numbers",
              )
              # Number of digits actually needed for binary representation.
              # Note that we need to cast to int64 because even if skip and num results
              # are int32, their sum may exceed the range and cause a negative value
              # which will crash tf.math.log.
              max_index = (
                  tf.cast(skip, dtype=tf.int64)
                  + tf.cast(num_results, dtype=tf.int64)
                  + 1
              )
              num_digits = tf.cast(
                  tf.math.ceil(
                      tf.math.log(tf.cast(max_index, tf.float64))
                      / _LN_2
                  ),
                  tf.int32,
              )
          # Direction numbers, reshaped and with the digits shifted as needed for the
          # bitwise xor operations below. Note that here and elsewhere we use bit
          # shifts rather than powers of two because exponentiating integers is not
          # currently supported on GPUs.
          direction_numbers = tf.bitwise.left_shift(
              direction_numbers[:dim, :num_digits],
              tf.range(num_digits - 1, -1, -1),
          )
          direction_numbers = tf.expand_dims(
              tf.transpose(a=direction_numbers), 1
          )
  
          # Build the binary matrix corresponding to the i values in Joe & Kuo[1]. It
          # is a matrix of the binary representation of the numbers (skip+1, skip+2,
          # ..., skip+num_results). For example, with skip=0 and num_results=6 the
          # binary matrix (before expanding the dimension) looks like this:
          # [[1 0 1 0 1 0]
          #  [0 1 1 0 0 1]
          #  [0 0 0 1 1 1]]
          irange = skip + 1 + tf.range(num_results)
          dig_range = tf.expand_dims(tf.range(num_digits), 1)
          binary_matrix = tf.bitwise.bitwise_and(
              1, tf.bitwise.right_shift(irange, dig_range)
          )
          binary_matrix = tf.expand_dims(binary_matrix, -1)
  
          # Multiply and bitwise-xor everything together. We use while_loop rather
          # than foldl(bitwise_xor(...)) because the latter is not currently supported
          # on GPUs.
          product = direction_numbers * binary_matrix
  
          def _cond(partial_result, i):
              del partial_result
              return i < num_digits
  
          def _body(partial_result, i):
              return (
                  tf.bitwise.bitwise_xor(
                      partial_result, product[i, :, :]
                  ),
                  i + 1,
              )
  
          result, _ = tf.while_loop(_cond, _body, (product[0, :, :], 1))
          # Shift back from integers to floats.
          dtype = dtype or tf.float32
          # By default, tensorflow interprets a literal number as tf.int32 (if within
          # range). As this is a signed integer, left shift can produce a negative
          # number if the shift is too large. Example:
          # tf.bitwise.left_shift(1, 31) = -2**31. To avoid this, we can either work
          # with unsigned ints or use a larger int type. We do the latter here.
          one = tf.constant(1, dtype=tf.int64)
          divisor = tf.bitwise.left_shift(
              one, tf.cast(num_digits, dtype=tf.int64)
          )
          return tf.cast(result, dtype) / tf.cast(divisor, dtype)
  
file_path: tf-quant-finance/tf_quant_finance/math/random_ops/sobol/sobol_impl.py
imports: import logging
  import os
  from typing import Optional, Tuple
  import numpy
  from six.moves import range
  import tensorflow.compat.v2
  from tf_quant_finance import types
label_desc: Use image node_id 1 for calling a global function with example usage: sample(dim, num_results, skip, validate_args, dtype, name) and returns: unknown, unknown, tf,  unknown