Skip to content

Instantly share code, notes, and snippets.

@DavidAce
Last active October 17, 2020 09:33
Show Gist options
  • Save DavidAce/be9c216d200977d70140f7070d5fd2fa to your computer and use it in GitHub Desktop.
Save DavidAce/be9c216d200977d70140f7070d5fd2fa to your computer and use it in GitHub Desktop.
diff --git a/Eigen/src/SVD/BDCSVD.h b/Eigen/src/SVD/BDCSVD.h
index a5b73f8f2..2a6b08f62 100644
--- a/Eigen/src/SVD/BDCSVD.h
+++ b/Eigen/src/SVD/BDCSVD.h
@@ -952,8 +952,18 @@ void BDCSVD<MatrixType>::perturbCol0
Index i = perm(l);
if(i!=k)
{
- Index j = i<k ? i : perm(l-1);
- prod *= ((singVals(j)+dk) / ((diag(i)+dk))) * ((mus(j)+(shifts(j)-dk)) / ((diag(i)-dk)));
+ //Index j = i<k ? i : perm(l-1);
+
+ //Sometimes we get i >= k and l == 0, leading to perm(l-1) being out of bounds
+ //Here we make sure that perm isn't accessed out of bounds.
+ //However, when this happens, the resulting U,S and V^T matrices will usually contain
+ //NAN's, but at least we then get a chance to do something about it, instead of segfault.
+ Index j;
+ if (i<k) j = i;
+ else if (l > 0 and l < m) j = perm(l-1);
+ else continue;
+
+prod *= ((singVals(j)+dk) / ((diag(i)+dk))) * ((mus(j)+(shifts(j)-dk)) / ((diag(i)-dk)));
#ifdef EIGEN_BDCSVD_DEBUG_VERBOSE
if(i!=k && numext::abs(((singVals(j)+dk)*(mus(j)+(shifts(j)-dk)))/((diag(i)+dk)*(diag(i)-dk)) - 1) > 0.9 )
std::cout << " " << ((singVals(j)+dk)*(mus(j)+(shifts(j)-dk)))/((diag(i)+dk)*(diag(i)-dk)) << " == (" << (singVals(j)+dk) << " * " << (mus(j)+(shifts(j)-dk))
diff --git a/Eigen/src/Core/products/Parallelizer.h b/Eigen/src/Core/products/Parallelizer.h
index 67b2442b53a114af3c08829af4344acc6be7a42f..a3cc05b77bbd19466e7f969d37ec18085ba3d36c 100644
--- a/Eigen/src/Core/products/Parallelizer.h
+++ b/Eigen/src/Core/products/Parallelizer.h
@@ -132,8 +132,7 @@ void parallelize_gemm(const Functor& func, Index rows, Index cols, Index depth,
ei_declare_aligned_stack_constructed_variable(GemmParallelInfo<Index>,info,threads,0);
- int errorCount = 0;
- #pragma omp parallel num_threads(threads) reduction(+: errorCount)
+ #pragma omp parallel num_threads(threads)
{
Index i = omp_get_thread_num();
// Note that the actual number of threads might be lower than the number of request ones.
@@ -152,14 +151,11 @@ void parallelize_gemm(const Functor& func, Index rows, Index cols, Index depth,
info[i].lhs_start = r0;
info[i].lhs_length = actualBlockRows;
- EIGEN_TRY {
- if(transpose) func(c0, actualBlockCols, 0, rows, info);
- else func(0, rows, c0, actualBlockCols, info);
- } EIGEN_CATCH(...) {
- ++errorCount;
- }
+ if(transpose)
+ func(c0, actualBlockCols, 0, rows, info);
+ else
+ func(0, rows, c0, actualBlockCols, info);
}
- if (errorCount) EIGEN_THROW_X(Eigen::eigen_assert_exception());
#endif
}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 0747aa6cb65a40a47fdee2685a2798f93c481ea0..b0257778082143ce27fc847cf163e845fa2afd1e 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -163,7 +163,7 @@ ei_add_test(constructor)
ei_add_test(linearstructure)
ei_add_test(integer_types)
ei_add_test(unalignedcount)
-if(NOT EIGEN_TEST_NO_EXCEPTIONS)
+if(NOT EIGEN_TEST_NO_EXCEPTIONS AND NOT EIGEN_TEST_OPENMP)
ei_add_test(exceptions)
endif()
ei_add_test(redux)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment