Inverse sparse matrix

Hey guys, so I have a matrix A which is block-diagonal, now I need to calculate the inverse of A. For block diagonal matrix, we can always inverse each block to obtain the inverse of A; so is there such kind of function in PyTorch to carry out the implementation?

p.s., the blocks are of different sizes, so reshape to a three-dimension tensor is not an option…