File tree Expand file tree Collapse file tree 1 file changed +25
-14
lines changed
Expand file tree Collapse file tree 1 file changed +25
-14
lines changed Original file line number Diff line number Diff line change @@ -35,36 +35,47 @@ pub trait Scalar
3535 + Conjugate
3636 + RandNormal
3737 + Debug {
38- }
39-
40- impl Scalar for f32 { }
41- impl Scalar for f64 { }
42- impl Scalar for c32 { }
43- impl Scalar for c64 { }
44-
45- pub trait RealScalar : Scalar + Float + Sum {
4638 fn from_f64 ( f64 ) -> Self ;
4739}
4840
49- impl RealScalar for f32 {
41+ impl Scalar for f32 {
5042 fn from_f64 ( f : f64 ) -> Self {
5143 f as f32
5244 }
5345}
54- impl RealScalar for f64 {
46+
47+ impl Scalar for f64 {
5548 fn from_f64 ( f : f64 ) -> Self {
5649 f
5750 }
5851}
5952
60- /// Convert `f64` into `RealScalar`
53+ impl Scalar for c32 {
54+ fn from_f64 ( f : f64 ) -> Self {
55+ Self :: new ( f as f32 , 0.0 )
56+ }
57+ }
58+
59+ impl Scalar for c64 {
60+ fn from_f64 ( f : f64 ) -> Self {
61+ Self :: new ( f, 0.0 )
62+ }
63+ }
64+
65+ pub trait RealScalar : Scalar + Float + Sum { }
66+ impl RealScalar for f32 { }
67+ impl RealScalar for f64 { }
68+
69+ /// Convert `f64` into `Scalar`
6170///
6271/// ```rust
63- /// fn mult2<A: RealScalar>(a: A) -> A {
64- /// a * into_real(2.0);
72+ /// use ndarray_linalg::*;
73+ /// fn mult<A: Scalar>(a: A) -> A {
74+ /// // a * 2.0 // Error!
75+ /// a * into_scalar(2.0)
6576/// }
6677/// ```
67- pub fn into_real < T : RealScalar > ( f : f64 ) -> T {
78+ pub fn into_scalar < T : Scalar > ( f : f64 ) -> T {
6879 T :: from_f64 ( f)
6980}
7081
You can’t perform that action at this time.
0 commit comments