{"record":{"id":"10fbe4080c504ff7","repo":"Yalantis/uCrop","slug":"symmetric-eigen-lapack-library-function-dsyev","errorCode":null,"errorMessage":"symmetric_eigen(): LAPACK library function dsyev_() returned error code %d.","messagePattern":"symmetric_eigen\\(\\): LAPACK library function dsyev_\\(\\) returned error code (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":33233,"sourceCode":"        val[0] = (t)l2;\n        val[1] = (t)l1;\n        if (n>0) { vec[0] = (t)(b/n); vec[2] = (t)((l2 - a)/n); } else { vec[0] = 1; vec[2] = 0; }\n        vec[1] = -vec[2];\n        vec[3] = vec[0];\n        return *this;\n      }\n\n#ifdef cimg_use_lapack\n      char JOB = 'V', UPLO = 'U';\n      int N = _width, LWORK = 4*N, INFO;\n      Tfloat\n        *const lapA = new Tfloat[N*N],\n        *const lapW = new Tfloat[N],\n        *const WORK = new Tfloat[LWORK];\n      cimg_forXY(*this,k,l) lapA[k*N + l] = (Tfloat)((*this)(k,l));\n      cimg::syev(JOB,UPLO,N,lapA,lapW,WORK,LWORK,INFO);\n      if (INFO)\n        cimg::warn(_cimg_instance\n                   \"symmetric_eigen(): LAPACK library function dsyev_() returned error code %d.\",\n                   cimg_instance,\n                   INFO);\n      if (!INFO) {\n        cimg_forY(val,i) val(i) = (T)lapW[N - 1 -i];\n        cimg_forXY(vec,k,l) vec(k,l) = (T)(lapA[(N - 1 - k)*N + l]);\n      } else { val.fill(0); vec.fill(0); }\n      delete[] lapA; delete[] lapW; delete[] WORK;\n\n#else\n      CImg<t> V(_width,_width);\n      Tfloat M = 0, m = (Tfloat)min_max(M), maxabs = cimg::max((Tfloat)1,cimg::abs(m),cimg::abs(M));\n      (CImg<Tfloat>(*this,false)/=maxabs).SVD(vec,val,V,false);\n      if (maxabs!=1) val*=maxabs;\n\n      bool is_ambiguous = false;\n      float eig = 0;\n      cimg_forY(val,p) { // Check for ambiguous cases","sourceCodeStart":33215,"sourceCodeEnd":33251,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L33215-L33251","documentation":"CImg::symmetric_eigen() computes eigenvalues/eigenvectors of a symmetric matrix via LAPACK dsyev_(); nonzero INFO means the eigen-decomposition failed to converge or received an invalid argument. CImg warns and leaves val/vec unset rather than throwing.","triggerScenarios":"Calling symmetric_eigen() on a matrix that is not actually symmetric (dsyev only reads one triangle, garbage in the other can cause divergence), non-square input, or extremely ill-conditioned matrices.","commonSituations":"Building covariance matrices with asymmetric accumulation bugs; NaN/Inf entries in the matrix; NDK LAPACK builds with mismatched dsyev_ ABI.","solutions":["Symmetrize the matrix explicitly before the call: A = (A + A.get_transpose())/2","Check for NaN/Inf entries and sanitize the input matrix","Verify the matrix is square and non-empty","Use double precision and scale the matrix to improve convergence","Provide a fallback (e.g. Jacobi eigen implementation) if dsyev_ keeps failing"],"exampleFix":"// before\nCImg<float> val, vec;\nA.symmetric_eigen(val, vec);\n// after\nCImg<float> S = (A + A.get_transpose())*0.5f;\nif (S.isnan().sum() > 0) S.nanf(0); // or reject input\nCImg<float> val, vec;\nS.symmetric_eigen(val, vec);","handlingStrategy":"validation","validationCode":"bool readyForEigen(const CImg<float>& A) {\n  if (A.width() != A.height() || A.width() == 0) return false;\n  for (int i = 0; i < A.width(); ++i)\n    for (int j = 0; j < A.height(); ++j)\n      if (std::isnan(A(i,j)) || std::isinf(A(i,j))) return false;\n  return true;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always symmetrize (A + A^T)/2 before symmetric_eigen()","Screen inputs for NaN/Inf","Scale very large/small magnitude matrices","Keep a fallback eigensolver for non-converging cases"],"tags":["cimg","lapack","eigenvalues"],"backgroundTag":"lapack-solver-failed","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}