code: def _dense_to_sparse(dense, dtype):
      indices = []
      values = []
      max_row_len = 0
      for row in dense:
          max_row_len = max(max_row_len, len(row))
      shape = [len(dense), max_row_len]
      row_ix = 0
      for row in dense:
          col_ix = 0
          for cell in row:
              indices.append([row_ix, col_ix])
              values.append(
                  str(cell) if dtype == dtypes.string else cell
              )
              col_ix += 1
          row_ix += 1
      return sparse_tensor_lib.SparseTensor(
          constant_op.constant(indices, dtypes.int64),
          constant_op.constant(values, dtype),
          constant_op.constant(shape, dtypes.int64),
      )
  
imports: from absl.testing import parameterized
  import numpy
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors_impl
  from tensorflow.python.framework import sparse_tensor
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import gen_set_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import sets
  from tensorflow.python.ops import sparse_ops
  from tensorflow.python.platform import googletest
label_desc: Use image node_id 3 for calling a global function with example usage: _dense_to_sparse(dense, dtype) and returns: sparse_tensor_lib