{"action":"created","comment":{"url":"https://api.github.com/repos/stan-dev/stan/pulls/comments/42398388","id":42398388,"diff_hunk":"@@ -0,0 +1,101 @@\n+#ifndef STAN_INTERFACE_CALLBACKS_WRITER_STREAM_WRITER_HPP\n+#define STAN_INTERFACE_CALLBACKS_WRITER_STREAM_WRITER_HPP\n+\n+#include <stan/interface_callbacks/writer/base_writer.hpp>\n+#include <iostream>\n+#include <vector>\n+#include <string>\n+\n+namespace stan {\n+  namespace interface_callbacks {\n+    namespace writer {\n+\n+      template <class Stream>\n+      class stream_writer: public base_writer {\n+      public:\n+        stream_writer(Stream& output,\n+                      const std::string& key_value_prefix = \"\"):\n+          output__(output), key_value_prefix__(key_value_prefix) {}\n+\n+        void operator()(const std::string& key, double value) {\n+          output__ << key_value_prefix__ << key << \" = \" << value << std::endl;\n+        }\n+\n+        void operator()(const std::string& key, int value) {\n+          output__ << key_value_prefix__ << key << \" = \" << value << std::endl;\n+        }\n+\n+        void operator()(const std::string& key, const std::string& value) {\n+          output__ << key_value_prefix__ << key << \" = \" << value << std::endl;\n+        }\n+\n+        void operator()(const std::string& key,\n+                        const double* values,\n+                        int n_values) {\n+          if (n_values == 0) return;\n+\n+          output__ << key_value_prefix__ << key << \": \";\n+\n+          output__ << values[0];\n+          for (int n = 1; n < n_values; ++n)\n+            output__ << \",\" << values[n];\n+          output__ << std::endl;\n+        }\n+\n+        void operator()(const std::string& key,\n+                        const double* values,\n+                        int n_rows, int n_cols) {\n+          if (n_rows == 0 || n_cols == 0) return;\n+\n+          output__ << key_value_prefix__ << key << std::endl;\n+\n+          for (int i = 0; i < n_rows; ++i) {\n+            output__ << key_value_prefix__ << values[i * n_cols];\n+            for (int j = 1; j < n_cols; ++j)\n+              output__ << \",\" << values[i * n_cols + j];\n+            output__ << std::endl;\n+          }\n+        }\n+\n+        void operator()(const std::vector<std::string>& names) {\n+          if (names.empty()) return;\n+\n+          std::vector<std::string>::const_iterator last = names.end();\n+          --last;\n+\n+          for (std::vector<std::string>::const_iterator it = names.begin();\n+               it != last; ++it)\n+            output__ << *it << \",\";\n+          output__ << names.back() << std::endl;\n+        }\n+\n+        void operator()(const std::vector<double>& state) {\n+          if (state.empty()) return;\n+\n+          std::vector<double>::const_iterator last = state.end();\n+          --last;\n+\n+          for (std::vector<double>::const_iterator it = state.begin();\n+               it != last; ++it)\n+            output__ << *it << \",\";\n+          output__ << state.back() << std::endl;\n+        }\n+\n+        void operator()() {\n+          output__ << std::endl;","path":"src/stan/interface_callbacks/writer/stream_writer.hpp","position":94,"original_position":85,"commit_id":"8e50b436df3d3ad7ef49225e39ddfff28d659e2b","original_commit_id":"f19846e3a07b2e96b7806144ae42c56c1f3731df","user":{"login":"bob-carpenter","id":3383807,"avatar_url":"https://avatars.githubusercontent.com/u/3383807?v=3","gravatar_id":"","url":"https://api.github.com/users/bob-carpenter","html_url":"https://github.com/bob-carpenter","followers_url":"https://api.github.com/users/bob-carpenter/followers","following_url":"https://api.github.com/users/bob-carpenter/following{/other_user}","gists_url":"https://api.github.com/users/bob-carpenter/gists{/gist_id}","starred_url":"https://api.github.com/users/bob-carpenter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bob-carpenter/subscriptions","organizations_url":"https://api.github.com/users/bob-carpenter/orgs","repos_url":"https://api.github.com/users/bob-carpenter/repos","events_url":"https://api.github.com/users/bob-carpenter/events{/privacy}","received_events_url":"https://api.github.com/users/bob-carpenter/received_events","type":"User","site_admin":false},"body":"Although this isn't the place to be having this discussion, I think we\nneed to use CSV format as intended.  That is, our CSV readers ignore\nall the comments, read the header, and read the contents.  I think every\nother kind of reader should go somewhere else, even if it reads the\ncomments of a CSV file.\n\n> On Oct 18, 2015, at 11:31 AM, Daniel Lee <notifications@github.com> wrote:\n> \n> In src/stan/interface_callbacks/writer/stream_writer.hpp:\n> \n> > +        }\n> > +\n> > +        void operator()(const std::vector<double>& state) {\n> > +          if (state.empty()) return;\n> > +\n> > +          std::vector<double>::const_iterator last = state.end();\n> > +          --last;\n> > +\n> > +          for (std::vector<double>::const_iterator it = state.begin();\n> > +               it != last; ++it)\n> > +            output__ << *it << \",\";\n> > +          output__ << state.back() << std::endl;\n> > +        }\n> > +\n> > +        void operator()() {\n> > +          output__ << std::endl;\n> \n> Hopefully we'd all agree that the asymmetry is non-ideal and we'd rather have it be symmetric.\n> \n> Although the behavior is changing, I know how the csv files are parsed, so I know this doesn't have an effect. It also doesn't affect RStan's ability to read csv files. A test needs to change to accommodate this behavior change, but not the code.\n> \n> Of course, I haven't accounted for other consumers of this format: do you need the extra blank lines in the csvs for something in particular? Or can they be marked as comments safely?\n> \n> —\n> Reply to this email directly or view it on GitHub.\n> \n\n","created_at":"2015-10-19T17:13:54Z","updated_at":"2015-10-19T17:13:54Z","html_url":"https://github.com/stan-dev/stan/pull/1630#discussion_r42398388","pull_request_url":"https://api.github.com/repos/stan-dev/stan/pulls/1630","_links":{"self":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/comments/42398388"},"html":{"href":"https://github.com/stan-dev/stan/pull/1630#discussion_r42398388"},"pull_request":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/1630"}}},"pull_request":{"url":"https://api.github.com/repos/stan-dev/stan/pulls/1630","id":47110123,"html_url":"https://github.com/stan-dev/stan/pull/1630","diff_url":"https://github.com/stan-dev/stan/pull/1630.diff","patch_url":"https://github.com/stan-dev/stan/pull/1630.patch","issue_url":"https://api.github.com/repos/stan-dev/stan/issues/1630","number":1630,"state":"open","locked":false,"title":"Implementing writers","user":{"login":"syclik","id":425751,"avatar_url":"https://avatars.githubusercontent.com/u/425751?v=3","gravatar_id":"","url":"https://api.github.com/users/syclik","html_url":"https://github.com/syclik","followers_url":"https://api.github.com/users/syclik/followers","following_url":"https://api.github.com/users/syclik/following{/other_user}","gists_url":"https://api.github.com/users/syclik/gists{/gist_id}","starred_url":"https://api.github.com/users/syclik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syclik/subscriptions","organizations_url":"https://api.github.com/users/syclik/orgs","repos_url":"https://api.github.com/users/syclik/repos","events_url":"https://api.github.com/users/syclik/events{/privacy}","received_events_url":"https://api.github.com/users/syclik/received_events","type":"User","site_admin":false},"body":"#### Summary:\r\n\r\nImplement writers.\r\n\r\n#### Intended Effect:\r\n\r\nUpdate writers to match feature/issue-1361-writer_callback.\r\nNone of the behavior changes.\r\n\r\n#### How to Verify:\r\n\r\nTake a look at the implementation.\r\n\r\n#### Side Effects:\r\n\r\nAll interfaces may need minor changes.\r\n\r\n#### Documentation:\r\n\r\nWe may need to fill in more doc.\r\n\r\n#### Reviewer Suggestions: \r\n\r\n@bob-carpenter ","created_at":"2015-10-08T04:15:33Z","updated_at":"2015-10-19T17:13:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"950778acfb4f6c3e6921535a49cc6554ea451640","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/stan-dev/stan/pulls/1630/commits","review_comments_url":"https://api.github.com/repos/stan-dev/stan/pulls/1630/comments","review_comment_url":"https://api.github.com/repos/stan-dev/stan/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stan-dev/stan/issues/1630/comments","statuses_url":"https://api.github.com/repos/stan-dev/stan/statuses/8e50b436df3d3ad7ef49225e39ddfff28d659e2b","head":{"label":"stan-dev:feature/issue-1602-implement-writers","ref":"feature/issue-1602-implement-writers","sha":"8e50b436df3d3ad7ef49225e39ddfff28d659e2b","user":{"login":"stan-dev","id":3374820,"avatar_url":"https://avatars.githubusercontent.com/u/3374820?v=3","gravatar_id":"","url":"https://api.github.com/users/stan-dev","html_url":"https://github.com/stan-dev","followers_url":"https://api.github.com/users/stan-dev/followers","following_url":"https://api.github.com/users/stan-dev/following{/other_user}","gists_url":"https://api.github.com/users/stan-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/stan-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stan-dev/subscriptions","organizations_url":"https://api.github.com/users/stan-dev/orgs","repos_url":"https://api.github.com/users/stan-dev/repos","events_url":"https://api.github.com/users/stan-dev/events{/privacy}","received_events_url":"https://api.github.com/users/stan-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":8043756,"name":"stan","full_name":"stan-dev/stan","owner":{"login":"stan-dev","id":3374820,"avatar_url":"https://avatars.githubusercontent.com/u/3374820?v=3","gravatar_id":"","url":"https://api.github.com/users/stan-dev","html_url":"https://github.com/stan-dev","followers_url":"https://api.github.com/users/stan-dev/followers","following_url":"https://api.github.com/users/stan-dev/following{/other_user}","gists_url":"https://api.github.com/users/stan-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/stan-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stan-dev/subscriptions","organizations_url":"https://api.github.com/users/stan-dev/orgs","repos_url":"https://api.github.com/users/stan-dev/repos","events_url":"https://api.github.com/users/stan-dev/events{/privacy}","received_events_url":"https://api.github.com/users/stan-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stan-dev/stan","description":"Stan development repository (home page is linked below). The master branch contains the current release. The develop branch contains the latest stable development.  See the Developer Process Wiki for details.  ","fork":false,"url":"https://api.github.com/repos/stan-dev/stan","forks_url":"https://api.github.com/repos/stan-dev/stan/forks","keys_url":"https://api.github.com/repos/stan-dev/stan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stan-dev/stan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stan-dev/stan/teams","hooks_url":"https://api.github.com/repos/stan-dev/stan/hooks","issue_events_url":"https://api.github.com/repos/stan-dev/stan/issues/events{/number}","events_url":"https://api.github.com/repos/stan-dev/stan/events","assignees_url":"https://api.github.com/repos/stan-dev/stan/assignees{/user}","branches_url":"https://api.github.com/repos/stan-dev/stan/branches{/branch}","tags_url":"https://api.github.com/repos/stan-dev/stan/tags","blobs_url":"https://api.github.com/repos/stan-dev/stan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stan-dev/stan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stan-dev/stan/git/refs{/sha}","trees_url":"https://api.github.com/repos/stan-dev/stan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stan-dev/stan/statuses/{sha}","languages_url":"https://api.github.com/repos/stan-dev/stan/languages","stargazers_url":"https://api.github.com/repos/stan-dev/stan/stargazers","contributors_url":"https://api.github.com/repos/stan-dev/stan/contributors","subscribers_url":"https://api.github.com/repos/stan-dev/stan/subscribers","subscription_url":"https://api.github.com/repos/stan-dev/stan/subscription","commits_url":"https://api.github.com/repos/stan-dev/stan/commits{/sha}","git_commits_url":"https://api.github.com/repos/stan-dev/stan/git/commits{/sha}","comments_url":"https://api.github.com/repos/stan-dev/stan/comments{/number}","issue_comment_url":"https://api.github.com/repos/stan-dev/stan/issues/comments{/number}","contents_url":"https://api.github.com/repos/stan-dev/stan/contents/{+path}","compare_url":"https://api.github.com/repos/stan-dev/stan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stan-dev/stan/merges","archive_url":"https://api.github.com/repos/stan-dev/stan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stan-dev/stan/downloads","issues_url":"https://api.github.com/repos/stan-dev/stan/issues{/number}","pulls_url":"https://api.github.com/repos/stan-dev/stan/pulls{/number}","milestones_url":"https://api.github.com/repos/stan-dev/stan/milestones{/number}","notifications_url":"https://api.github.com/repos/stan-dev/stan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stan-dev/stan/labels{/name}","releases_url":"https://api.github.com/repos/stan-dev/stan/releases{/id}","created_at":"2013-02-06T03:25:04Z","updated_at":"2015-10-19T16:03:19Z","pushed_at":"2015-10-17T03:19:08Z","git_url":"git://github.com/stan-dev/stan.git","ssh_url":"git@github.com:stan-dev/stan.git","clone_url":"https://github.com/stan-dev/stan.git","svn_url":"https://github.com/stan-dev/stan","homepage":"http://mc-stan.org","size":361428,"stargazers_count":460,"watchers_count":460,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":108,"mirror_url":null,"open_issues_count":208,"forks":108,"open_issues":208,"watchers":460,"default_branch":"develop"}},"base":{"label":"stan-dev:develop","ref":"develop","sha":"bac3b183f2c41e1141942ecfc624c25b7fc9d0cf","user":{"login":"stan-dev","id":3374820,"avatar_url":"https://avatars.githubusercontent.com/u/3374820?v=3","gravatar_id":"","url":"https://api.github.com/users/stan-dev","html_url":"https://github.com/stan-dev","followers_url":"https://api.github.com/users/stan-dev/followers","following_url":"https://api.github.com/users/stan-dev/following{/other_user}","gists_url":"https://api.github.com/users/stan-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/stan-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stan-dev/subscriptions","organizations_url":"https://api.github.com/users/stan-dev/orgs","repos_url":"https://api.github.com/users/stan-dev/repos","events_url":"https://api.github.com/users/stan-dev/events{/privacy}","received_events_url":"https://api.github.com/users/stan-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":8043756,"name":"stan","full_name":"stan-dev/stan","owner":{"login":"stan-dev","id":3374820,"avatar_url":"https://avatars.githubusercontent.com/u/3374820?v=3","gravatar_id":"","url":"https://api.github.com/users/stan-dev","html_url":"https://github.com/stan-dev","followers_url":"https://api.github.com/users/stan-dev/followers","following_url":"https://api.github.com/users/stan-dev/following{/other_user}","gists_url":"https://api.github.com/users/stan-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/stan-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stan-dev/subscriptions","organizations_url":"https://api.github.com/users/stan-dev/orgs","repos_url":"https://api.github.com/users/stan-dev/repos","events_url":"https://api.github.com/users/stan-dev/events{/privacy}","received_events_url":"https://api.github.com/users/stan-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stan-dev/stan","description":"Stan development repository (home page is linked below). The master branch contains the current release. The develop branch contains the latest stable development.  See the Developer Process Wiki for details.  ","fork":false,"url":"https://api.github.com/repos/stan-dev/stan","forks_url":"https://api.github.com/repos/stan-dev/stan/forks","keys_url":"https://api.github.com/repos/stan-dev/stan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stan-dev/stan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stan-dev/stan/teams","hooks_url":"https://api.github.com/repos/stan-dev/stan/hooks","issue_events_url":"https://api.github.com/repos/stan-dev/stan/issues/events{/number}","events_url":"https://api.github.com/repos/stan-dev/stan/events","assignees_url":"https://api.github.com/repos/stan-dev/stan/assignees{/user}","branches_url":"https://api.github.com/repos/stan-dev/stan/branches{/branch}","tags_url":"https://api.github.com/repos/stan-dev/stan/tags","blobs_url":"https://api.github.com/repos/stan-dev/stan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stan-dev/stan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stan-dev/stan/git/refs{/sha}","trees_url":"https://api.github.com/repos/stan-dev/stan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stan-dev/stan/statuses/{sha}","languages_url":"https://api.github.com/repos/stan-dev/stan/languages","stargazers_url":"https://api.github.com/repos/stan-dev/stan/stargazers","contributors_url":"https://api.github.com/repos/stan-dev/stan/contributors","subscribers_url":"https://api.github.com/repos/stan-dev/stan/subscribers","subscription_url":"https://api.github.com/repos/stan-dev/stan/subscription","commits_url":"https://api.github.com/repos/stan-dev/stan/commits{/sha}","git_commits_url":"https://api.github.com/repos/stan-dev/stan/git/commits{/sha}","comments_url":"https://api.github.com/repos/stan-dev/stan/comments{/number}","issue_comment_url":"https://api.github.com/repos/stan-dev/stan/issues/comments{/number}","contents_url":"https://api.github.com/repos/stan-dev/stan/contents/{+path}","compare_url":"https://api.github.com/repos/stan-dev/stan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stan-dev/stan/merges","archive_url":"https://api.github.com/repos/stan-dev/stan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stan-dev/stan/downloads","issues_url":"https://api.github.com/repos/stan-dev/stan/issues{/number}","pulls_url":"https://api.github.com/repos/stan-dev/stan/pulls{/number}","milestones_url":"https://api.github.com/repos/stan-dev/stan/milestones{/number}","notifications_url":"https://api.github.com/repos/stan-dev/stan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stan-dev/stan/labels{/name}","releases_url":"https://api.github.com/repos/stan-dev/stan/releases{/id}","created_at":"2013-02-06T03:25:04Z","updated_at":"2015-10-19T16:03:19Z","pushed_at":"2015-10-17T03:19:08Z","git_url":"git://github.com/stan-dev/stan.git","ssh_url":"git@github.com:stan-dev/stan.git","clone_url":"https://github.com/stan-dev/stan.git","svn_url":"https://github.com/stan-dev/stan","homepage":"http://mc-stan.org","size":361428,"stargazers_count":460,"watchers_count":460,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":108,"mirror_url":null,"open_issues_count":208,"forks":108,"open_issues":208,"watchers":460,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/1630"},"html":{"href":"https://github.com/stan-dev/stan/pull/1630"},"issue":{"href":"https://api.github.com/repos/stan-dev/stan/issues/1630"},"comments":{"href":"https://api.github.com/repos/stan-dev/stan/issues/1630/comments"},"review_comments":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/1630/comments"},"review_comment":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stan-dev/stan/pulls/1630/commits"},"statuses":{"href":"https://api.github.com/repos/stan-dev/stan/statuses/8e50b436df3d3ad7ef49225e39ddfff28d659e2b"}}}}