Skip to content

Commit

Permalink
Merge pull request #1260 from stan-dev/tweak/bool-arg-output
Browse files Browse the repository at this point in the history
Print boolean arguments as true/false rather than 1/0
  • Loading branch information
WardBrian authored Apr 2, 2024
2 parents 6d111b6 + e9bdc65 commit 4ea9ea7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 30 deletions.
21 changes: 0 additions & 21 deletions src/cmdstan/arguments/arg_save_warmup.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions src/cmdstan/arguments/arg_single_bool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class arg_single_bool : public bool_argument {
: bool_argument() {
_name = name;
_description = desc;
_validity = "[0, 1]";
_default = std::to_string(def);
_validity = "[0, 1, false, true]";
_default = internal::to_string(def);
_default_value = def;
_value = _default_value;
}
Expand Down
2 changes: 2 additions & 0 deletions src/cmdstan/arguments/singleton_argument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ std::string to_string(double &src) {
return ss.str();
}

std::string to_string(bool &src) { return src ? "true" : "false"; }

template <typename T>
std::string to_string(T &src) {
return std::to_string(src);
Expand Down
6 changes: 3 additions & 3 deletions src/test/interface/optimization_output_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ TEST_F(CmdStan, optimize_default) {

int jacobian_idx = idx_first_match(config, jacobian);
EXPECT_NE(jacobian_idx, -1);
EXPECT_TRUE(boost::contains(config[jacobian_idx], "= 0 (Default)"));
EXPECT_TRUE(boost::contains(config[jacobian_idx], "= false (Default)"));

ASSERT_NEAR(0, values[0], 0.00001);
EXPECT_FLOAT_EQ(1, values[1]);
Expand Down Expand Up @@ -156,7 +156,7 @@ TEST_F(CmdStan, optimize_jacobian_adjust) {

int jacobian_idx = idx_first_match(config1, jacobian);
EXPECT_NE(jacobian_idx, -1);
EXPECT_TRUE(boost::contains(config1[jacobian_idx], "= 0 (Default)"));
EXPECT_TRUE(boost::contains(config1[jacobian_idx], "= false (Default)"));

ASSERT_NEAR(0, values1[0], 0.00001);
ASSERT_NEAR(3, values1[1], 0.01);
Expand All @@ -174,7 +174,7 @@ TEST_F(CmdStan, optimize_jacobian_adjust) {

jacobian_idx = idx_first_match(config2, jacobian);
EXPECT_NE(jacobian_idx, -1);
EXPECT_TRUE(boost::contains(config2[jacobian_idx], "= 1"));
EXPECT_TRUE(boost::contains(config2[jacobian_idx], "= true"));

ASSERT_NEAR(3.3, values2[1], 0.01);
}
8 changes: 4 additions & 4 deletions src/test/interface/pathfinder_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ TEST_F(CmdStan, pathfinder_defaults) {
EXPECT_EQ(1, count_matches(" seconds (Pathfinders)", output));
EXPECT_EQ(1, count_matches(" seconds (PSIS)", output));
EXPECT_EQ(1, count_matches(" seconds (Total)", output));
EXPECT_EQ(1, count_matches("save_single_paths = 0 (Default)", output));
EXPECT_EQ(1, count_matches("save_single_paths = false (Default)", output));
EXPECT_EQ(1, count_matches("num_paths = 4 (Default)", output));
}

Expand All @@ -89,7 +89,7 @@ TEST_F(CmdStan, pathfinder_40_draws) {
EXPECT_EQ(1, count_matches(" seconds (Total)", output));
EXPECT_EQ(1, count_matches("num_psis_draws = 40", output));
EXPECT_EQ(1, count_matches("num_paths = 4 (Default)", output));
EXPECT_EQ(1, count_matches("save_single_paths = 0 (Default)", output));
EXPECT_EQ(1, count_matches("save_single_paths = false (Default)", output));
}

TEST_F(CmdStan, pathfinder_single) {
Expand All @@ -110,7 +110,7 @@ TEST_F(CmdStan, pathfinder_single) {
EXPECT_EQ(1, count_matches("Elapsed Time:", output));
EXPECT_EQ(1, count_matches("seconds (Pathfinder)", output));
EXPECT_EQ(1, count_matches("num_paths = 1", output));
EXPECT_EQ(1, count_matches("save_single_paths = 0 (Default)", output));
EXPECT_EQ(1, count_matches("save_single_paths = false (Default)", output));
}

bool is_whitespace(char c) { return c == ' ' || c == '\n'; }
Expand All @@ -134,7 +134,7 @@ TEST_F(CmdStan, pathfinder_save_single_default_num_paths) {
std::string single_csv = result_sstream.str();
EXPECT_EQ(1, count_matches("Elapsed Time:", single_csv));
EXPECT_EQ(1, count_matches("seconds (Pathfinder)", single_csv));
EXPECT_EQ(1, count_matches("save_single_paths = 1", single_csv));
EXPECT_EQ(1, count_matches("save_single_paths = true", single_csv));

std::fstream single_json_stream(convert_model_path(output_single_json));
std::stringstream result_json_sstream;
Expand Down

0 comments on commit 4ea9ea7

Please sign in to comment.