Generate mask of non-infinite of a mat

Hello,
I simply want to copy non-infinite data of a mat.
Firtst, I need to generate a mask of the mat checking each pixel was inf or nan.
Then copy the data to a new mat.
after searching, I found (oriMat != oriMat) can generate a mask but not sure it works for both NaN and Inf.
Is there any other way to do with this.
Thanks.

please explain your use-case, what this is all about !

(masks in computer-vision are usually binary, while inf and nan only make sense with float data)

sounds like OP is asking for the C++ equivalent of np.isnan/np.isinf, elementwise application