1+ #![ allow( warnings) ]
2+ /// prc_cal_prod_ijn:
3+ /// Precomputing the product of IJn yields marginal speed gains
4+ /// while increasing code complexity; this optimization is not adopted.
5+ /// cargo run -r --example prc_cal_prod_ijn
6+ ///
7+ use seuif97:: r1:: IJn ;
8+ use std:: fs:: File ;
9+ use std:: io:: Write ;
10+
11+ fn main ( ) {
12+ let mut n_I = Vec :: new ( ) ;
13+ let mut n_I_I1 = Vec :: new ( ) ;
14+ let mut n_J = Vec :: new ( ) ;
15+ let mut n_I_J = Vec :: new ( ) ;
16+ let mut n_J_J1 = Vec :: new ( ) ;
17+
18+ for e in IJn {
19+ n_I. push ( e. 2 * e. 0 as f64 ) ;
20+ n_I_I1. push ( e. 2 * ( e. 0 * ( e. 0 - 1 ) ) as f64 ) ;
21+ n_J. push ( e. 2 * e. 1 as f64 ) ;
22+ n_I_J. push ( e. 2 * e. 0 as f64 * e. 1 as f64 ) ;
23+ n_J_J1. push ( e. 2 * ( e. 1 * ( e. 1 - 1 ) ) as f64 ) ;
24+ }
25+
26+ let output = format ! (
27+ "pub const n_I_prod: [f64; 34] = [ {} ];\n \
28+ pub const n_I_I1_prod: [f64; 34] = [{}; ]\n \
29+ pub const n_J_prod: [f64; 34] = [ {} ];\n \
30+ pub const n_I_J_prod: [f64; 34] = [ {} ];\n \
31+ pub const n_J_J1_prod: [f64; 34] = [ {} ];\n ",
32+ n_I. iter( ) . map( |v| format!( "{:.15e}" , v) ) . collect:: <Vec <_>>( ) . join( ", " ) ,
33+ n_I_I1. iter( ) . map( |v| format!( "{:.15e}" , v) ) . collect:: <Vec <_>>( ) . join( ", " ) ,
34+ n_J. iter( ) . map( |v| format!( "{:.15e}" , v) ) . collect:: <Vec <_>>( ) . join( ", " ) ,
35+ n_I_J. iter( ) . map( |v| format!( "{:.15e}" , v) ) . collect:: <Vec <_>>( ) . join( ", " ) ,
36+ n_J_J1. iter( ) . map( |v| format!( "{:.15e}" , v) ) . collect:: <Vec <_>>( ) . join( ", " ) ,
37+ ) ;
38+
39+ let filename = "prc_cal_prod_ijn_results.txt" ;
40+ match File :: create ( filename) {
41+ Ok ( mut file) => {
42+ if let Err ( e) = file. write_all ( output. as_bytes ( ) ) {
43+ eprintln ! ( "Error writing to file: {}" , e) ;
44+ } else {
45+ println ! ( "Results saved to: {}" , filename) ;
46+ }
47+ }
48+ Err ( e) => {
49+ eprintln ! ( "Error creating file: {}" , e) ;
50+ }
51+ }
52+
53+ println ! ( "{}" , output) ;
54+ }
0 commit comments