@@ -4,6 +4,7 @@ use crate::features::_periodogram_peaks::PeriodogramPeaks;
44use crate :: periodogram;
55use crate :: periodogram:: { AverageNyquistFreq , NyquistFreq , PeriodogramPower , PeriodogramPowerFft } ;
66
7+ use ndarray:: Array1 ;
78use std:: convert:: TryInto ;
89use std:: fmt:: Debug ;
910
@@ -32,7 +33,7 @@ series without observation errors (unity weights are used if required). You can
3233#[ doc = DOC ! ( ) ]
3334#[ derive( Clone , Debug , Deserialize , Serialize ) ]
3435#[ serde(
35- bound = "T: Float, F: FeatureEvaluator<T> + From<PeriodogramPeaks> + TryInto<PeriodogramPeaks>, <F as std::convert:: TryInto<PeriodogramPeaks>>::Error: Debug," ,
36+ bound = "T: Float, F: FeatureEvaluator<T> + From<PeriodogramPeaks> + TryInto<PeriodogramPeaks>, <F as TryInto<PeriodogramPeaks>>::Error: Debug," ,
3637 from = "PeriodogramParameters<T, F>" ,
3738 into = "PeriodogramParameters<T, F>"
3839) ]
4344 resolution : f32 ,
4445 max_freq_factor : f32 ,
4546 nyquist : NyquistFreq ,
46- feature_extractor : FeatureExtractor < T , F > ,
47+ pub ( crate ) feature_extractor : FeatureExtractor < T , F > ,
4748 periodogram_algorithm : PeriodogramPower < T > ,
4849 properties : Box < EvaluatorProperties > ,
4950}
@@ -119,24 +120,24 @@ where
119120 self
120121 }
121122
122- fn periodogram ( & self , ts : & mut TimeSeries < T > ) -> periodogram:: Periodogram < T > {
123+ pub ( crate ) fn periodogram ( & self , t : & [ T ] ) -> periodogram:: Periodogram < T > {
123124 periodogram:: Periodogram :: from_t (
124125 self . periodogram_algorithm . clone ( ) ,
125- ts . t . as_slice ( ) ,
126+ t ,
126127 self . resolution ,
127128 self . max_freq_factor ,
128129 self . nyquist . clone ( ) ,
129130 )
130131 }
131132
132- pub fn power ( & self , ts : & mut TimeSeries < T > ) -> Vec < T > {
133- self . periodogram ( ts) . power ( ts)
133+ pub fn power ( & self , ts : & mut TimeSeries < T > ) -> Array1 < T > {
134+ self . periodogram ( ts. t . as_slice ( ) ) . power ( ts)
134135 }
135136
136- pub fn freq_power ( & self , ts : & mut TimeSeries < T > ) -> ( Vec < T > , Vec < T > ) {
137- let p = self . periodogram ( ts) ;
137+ pub fn freq_power ( & self , ts : & mut TimeSeries < T > ) -> ( Array1 < T > , Array1 < T > ) {
138+ let p = self . periodogram ( ts. t . as_slice ( ) ) ;
138139 let power = p. power ( ts) ;
139- let freq = ( 0 ..power. len ( ) ) . map ( |i| p. freq ( i) ) . collect :: < Vec < _ > > ( ) ;
140+ let freq = ( 0 ..power. len ( ) ) . map ( |i| p. freq_by_index ( i) ) . collect ( ) ;
140141 ( freq, power)
141142 }
142143}
@@ -190,15 +191,12 @@ impl<T, F> Periodogram<T, F>
190191where
191192 T : Float ,
192193 F : FeatureEvaluator < T > + From < PeriodogramPeaks > + TryInto < PeriodogramPeaks > ,
193- <F as std :: convert :: TryInto < PeriodogramPeaks > >:: Error : Debug ,
194+ <F as TryInto < PeriodogramPeaks > >:: Error : Debug ,
194195{
195196 fn transform_ts ( & self , ts : & mut TimeSeries < T > ) -> Result < TmArrays < T > , EvaluatorError > {
196- self . check_ts_length ( ts) ?;
197+ self . check_ts ( ts) ?;
197198 let ( freq, power) = self . freq_power ( ts) ;
198- Ok ( TmArrays {
199- t : freq. into ( ) ,
200- m : power. into ( ) ,
201- } )
199+ Ok ( TmArrays { t : freq, m : power } )
202200 }
203201}
204202
@@ -225,7 +223,7 @@ impl<T, F> EvaluatorInfoTrait for Periodogram<T, F>
225223where
226224 T : Float ,
227225 F : FeatureEvaluator < T > + From < PeriodogramPeaks > + TryInto < PeriodogramPeaks > ,
228- <F as std :: convert :: TryInto < PeriodogramPeaks > >:: Error : Debug ,
226+ <F as TryInto < PeriodogramPeaks > >:: Error : Debug ,
229227{
230228 fn get_info ( & self ) -> & EvaluatorInfo {
231229 & self . properties . info
@@ -236,7 +234,7 @@ impl<T, F> FeatureNamesDescriptionsTrait for Periodogram<T, F>
236234where
237235 T : Float ,
238236 F : FeatureEvaluator < T > + From < PeriodogramPeaks > + TryInto < PeriodogramPeaks > ,
239- <F as std :: convert :: TryInto < PeriodogramPeaks > >:: Error : Debug ,
237+ <F as TryInto < PeriodogramPeaks > >:: Error : Debug ,
240238{
241239 fn get_names ( & self ) -> Vec < & str > {
242240 self . properties . names . iter ( ) . map ( String :: as_str) . collect ( )
@@ -255,7 +253,7 @@ impl<T, F> FeatureEvaluator<T> for Periodogram<T, F>
255253where
256254 T : Float ,
257255 F : FeatureEvaluator < T > + From < PeriodogramPeaks > + TryInto < PeriodogramPeaks > ,
258- <F as std :: convert :: TryInto < PeriodogramPeaks > >:: Error : Debug ,
256+ <F as TryInto < PeriodogramPeaks > >:: Error : Debug ,
259257{
260258 transformer_eval ! ( ) ;
261259}
@@ -279,7 +277,7 @@ impl<T, F> From<Periodogram<T, F>> for PeriodogramParameters<T, F>
279277where
280278 T : Float ,
281279 F : FeatureEvaluator < T > + From < PeriodogramPeaks > + TryInto < PeriodogramPeaks > ,
282- <F as std :: convert :: TryInto < PeriodogramPeaks > >:: Error : Debug ,
280+ <F as TryInto < PeriodogramPeaks > >:: Error : Debug ,
283281{
284282 fn from ( f : Periodogram < T , F > ) -> Self {
285283 let Periodogram {
0 commit comments