Skip to content

Replaced faer SVD with kornia_linalg::svd3 in ICP crate #337

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ya-shh
Copy link

@Ya-shh Ya-shh commented Apr 3, 2025

This PR updates the kornia-icp crate to use the optimized kornia_linalg::svd3 function instead of faer's SVD implementation.

Changes made:

  • Added kornia-linalg as a dependency in kornia-icp's Cargo.toml
  • Removed faer dependency from kornia-icp
  • Updated the ops.rs file to use kornia_linalg::svd3 instead of faer's SVD
  • Converted data structures from faer matrices to glam's Mat3 and Vec3
  • Updated tests to use assert_relative_eq for floating-point comparisons

These changes should make the ICP algorithms more efficient for SVD operations on 3×3 matrices while maintaining the same mathematical accuracy.

@Ya-shh
Copy link
Author

Ya-shh commented Apr 3, 2025

@edgarriba

Could you please review this? I noticed that a PR has already been created for this, but it isn't solving the issue. Therefore, I created this PR, which correctly addresses the main issue

let p_dst = faer::col![p_in_dst[0], p_in_dst[1], p_in_dst[2]] - &dst_centroid;
hh += p_src * p_dst.transpose();
let p_src = Vec3::new(
(p_in_src[0] - src_centroid.x) as f32,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done directly with glam semantics as before

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precision should be kept

}

// compute translation vector t = C_dst - R * C_src
let t = dst_centroid - &rr * src_centroid;
let src_centroid_f32 = Vec3::new(src_centroid.x as f32, src_centroid.y as f32, src_centroid.z as f32);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the casting ? Precision should be kept


for (p1, p2) in points1.iter().zip(points2.iter()) {
centroid1 += faer::col![p1[0], p1[1], p1[2]];
centroid2 += faer::col![p2[0], p2[1], p2[2]];
centroid1 += Vec3::new(p1[0] as f32, p1[1] as f32, p1[2] as f32);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No casts

@@ -65,17 +81,17 @@ pub(crate) fn fit_transformation(
pub(crate) fn compute_centroids(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it easy, inputs should be also ported

@edgarriba edgarriba requested a review from Copilot April 3, 2025 09:54
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the previous faer SVD implementation with the optimized kornia_linalg::svd3 function in the ICP crate, while converting matrix types from faer to glam.

  • Removed the faer dependency and added kornia-linalg in Cargo.toml
  • Updated ops.rs to use glam’s Mat3 and Vec3 along with kornia_linalg’s svd3
  • Revised tests to use assert_relative_eq for floating-point comparisons

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/kornia-icp/src/ops.rs Updated matrix and vector operations, SVD computation, and conversion logic
crates/kornia-icp/Cargo.toml Updated dependencies by removing faer and adding kornia-linalg

Copy link
Member

@edgarriba edgarriba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As tests showing I don't think you tried to compile yourself locally.
No ai generate codes are allowed

@Ya-shh Ya-shh force-pushed the update-icp-with-svd3 branch from 002f1bc to 24ecbd8 Compare April 4, 2025 14:53
Copy link

sonarqubecloud bot commented Apr 4, 2025

@Ya-shh
Copy link
Author

Ya-shh commented Apr 4, 2025

@edgarriba Thanks for pointing out these issues. Now the tests are passing, and I have run them locally

@Ya-shh
Copy link
Author

Ya-shh commented Apr 4, 2025

@edgarriba
1.Added kornia-linalg and glam as dependencies in the Cargo.toml file
2.Added the kornia_linalg import in ops.rs

The actual switch to kornia_linalg::svd3 will require addressing precision issues since kornia_linalg works with f32 (glam::Mat3) while the current code uses f64 (faer::Mat).

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.

2 participants