class_docstr: File writer for TFRecord dataset.
  
  TFRecordWriter serializes tensors in tf.Example schema and write them
  into files in TFRecord format. The written file can be loaded with
  tf.data.TFRecordDataset.
class_docstr_tok: ["File","writer","for","TFRecord","dataset",".","TFRecordWriter","serializes","tensors","in","tf.Example","schema","and","write","them","into","files","in","TFRecord","format",".","The","written","file","can","be","loaded","with","tf.data.TFRecordDataset","."]
code: def _add_sparse_tensor_to_features(self, name, tensor, features):
      indices_name = name + TFRecordWriter._SPARSE_INDICES_SUFFIX
      values_name = name + TFRecordWriter._SPARSE_VALUES_SUFFIX
  
      rank = len(tensor.shape.as_list())
      indices = (
          tensor.indices.numpy()
      )  # indices tensor must be a 2D array
      # Split indices array along the second dimension so that the split arrays
      # contain the indices for separate dimension. For example,
      # indices = [[0, 1], [2, 3], [4, 5]] =>
      #   indices_at_dim0 = [[0], [2], [4]] and
      #   indices_at_dim1 = [[1], [3], [5]].
      split_indices = np.split(indices, rank, axis=1)
      for dim in range(rank):
          indices_name_at_dim = indices_name + str(dim)
          self._add_dense_tensor_to_features(
              name=indices_name_at_dim,
              value=split_indices[dim],
              dtype=tensor.indices.dtype,
              features=features,
          )
  
      self._add_dense_tensor_to_features(
          name=values_name,
          value=tensor.values.numpy(),
          dtype=tensor.values.dtype,
          features=features,
      )
  
file_path: io/tests/test_atds_avro/utils/tf_record_writer.py
imports: import os
  from tests.test_atds_avro.utils.generator.tensor_generator import TensorGeneratorBase
  from tests.test_atds_avro.utils.generator.sparse_tensor_generator import SparseTensorGeneratorBase
  from tests.test_atds_avro.utils.generator.varlen_tensor_generator import VarLenTensorGeneratorBase
  import numpy
  import tensorflow
  from tests.test_atds_avro.utils.file_writer import FileWriter
label_desc: Use image node_id 7 for calling the TFRecordWriter obj's underlying member method code with example usage: obj._add_sparse_tensor_to_features(name, tensor, features) without return types