code: def _grid_from_time_step(*, times, time_step, dtype, tolerance):
      """Creates a time grid from an input time step."""
      grid = tf.range(0.0, times[-1], time_step, dtype=dtype)
      all_times = tf.concat([times, grid], axis=0)
      all_times = tf.sort(all_times)
  
      # Remove duplicate points
      dt = all_times[1:] - all_times[:-1]
      dt = tf.concat([[1.0], dt], axis=-1)
      duplicate_mask = tf.math.greater(dt, tolerance)
      all_times = tf.boolean_mask(all_times, duplicate_mask)
      time_indices = tf.searchsorted(
          all_times, times, out_type=tf.int32
      )
      time_indices = tf.math.minimum(
          time_indices, tf.shape(all_times)[0] - 1
      )
  
      # Move `time_indices` to the left, if the requested `times` are removed from
      # `all_times` during deduplication
      time_indices = tf.where(
          tf.gather(all_times, time_indices) - times > tolerance,
          time_indices - 1,
          time_indices,
      )
  
      return all_times, time_indices
  
file_path: tf-quant-finance/tf_quant_finance/models/utils.py
imports: import tensorflow.compat.v2
  from tf_quant_finance.math import random_ops
label_desc: Use image node_id 4 for calling a global function with example usage: _grid_from_time_step() and returns: all_times,  time_indices