How to inverse a matrix?

I want to inverse a 2x2 matrix. What should I do?
In addition, can I inverse a 2x2 ti.var instead of matrix?

If A is the 2x2 matrix, you can use A.inverse() to get its inverse.
If you want to inverse a 2x2 ti.var (scalar tensor), please first assemble a 2x2 matrix out of it, e.g.

A = ti.Matrix([[a[0, 0], a[0, 1]], [a[1, 0], a[1, 1]]])
inv_A = A.inverse()