77// except according to those terms.
88#![ cfg( feature = "std" ) ]
99
10+ use crate :: finite_bounds:: { Bound , FiniteBounds } ;
11+
1012use num_traits:: Float ;
11- use std:: ops:: { Bound , RangeBounds } ;
1213
1314/// An iterator of a sequence of logarithmically spaced number.
1415///
1516/// Iterator element type is `F`.
16- pub struct Logspace < F >
17- {
17+ pub struct Logspace < F > {
1818 sign : F ,
1919 base : F ,
2020 start : F ,
@@ -24,13 +24,13 @@ pub struct Logspace<F>
2424}
2525
2626impl < F > Iterator for Logspace < F >
27- where F : Float
27+ where
28+ F : Float ,
2829{
2930 type Item = F ;
3031
3132 #[ inline]
32- fn next ( & mut self ) -> Option < F >
33- {
33+ fn next ( & mut self ) -> Option < F > {
3434 if self . index >= self . len {
3535 None
3636 } else {
@@ -43,19 +43,18 @@ where F: Float
4343 }
4444
4545 #[ inline]
46- fn size_hint ( & self ) -> ( usize , Option < usize > )
47- {
46+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
4847 let n = self . len - self . index ;
4948 ( n, Some ( n) )
5049 }
5150}
5251
5352impl < F > DoubleEndedIterator for Logspace < F >
54- where F : Float
53+ where
54+ F : Float ,
5555{
5656 #[ inline]
57- fn next_back ( & mut self ) -> Option < F >
58- {
57+ fn next_back ( & mut self ) -> Option < F > {
5958 if self . index >= self . len {
6059 None
6160 } else {
@@ -83,15 +82,12 @@ impl<F> ExactSizeIterator for Logspace<F> where Logspace<F>: Iterator {}
8382#[ inline]
8483pub fn logspace < R , F > ( base : F , range : R , n : usize ) -> Logspace < F >
8584where
86- R : RangeBounds < F > ,
85+ R : FiniteBounds < F > ,
8786 F : Float ,
8887{
8988 let ( a, b, num_steps) = match ( range. start_bound ( ) , range. end_bound ( ) ) {
90- ( Bound :: Included ( a) , Bound :: Included ( b) ) =>
91- ( * a, * b, F :: from ( n - 1 ) . expect ( "Converting number of steps to `A` must not fail." ) ) ,
92- ( Bound :: Included ( a) , Bound :: Excluded ( b) ) =>
93- ( * a, * b, F :: from ( n) . expect ( "Converting number of steps to `A` must not fail." ) ) ,
94- _ => panic ! ( "Only a..b and a..=b ranges are supported." ) ,
89+ ( a, Bound :: Included ( b) ) => ( a, b, F :: from ( n - 1 ) . expect ( "Converting number of steps to `A` must not fail." ) ) ,
90+ ( a, Bound :: Excluded ( b) ) => ( a, b, F :: from ( n) . expect ( "Converting number of steps to `A` must not fail." ) ) ,
9591 } ;
9692
9793 let step = if num_steps > F :: zero ( ) {
@@ -111,14 +107,12 @@ where
111107}
112108
113109#[ cfg( test) ]
114- mod tests
115- {
110+ mod tests {
116111 use super :: logspace;
117112
118113 #[ test]
119114 #[ cfg( feature = "approx" ) ]
120- fn valid ( )
121- {
115+ fn valid ( ) {
122116 use crate :: { arr1, Array1 } ;
123117 use approx:: assert_abs_diff_eq;
124118
@@ -136,8 +130,7 @@ mod tests
136130 }
137131
138132 #[ test]
139- fn iter_forward ( )
140- {
133+ fn iter_forward ( ) {
141134 let mut iter = logspace ( 10.0f64 , 0.0 ..=3.0 , 4 ) ;
142135
143136 assert ! ( iter. size_hint( ) == ( 4 , Some ( 4 ) ) ) ;
@@ -152,8 +145,7 @@ mod tests
152145 }
153146
154147 #[ test]
155- fn iter_backward ( )
156- {
148+ fn iter_backward ( ) {
157149 let mut iter = logspace ( 10.0f64 , 0.0 ..=3.0 , 4 ) ;
158150
159151 assert ! ( iter. size_hint( ) == ( 4 , Some ( 4 ) ) ) ;
0 commit comments