Commit 175d860 1 parent 802d7da commit 175d860 Copy full SHA for 175d860
File tree 1 file changed +16
-9
lines changed
kifmm/src/fmm/field_translation/metadata
1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -55,21 +55,28 @@ use crate::{
55
55
56
56
/// Compute the cutoff rank for an SVD decomposition of a matrix from its singular values
57
57
/// using a specified `threshold` as a tolerance parameter
58
- pub fn find_cutoff_rank < T : Float + RlstScalar + Gemm > (
58
+ pub ( crate ) fn find_cutoff_rank < T : Float + RlstScalar + Gemm > (
59
59
singular_values : & [ T ] ,
60
60
threshold : T ,
61
- max_rank : usize ,
61
+ max_rank : usize
62
62
) -> usize {
63
+
63
64
let len = singular_values. len ( ) . min ( max_rank) ;
65
+ let mut frob_k: Vec < T > = singular_values. iter ( )
66
+ . rev ( ) // Reverse order
67
+ . map ( |& x| x * x) // Square each element
68
+ . scan ( T :: zero ( ) , |acc, x| {
69
+ * acc += x;
70
+ Some ( * acc)
71
+ } ) // Compute cumulative sum
72
+ . map ( <T as RlstScalar >:: sqrt) // Take the square root
73
+ . collect ( ) ;
74
+
75
+ frob_k. reverse ( ) ; // Reverse back to original order
76
+ frob_k. iter ( ) . position ( |& x| x < threshold) . unwrap_or ( len - 1 )
77
+ }
64
78
65
- for ( i, & s) in singular_values. iter ( ) . take ( len) . enumerate ( ) {
66
- if s <= threshold {
67
- return i;
68
- }
69
- }
70
79
71
- len - 1
72
- }
73
80
impl < Scalar , FieldTranslation > SourceTranslationMetadata
74
81
for KiFmm < Scalar , Laplace3dKernel < Scalar > , FieldTranslation >
75
82
where
You can’t perform that action at this time.
0 commit comments