code: def constrained_tensors(
      constraint_fn, shape, dtype=np.float32, elements=None
  ):
      """Strategy for drawing a constrained Tensor.
  
      Args:
        constraint_fn: Function mapping the unconstrained space to the desired
          constrained space.
        shape: Shape of the desired Tensors as a Python list.
        dtype: Dtype for constrained Tensors.
        elements: Optional strategy for selecting array elements.
  
      Returns:
        tensors: A strategy for drawing constrained Tensors of the given shape.
      """
      # TODO(bjp): Allow a wider range of floats.
      # float32s = hps.floats(
      #     np.finfo(np.float32).min / 2, np.finfo(np.float32).max / 2,
      #     allow_nan=False, allow_infinity=False)
      if elements is None:
          if dtype_util.is_floating(dtype):
              width = (
                  np.dtype(dtype_util.as_numpy_dtype(dtype)).itemsize
                  * 8
              )
              elements = hps.floats(
                  -200,
                  200,
                  allow_nan=False,
                  allow_infinity=False,
                  width=width,
              )
          elif dtype_util.is_bool(dtype):
              elements = hps.booleans()
          else:
              raise NotImplementedError(dtype)
  
      def mapper(x):
          x = constraint_fn(tf.convert_to_tensor(x, dtype_hint=dtype))
          if dtype_util.is_floating(x.dtype) and tf.executing_eagerly():
              # We'll skip this check in graph mode; too expensive.
              if not np.all(np.isfinite(np.array(x))):
                  raise AssertionError(
                      "{} generated non-finite param value: {}".format(
                          constraint_fn, np.array(x)
                      )
                  )
          return x
  
      return hpnp.arrays(
          dtype=dtype, shape=shape, elements=elements
      ).map(mapper)
  
imports: import contextlib
  import os
  import re
  import traceback
  import unittest
  import hypothesis
  from hypothesis.extra import numpy
  import hypothesis.strategies
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.util.deferred_tensor import DeferredTensor
label_desc: Use image node_id 18 for calling a global function with example usage: constrained_tensors(constraint_fn, shape, dtype, elements) and returns: hpnp, x