Skip to content

Commit

Permalink
[Jenkins] auto-formatting by clang-format version 6.0.1-14 (tags/RELE…
Browse files Browse the repository at this point in the history
…ASE_601/final)
  • Loading branch information
stan-buildbot committed Aug 29, 2020
1 parent a0668d9 commit 8f82d77
Show file tree
Hide file tree
Showing 16 changed files with 1,173 additions and 1,222 deletions.
1,062 changes: 552 additions & 510 deletions src/cmdstan/cli.hpp

Large diffs are not rendered by default.

71 changes: 34 additions & 37 deletions src/cmdstan/command/diagnose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,50 @@

namespace cmdstan {

int diagnose(CLI::App& app,
SharedOptions& shared_options,
DiagnoseOptions& diagnose_options) {
stan::callbacks::stream_writer info(std::cout);
stan::callbacks::stream_writer err(std::cout);
stan::callbacks::stream_logger logger(std::cout, std::cout, std::cout,
std::cerr, std::cerr);
int diagnose(CLI::App& app, SharedOptions& shared_options,
DiagnoseOptions& diagnose_options) {
stan::callbacks::stream_writer info(std::cout);
stan::callbacks::stream_writer err(std::cout);
stan::callbacks::stream_logger logger(std::cout, std::cout, std::cout,
std::cerr, std::cerr);

// Read arguments
write_parallel_info(info);
write_opencl_device(info);
info();
// Read arguments
write_parallel_info(info);
write_opencl_device(info);
info();

stan::callbacks::writer init_writer;
stan::callbacks::interrupt interrupt;
stan::callbacks::writer init_writer;
stan::callbacks::interrupt interrupt;

std::fstream output_stream(shared_options.output_file.c_str(),
std::fstream::out);
stan::callbacks::stream_writer sample_writer(output_stream, "# ");
std::fstream output_stream(shared_options.output_file.c_str(),
std::fstream::out);
stan::callbacks::stream_writer sample_writer(output_stream, "# ");

//////////////////////////////////////////////////
// Initialize Model //
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// Initialize Model //
//////////////////////////////////////////////////

std::shared_ptr<stan::io::var_context> var_context
std::shared_ptr<stan::io::var_context> var_context
= get_var_context(shared_options.data_file);

stan::model::model_base &model
stan::model::model_base& model
= new_model(*var_context, shared_options.seed, &std::cout);

write_stan(sample_writer);
write_model(sample_writer, model.model_name());
print_old_command_header(app, shared_options, diagnose_options, sample_writer);
write_parallel_info(sample_writer);
write_opencl_device(sample_writer);
write_stan(sample_writer);
write_model(sample_writer, model.model_name());
print_old_command_header(app, shared_options, diagnose_options,
sample_writer);
write_parallel_info(sample_writer);
write_opencl_device(sample_writer);

std::shared_ptr<stan::io::var_context> init_context = get_var_context(shared_options.init_file);
std::shared_ptr<stan::io::var_context> init_context
= get_var_context(shared_options.init_file);

return stan::services::diagnose
::diagnose(model, *init_context,
shared_options.seed,
shared_options.id,
shared_options.init_radius,
diagnose_options.epsilon,
diagnose_options.threshold,
interrupt, logger, init_writer,
sample_writer);
}
return stan::services::diagnose ::diagnose(
model, *init_context, shared_options.seed, shared_options.id,
shared_options.init_radius, diagnose_options.epsilon,
diagnose_options.threshold, interrupt, logger, init_writer,
sample_writer);
}
} // namespace cmdstan
#endif
156 changes: 74 additions & 82 deletions src/cmdstan/command/generate_quantities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,106 +25,98 @@

