{"action":"created","issue":{"url":"https://api.github.com/repos/stan-dev/rstan/issues/464","repository_url":"https://api.github.com/repos/stan-dev/rstan","labels_url":"https://api.github.com/repos/stan-dev/rstan/issues/464/labels{/name}","comments_url":"https://api.github.com/repos/stan-dev/rstan/issues/464/comments","events_url":"https://api.github.com/repos/stan-dev/rstan/issues/464/events","html_url":"https://github.com/stan-dev/rstan/issues/464","id":271119156,"number":464,"title":"rstan crashes R (and RStudio) when generated quantities contain array of large matrices","user":{"login":"lutzgruber","id":33359648,"avatar_url":"https://avatars3.githubusercontent.com/u/33359648?v=4","gravatar_id":"","url":"https://api.github.com/users/lutzgruber","html_url":"https://github.com/lutzgruber","followers_url":"https://api.github.com/users/lutzgruber/followers","following_url":"https://api.github.com/users/lutzgruber/following{/other_user}","gists_url":"https://api.github.com/users/lutzgruber/gists{/gist_id}","starred_url":"https://api.github.com/users/lutzgruber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lutzgruber/subscriptions","organizations_url":"https://api.github.com/users/lutzgruber/orgs","repos_url":"https://api.github.com/users/lutzgruber/repos","events_url":"https://api.github.com/users/lutzgruber/events{/privacy}","received_events_url":"https://api.github.com/users/lutzgruber/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2017-11-03T21:07:46Z","updated_at":"2017-11-10T23:31:41Z","closed_at":null,"author_association":"NONE","body":"#### Summary:\r\nrstan crashes R (and RStudio) when the generated quantities block contains an array of large matrices, for example, `matrix[5000, 5] testobject[50]`.\r\n\r\n#### Description:\r\nMain problem: The R session crashes and takes down RStudio with it when the generated quantities block of a stan model contains an array of large matrices, for example `matrix[5000, 5] testobject[50]`.\r\n\r\nAdditional notes: The model runs fine for arrays of very small matrices, for example, `matrix[50, 5] testobject[50]`, in which case the rstan function call completes in about 2 seconds. The model does not crash for arrays of medium size matrices, for example, `matrix[500, 5] testobject[50]`, but takes disproportionally longer to complete (about 380 seconds).\r\n\r\nThis crash is likely not caused by a lack of available memory, given that there were more than 64GB of free memory at the time of the crash and memory usage of the R session only went up to 0.7GB by the time the crash occurred.\r\n\r\n#### Reproducible Steps:\r\n\r\n```\r\nlibrary(Rcpp)\r\n\r\ntest_model = rstan::stan_model(\r\n    model_code = \"data {\r\n      int nrow;\r\n      int ncol;\r\n      int nmatrices;\r\n    }\r\n    generated quantities {\r\n      matrix[nrow, ncol] testobject[nmatrices];\r\n\r\n      for (i in 1:nmatrices) {\r\n        testobject[i] = rep_matrix(0.0 + i, nrow, ncol);\r\n      }\r\n    }\"\r\n)\r\n\r\n# takes about 2 seconds\r\nsystem.time({\r\ntest_result1 = rstan::sampling(\r\n    object = test_model,\r\n    algorithm = \"Fixed_param\",\r\n    chains = 1,\r\n    iter = 1,\r\n    verbose = TRUE,\r\n    data = list(nrow = 50, ncol = 5, nmatrices = 50)\r\n)\r\n})\r\n\r\n# takes about 380 seconds\r\nsystem.time({\r\ntest_result2 = rstan::sampling(\r\n    object = test_model,\r\n    algorithm = \"Fixed_param\",\r\n    chains = 1,\r\n    iter = 1,\r\n    verbose = TRUE,\r\n    data = list(nrow = 500, ncol = 5, nmatrices = 50)\r\n)\r\n})\r\n\r\n# crash\r\nsystem.time({\r\ntest_result3 = rstan::sampling(\r\n    object = test_model,\r\n    algorithm = \"Fixed_param\",\r\n    chains = 1,\r\n    iter = 1,\r\n    verbose = TRUE,\r\n    data = list(nrow = 5000, ncol = 5, nmatrices = 50)\r\n)\r\n})\r\n```\r\n\r\n#### Current Output:\r\nCrashed R/RStudio session\r\n\r\n#### Expected Output:\r\nNo crash for arrays of large matrices; shorter runtime for array of medium size matrices. Any help is appreciated!\r\n\r\n#### RStan Version:\r\n2.16.2\r\n\r\n#### R Version:\r\nR version 3.4.2 (2017-09-28)\r\n\r\n#### Operating System:\r\nWindows Server 2016\r\n"},"comment":{"url":"https://api.github.com/repos/stan-dev/rstan/issues/comments/343614348","html_url":"https://github.com/stan-dev/rstan/issues/464#issuecomment-343614348","issue_url":"https://api.github.com/repos/stan-dev/rstan/issues/464","id":343614348,"user":{"login":"bgoodri","id":3386282,"avatar_url":"https://avatars2.githubusercontent.com/u/3386282?v=4","gravatar_id":"","url":"https://api.github.com/users/bgoodri","html_url":"https://github.com/bgoodri","followers_url":"https://api.github.com/users/bgoodri/followers","following_url":"https://api.github.com/users/bgoodri/following{/other_user}","gists_url":"https://api.github.com/users/bgoodri/gists{/gist_id}","starred_url":"https://api.github.com/users/bgoodri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bgoodri/subscriptions","organizations_url":"https://api.github.com/users/bgoodri/orgs","repos_url":"https://api.github.com/users/bgoodri/repos","events_url":"https://api.github.com/users/bgoodri/events{/privacy}","received_events_url":"https://api.github.com/users/bgoodri/received_events","type":"User","site_admin":false},"created_at":"2017-11-10T23:31:41Z","updated_at":"2017-11-10T23:31:41Z","author_association":"CONTRIBUTOR","body":"The `sample_file` argument tells Stan where to write the CSV file with all\nthe parameter draws to. If you also do `pars = \"\"`, then you will likely\navoid the bug you encountered.\n\nOn Fri, Nov 10, 2017 at 6:18 PM, lutzgruber <notifications@github.com>\nwrote:\n\n> Ok, thanks for checking!\n>\n> @bgoodri <https://github.com/bgoodri> how would specifying a sample_file\n> help me here? I was trying to export an array of matrices from stan into R,\n> not import it from R into my stan program.\n>\n> —\n> You are receiving this because you were mentioned.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/stan-dev/rstan/issues/464#issuecomment-343612423>, or mute\n> the thread\n> <https://github.com/notifications/unsubscribe-auth/ADOrqlfiAskaQXt4R1QB9H1RzyH3jUR-ks5s1NnYgaJpZM4QRrjr>\n> .\n>\n"}}
{"actor":{"display_login":"bgoodri"}}