# tensorflow pseudo inverse doesn't work for complex matrices!

The Tensorflow documentation here says that:

tf.linalg.pinv is ''analogous to numpy.linalg.pinv. It differs only in default value of rcond''.

However, tf.linalg.pinv requires the matrix to be float type while np.linalg.pinv could be used with complex matrices.

I was wondering why they would only create it for float types and if there is a straightforward way to modify tf.linalg.pinv to be used with complex matrices.

I just faced the same situation. If you need to explicitly build the inverse, check this paper:

In particular, given a Matrix M that you need to invert, you can just do:

    A = tf.math.real(M)
C = tf.math.imag(M)

r0  = tf.linalg.pinv(A) @ C
y11 = tf.linalg.pinv(C @ r0 + A)
y10 = -r0 @ y11

M_inverse = tf.cast(tf.complex(y11,y10), dtype = M.dtype)


The complexity is a bit higher than the pure-complex implementation, but so far it has proven to be pretty stable for me.