#NEWLINE# def sum( self , axis = None ) : #NEWLINE# #INDENT# 'Sum the matrix over the given axis.  If the axis is None, sum\n        over both rows and columns, returning a scalar.\n        ' #NEWLINE# if ( axis is None ) : #NEWLINE# #INDENT# return self . data . sum ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not hasattr ( self , 'blocksize' ) ) and ( axis in self . _swap ( ( ( 1 , ( - 1 ) ) , ( 0 , 2 ) ) ) [ 0 ] ) ) : #NEWLINE# #INDENT# res_dtype = get_sum_dtype ( self . dtype ) #NEWLINE# ret = np . zeros ( ( len ( self . indptr ) - 1 ) , dtype = res_dtype ) #NEWLINE# ( major_index , value ) = self . _minor_reduce ( np . add ) #NEWLINE# ret [ major_index ] = value #NEWLINE# ret = np . asmatrix ( ret ) #NEWLINE# if ( ( axis % 2 ) == 1 ) : #NEWLINE# #INDENT# ret = ret . T #NEWLINE# #UNINDENT# return self #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return spmatrix . sum ( self , axis )