code: def _calculate_spline_coeffs_natural(
      dx, superdiag, subdiag, diag_values, rhs, dtype
  ):
      """Calculates spline coefficients for the NATURAL boundary condition."""
      # remove duplicate
      corr_term = tf.logical_or(
          tf.equal(superdiag, 0), tf.equal(subdiag, 0)
      )
      diag_values_corr = tf.where(
          corr_term, tf.ones_like(diag_values), diag_values
      )
      superdiag_corr = tf.where(
          tf.equal(subdiag, 0), tf.zeros_like(superdiag), superdiag
      )
      subdiag_corr = tf.where(
          tf.equal(superdiag, 0), tf.zeros_like(subdiag), subdiag
      )
      diagonals = tf.stack(
          [superdiag_corr, diag_values_corr, subdiag_corr], axis=-2
      )
      # Transform a matrix to make it invertible.
      # For the cases input x_data and y_data contains duplicate points.
      rhs = tf.where(corr_term, tf.zeros_like(rhs), rhs)
  
      # Partial pivoting is unnecessary since the matrix is diagonally dominant.
      spline_coeffs = tf.linalg.tridiagonal_solve(
          diagonals, rhs, partial_pivoting=False
      )
      # Reshape `spline_coeffs`
      zero = tf.zeros_like(dx[..., :1], dtype=dtype)
      spline_coeffs = tf.concat([zero, spline_coeffs, zero], axis=-1)
      return spline_coeffs
  
file_path: tf-quant-finance/tf_quant_finance/math/interpolation/cubic/cubic_interpolation.py
imports: import enum
  import tensorflow.compat.v2
  from tf_quant_finance import types
  from tf_quant_finance import utils
label_desc: Use image node_id 3 for calling a global function with example usage: _calculate_spline_coeffs_natural(dx, superdiag, subdiag, diag_values, rhs, dtype) and returns: spline_coeffs