def _make_dense_to_sparse_fn(self, is_scalar):

    def dense_to_sparse_scalar(tensor):
        indices = [[]]
        values = array_ops.expand_dims(tensor, 0)
        shape = []
        return sparse_tensor.SparseTensorValue(indices, values, shape)

    def dense_to_sparse_non_scalar(tensor):
        indices = array_ops.where(array_ops.ones_like(tensor, dtype=dtypes.bool))
        values = array_ops.gather_nd(tensor, indices)
        shape = array_ops.shape(tensor, out_type=dtypes.int64)
        return sparse_tensor.SparseTensorValue(indices, values, shape)
    if is_scalar:
        return dense_to_sparse_scalar
    return dense_to_sparse_non_scalar
def _make_dense_to_sparse_fn(self, is_scalar):

    def dense_to_sparse_scalar(tensor):
        indices = [[]]
        values = array_ops.expand_dims(tensor, 0)
        shape = []
        return sparse_tensor.SparseTensorValue(indices, values, shape)

    def dense_to_sparse_non_scalar(tensor):
        indices = array_ops.where(array_ops.ones_like(tensor, dtype=dtypes.bool))
        values = array_ops.gather_nd(tensor, indices)
        shape = array_ops.shape(tensor, out_type=dtypes.int64)
        return sparse_tensor.SparseTensorValue(indices, values, shape)
    if is_scalar:
        return dense_to_sparse_scalar
    return dense_to_sparse_non_scalar