code: def random_patches(
      focal: tf.Tensor,
      principal_point: tf.Tensor,
      height: int,
      width: int,
      patch_height: int,
      patch_width: int,
      scale: float = 1.0,
      name: str = "random_patches",
  ) -> Tuple[tf.Tensor, tf.Tensor]:
      """Sample patches at different scales and from an image.
  
      Args:
        focal: A tensor of shape `[A1, ..., An, 2]`
        principal_point: A tensor of shape `[A1, ..., An, 2]`
        height: The height of the image plane in pixels.
        width: The width of the image plane in pixels.
        patch_height: The height M of the patch in pixels.
        patch_width: The width N of the patch in pixels.
        scale: The scale of the patch.
        name: A name for this op that defaults to "random_patches".
  
      Returns:
        A tensor of shape `[A1, ..., An, M*N, 3]` where the last dimension is the
          ray directions in 3D passing from the M*N pixels of the patch and
        a tensor of shape `[A1, ..., An, M*N, 2]` with the pixel x, y locations.
      """
      with tf.name_scope(name):
          focal = tf.convert_to_tensor(value=focal)
          principal_point = tf.convert_to_tensor(value=principal_point)
  
          shape.check_static(
              tensor=focal, tensor_name="focal", has_dim_equals=(-1, 2)
          )
          shape.check_static(
              tensor=principal_point,
              tensor_name="principal_point",
              has_dim_equals=(-1, 2),
          )
          shape.compare_batch_dimensions(
              tensors=(focal, principal_point),
              tensor_names=("focal", "principal_point"),
              last_axes=-2,
              broadcast_compatible=True,
          )
  
          batch_shape = tf.shape(focal)[:-1]
          patch_ij = grid.generate(
              [0, 0],
              [patch_height - 1, patch_width - 1],
              [patch_height, patch_width],
          )  # storing is in 'ij'
          patch_ij = tf.cast(patch_ij, tf.float32)
          patch_ij = patch_ij * scale
          interm_shape = tf.concat(
              [tf.ones_like(batch_shape), tf.shape(patch_ij)], axis=0
          )
          patch_ij = tf.reshape(patch_ij, interm_shape)
          random_y = tf.random.uniform(
              batch_shape,
              minval=0,
              maxval=height - int(patch_height * scale) + 1,
              dtype=tf.int32,
          )
          random_x = tf.random.uniform(
              batch_shape,
              minval=0,
              maxval=width - int(patch_width * scale) + 1,
              dtype=tf.int32,
          )
          patch_origins = tf.cast(
              tf.stack([random_y, random_x], axis=-1), tf.float32
          )
          patch_origins = tf.expand_dims(
              tf.expand_dims(patch_origins, -2), -2
          )
          pixels_ij = tf.cast(patch_ij + patch_origins, tf.float32)
          final_shape = tf.concat(
              [batch_shape, [patch_height * patch_width, 2]], axis=0
          )
          pixels_ij = tf.reshape(pixels_ij, final_shape)
          patch_xy = tf.reverse(pixels_ij, axis=[-1])
          rays = ray(
              patch_xy,
              tf.expand_dims(focal, -2),
              tf.expand_dims(principal_point, -2),
          )
          return rays, patch_xy
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  from typing import Tuple
  import tensorflow
  from tensorflow_graphics.geometry.representation import grid
  from tensorflow_graphics.util import asserts
  from tensorflow_graphics.util import export_api
  from tensorflow_graphics.util import safe_ops
  from tensorflow_graphics.util import shape
  from tensorflow_graphics.util import type_alias
label_desc: Use image node_id 8 for calling a global function with example usage: random_patches(focal, principal_point, height, width, patch_height, patch_width, scale, name) and returns: rays,  patch_xy