def safe_sparse_dot(a, b, dense_output=False):
 if (issparse(a) or issparse(b)):
  ret = (a * b)
  if (dense_output and hasattr(ret, 'toarray')):
   ret = ret.toarray()
  return ret
 else:
  return fast_dot(a, b)

def safe_sparse_dot ( a , b , dense_output = False ) : if ( issparse ( a ) or issparse ( b ) ) : ret = ( a * b ) if ( dense_output and hasattr ( ret , 'toarray' ) ) : ret = ret . toarray ( ) return ret else : return fast_dot ( a , b )
dot product that handle the sparse matrix case correctly uses blas gemm as replacement for numpy .