-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-data.pl
104 lines (77 loc) · 3.68 KB
/
build-data.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/perl
# Reads the frcapp{01,...,12}.txt and frmapp{01,...,12} and builds a C header
# including all the data.
use strict;
use warnings;
use DataParser;
my $datadir = @ARGV ? shift : ".";
my $top_q = 12;
my $frcappdata = DataParser::parse_files("$datadir/frcapp", $top_q);
my $frmappdata = DataParser::parse_files("$datadir/frmapp", $top_q);
my $bvaluesdata = DataParser::bvalues();
my $pvaluesdata = DataParser::pvalues();
my $pvalues = @DataParser::PVALUES;
my $bvalues = @DataParser::BVALUES;
my $header_dir = "fracdist";
my $header_file = "fracdist/data.hpp";
my $data_file = "fracdist/data.cpp";
my $header = qq!#pragma once
#include <cstdlib>
#include <array>
/** \@file $header_file
* \@brief Header file for accessing the various fracdist data and data properties.
*
* This file is automatically generated when building the fracdist package.
*/
namespace fracdist {
constexpr size_t
/// The number of `q` values (from 1 to $DataParser::NUM_Q) in fracdist::q_const and fracdist::q_noconst.
q_length = $DataParser::NUM_Q,
/// The number of `b` values in fracdist::bvalues. `b_length == bvalues.size()` will be true.
b_length = $bvalues,
/** The number of probability values and associated quantiles in `fracdist::pvalues`,
* `fracdist::q_const[i][j]`, and `fracdist::q_noconst[i][j]` (for any admissable `i` and `j`). */
p_length = $pvalues;
/** The bvalues: `bvalues[j]` is the b value corresponding to the quantiles contained in
* `fracdist::q_const[i][j]`
*/
extern const std::array<double, b_length> bvalues;
/** The pvalues; `pvalues[k]` is the pvalue associated with quantile
* `fracdist::q_const[i][j][k]`
*/
extern const std::array<double, p_length> pvalues;
/** A `double[][][]` (wrapped in nested `std::array`) where `q_const[x][y][z]` corresponds to the quantile with
\\f\$q = z+1\\f\$, \\f\$b={}\\f\$`fracdist::bvalues[y]`, and \\f\$p={}\\f\$`fracdist::pvalues[z]`. For example, if `bvalues[5] == 0.75` and
`pvalues[20] == 0.05` then `q_const[3][5][20]` is the 0.05 quantile for \\f\$q=4, b=0.75\\f\$ for a model with a constant. This
variable is for models estimated *with* a constant.
*/
extern const std::array<const std::array<const std::array<double, p_length>, b_length>, q_length> q_const;
/** A `double[][][]` (wrapped in nested `std::array`) where `q_noconst[x][y][z]` corresponds to the quantile with
\\f\$q = z+1\\f\$, \\f\$b={}\\f\$`fracdist::bvalues[y]`, and \\f\$p={}\\f\$`fracdist::pvalues[z]`. For example, if `bvalues[5] == 0.75` and
`pvalues[20] == 0.05` then `q_noconst[3][5][20]` is the 0.05 quantile for \\f\$q=4, b=0.75\\f\$ for a model without a constant. This
variable is for models estimated *without* a constant.
*/
extern const std::array<const std::array<const std::array<double, p_length>, b_length>, q_length> q_noconst;
}!;
my $runtime = qq!#include "$header_file"
namespace fracdist {
/** \@file $data_file
* \@brief Contains the actual fracdist data.
*
* This file is automatically generated when building the fracdist package.
*/
const std::array<double, b_length> bvalues {{\n$bvaluesdata\n}};
const std::array<double, p_length> pvalues {{\n$pvaluesdata\n}};
const std::array<const std::array<const std::array<double, p_length>, b_length>, q_length> q_const {{\n$frcappdata}};
const std::array<const std::array<const std::array<double, p_length>, b_length>, q_length> q_noconst {{\n$frmappdata}};
};
!;
if (!-d $header_dir) {
mkdir $header_dir or die "Unable to mkdir($header_dir): $!";
}
open my $frac_h, '>', $header_file or die "Unable to write to $header_file: $!";
print $frac_h $header;
close $frac_h;
open my $frac_data, '>', $data_file or die "Unable to write to $data_file: $!";
print $frac_data $runtime;
close $frac_data;