class_docstr: Generic matlab matrix writing class 
docstr: Sparse matrices are 2D
          
docstr_tok: ["Sparse","matrices","are","2D"]
code: def write_sparse(self, arr):
      """Sparse matrices are 2D"""
      A = arr.tocsc()  # convert to sparse CSC format
      A.sort_indices()  # MATLAB expects sorted row indices
      is_complex = A.dtype.kind == "c"
      is_logical = A.dtype.kind == "b"
      nz = A.nnz
      self.write_header(
          matdims(arr, self.oned_as),
          mxSPARSE_CLASS,
          is_complex=is_complex,
          is_logical=is_logical,
          # matlab won't load file with 0 nzmax
          nzmax=1 if nz == 0 else nz,
      )
      self.write_element(A.indices.astype("i4"))
      self.write_element(A.indptr.astype("i4"))
      self.write_element(A.data.real)
      if is_complex:
          self.write_element(A.data.imag)
  
imports: import os
  import time
  import sys
  import zlib
  from io import BytesIO
  import warnings
  import numpy
  import scipy.sparse
  from .byteordercodes import native_code, swapped_code
  from .miobase import MatFileReader, docfiller, matdims, read_dtype, arr_to_chars, arr_dtype_number, MatWriteError, MatReadError, MatReadWarning
  from .mio5_utils import VarReader5
  from .mio5_params import MatlabObject, MatlabFunction, MDTYPES, NP_TO_MTYPES, NP_TO_MXTYPES, miCOMPRESSED, miMATRIX, miINT8, miUTF8, miUINT32, mxCELL_CLASS, mxSTRUCT_CLASS, mxOBJECT_CLASS, mxCHAR_CLASS, mxSPARSE_CLASS, mxDOUBLE_CLASS, mclass_info, mat_struct
  from .streams import ZlibInputStream
label_desc: Use image node_id 13 for calling the VarWriter5 obj's underlying member method code with example usage: obj.write_sparse(arr) without return types