11use super :: helpers:: { self , ConvFuns , ConvoluteMode } ;
2+ use super :: pdf_backend:: { PdfBackend , PdfSetBackend } ;
23use super :: { GlobalConfiguration , Subcommand } ;
34use anyhow:: { Error , Result } ;
45use clap:: { Parser , ValueHint } ;
5- use lhapdf:: { Pdf , PdfSet } ;
66use prettytable:: { Row , cell} ;
77use rayon:: { ThreadPoolBuilder , prelude:: * } ;
88use std:: num:: NonZeroUsize ;
@@ -52,10 +52,16 @@ impl Subcommand for Opts {
5252 fn run ( & self , cfg : & GlobalConfiguration ) -> Result < ExitCode > {
5353 let grid = helpers:: read_grid ( & self . input ) ?;
5454
55- let ( set1, mut conv_funs1) =
56- helpers:: create_conv_funs_for_set ( & self . conv_funs1 , self . pull_from ) ?;
57- let ( set2, mut conv_funs2) =
58- helpers:: create_conv_funs_for_set ( & self . conv_funs2 , self . pull_from ) ?;
55+ let ( set1, mut conv_funs1) = helpers:: create_conv_funs_for_set_with_backend (
56+ & self . conv_funs1 ,
57+ self . pull_from ,
58+ cfg. pdf_backend ,
59+ ) ?;
60+ let ( set2, mut conv_funs2) = helpers:: create_conv_funs_for_set_with_backend (
61+ & self . conv_funs2 ,
62+ self . pull_from ,
63+ cfg. pdf_backend ,
64+ ) ?;
5965
6066 ThreadPoolBuilder :: new ( )
6167 . num_threads ( self . threads )
@@ -67,7 +73,7 @@ impl Subcommand for Opts {
6773 let results1: Vec < _ > = conv_funs1
6874 . par_iter_mut ( )
6975 . map ( |funs| {
70- Ok :: < _ , Error > ( helpers:: convolve (
76+ Ok :: < _ , Error > ( helpers:: convolve_with_backend (
7177 & grid,
7278 funs,
7379 & self . conv_funs1 . conv_types ,
@@ -86,7 +92,7 @@ impl Subcommand for Opts {
8692 let results2: Vec < _ > = conv_funs2
8793 . par_iter_mut ( )
8894 . map ( |funs| {
89- Ok :: < _ , Error > ( helpers:: convolve (
95+ Ok :: < _ , Error > ( helpers:: convolve_with_backend (
9096 & grid,
9197 funs,
9298 & self . conv_funs2 . conv_types ,
@@ -141,79 +147,81 @@ impl Subcommand for Opts {
141147 ( diff / unc1. hypot ( unc2) , unc1, unc2)
142148 } ;
143149
144- let channel_results =
145- |conv_funs : & ConvFuns , pdfset : & mut [ Vec < Pdf > ] , set : & PdfSet | -> Vec < f64 > {
146- if let Some ( member) = conv_funs. members [ self . pull_from ] {
147- ( 0 ..grid. channels ( ) . len ( ) )
148- . map ( |channel| {
149- let mut channel_mask = vec ! [ false ; grid. channels( ) . len( ) ] ;
150- channel_mask[ channel] = true ;
151- match helpers:: convolve (
152- & grid,
153- & mut pdfset[ member] ,
154- & conv_funs. conv_types ,
155- & self . orders ,
156- & [ bin] ,
157- & channel_mask,
158- 1 ,
159- ConvoluteMode :: Normal ,
160- cfg,
161- )
162- . as_slice ( )
163- {
164- [ value] => * value,
165- _ => unreachable ! ( ) ,
166- }
167- } )
168- . collect ( )
169- } else {
170- let results: Vec < _ > = pdfset
171- . iter_mut ( )
172- . flat_map ( |fun| {
173- ( 0 ..grid. channels ( ) . len ( ) )
174- . map ( |channel| {
175- let mut channel_mask = vec ! [ false ; grid. channels( ) . len( ) ] ;
176- channel_mask[ channel] = true ;
177- match helpers:: convolve (
178- & grid,
179- fun,
180- & conv_funs. conv_types ,
181- & self . orders ,
182- & [ bin] ,
183- & channel_mask,
184- 1 ,
185- ConvoluteMode :: Normal ,
186- cfg,
187- )
188- . as_slice ( )
189- {
190- [ value] => * value,
191- _ => unreachable ! ( ) ,
192- }
193- } )
194- . collect :: < Vec < _ > > ( )
195- } )
196- . collect ( ) ;
197-
198- ( 0 ..grid. channels ( ) . len ( ) )
199- . map ( |channel| {
200- let central: Vec < _ > = results
201- . iter ( )
202- . skip ( channel)
203- . step_by ( grid. channels ( ) . len ( ) )
204- . copied ( )
205- . collect ( ) ;
206- set. uncertainty ( & central, self . cl , false ) . unwrap ( ) . central
207- } )
208- . collect ( )
209- }
210- } ;
150+ let channel_results = |conv_funs : & ConvFuns ,
151+ pdfset : & mut [ Vec < Box < dyn PdfBackend > > ] ,
152+ set : & dyn PdfSetBackend |
153+ -> Vec < f64 > {
154+ if let Some ( member) = conv_funs. members [ self . pull_from ] {
155+ ( 0 ..grid. channels ( ) . len ( ) )
156+ . map ( |channel| {
157+ let mut channel_mask = vec ! [ false ; grid. channels( ) . len( ) ] ;
158+ channel_mask[ channel] = true ;
159+ match helpers:: convolve_with_backend (
160+ & grid,
161+ & mut pdfset[ member] ,
162+ & conv_funs. conv_types ,
163+ & self . orders ,
164+ & [ bin] ,
165+ & channel_mask,
166+ 1 ,
167+ ConvoluteMode :: Normal ,
168+ cfg,
169+ )
170+ . as_slice ( )
171+ {
172+ [ value] => * value,
173+ _ => unreachable ! ( ) ,
174+ }
175+ } )
176+ . collect ( )
177+ } else {
178+ let results: Vec < _ > = pdfset
179+ . iter_mut ( )
180+ . flat_map ( |fun| {
181+ ( 0 ..grid. channels ( ) . len ( ) )
182+ . map ( |channel| {
183+ let mut channel_mask = vec ! [ false ; grid. channels( ) . len( ) ] ;
184+ channel_mask[ channel] = true ;
185+ match helpers:: convolve_with_backend (
186+ & grid,
187+ fun,
188+ & conv_funs. conv_types ,
189+ & self . orders ,
190+ & [ bin] ,
191+ & channel_mask,
192+ 1 ,
193+ ConvoluteMode :: Normal ,
194+ cfg,
195+ )
196+ . as_slice ( )
197+ {
198+ [ value] => * value,
199+ _ => unreachable ! ( ) ,
200+ }
201+ } )
202+ . collect :: < Vec < _ > > ( )
203+ } )
204+ . collect ( ) ;
205+
206+ ( 0 ..grid. channels ( ) . len ( ) )
207+ . map ( |channel| {
208+ let central: Vec < _ > = results
209+ . iter ( )
210+ . skip ( channel)
211+ . step_by ( grid. channels ( ) . len ( ) )
212+ . copied ( )
213+ . collect ( ) ;
214+ set. uncertainty ( & central, self . cl , false ) . unwrap ( ) . central
215+ } )
216+ . collect ( )
217+ }
218+ } ;
211219
212220 let mut pull_tuples = if self . limit == 0 {
213221 Vec :: new ( )
214222 } else {
215- let channel_results1 = channel_results ( & self . conv_funs1 , & mut conv_funs1, & set1) ;
216- let channel_results2 = channel_results ( & self . conv_funs2 , & mut conv_funs2, & set2) ;
223+ let channel_results1 = channel_results ( & self . conv_funs1 , & mut conv_funs1, & * set1) ;
224+ let channel_results2 = channel_results ( & self . conv_funs2 , & mut conv_funs2, & * set2) ;
217225
218226 let pull_tuples: Vec < _ > = channel_results2
219227 . iter ( )
0 commit comments