Torch::cholesky ignoring exception

I’m having for some matrices on my batch exception due singular matrices.

cholesky_cpu: For batch 51100: U(22,22) is zero, singular U

I would like to ignore the exception for those and further set as Nan is it possible somehow?

Actually if I catch the exception and use continue still it doesn’t finish the calculations of the other matrices.

Could you post the code you are using to catch the exception?

Thanks @ptrblck here is the code

        th::Tensor L;
        try {
            L = th::cholesky(Xt.bmm(Xbtc));
        catch (const std::exception & ex) {
            std::cout << "c++ exception: " << std::endl;
        std::cout << L << std::endl;
        auto Gi = th::cholesky_solve(th::eye(p + 3, dtype_option.device(deviceifGPU)), L); // (X ^ T.X) ^ -1

It prints:

c++ exception:
[ Tensor (undefined) ]

Thanks for the code.
It seems you want to ignore this single sample in the calculation.
I’m not sure, but I would assume that removing this sample from the batch and call cholesky again on the cleaned batch of matrices might work.

Thank you!
Unfortunantly I would loose my peformance gain if I had to analyse which samples fail and remove those specifically. There might be more than one.

I am running this here

I really would like to run the cholesky ignoring those and dealing with nans or infs after.
Is it possible somehow?

I guess there is no way then. I think I will try tensorflow then… But thanks @ptrblck

Sure! Feel free to let us know, how you solved your use case in the end. :slight_smile:

1 Like