def count_blocks(A, blocksize):
 (r, c) = blocksize
 if ((r < 1) or (c < 1)):
  raise ValueError('r and c must be positive')
 if isspmatrix_csr(A):
  (M, N) = A.shape
  return csr_count_blocks(M, N, r, c, A.indptr, A.indices)
 elif isspmatrix_csc(A):
  return count_blocks(A.T, (c, r))
 else:
  return count_blocks(csr_matrix(A), blocksize)

def count_blocks ( A , blocksize ) : ( r , c ) = blocksize if ( ( r < 1 ) or ( c < 1 ) ) : raise ValueError ( 'r and c must be positive' ) if isspmatrix_csr ( A ) : ( M , N ) = A . shape return csr_count_blocks ( M , N , r , c , A . indptr , A . indices ) elif isspmatrix_csc ( A ) : return count_blocks ( A . T , ( c , r ) ) else : return count_blocks ( csr_matrix ( A ) , blocksize )
for a given blocksize= count the number of occupied blocks in a sparse matrix a .