class_docstr: Sparse matrix with DIAgonal storage
  
  This can be instantiated in several ways:
      dia_matrix(D)
          with a dense matrix
  
      dia_matrix(S)
          with another sparse matrix S (equivalent to S.todia())
  
      dia_matrix((M, N), [dtype])
          to construct an empty matrix with shape (M, N),
          dtype is optional, defaulting to dtype='d'.
  
      dia_matrix((data, offsets), shape=(M, N))
          where the ``data[k,:]`` stores the diagonal entries for
          diagonal ``offsets[k]`` (See example below)
  
  Attributes
  ----------
  dtype : dtype
      Data type of the matrix
  shape : 2-tuple
      Shape of the matrix
  ndim : int
      Number of dimensions (this is always 2)
  nnz
      Number of nonzero elements
  data
      DIA format data array of the matrix
  offsets
      DIA format offset array of the matrix
  
  Notes
  -----
  
  Sparse matrices can be used in arithmetic operations: they support
  addition, subtraction, multiplication, division, and matrix power.
  
  Examples
  --------
  
  >>> import numpy as np
  >>> from scipy.sparse import dia_matrix
  >>> dia_matrix((3, 4), dtype=np.int8).toarray()
  array([[0, 0, 0, 0],
         [0, 0, 0, 0],
         [0, 0, 0, 0]], dtype=int8)
  
  >>> data = np.array([[1, 2, 3, 4]]).repeat(3, axis=0)
  >>> offsets = np.array([0, -1, 2])
  >>> dia_matrix((data, offsets), shape=(4, 4)).toarray()
  array([[1, 0, 3, 0],
         [1, 2, 0, 4],
         [0, 2, 3, 0],
         [0, 0, 3, 4]])
code: def sum(self, axis=None, dtype=None, out=None):
      validateaxis(axis)
  
      if axis is not None and axis < 0:
          axis += 2
  
      res_dtype = get_sum_dtype(self.dtype)
      num_rows, num_cols = self.shape
      ret = None
  
      if axis == 0:
          mask = self._data_mask()
          x = (self.data * mask).sum(axis=0)
          if x.shape[0] == num_cols:
              res = x
          else:
              res = np.zeros(num_cols, dtype=x.dtype)
              res[: x.shape[0]] = x
          ret = matrix(res, dtype=res_dtype)
  
      else:
          row_sums = np.zeros(num_rows, dtype=res_dtype)
          one = np.ones(num_cols, dtype=res_dtype)
          dia_matvec(
              num_rows,
              num_cols,
              len(self.offsets),
              self.data.shape[1],
              self.offsets,
              self.data,
              one,
              row_sums,
          )
  
          row_sums = matrix(row_sums)
  
          if axis is None:
              return row_sums.sum(dtype=dtype, out=out)
  
          if axis is not None:
              row_sums = row_sums.T
  
          ret = matrix(row_sums.sum(axis=axis))
  
      if out is not None and out.shape != ret.shape:
          raise ValueError("dimensions do not match")
  
      return ret.sum(axis=(), dtype=dtype, out=out)
  
imports: from __future__ import division, print_function, absolute_import
  import numpy
  from .base import isspmatrix, _formats, spmatrix
  from .data import _data_matrix
  from .sputils import isshape, upcast_char, getdtype, get_index_dtype, get_sum_dtype, validateaxis, check_shape, matrix
  from ._sparsetools import dia_matvec
label_desc: Use image node_id 6 for calling the dia_matrix obj's underlying member method code with example usage: obj.sum(axis, dtype, out) and returns: ret, row_sums