8000 Replace deprecated Eigen nonZeros() call for most recent Eigen versions. by nackjaylor · Pull Request #1494 · colmap/colmap · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replace deprecated Eigen nonZeros() call for most recent Eigen versions. #1494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 20, 2022

Conversation

nackjaylor
Copy link
Contributor

Hi team,

Small change proposed which allows COLMAP to be built from source on the most recent versions of Eigen.

Removal of nonZeros() call which was deprecated in https://gitlab.com/libeigen/eigen/-/commit/08da52eb8537107e2853452bb13c369856d1f84a corresponding to a redundant function call to size().

Issue: COLMAP does not build on Eigen 3.4.90 (and presumably sub-releases since above commit).
Fix: Adjust nonZeros() call to be size().

This is a somewhat interesting issue, because if COLMAP intends to check the number of non-zero elements, the original implementation seemingly did not do that. If the intention was indeed to check non-zero elements a custom check of the matrices is needed pending an appropriate fix in Eigen.

More details on the Eigen front here:
https://gitlab.com/libeigen/eigen/-/issues/2382

Happy to discuss any other workarounds you can think of.

Cheers,
Jack

Removal of nonZeros() call which was deprecated in https://gitlab.com/libeigen/eigen/-/commit/08da52eb8537107e2853452bb13c369856d1f84a corresponding to a redundant function call to size().

Issue: COLMAP does not build on Eigen 3.4.90
Fix: Adjust nonZeros() call to be size().

https://gitlab.com/libeigen/eigen/-/issues/2382
@ahojnnes
Copy link
Contributor

Thanks for the fix, but the new logic is incorrect. The size of the column is always 3. If .nonZeros() is broken in latest Eigen versions, then we probably want something like .abs().sum() instead ?

Compute the L1-norm of the vectors to check for non-zeros. If vector has no non-zero elements, the norm will be zero, else the norm will be greater than zero.

Updated with clarification from COLMAP devs re: checking for nonZero elements following Eigen implementation deprecation (and clarifying that original nonZeros() always returned size()).
@nackjaylor
Copy link
Contributor Author

Thanks @ahojnnes !

Apologies, I should have been clearer: my initial fix was merely removing the redundant function call since as far as I can tell nonZeros() has always returned size() (i.e. nonZeros has always been misleading). I've taken this comment from the Eigen repo issue and included below which implies this:

Antonio Sánchez @cantonios · 4 months ago
Owner

Probably. Going back through blames, Gael introduced it over 12 years ago when creating Array.h, which then got factored out into DenseBase.h. It has always returned .size() for dense arrays. It's not particularly useful for dense objects, and I'd be surprised if it's ever actually used. My vote would be to remove it and see if anything breaks.

Checking through the file history on Gitlab to some random old commits, this looks to be the case. As you say, the size of these in COLMAP is always 3, which I believe means that the condition was never satisfied and those lines of code might not have ever run.

In any case: your proposed fix works, I've just used the inbuilt l1-norm to wrap it up together.

@ahojnnes ahojnnes merged commit 4d737b8 into colmap:dev Apr 20, 2022
@ahojnnes
Copy link
Contributor

Thanks!

lucasthahn pushed a commit to tne-ai/colmap that referenced this pull request Aug 17, 2022
…ns. (colmap#1494)

* Remove nonZeros() call from Eigen::DenseBase

Removal of nonZeros() call which was deprecated in https://gitlab.com/libeigen/eigen/-/commit/08da52eb8537107e2853452bb13c369856d1f84a corresponding to a redundant function call to size().

Issue: COLMAP does not build on Eigen 3.4.90
Fix: Adjust nonZeros() call to be size().

https://gitlab.com/libeigen/eigen/-/issues/2382

* Compute l1-norm to check for non-zeros

Compute the L1-norm of the vectors to check for non-zeros. If vector has no non-zero elements, the norm will be zero, else the norm will be greater than zero.

Updated with clarification from COLMAP devs re: checking for nonZero elements following Eigen implementation deprecation (and clarifying that original nonZeros() always returned size()).
@yurybura
Copy link
yurybura commented May 2, 2025

I have a compiler error when building with Eigen 3.4.90 here:

const int rank = D_dense.nonZeros();

\src\colmap\estimators\covariance.cc(185): error C2039: 'nonZeros': not a member of 'Eigen::Matrix<double,-1,1,0,-1,1>'

Should I replace it with a call to size() or something else?

ahojnnes pushed a commit that referenced this pull request Jun 28, 2025
The `nonZeros()` method is a member of Eigen's sparse types, but
`D_dense` is a dense vector - in this case it always returns
`D_dense.size()`, which is incorrect. See related discussion in
#1494.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0