Repository navigation
Expand file tree
/
Copy pathoutput_sig_figs_test.cpp
More file actions
89 lines (77 loc) · 3.53 KB
/
Copy pathoutput_sig_figs_test.cpp
File metadata and controls
89 lines (77 loc) · 3.53 KB
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
#include <cmdstan/stansummary_helper.hpp>
#include <stan/io/stan_csv_reader.hpp>
#include <stan/services/error_codes.hpp>
#include <test/utility.hpp>
#include <gtest/gtest.h>
TEST(interface, output_sig_figs_1) {
std::vector<std::string> model_path;
model_path.push_back("src");
model_path.push_back("test");
model_path.push_back("test-models");
model_path.push_back("proper_sig_figs");
std::string command
= cmdstan::test::convert_model_path(model_path)
+ " sample num_warmup=200 num_samples=1" + " output file="
+ cmdstan::test::convert_model_path(model_path) + ".csv sig_figs=1";
cmdstan::test::run_command_output out = cmdstan::test::run_command(command);
EXPECT_EQ(int(stan::services::error_codes::OK), out.err_code);
EXPECT_FALSE(out.hasError);
std::string csv_file = cmdstan::test::convert_model_path(model_path) + ".csv";
std::vector<std::string> filenames;
filenames.push_back(csv_file);
stan::io::stan_csv_metadata metadata;
Eigen::VectorXd warmup_times(filenames.size());
Eigen::VectorXd sampling_times(filenames.size());
Eigen::VectorXi thin(filenames.size());
auto chains = parse_csv_files(filenames, metadata, warmup_times,
sampling_times, thin, &std::cout);
EXPECT_NEAR(chains.samples(8)(0, 0), 0.1, 1E-16);
}
TEST(interface, output_sig_figs_2) {
std::vector<std::string> model_path;
model_path.push_back("src");
model_path.push_back("test");
model_path.push_back("test-models");
model_path.push_back("proper_sig_figs");
std::string command
= cmdstan::test::convert_model_path(model_path)
+ " sample num_warmup=200 num_samples=1" + " output file="
+ cmdstan::test::convert_model_path(model_path) + ".csv sig_figs=2";
cmdstan::test::run_command_output out = cmdstan::test::run_command(command);
EXPECT_EQ(int(stan::services::error_codes::OK), out.err_code);
EXPECT_FALSE(out.hasError);
std::string csv_file = cmdstan::test::convert_model_path(model_path) + ".csv";
std::vector<std::string> filenames;
filenames.push_back(csv_file);
stan::io::stan_csv_metadata metadata;
Eigen::VectorXd warmup_times(filenames.size());
Eigen::VectorXd sampling_times(filenames.size());
Eigen::VectorXi thin(filenames.size());
auto chains = parse_csv_files(filenames, metadata, warmup_times,
sampling_times, thin, &std::cout);
EXPECT_NEAR(chains.samples(8)(0, 0), 0.12, 1E-16);
}
TEST(interface, output_sig_figs_9) {
std::vector<std::string> model_path;
model_path.push_back("src");
model_path.push_back("test");
model_path.push_back("test-models");
model_path.push_back("proper_sig_figs");
std::string command
= cmdstan::test::convert_model_path(model_path)
+ " sample num_warmup=200 num_samples=1" + " output file="
+ cmdstan::test::convert_model_path(model_path) + ".csv sig_figs=9";
cmdstan::test::run_command_output out = cmdstan::test::run_command(command);
EXPECT_EQ(int(stan::services::error_codes::OK), out.err_code);
EXPECT_FALSE(out.hasError);
std::string csv_file = cmdstan::test::convert_model_path(model_path) + ".csv";
std::vector<std::string> filenames;
filenames.push_back(csv_file);
stan::io::stan_csv_metadata metadata;
Eigen::VectorXd warmup_times(filenames.size());
Eigen::VectorXd sampling_times(filenames.size());
Eigen::VectorXi thin(filenames.size());
auto chains = parse_csv_files(filenames, metadata, warmup_times,
sampling_times, thin, &std::cout);
EXPECT_NEAR(chains.samples(8)(0, 0), 0.123456789, 1E-16);
}