You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Converts a slice of scalar values to a vector of the same length, returns an error if conversion fails
7
+
pubfntry_convert_scalar_slice<
8
+
ScalarFrom:Copy + Debug,
9
+
ScalarTo,
10
+
F:Fn(ScalarFrom) -> Option<ScalarTo>,
11
+
>(
12
+
values:&[ScalarFrom],
13
+
f:F,
14
+
) -> Result<Vec<ScalarTo>, anyhow::Error>{
15
+
values
16
+
.iter()
17
+
.copied()
18
+
.map(|v| {
19
+
f(v).ok_or_else(|| {
20
+
anyhow!(
21
+
"failed to convert value {:?} from type {} to {}",
22
+
v,
23
+
std::any::type_name::<ScalarFrom>(),
24
+
std::any::type_name::<ScalarTo>()
25
+
)
26
+
})
27
+
})
28
+
.try_collect_with_capacity(values.len())
29
+
}
30
+
31
+
/// Converts a slice of scalar values to a vector of [`nalgebra::SVector`], returns an error if conversion fails or the input slice's length is not a multiple of the vector length.
Copy file name to clipboardExpand all lines: splashsurf_lib/src/utils.rs
-114Lines changed: 0 additions & 114 deletions
Original file line number
Diff line number
Diff line change
@@ -1,100 +1,8 @@
1
1
//! Internal helper functions and types
2
2
3
-
use anyhow::{Context, anyhow};
4
3
use log::info;
5
-
use nalgebra::{SVector,Scalar};
6
-
use num_traits::Zero;
7
4
use rayon::prelude::*;
8
5
use std::cell::UnsafeCell;
9
-
use std::fmt::Debug;
10
-
11
-
/// Converts a slice of scalar values to a vector of the same length, returns an error if conversion fails
12
-
pubfntry_convert_scalar_slice<
13
-
ScalarFrom:Copy + Debug,
14
-
ScalarTo,
15
-
F:Fn(ScalarFrom) -> Option<ScalarTo>,
16
-
>(
17
-
values:&[ScalarFrom],
18
-
f:F,
19
-
) -> Result<Vec<ScalarTo>, anyhow::Error>{
20
-
values
21
-
.iter()
22
-
.copied()
23
-
.map(|v| {
24
-
f(v).ok_or_else(|| {
25
-
anyhow!(
26
-
"failed to convert value {:?} from type {} to {}",
27
-
v,
28
-
std::any::type_name::<ScalarFrom>(),
29
-
std::any::type_name::<ScalarTo>()
30
-
)
31
-
})
32
-
})
33
-
.try_collect_with_capacity(values.len())
34
-
}
35
-
36
-
/// Converts a slice of scalar values to a vector of [`nalgebra::SVector`], returns an error if conversion fails or the input slice's length is not a multiple of the vector length.
0 commit comments