Prevent exceptions from cholesky

I want to do batched cholesky decompostion but some matrixes are not positive definite, due to round-off. So pytorch raises an exception, failing the entire batch. Is there a way to just get the information that a particular element in the batch failed, like for lu decomposition? Repeating the analysis until all failed elements are removed would cancel the utility of using GPU since it becomes too slow. As far as I can see the underlying MAGMA functions support this but it is not exposed to user:

If you do your batch using a loop in c++, you can do:
for (…) {
try {
cholesky decomposition for 1 matrix
catch(…) {
// catch exception but do nothing, so your code can pass through with exception
If you do care about what exception is thrown, you can catch the actual exception.

I suspect this will be rather slow since it cannot make use of doing things in parallel. I don’t know how to setup torch in c++ so can someone comment on if this could be a good solution before I start to walk down that road.

Let me clarify.
This won’t affect parallel, you can split your batch in multiple threads or different cores. try/catch only wrapped your cholesky code, so the exception won’t stop your process. It will be a little bit slower compare to not using try/catch.

The only thing is that you can only process one matrix at a time, though pytorch cholesky function support batches, but it will stop when process a not-valid matrix. What you can do is to have a loop, and process one matrix each time with try/catch so it won’t break, if you want to print out error, you can catch(std::exception& e) and print the error msg. You can scale the loop in multiple threads or cores for sure.