def _iteration_l_moments_sparse(
    current_index, l1_sum, l2_sum, l3_sum, l4_sum, count_samples,
    count_pairs, count_triplets, count_quadruplets, x_rank_2):
  """Process one column of a `SparseTensor` and updates L-moments variables."""
  current_x = tf.boolean_mask(
      x_rank_2.values,
      tf.math.equal(x_rank_2.indices[:, 1], [current_index]))
  sorted_x = tf.sort(current_x, axis=0)
  num_samples = tf.shape(current_x)[0]
  (current_samples, current_pairs, current_triplets, current_quadruplets,
   l1_factors, l2_factors, l3_factors,
   l4_factors) = _num_terms_and_factors(num_samples, x_rank_2.values.dtype)

  dim_1 = x_rank_2.dense_shape[1]
  new_l1_sum = l1_sum + tf.scatter_nd(
      [[current_index]],
      [tf.reduce_sum(tf.multiply(sorted_x, l1_factors), axis=0)], [dim_1])
  new_l2_sum = l2_sum + tf.scatter_nd(
      [[current_index]],
      [tf.reduce_sum(tf.multiply(sorted_x, l2_factors), axis=0)], [dim_1])
  new_l3_sum = l3_sum + tf.scatter_nd(
      [[current_index]],
      [tf.reduce_sum(tf.multiply(sorted_x, l3_factors), axis=0)], [dim_1])
  new_l4_sum = l4_sum + tf.scatter_nd(
      [[current_index]],
      [tf.reduce_sum(tf.multiply(sorted_x, l4_factors), axis=0)], [dim_1])

  new_count_samples = count_samples + tf.scatter_nd(
      [[current_index]], [current_samples], [dim_1])
  new_count_pairs = count_pairs + tf.scatter_nd(
      [[current_index]], [current_pairs], [dim_1])
  new_count_triplets = count_triplets + tf.scatter_nd(
      [[current_index]], [current_triplets], [dim_1])
  new_count_quadruplets = count_quadruplets + tf.scatter_nd(
      [[current_index]], [current_quadruplets], [dim_1])

  return (tf.add(current_index, 1),
          new_l1_sum, new_l2_sum, new_l3_sum, new_l4_sum,
          new_count_samples, new_count_pairs, new_count_triplets,
          new_count_quadruplets, x_rank_2)
Process one column of a `SparseTensor` and updates L-moments variables.
tensorflow_transform/tf_utils.py