Skip to content

Commit

Permalink
merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mitzimorris committed Mar 6, 2025
2 parents e082f64 + 89d756b commit db29cfa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ pipeline {
agent {
docker {
image 'stanorg/ci:gpu'
label 'linux'
label 'linux && gpu'
args '--pull always --gpus 1'
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/stan_math
1 change: 1 addition & 0 deletions src/stan/callbacks/dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <type_traits>
#include <variant>


namespace stan {
namespace callbacks {

Expand Down
43 changes: 34 additions & 9 deletions src/test/unit/callbacks/dispatcher_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <Eigen/Dense>

// For this test we assume that InfoType has at least these values:
using stan::callbacks::InfoType;
using stan::callbacks::dispatcher;
using stan::callbacks::InfoType;

struct deleter_noop {
template <typename T>
Expand All @@ -21,14 +21,15 @@ struct deleter_noop {

class DispatcherTest : public ::testing::Test {
public:
DispatcherTest() :
ss_sample(),
ss_config(),
ss_metric(),
writer_sample(ss_sample),
writer_config(ss_config),
writer_metric(std::unique_ptr<std::stringstream, deleter_noop>(&ss_metric)),
dispatcher() {}
DispatcherTest()
: ss_sample(),
ss_config(),
ss_metric(),
writer_sample(ss_sample),
writer_config(ss_config),
writer_metric(
std::unique_ptr<std::stringstream, deleter_noop>(&ss_metric)),
dispatcher() {}

void SetUp() {
ss_sample.str(std::string());
Expand Down Expand Up @@ -146,6 +147,29 @@ TEST_F(DispatcherTest, StructuredBeginEndRecord) {
// JSON output should contain opening and closing braces
EXPECT_NE(output.find("{"), std::string::npos);
EXPECT_NE(output.find("}"), std::string::npos);
=======
TEST_F(DispatcherTest, MetricStructuredKeyValueRecord) {
// For METRIC (structured writer), open a record, dispatch key/value pairs,
// then close the record.
dispatcher.begin_record(InfoType::METRIC);
dispatcher.dispatch(InfoType::METRIC, "metric_type", std::string("diag"));
dispatcher.dispatch(InfoType::METRIC, "stepsize", 0.6789);
// For the inv_metric, assume the caller converts the vector to a
// comma-separated string.
std::vector<double> inv_metric = {0.1, 0.2, 0.3};
std::string inv_metric_str;
for (size_t i = 0; i < inv_metric.size(); ++i) {
inv_metric_str += std::to_string(inv_metric[i]);
if (i != inv_metric.size() - 1)
inv_metric_str += ",";
}
dispatcher.dispatch(InfoType::METRIC, "inv_metric", inv_metric_str);
dispatcher.end_record(InfoType::METRIC);
// Expected output:
// Begin record marker, followed by key/value pairs each formatted as
// "key:value;" and then end record marker.
std::cout << ss_metric.str() << std::endl;
>>>>>>> 89d756b23a601c560cb63a09930f5fcbce011efc
}

// Test structured writer key-value pairs with string value
Expand All @@ -159,6 +183,7 @@ TEST_F(DispatcherTest, StructuredKeyStringValue) {
EXPECT_NE(output.find("value1"), std::string::npos);
}

<<<<<<< HEAD
// Test structured writer with multiple key-value types
TEST_F(DispatcherTest, StructuredMultipleValueTypes) {
dispatcher.begin_record(InfoType::METRIC);
Expand Down

0 comments on commit db29cfa

Please sign in to comment.