code: def _dump_svmlight(X, y, f, multilabel, one_based, comment, query_id):
      X_is_sp = int(hasattr(X, "tocsr"))
      y_is_sp = int(hasattr(y, "tocsr"))
      if X.dtype.kind == "i":
          value_pattern = u("%d:%d")
      else:
          value_pattern = u("%d:%.16g")
  
      if y.dtype.kind == "i":
          label_pattern = u("%d")
      else:
          label_pattern = u("%.16g")
  
      line_pattern = u("%s")
      if query_id is not None:
          line_pattern += u(" qid:%d")
      line_pattern += u(" %s\n")
  
      if comment:
          f.write(
              b(
                  "# Generated by dump_svmlight_file from scikit-learn %s\n"
                  % __version__
              )
          )
          f.write(
              b(
                  "# Column indices are %s-based\n"
                  % ["zero", "one"][one_based]
              )
          )
  
          f.write(b("#\n"))
          f.writelines(
              b("# %s\n" % line) for line in comment.splitlines()
          )
  
      for i in range(X.shape[0]):
          if X_is_sp:
              span = slice(X.indptr[i], X.indptr[i + 1])
              row = zip(X.indices[span], X.data[span])
          else:
              nz = X[i] != 0
              row = zip(np.where(nz)[0], X[i, nz])
  
          s = " ".join(
              value_pattern % (j + one_based, x) for j, x in row
          )
  
          if multilabel:
              if y_is_sp:
                  nz_labels = y[i].nonzero()[1]
              else:
                  nz_labels = np.where(y[i] != 0)[0]
              labels_str = ",".join(
                  label_pattern % j for j in nz_labels
              )
          else:
              if y_is_sp:
                  labels_str = label_pattern % y.data[i]
              else:
                  labels_str = label_pattern % y[i]
  
          if query_id is not None:
              feat = (labels_str, query_id[i], s)
          else:
              feat = (labels_str, s)
  
          f.write((line_pattern % feat).encode("ascii"))
  
file_path: catboost/contrib/python/scikit-learn/py2/sklearn/datasets/svmlight_format.py
imports: from contextlib import closing
  import io
  import os.path
  import numpy
  import scipy.sparse
  from ._svmlight_format import _load_svmlight_file
  from ..None import __version__
  from ..externals import six
  from ..externals.six import u, b
  from ..externals.six.moves import range, zip
  from ..utils import check_array
  from ..utils.fixes import frombuffer_empty
label_desc: Use image node_id 5 for calling a global function with example usage: _dump_svmlight(X, y, f, multilabel, one_based, comment, query_id) without return types