namespace cmdstan {

int generate_quantities(CLI::App& app,
SharedOptions& shared_options,
GenerateQuantitiesOptions& gq_options) {
static int hmc_fixed_cols = 7; // hmc sampler outputs columns __lp + 6
int generate_quantities(CLI::App& app, SharedOptions& shared_options,
GenerateQuantitiesOptions& gq_options) {
static int hmc_fixed_cols = 7; // hmc sampler outputs columns __lp + 6

stan::callbacks::stream_writer info(std::cout);
stan::callbacks::stream_writer err(std::cout);
stan::callbacks::stream_logger logger(std::cout, std::cout, std::cout,
std::cerr, std::cerr);
stan::callbacks::stream_writer info(std::cout);
stan::callbacks::stream_writer err(std::cout);
stan::callbacks::stream_logger logger(std::cout, std::cout, std::cout,
std::cerr, std::cerr);

// Read arguments
write_parallel_info(info);
write_opencl_device(info);
info();
// Read arguments
write_parallel_info(info);
write_opencl_device(info);
info();

if (gq_options.fitted_params == shared_options.output_file) {
std::stringstream msg;
msg << "Filename conflict, fitted_params file "
<< gq_options.fitted_params
<< " and output file have same name, must be different."
<< std::endl;
throw std::invalid_argument(msg.str());
}
if (gq_options.fitted_params == shared_options.output_file) {
std::stringstream msg;
msg << "Filename conflict, fitted_params file " << gq_options.fitted_params
<< " and output file have same name, must be different." << std::endl;
throw std::invalid_argument(msg.str());
}

stan::callbacks::interrupt interrupt;
stan::callbacks::interrupt interrupt;

std::fstream output_stream(shared_options.output_file.c_str(),
std::fstream::out);
stan::callbacks::stream_writer sample_writer(output_stream, "# ");
std::fstream output_stream(shared_options.output_file.c_str(),
std::fstream::out);
stan::callbacks::stream_writer sample_writer(output_stream, "# ");

//////////////////////////////////////////////////
// Initialize Model //
//////////////////////////////////////////////////
//////////////////////////////////////////////////
// Initialize Model //
//////////////////////////////////////////////////

std::shared_ptr<stan::io::var_context> var_context
std::shared_ptr<stan::io::var_context> var_context
= get_var_context(shared_options.data_file);

stan::model::model_base &model
stan::model::model_base& model
= new_model(*var_context, shared_options.seed, &std::cout);

write_stan(sample_writer);
write_model(sample_writer, model.model_name());
print_old_command_header(app, shared_options, gq_options, sample_writer);
write_parallel_info(sample_writer);
write_opencl_device(sample_writer);

std::ifstream stream(gq_options.fitted_params.c_str());
if (stream.rdstate() & std::ifstream::failbit) {
std::stringstream msg;
msg << "Can't open specified file, \""
<< gq_options.fitted_params << "\""
<< std::endl;
throw std::invalid_argument(msg.str());
}
write_stan(sample_writer);
write_model(sample_writer, model.model_name());
print_old_command_header(app, shared_options, gq_options, sample_writer);
write_parallel_info(sample_writer);
write_opencl_device(sample_writer);

stan::io::stan_csv fitted_params;
std::ifstream stream(gq_options.fitted_params.c_str());
if (stream.rdstate() & std::ifstream::failbit) {
std::stringstream msg;
stan::io::stan_csv_reader
::read_metadata(stream, fitted_params.metadata, &msg);
if (!stan::io::stan_csv_reader
::read_header(stream, fitted_params.header,
&msg, false)) {
msg << "Error reading fitted param names from sample csv file \""
<< gq_options.fitted_params << "\"" << std::endl;
throw std::invalid_argument(msg.str());
}
stan::io::stan_csv_reader
::read_adaptation(stream, fitted_params.adaptation, &msg);
fitted_params.timing.warmup = 0;
fitted_params.timing.sampling = 0;
stan::io::stan_csv_reader::read_samples(stream,
fitted_params.samples,
fitted_params.timing, &msg);
stream.close();
msg << "Can't open specified file, \"" << gq_options.fitted_params << "\""
<< std::endl;
throw std::invalid_argument(msg.str());
}

stan::io::stan_csv fitted_params;
std::stringstream msg;
stan::io::stan_csv_reader ::read_metadata(stream, fitted_params.metadata,
&msg);
if (!stan::io::stan_csv_reader ::read_header(stream, fitted_params.header,
&msg, false)) {
msg << "Error reading fitted param names from sample csv file \""
<< gq_options.fitted_params << "\"" << std::endl;
throw std::invalid_argument(msg.str());
}
stan::io::stan_csv_reader ::read_adaptation(stream, fitted_params.adaptation,
&msg);
fitted_params.timing.warmup = 0;
fitted_params.timing.sampling = 0;
stan::io::stan_csv_reader::read_samples(stream, fitted_params.samples,
fitted_params.timing, &msg);
stream.close();

std::vector<std::string> param_names;
model.constrained_param_names(param_names, false, false);
size_t num_cols = param_names.size();
size_t num_rows = fitted_params.metadata.num_samples;
// check that all parameter names are in sample, in order
if (num_cols + hmc_fixed_cols > fitted_params.header.size()) {
std::vector<std::string> param_names;
model.constrained_param_names(param_names, false, false);
size_t num_cols = param_names.size();
size_t num_rows = fitted_params.metadata.num_samples;
// check that all parameter names are in sample, in order
if (num_cols + hmc_fixed_cols > fitted_params.header.size()) {
std::stringstream msg;
msg << "Mismatch between model and fitted_parameters csv file \""
<< gq_options.fitted_params << "\"" << std::endl;
throw std::invalid_argument(msg.str());
}
for (size_t i = 0; i < num_cols; ++i) {
if (param_names[i].compare(fitted_params.header[i + hmc_fixed_cols]) != 0) {
std::stringstream msg;
msg << "Mismatch between model and fitted_parameters csv file \""
<< gq_options.fitted_params << "\"" << std::endl;
<< gq_options.fitted_params << "\"" << std::endl;
throw std::invalid_argument(msg.str());
}
for (size_t i = 0; i < num_cols; ++i) {
if (param_names[i].compare(fitted_params.header[i + hmc_fixed_cols])
!= 0) {
std::stringstream msg;
msg << "Mismatch between model and fitted_parameters csv file \""
<< gq_options.fitted_params << "\"" << std::endl;
throw std::invalid_argument(msg.str());
}
}
return stan::services
::standalone_generate(model,
fitted_params.samples.block(0, hmc_fixed_cols, num_rows, num_cols),
shared_options.seed, interrupt, logger, sample_writer);
return stan::services::error_codes::CONFIG;
}
return stan::services ::standalone_generate(
model, fitted_params.samples.block(0, hmc_fixed_cols, num_rows, num_cols),
shared_options.seed, interrupt, logger, sample_writer);
return stan::services::error_codes::CONFIG;
}
} // namespace cmdstan
#endif
Loading

0 comments on commit 8f82d77

Please sign in to comment.