code: def _prepare_grid(
      times,
      time_step,
      dtype,
      *params,
      num_time_steps=None,
      times_grid=None,
  ):
      """Prepares grid of times for path generation.
  
      Args:
        times:  Rank 1 `Tensor` of increasing positive real values. The times at
          which the path points are to be evaluated.
        time_step: Rank 0 real `Tensor`. Maximal distance between points in
          resulting grid.
        dtype: `tf.Dtype` of the input and output `Tensor`s.
        *params: Parameters of the Heston model. Either scalar `Tensor`s of the
          same `dtype` or instances of `PiecewiseConstantFunc`.
        num_time_steps: Number of points on the grid. If suppied, a uniform grid
          is constructed for `[time_step, times[-1] - time_step]` consisting of
          max(0, num_time_steps - len(times)) points that is then concatenated with
          times. This parameter guarantees the number of points on the time grid
          is `max(len(times), num_time_steps)` and that `times` are included to the
          grid.
          Default value: `None`, which means that a uniform grid is created.
          containing all points from 'times` and the uniform grid of points between
          `[0, times[-1]]` with grid size equal to `time_step`.
        times_grid: An optional rank 1 `Tensor` representing time discretization
          grid. If `times` are not on the grid, then the nearest points from the
          grid are used.
          Default value: `None`, which means that times grid is computed using
          `time_step` and `num_time_steps`.
  
      Returns:
        Tuple `(all_times, mask)`.
        `all_times` is a 1-D real `Tensor` containing all points from 'times`, the
        uniform grid of points between `[0, times[-1]]` with grid size equal to
        `time_step`, and jump locations of piecewise constant parameters The
        `Tensor` is sorted in ascending order and may contain duplicates.
        `mask` is a boolean 1-D `Tensor` of the same shape as 'all_times', showing
        which elements of 'all_times' correspond to THE values from `times`.
        Guarantees that times[0]=0 and mask[0]=False.
      """
      additional_times = []
      for param in params:
          if isinstance(param, piecewise.PiecewiseConstantFunc):
              additional_times.append(param.jump_locations())
      if times_grid is None:
          if time_step is not None:
              grid = tf.range(0.0, times[-1], time_step, dtype=dtype)
              all_times = tf.concat(
                  [grid, times] + additional_times, axis=0
              )
          elif num_time_steps is not None:
              grid = tf.linspace(
                  tf.convert_to_tensor(0.0, dtype=dtype),
                  times[-1] - time_step,
                  num_time_steps,
              )
              all_times = tf.concat(
                  [grid, times] + additional_times, axis=0
              )
  
          additional_times_mask = [
              tf.zeros_like(times, dtype=tf.bool)
              for times in additional_times
          ]
          mask = tf.concat(
              [
                  tf.zeros_like(grid, dtype=tf.bool),
                  tf.ones_like(times, dtype=tf.bool),
              ]
              + additional_times_mask,
              axis=0,
          )
          perm = tf.argsort(all_times, stable=True)
          all_times = tf.gather(all_times, perm)
          mask = tf.gather(mask, perm)
      else:
          all_times, mask, _ = utils.prepare_grid(
              times=times,
              time_step=time_step,
              times_grid=times_grid,
              dtype=dtype,
          )
      return all_times, mask
  
file_path: tf-quant-finance/tf_quant_finance/models/heston/heston_model.py
imports: from typing import Union, Callable, Optional
  import numpy
  import tensorflow.compat.v2
  from tf_quant_finance import types
  from tf_quant_finance import utils
  from tf_quant_finance.math import piecewise
  from tf_quant_finance.math import random_ops
  from tf_quant_finance.models import generic_ito_process
  from tf_quant_finance.models import utils
label_desc: Use image node_id 4 for calling a global function with example usage: _prepare_grid(times, time_step, dtype) and returns: all_times,  mask