code: def count_blocks(A, blocksize):
      """For a given blocksize=(r,c) count the number of occupied
      blocks in a sparse matrix A
      """
      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)
  
imports: from .csr import isspmatrix_csr, csr_matrix
  from .csc import isspmatrix_csc
  from ._sparsetools import csr_count_blocks
label_desc: Use image node_id 2 for calling a global function with example usage: count_blocks(A, blocksize) and returns: csr_count_blocks, count_blocks, count_blocks