stan-dev / stanc3

The Stan transpiler (from Stan to C++ and beyond).
BSD 3-Clause "New" or "Revised" License
140 stars 44 forks source link

Internal compiler error: TypeError: a.charCodeAt is not a function #1446

Open tuulam opened 4 weeks ago

tuulam commented 4 weeks ago

This happened also a couple of days ago. Now I have the code that caused it:

lambda_true = 3
N = 5
set.seed(111111)
(y = rpois(N, lambda_true))
poisson_dat = list(y = y, N = N)
alpha = beta = 1
data {
    int<lower=0> N;
    array[N] int<lower=0> y;
}

parameters {
    real<lower=0> lambda;
}
model {
    lambda ~ lognormal(0,1);
    y ~ poisson(lambda);
}
fit2 <- stan('poisson_lognormal.stan', poisson_dat, iter = 20000, chains = 4)

The error message:
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  0
Internal compiler error:
TypeError: a.charCodeAt is not a function

Rstan 2.35.0.9000

This should never happen. Please file a bug at https://github.com/stan-dev/stanc3/issues/new and include this message and the model that caused this issue.

I removed the package V8 but it didn't change the situation.

andrjohns commented 4 weeks ago

And can you post the results of the same debugging steps from earlier (calling stanc on the model code as a string and then on the file)?

tuulam commented 4 weeks ago

Error in stanc(file = file, model_code = model_code, model_name = model_name, : 0 Internal compiler error: TypeError: a.charCodeAt is not a function

This should never happen. Please file a bug at https://github.com/stan-dev/stanc3/issues/new and include this message and the model that caused this issue.


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 12:44 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Author @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

And can you post the results of the same debugging steps from earlier (calling stanc on the model code as a string and then on the file)?

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293187707, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U23CPXHNZMIHWJSR6TZRXCY7AVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGE4DONZQG4. You are receiving this because you authored the thread.Message ID: @.***>

andrjohns commented 4 weeks ago

Can you show the full R code that you used? Just so I can be running the same thing

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: tuulam @.> Sent: Friday, August 16, 2024 12:55:04 PM To: stan-dev/stanc3 @.> Cc: Andrew Johnson @.>; Comment @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

Error in stanc(file = file, model_code = model_code, model_name = model_name, : 0 Internal compiler error: TypeError: a.charCodeAt is not a function

This should never happen. Please file a bug at https://github.com/stan-dev/stanc3/issues/new and include this message and the model that caused this issue.


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 12:44 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Author @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

And can you post the results of the same debugging steps from earlier (calling stanc on the model code as a string and then on the file)?

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293187707, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U23CPXHNZMIHWJSR6TZRXCY7AVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGE4DONZQG4. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293202724, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGTPCCBOTCXHVCCPBODHJJTZRXD7RAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGIYDENZSGQ. You are receiving this because you commented.Message ID: @.***>

tuulam commented 4 weeks ago

lambda_true = 3 N = 5 set.seed(111111) (y = rpois(N, lambda_true)) poisson_dat = list(y = y, N = N) alpha = beta = 1

fit2 <- stan('poisson_lognormal.stan', poisson_dat, iter = 20000, chains = 4)

The stan file is the following

data {       int N;       array[N] int y; }

parameters {       real lambda; } model {       lambda ~ lognormal(0,1);       y ~ poisson(lambda); }


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 12:56 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Author @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

Can you show the full R code that you used? Just so I can be running the same thing

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: tuulam @.> Sent: Friday, August 16, 2024 12:55:04 PM To: stan-dev/stanc3 @.> Cc: Andrew Johnson @.>; Comment @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

Error in stanc(file = file, model_code = model_code, model_name = model_name, : 0 Internal compiler error: TypeError: a.charCodeAt is not a function

This should never happen. Please file a bug at https://github.com/stan-dev/stanc3/issues/new and include this message and the model that caused this issue.


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 12:44 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Author @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

And can you post the results of the same debugging steps from earlier (calling stanc on the model code as a string and then on the file)?

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293187707, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U23CPXHNZMIHWJSR6TZRXCY7AVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGE4DONZQG4. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293202724, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGTPCCBOTCXHVCCPBODHJJTZRXD7RAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGIYDENZSGQ. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293205457, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U35OX4475CSCSELQ7DZRXEFXAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGIYDKNBVG4. You are receiving this because you authored the thread.Message ID: @.***>

andrjohns commented 4 weeks ago

lambda_true = 3 N = 5 set.seed(111111) (y = rpois(N, lambda_true)) poisson_dat = list(y = y, N = N) alpha = beta = 1

fit2 <- stan('poisson_lognormal.stan', poisson_dat, iter = 20000, chains = 4)

The stan file is the following

data {       int N;       array[N] int y; }

parameters {       real lambda; } model {       lambda ~ lognormal(0,1);       y ~ poisson(lambda); }


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 12:56 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Author @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

Can you show the full R code that you used? Just so I can be running the same thing

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: tuulam @.> Sent: Friday, August 16, 2024 12:55:04 PM To: stan-dev/stanc3 @.> Cc: Andrew Johnson @.>; Comment @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

Error in stanc(file = file, model_code = model_code, model_name = model_name, : 0 Internal compiler error: TypeError: a.charCodeAt is not a function

This should never happen. Please file a bug at https://github.com/stan-dev/stanc3/issues/new and include this message and the model that caused this issue.


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 12:44 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Author @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

And can you post the results of the same debugging steps from earlier (calling stanc on the model code as a string and then on the file)?

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293187707, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U23CPXHNZMIHWJSR6TZRXCY7AVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGE4DONZQG4. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293202724, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGTPCCBOTCXHVCCPBODHJJTZRXD7RAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGIYDENZSGQ. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293205457, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U35OX4475CSCSELQ7DZRXEFXAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGIYDKNBVG4. You are receiving this because you authored the thread.Message ID: @.***>

And can you do the same for running stanc on the model as a string? (The full R code and the results)

tuulam commented 4 weeks ago

I am not sure what I am supposed to do. I created a string

m = str('{data {

and ran

stanc(fit2 <- stan('poisson_lognormal.stan', m, iter = 20000, chains = 4))

I got an error message:

Error : Exception: variable does not exist; processing stage=data initialization; variable name=N; base type=int (in 'string', line 2, column 1 to column 16) failed to create the sampler; sampling not done Error in isTRUE(!nzchar(file)) : no method for coercing this S4 class to a vector


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 1:02 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Author @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

lambda_true = 3 N = 5 set.seed(111111) (y = rpois(N, lambda_true)) poisson_dat = list(y = y, N = N) alpha = beta = 1

fit2 <- stan('poisson_lognormal.stan', poisson_dat, iter = 20000, chains = 4)

The stan file is the following

data {       int N;       array[N] int y; }

parameters {       real lambda; } model {       lambda ~ lognormal(0,1);       y ~ poisson(lambda); }


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 12:56 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Author @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446https://github.com/stan-dev/stanc3/issues/1446)

Can you show the full R code that you used? Just so I can be running the same thing

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: tuulam @.> Sent: Friday, August 16, 2024 12:55:04 PM To: stan-dev/stanc3 @.> Cc: Andrew Johnson @.>; Comment @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446https://github.com/stan-dev/stanc3/issues/1446)

Error in stanc(file = file, model_code = model_code, model_name = model_name, : 0 Internal compiler error: TypeError: a.charCodeAt is not a function

This should never happen. Please file a bug at https://github.com/stan-dev/stanc3/issues/new and include this message and the model that caused this issue.


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 12:44 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Author @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446https://github.com/stan-dev/stanc3/issues/1446)

And can you post the results of the same debugging steps from earlier (calling stanc on the model code as a string and then on the file)?

— Reply to this email directly, view it on GitHub#1446 (comment)https://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293187707, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U23CPXHNZMIHWJSR6TZRXCY7AVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGE4DONZQG4. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub#1446 (comment)https://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293202724, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGTPCCBOTCXHVCCPBODHJJTZRXD7RAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGIYDENZSGQ. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub#1446 (comment)https://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293205457, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U35OX4475CSCSELQ7DZRXEFXAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGIYDKNBVG4. You are receiving this because you authored the thread.Message ID: @.***>

And can you do the same for running stanc on the model as a string? (The full R code and the results)

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293216324, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U47TTLXYB2KLUN7H6TZRXE25AVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGIYTMMZSGQ. You are receiving this because you authored the thread.Message ID: @.***>

andrjohns commented 4 weeks ago

I am not sure what I am supposed to do.

Like the following:

stancode <- "YOUR MODEL CODE"
rstan::stanc(model_code=stancode)
tuulam commented 4 weeks ago

What do you mean by model code, the stan-file, or fit-function?

On Fri, 16 Aug 2024 at 13:15, Andrew Johnson @.***> wrote:

I am not sure what I am supposed to do.

Like the following:

stancode <- "YOUR MODEL CODE"rstan::stanc(model_code=stanc)

— Reply to this email directly, view it on GitHub https://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293236501, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALZZ4U6PNX57EMS6ZXW43K3ZRXGK3AVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGIZTMNJQGE . You are receiving this because you authored the thread.Message ID: @.***>

andrjohns commented 4 weeks ago

If your model is:

data {
  int<lower=0> N;
  array[N] int<lower=0> y;
}

parameters {
  real<lower=0> lambda;
}
model {
  lambda ~ lognormal(0,1);
  y ~ poisson(lambda);
}

Then run:

stancode <- "
data {
  int<lower=0> N;
  array[N] int<lower=0> y;
}

parameters {
  real<lower=0> lambda;
}
model {
  lambda ~ lognormal(0,1);
  y ~ poisson(lambda);
}
"

rstan::stanc(model_code=stancode)

And post the R code you used and the result

tuulam commented 4 weeks ago

From: Andrew Johnson @.> Sent: Friday, August 16, 2024 2:33 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Author @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

If your model is:

data { int N; array[N] int y; }

parameters { real lambda; } model { lambda ~ lognormal(0,1); y ~ poisson(lambda); }

Then run:

stancode <- " data { int N; array[N] int y; }

parameters { real lambda; } model { lambda ~ lognormal(0,1); y ~ poisson(lambda); } "

rstan::stanc(model_code=stancode)

And post the R code you used and the result

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293340034, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U7ZZHTIN7QE4XR7F2LZRXPPNAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGM2DAMBTGQ. You are receiving this because you authored the thread.Message ID: @.***>

WardBrian commented 4 weeks ago

Hi @tuulam -- your last reply seems to be blank. Could you send the output again?

tuulam commented 4 weeks ago

On Fri, 16 Aug 2024 at 17:36, Brian Ward @.***> wrote:

Hi @tuulam https://github.com/tuulam -- your last reply seems to be blank. Could you send the output again?

— Reply to this email directly, view it on GitHub https://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293628848, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALZZ4U4JDDHJBR7YFE5WMVTZRYE6VAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTGYZDQOBUHA . You are receiving this because you were mentioned.Message ID: @.***>

stancode <- "

  • data {
  • int N;
  • array[N] int y;
  • }
  • parameters {
  • real lambda;
  • }
  • model {
  • lambda ~ lognormal(0,1);
  • y ~ poisson(lambda);
  • }
  • "

rstan::stanc(model_code=stancode) $status [1] TRUE

$model_cppname [1] "model38d83c842f2_file38d8327b67a4"

$cppcode [1] "#ifndef USE_STANC3\n#define USE_STANC3\n#endif\n// Code generated by stanc v2.35.0\n#include <stan/model/model_header.hpp>\nnamespace model38d83c842f2_file38d8327b67a4_namespace {\nusing stan::model::model_base_crtp;\nusing namespace stan::math;\nstan::math::profile_map profiles;\nstatic constexpr std::array<const char*, 7> locations_array__ =\n {\" (found before start of program)\",\n \" (in 'string', line 6, column 0 to column 21)\",\n \" (in 'string', line 9, column 0 to column 24)\",\n \" (in 'string', line 10, column 0 to column 20)\",\n \" (in 'string', line 2, column 0 to column 15)\",\n \" (in 'string', line 3, column 6 to column 7)\",\n \" (in 'string', line 3, column 0 to column 24)\"};\nclass model38d83c842f2_file38d8327b67a4 final : public model_base_crtp {\nprivate:\n int N;\n std::vector y;\npublic:\n ~model38d83c842f2_file38d8327b67a4() {}\n model38d83c842f2_file38d8327b67a4(stan::io::var_context& context,\n unsigned int random_seed = 0,\n std::ostream* pstream = nullptr)\n : model_base_crtp(0) {\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement;\n using local_scalar_t = double;\n auto base_rng = stan::services::util::create_rng(random_seed, 0);\n // suppress unused var warning\n (void) base_rng;\n static constexpr const char* function =\n \"model38d83c842f2_file38d8327b67a4_namespace::model38d83c842f2_file38d8327b67a4\";\n // suppress unused var warning\n (void) function;\n local_scalar_t DUMMY_VAR__(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR;\n try {\n current_statement = 4;\n context.validate_dims(\"data initialization\", \"N\", \"int\",\n std::vector{});\n N = std::numeric_limits::min();\n current_statement = 4;\n N = context.vals_i(\"N\")[(1 - 1)];\n current_statement = 4;\n stan::math::check_greater_or_equal(function__, \"N\", N, 0);\n current_statement = 5;\n stan::math::validate_non_negative_index(\"y\", \"N\", N);\n current_statement = 6;\n context.validate_dims(\"data initialization\", \"y\", \"int\",\n std::vector{static_cast(N)});\n y = std::vector(N, std::numeric_limits::min());\n current_statement = 6;\n y = context.vals_i(\"y\");\n current_statement = 6;\n stan::math::check_greater_or_equal(function, \"y\", y, 0);\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array[current_statement]);\n }\n num_params_r = 1;\n }\n inline std::string model_name() const final {\n return \"model38d83c842f2_file38d8327b67a4\";\n }\n inline std::vector model_compile_info() const noexcept {\n return std::vector{\"stanc_version = stanc3 v2.35.0\",\n \"stancflags = --\"};\n }\n // Base log prob\n template <bool propto, bool jacobian, typename VecR, typename VecI,\n stan::require_vector_like_t = nullptr,\n stan::require_vector_like_vt<std::is_integral, VecI> = nullptr,\n stan::require_not_st_var* = nullptr>\n inline stan::scalar_type_t\n log_prob_impl(VecR& params_r, VecI& params_i, std::ostream*\n pstream = nullptr) const {\n using T = stan::scalar_type_t;\n using local_scalar_t = T;\n T lp(0.0);\n stan::math::accumulator<T> lp_accum;\n stan::io::deserializer<local_scalar_t> in(params_r__, params_i);\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement;\n local_scalar_t DUMMY_VAR(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR;\n static constexpr const char* function =\n \"model38d83c842f2_file38d8327b67a4_namespace::log_prob\";\n // suppress unused var warning\n (void) function;\n try {\n local_scalar_t lambda = DUMMY_VAR;\n current_statement = 1;\n lambda = in.template read_constrain_lb<local_scalar_t,\n jacobian>(0, lp__);\n {\n current_statement = 2;\n lp_accum.add(stan::math::lognormal_lpdf(lambda, 0, 1));\n current_statement = 3;\n lp_accum.add(stan::math::poisson_lpmf(y, lambda));\n }\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array__[current_statement]);\n }\n lp_accum.add(lp);\n return lp_accum.sum();\n }\n // Reverse mode autodiff log prob\n template <bool propto, bool jacobian, typename VecR, typename VecI,\n stan::require_vector_like_t = nullptr,\n stan::require_vector_like_vt<std::is_integral, VecI> = nullptr,\n stan::require_st_var* = nullptr>\n inline stan::scalar_type_t\n log_prob_impl(VecR& params_r, VecI& params_i, std::ostream*\n pstream = nullptr) const {\n using T = stan::scalar_type_t;\n using local_scalar_t = T;\n T lp(0.0);\n stan::math::accumulator<T> lp_accum;\n stan::io::deserializer<local_scalar_t> in(params_r__, params_i);\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement;\n local_scalar_t DUMMY_VAR(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR;\n static constexpr const char* function =\n \"model38d83c842f2_file38d8327b67a4_namespace::log_prob\";\n // suppress unused var warning\n (void) function;\n try {\n local_scalar_t lambda = DUMMY_VAR;\n current_statement = 1;\n lambda = in.template read_constrain_lb<local_scalar_t,\n jacobian>(0, lp__);\n {\n current_statement = 2;\n lp_accum.add(stan::math::lognormal_lpdf(lambda, 0, 1));\n current_statement = 3;\n lp_accum.add(stan::math::poisson_lpmf(y, lambda));\n }\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array__[current_statement]);\n }\n lp_accum.add(lp);\n return lp_accum.sum();\n }\n template <typename RNG, typename VecR, typename VecI, typename VecVar,\n stan::require_vector_like_vt<std::is_floating_point,\n VecR> = nullptr, stan::require_vector_like_vt<std::is_integral,\n VecI> = nullptr, stan::require_vector_vt<std::is_floating_point,\n VecVar>* = nullptr>\n inline void\n write_array_impl(RNG& base_rng, VecR& params_r, VecI& params_i,\n VecVar& vars, const bool\n emit_transformed_parameters = true, const bool\n emit_generated_quantities = true, std::ostream*\n pstream = nullptr) const {\n using local_scalar_t = double;\n stan::io::deserializer in__(params_r, params_i);\n stan::io::serializer<local_scalar_t> out(vars);\n static constexpr bool propto = true;\n // suppress unused var warning\n (void) propto;\n double lp = 0.0;\n // suppress unused var warning\n (void) lp;\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement__;\n stan::math::accumulator lp_accum;\n local_scalar_t DUMMY_VAR__(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR;\n constexpr bool jacobian = false;\n // suppress unused var warning\n (void) jacobian;\n static constexpr const char function =\n \"model38d83c842f2_file38d8327b67a4_namespace::write_array\";\n // suppress unused var warning\n (void) function__;\n try {\n double lambda = std::numeric_limits::quiet_NaN();\n current_statement = 1;\n lambda = in.template read_constrain_lb<local_scalar_t,\n jacobian>(0, lp);\n out.write(lambda);\n if (stan::math::logical_negation(\n (stan::math::primitive_value(emit_transformed_parameters) ||\n stan::math::primitive_value(emit_generated_quantities)))) {\n return ;\n }\n if (stan::math::logical_negation(emit_generated_quantities)) {\n return ;\n }\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array[current_statement]);\n }\n }\n template <typename VecVar, typename VecI,\n stan::require_vector_t = nullptr,\n stan::require_vector_like_vt<std::is_integral, VecI> = nullptr>\n inline void\n unconstrain_array_impl(const VecVar& params_r__, const VecI& params_i,\n VecVar& vars, std::ostream pstream = nullptr) const {\n using local_scalar_t = double;\n stan::io::deserializer in(params_r__, params_i);\n stan::io::serializer out(vars);\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement;\n local_scalar_t DUMMY_VAR(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR;\n try {\n local_scalar_t lambda = DUMMY_VAR;\n current_statement = 1;\n lambda = in.read();\n out.write_free_lb(0, lambda);\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array[current_statement]);\n }\n }\n template <typename VecVar, stan::require_vector_t = nullptr>\n inline void\n transform_inits_impl(const stan::io::var_context& context, VecVar&\n vars, std::ostream pstream = nullptr) const {\n using local_scalar_t = double;\n stan::io::serializer out(vars);\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement;\n local_scalar_t DUMMY_VAR(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR;\n try {\n current_statement = 1;\n context.validate_dims(\"parameter initialization\", \"lambda\", \"double\",\n std::vector{});\n local_scalar_t__ lambda = DUMMY_VAR;\n current_statement = 1;\n lambda = context.vals_r(\"lambda\")[(1 - 1)];\n out.write_free_lb(0, lambda);\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array[current_statement]);\n }\n }\n inline void\n get_param_names(std::vector& names, const bool\n emit_transformed_parameters = true, const bool\n emit_generated_quantities = true) const {\n names = std::vector{\"lambda\"};\n if (emit_transformed_parameters) {}\n if (emit_generated_quantities) {}\n }\n inline void\n get_dims(std::vector<std::vector>& dimss, const bool\n emit_transformed_parameters = true, const bool\n emit_generated_quantities = true) const {\n dimss = std::vector<std::vector>{std::vector{}};\n if (emit_transformed_parameters) {}\n if (emit_generated_quantities) {}\n }\n inline void\n constrained_param_names(std::vector& param_names, bool\n emit_transformed_parameters = true, bool\n emit_generated_quantities__ = true) const final {\n param_names.emplace_back(std::string() + \"lambda\");\n if (emit_transformed_parameters) {}\n if (emit_generated_quantities) {}\n }\n inline void\n unconstrained_param_names(std::vector& param_names, bool\n emit_transformed_parameters = true, bool\n emit_generated_quantities = true) const final {\n param_names__.emplace_back(std::string() + \"lambda\");\n if (emit_transformed_parameters) {}\n if (emit_generated_quantities) {}\n }\n inline std::string get_constrained_sizedtypes() const {\n return std::string(\"[{\\"name\\":\\"lambda\\",\\"type\\":{\\"name\\":\\"real\\"},\\"block\\":\\"parameters\\"}]\");\n }\n inline std::string get_unconstrained_sizedtypes() const {\n return std::string(\"[{\\"name\\":\\"lambda\\",\\"type\\":{\\"name\\":\\"real\\"},\\"block\\":\\"parameters\\"}]\");\n }\n // Begin method overload boilerplate\n template inline void\n write_array(RNG& base_rng, Eigen::Matrix<double,-1,1>& params_r,\n Eigen::Matrix<double,-1,1>& vars, const bool\n emit_transformed_parameters = true, const bool\n emit_generated_quantities = true, std::ostream\n pstream = nullptr) const {\n const size_t num_params__ = 1;\n const size_t num_transformed = emit_transformed_parameters (0);\n const size_t num_gen_quantities = emit_generated_quantities * (0);\n const size_t num_to_write = num_params + num_transformed +\n num_gen_quantities;\n std::vector params_i;\n vars = Eigen::Matrix<double,-1,1>::Constant(num_to_write,\n std::numeric_limits::quiet_NaN());\n write_array_impl(base_rng, params_r, params_i, vars,\n emit_transformed_parameters, emit_generated_quantities, pstream);\n }\n template inline void\n write_array(RNG& base_rng, std::vector& params_r, std::vector&\n params_i, std::vector& vars, bool\n emit_transformed_parameters = true, bool\n emit_generated_quantities = true, std::ostream\n pstream = nullptr) const {\n const size_t num_params__ = 1;\n const size_t num_transformed = emit_transformed_parameters (0);\n const size_t num_gen_quantities = emit_generated_quantities (0);\n const size_t num_to_write = num_params + num_transformed +\n num_gen_quantities;\n vars = std::vector(num_to_write,\n std::numeric_limits::quiet_NaN());\n write_array_impl(base_rng, params_r, params_i, vars,\n emit_transformed_parameters, emit_generated_quantities, pstream);\n }\n template <bool propto, bool jacobian_, typename T> inline T_\n logprob(Eigen::Matrix<T,-1,1>& params_r, std::ostream pstream = nullptr) const {\n Eigen::Matrix<int,-1,1> params_i;\n return log_prob_impl<propto, jacobian>(params_r, paramsi, pstream);\n }\n template <bool propto, bool jacobian, typename T> inline T_\n logprob(std::vector<T>& params_r, std::vector& params_i,\n std::ostream pstream = nullptr) const {\n return log_prob_impl<propto, jacobian>(params_r, params_i, pstream);\n }\n inline void\n transform_inits(const stan::io::var_context& context,\n Eigen::Matrix<double,-1,1>& params_r, std::ostream\n pstream = nullptr) const final {\n std::vector params_r_vec(params_r.size());\n std::vector params_i;\n transform_inits(context, params_i, params_r_vec, pstream);\n params_r = Eigen::Map<Eigen::Matrix<double,-1,1>>(params_r_vec.data(),\n params_r_vec.size());\n }\n inline void\n transform_inits(const stan::io::var_context& context, std::vector&\n params_i, std::vector& vars, std::ostream\n pstream = nullptr) const {\n vars.resize(num_params_r);\n transform_inits_impl(context, vars, pstream__);\n }\n inline void\n unconstrain_array(const std::vector& params_constrained,\n std::vector& params_unconstrained, std::ostream\n pstream = nullptr) const {\n const std::vector params_i;\n params_unconstrained = std::vector(num_params_r,\n std::numeric_limits::quiet_NaN());\n unconstrain_array_impl(params_constrained, params_i,\n params_unconstrained, pstream);\n }\n inline void\n unconstrain_array(const Eigen::Matrix<double,-1,1>& params_constrained,\n Eigen::Matrix<double,-1,1>& params_unconstrained,\n std::ostream* pstream = nullptr) const {\n const std::vector params_i;\n params_unconstrained = Eigen::Matrix<double,-1,1>::Constant(num_params_r,\n std::numeric_limits::quiet_NaN());\n unconstrain_array_impl(params_constrained, params_i,\n params_unconstrained, pstream);\n }\n};\n}\nusing stan_model = model38d83c842f2_file38d8327b67a4_namespace::model38d83c842f2_file38d8327b67a4;\n#ifndef USING_R\n// Boilerplate\nstan::model::model_base&\nnew_model(stan::io::var_context& data_context, unsigned int seed,\n std::ostream msg_stream) {\n stan_model m = new stan_model(data_context, seed, msg_stream);\n return *m;\n}\nstan::math::profile_map& get_stan_profile_data() {\n return model38d83c842f2_file38d8327b67a4_namespace::profiles__;\n}\n#endif"

$model_name [1] "file38d8327b67a4"

$model_code [1] "data {\nint N;\narray[N] int y;\n}\nparameters {\nreal lambda;\n}\nmodel {\nlambda ~ lognormal(0,1);\ny ~ poisson(lambda);\n}" attr(,"model_name2") [1] "file38d8327b67a4"

andrjohns commented 4 weeks ago

That indicates no error, are you still getting the error with your Stan file?

tuulam commented 4 weeks ago

Unfortunately, yes I do.


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 8:57 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Mention @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

That indicates no error, are you still getting the error with your Stan file?

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293924973, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U4V4ULENJMOJ2ZZ6S3ZRY4PNAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTHEZDIOJXGM. You are receiving this because you were mentioned.Message ID: @.***>

andrjohns commented 4 weeks ago

Interesting!

Can you run:

cat("poisson_lognormal.stan", sep="\n")
rstan::stanc(file="poisson_lognormal.stan")
andrjohns commented 4 weeks ago

cat("poisson_lognormal.stan", sep="\n")

Oops, that should be: readLines("poisson_lognormal.stan") instead

tuulam commented 4 weeks ago

On Fri, 16 Aug 2024 at 21:08, Andrew Johnson @.***> wrote:

cat("poisson_lognormal.stan", sep="\n")

Oops, that should be: readLines("poisson_lognormal.stan") instead

— Reply to this email directly, view it on GitHub https://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293939562, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALZZ4U3BLBF3ICHKCOIS2U3ZRY5ZXAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTHEZTSNJWGI . You are receiving this because you were mentioned.Message ID: @.***>

readLines("poisson_lognormal.stan") [1] "data {" "\tint N;" "\tarray[N] int y;" [4] "}" "" "parameters {"
[7] "\treal lambda;" "}" "model {"
[10] "\tlambda ~ lognormal(0,1);" "\ty ~ poisson(lambda);" "}"
rstan::stanc(file="poisson_lognormal.stan") $status [1] TRUE

$model_cppname [1] "model38d81c9023cf_poisson_lognormal"

$cppcode [1] "#ifndef USE_STANC3\n#define USE_STANC3\n#endif\n// Code generated by stanc v2.35.0\n#include <stan/model/model_header.hpp>\nnamespace model38d81c9023cf_poisson_lognormal_namespace {\nusing stan::model::model_base_crtp;\nusing namespace stan::math;\nstan::math::profile_map profiles;\nstatic constexpr std::array<const char*, 7> locations_array__ =\n {\" (found before start of program)\",\n \" (in 'string', line 6, column 1 to column 22)\",\n \" (in 'string', line 9, column 1 to column 25)\",\n \" (in 'string', line 10, column 1 to column 21)\",\n \" (in 'string', line 2, column 1 to column 16)\",\n \" (in 'string', line 3, column 7 to column 8)\",\n \" (in 'string', line 3, column 1 to column 25)\"};\nclass model38d81c9023cf_poisson_lognormal final : public model_base_crtp {\nprivate:\n int N;\n std::vector y;\npublic:\n ~model38d81c9023cf_poisson_lognormal() {}\n model38d81c9023cf_poisson_lognormal(stan::io::var_context& context,\n unsigned int random_seed = 0,\n std::ostream* pstream = nullptr)\n : model_base_crtp(0) {\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement;\n using local_scalar_t = double;\n auto base_rng = stan::services::util::create_rng(random_seed, 0);\n // suppress unused var warning\n (void) base_rng;\n static constexpr const char* function =\n \"model38d81c9023cf_poisson_lognormal_namespace::model38d81c9023cf_poisson_lognormal\";\n // suppress unused var warning\n (void) function;\n local_scalar_t DUMMY_VAR__(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR;\n try {\n current_statement = 4;\n context.validate_dims(\"data initialization\", \"N\", \"int\",\n std::vector{});\n N = std::numeric_limits::min();\n current_statement = 4;\n N = context.vals_i(\"N\")[(1 - 1)];\n current_statement = 4;\n stan::math::check_greater_or_equal(function__, \"N\", N, 0);\n current_statement = 5;\n stan::math::validate_non_negative_index(\"y\", \"N\", N);\n current_statement = 6;\n context.validate_dims(\"data initialization\", \"y\", \"int\",\n std::vector{static_cast(N)});\n y = std::vector(N, std::numeric_limits::min());\n current_statement = 6;\n y = context.vals_i(\"y\");\n current_statement = 6;\n stan::math::check_greater_or_equal(function, \"y\", y, 0);\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array[current_statement]);\n }\n num_params_r = 1;\n }\n inline std::string model_name() const final {\n return \"model38d81c9023cf_poisson_lognormal\";\n }\n inline std::vector model_compile_info() const noexcept {\n return std::vector{\"stanc_version = stanc3 v2.35.0\",\n \"stancflags = --\"};\n }\n // Base log prob\n template <bool propto, bool jacobian, typename VecR, typename VecI,\n stan::require_vector_like_t = nullptr,\n stan::require_vector_like_vt<std::is_integral, VecI> = nullptr,\n stan::require_not_st_var* = nullptr>\n inline stan::scalar_type_t\n log_prob_impl(VecR& params_r__, VecI& params_i, std::ostream\n pstream = nullptr) const {\n using T = stan::scalar_type_t;\n using local_scalar_t = T;\n T lp(0.0);\n stan::math::accumulator lp_accum;\n stan::io::deserializer<local_scalar_t> in(params_r__, params_i);\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement;\n local_scalar_t DUMMY_VAR(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR__;\n static constexpr const char function =\n \"model38d81c9023cf_poisson_lognormal_namespace::log_prob\";\n // suppress unused var warning\n (void) function;\n try {\n local_scalar_t lambda = DUMMY_VAR__;\n current_statement = 1;\n lambda = in.template read_constrain_lb<local_scalar_t,\n jacobian>(0, lp);\n {\n current_statement = 2;\n lp_accum__.add(stan::math::lognormal_lpdf<propto>(lambda, 0, 1));\n current_statement = 3;\n lp_accum__.add(stan::math::poisson_lpmf<propto>(y, lambda));\n }\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array[current_statement__]);\n }\n lp_accum.add(lp);\n return lp_accum.sum();\n }\n // Reverse mode autodiff log prob\n template <bool propto, bool jacobian, typename VecR, typename VecI,\n stan::require_vector_like_t = nullptr,\n stan::require_vector_like_vt<std::is_integral, VecI> = nullptr,\n stan::require_st_var* = nullptr>\n inline stan::scalar_type_t\n log_prob_impl(VecR& params_r, VecI& params_i, std::ostream\n pstream = nullptr) const {\n using T = stan::scalar_type_t;\n using local_scalar_t = T;\n T lp(0.0);\n stan::math::accumulator lp_accum;\n stan::io::deserializer<local_scalar_t> in(params_r__, params_i);\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement;\n local_scalar_t DUMMY_VAR(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR__;\n static constexpr const char function =\n \"model38d81c9023cf_poisson_lognormal_namespace::log_prob\";\n // suppress unused var warning\n (void) function;\n try {\n local_scalar_t lambda = DUMMY_VAR__;\n current_statement = 1;\n lambda = in.template read_constrain_lb<local_scalar_t,\n jacobian>(0, lp);\n {\n current_statement = 2;\n lp_accum__.add(stan::math::lognormal_lpdf<propto>(lambda, 0, 1));\n current_statement = 3;\n lp_accum__.add(stan::math::poisson_lpmf<propto>(y, lambda));\n }\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array[current_statement__]);\n }\n lp_accum.add(lp);\n return lp_accum.sum();\n }\n template <typename RNG, typename VecR, typename VecI, typename VecVar,\n stan::require_vector_like_vt<std::is_floating_point,\n VecR> = nullptr, stan::require_vector_like_vt<std::is_integral,\n VecI> = nullptr, stan::require_vector_vt<std::is_floating_point,\n VecVar>* = nullptr>\n inline void\n write_array_impl(RNG& base_rng, VecR& params_r, VecI& params_i,\n VecVar& vars, const bool\n emit_transformed_parameters = true, const bool\n emit_generated_quantities = true, std::ostream\n pstream = nullptr) const {\n using local_scalar_t = double;\n stan::io::deserializer in(params_r__, params_i);\n stan::io::serializer out(vars);\n static constexpr bool propto = true;\n // suppress unused var warning\n (void) propto;\n double lp = 0.0;\n // suppress unused var warning\n (void) lp;\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement__;\n stan::math::accumulator lp_accum;\n local_scalar_t DUMMY_VAR__(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR;\n constexpr bool jacobian = false;\n // suppress unused var warning\n (void) jacobian;\n static constexpr const char function =\n \"model38d81c9023cf_poisson_lognormal_namespace::write_array\";\n // suppress unused var warning\n (void) function;\n try {\n double lambda = std::numeric_limits::quiet_NaN();\n current_statement = 1;\n lambda = in.template read_constrain_lb<local_scalar_t,\n jacobian>(0, lp);\n out.write(lambda);\n if (stan::math::logical_negation(\n (stan::math::primitive_value(emit_transformed_parameters) ||\n stan::math::primitive_value(emit_generated_quantities__)))) {\n return ;\n }\n if (stan::math::logical_negation(emit_generated_quantities)) {\n return ;\n }\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array[current_statement__]);\n }\n }\n template <typename VecVar, typename VecI,\n stan::require_vector_t = nullptr,\n stan::require_vector_like_vt<std::is_integral, VecI> = nullptr>\n inline void\n unconstrain_array_impl(const VecVar& params_r, const VecI& params_i,\n VecVar& vars, std::ostream pstream = nullptr) const {\n using local_scalar_t = double;\n stan::io::deserializer in(params_r__, params_i);\n stan::io::serializer out(vars);\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement;\n local_scalar_t DUMMY_VAR(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR;\n try {\n local_scalar_t lambda = DUMMY_VAR;\n current_statement = 1;\n lambda = in.read();\n out.write_free_lb(0, lambda);\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array[current_statement]);\n }\n }\n template <typename VecVar, stan::require_vector_t = nullptr>\n inline void\n transform_inits_impl(const stan::io::var_context& context, VecVar&\n vars, std::ostream pstream = nullptr) const {\n using local_scalar_t = double;\n stan::io::serializer out(vars);\n int current_statement = 0;\n // suppress unused var warning\n (void) current_statement;\n local_scalar_t DUMMY_VAR(std::numeric_limits::quiet_NaN());\n // suppress unused var warning\n (void) DUMMY_VAR;\n try {\n current_statement = 1;\n context.validate_dims(\"parameter initialization\", \"lambda\", \"double\",\n std::vector{});\n local_scalar_t__ lambda = DUMMY_VAR;\n current_statement = 1;\n lambda = context.vals_r(\"lambda\")[(1 - 1)];\n out.write_free_lb(0, lambda);\n } catch (const std::exception& e) {\n stan::lang::rethrow_located(e, locations_array[current_statement]);\n }\n }\n inline void\n get_param_names(std::vector& names, const bool\n emit_transformed_parameters = true, const bool\n emit_generated_quantities = true) const {\n names = std::vector{\"lambda\"};\n if (emit_transformed_parameters) {}\n if (emit_generated_quantities) {}\n }\n inline void\n get_dims(std::vector<std::vector>& dimss, const bool\n emit_transformed_parameters = true, const bool\n emit_generated_quantities = true) const {\n dimss = std::vector<std::vector>{std::vector{}};\n if (emit_transformed_parameters) {}\n if (emit_generated_quantities) {}\n }\n inline void\n constrained_param_names(std::vector& param_names, bool\n emit_transformed_parameters = true, bool\n emit_generated_quantities__ = true) const final {\n param_names.emplace_back(std::string() + \"lambda\");\n if (emit_transformed_parameters) {}\n if (emit_generated_quantities) {}\n }\n inline void\n unconstrained_param_names(std::vector& param_names, bool\n emit_transformed_parameters = true, bool\n emit_generated_quantities = true) const final {\n param_names__.emplace_back(std::string() + \"lambda\");\n if (emit_transformed_parameters) {}\n if (emit_generated_quantities__) {}\n }\n inline std::string get_constrained_sizedtypes() const {\n return std::string(\"[{\\"name\\":\\"lambda\\",\\"type\\":{\\"name\\":\\"real\\"},\\"block\\":\\"parameters\\"}]\");\n }\n inline std::string get_unconstrained_sizedtypes() const {\n return std::string(\"[{\\"name\\":\\"lambda\\",\\"type\\":{\\"name\\":\\"real\\"},\\"block\\":\\"parameters\\"}]\");\n }\n // Begin method overload boilerplate\n template inline void\n write_array(RNG& base_rng, Eigen::Matrix<double,-1,1>& params_r,\n Eigen::Matrix<double,-1,1>& vars, const bool\n emit_transformed_parameters = true, const bool\n emit_generated_quantities = true, std::ostream\n pstream = nullptr) const {\n const size_t num_params = 1;\n const size_t num_transformed = emit_transformed_parameters (0);\n const size_t num_gen_quantities = emit_generated_quantities (0);\n const size_t num_to_write = num_params__ + num_transformed +\n num_gen_quantities;\n std::vector params_i;\n vars = Eigen::Matrix<double,-1,1>::Constant(num_to_write,\n std::numeric_limits::quiet_NaN());\n write_array_impl(base_rng, params_r, params_i, vars,\n emit_transformed_parameters, emit_generated_quantities, pstream);\n }\n template inline void\n write_array(RNG& base_rng, std::vector& params_r, std::vector&\n params_i, std::vector& vars, bool\n emit_transformed_parameters = true, bool\n emit_generated_quantities = true, std::ostream*\n pstream = nullptr) const {\n const size_t num_params = 1;\n const size_t num_transformed = emit_transformed_parameters (0);\n const size_t num_gen_quantities = emit_generated_quantities (0);\n const size_t num_to_write = num_params + num_transformed +\n num_gen_quantities;\n vars = std::vector(num_to_write,\n std::numeric_limits::quiet_NaN());\n write_array_impl(base_rng, params_r, params_i, vars,\n emit_transformed_parameters, emit_generated_quantities, pstream);\n }\n template <bool propto, bool jacobian, typename T> inline T\n logprob(Eigen::Matrix<T,-1,1>& params_r, std::ostream* pstream = nullptr) const {\n Eigen::Matrix<int,-1,1> params_i;\n return log_prob_impl<propto, jacobian>(params_r, params_i, pstream);\n }\n template <bool propto, bool jacobian, typename T> inline T\n logprob(std::vector<T>& params_r, std::vector& params_i,\n std::ostream* pstream = nullptr) const {\n return log_prob_impl<propto, jacobian>(params_r, params_i, pstream);\n }\n inline void\n transform_inits(const stan::io::var_context& context,\n Eigen::Matrix<double,-1,1>& params_r, std::ostream\n pstream = nullptr) const final {\n std::vector params_r_vec(params_r.size());\n std::vector params_i;\n transform_inits(context, params_i, params_r_vec, pstream);\n params_r = Eigen::Map<Eigen::Matrix<double,-1,1>>(params_r_vec.data(),\n params_r_vec.size());\n }\n inline void\n transform_inits(const stan::io::var_context& context, std::vector&\n params_i, std::vector& vars, std::ostream\n pstream = nullptr) const {\n vars.resize(num_params_r);\n transform_inits_impl(context, vars, pstream__);\n }\n inline void\n unconstrain_array(const std::vector& params_constrained,\n std::vector& params_unconstrained, std::ostream*\n pstream = nullptr) const {\n const std::vector params_i;\n params_unconstrained = std::vector(num_params_r,\n std::numeric_limits::quiet_NaN());\n unconstrain_array_impl(params_constrained, params_i,\n params_unconstrained, pstream);\n }\n inline void\n unconstrain_array(const Eigen::Matrix<double,-1,1>& params_constrained,\n Eigen::Matrix<double,-1,1>& params_unconstrained,\n std::ostream pstream = nullptr) const {\n const std::vector params_i;\n params_unconstrained = Eigen::Matrix<double,-1,1>::Constant(num_params_r__,\n std::numeric_limits::quiet_NaN());\n unconstrain_array_impl(params_constrained, params_i,\n params_unconstrained, pstream);\n }\n};\n}\nusing stan_model = model38d81c9023cf_poisson_lognormal_namespace::model38d81c9023cf_poisson_lognormal;\n#ifndef USING_R\n// Boilerplate\nstan::model::model_base&\nnew_model(stan::io::var_context& data_context, unsigned int seed,\n std::ostream msg_stream) {\n stan_model m = new stan_model(data_context, seed, msg_stream);\n return m;\n}\nstan::math::profile_map& get_stan_profile_data() {\n return model38d81c9023cf_poisson_lognormal_namespace::profiles__;\n}\n#endif"

$model_name [1] "poisson_lognormal"

$model_code [1] "data {\n\tint N;\n\tarray[N] int y;\n}\nparameters {\n\treal lambda;\n}\nmodel {\n\tlambda ~ lognormal(0,1);\n\ty ~ poisson(lambda);\n}" attr(,"model_name2") [1] "poisson_lognormal"

andrjohns commented 4 weeks ago

Hmm also no error there, and if you run:

rstan::stan("poisson_lognormal.stan", data = list(N=1, y=1))
tuulam commented 4 weeks ago

rstan::stan("poisson_lognormal.stan", data = list(N=1, y=1))Error : Exception: mismatch in number dimensions declared and found in context; processing stage=data initialization; variable name=y; dims declared=(1); dims found=() (in 'string', line 3, column 1 to column 25) failed to create the sampler; sampling not done

On Fri, 16 Aug 2024 at 21:23, Andrew Johnson @.***> wrote:

Hmm also no error there, and if you run:

rstan::stan("poisson_lognormal.stan", data = list(N=1, y=1))

— Reply to this email directly, view it on GitHub https://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293960125, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALZZ4U7IDOJYWWBSQP4FNWTZRY7THAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTHE3DAMJSGU . You are receiving this because you were mentioned.Message ID: @.***>

andrjohns commented 4 weeks ago

Ah, try this instead:

rstan::stan("poisson_lognormal.stan", data = list(N=2, y=c(1, 2)))
tuulam commented 4 weeks ago

On Fri, 16 Aug 2024 at 21:28, Andrew Johnson @.***> wrote:

Ah, try this instead:

rstan::stan("poisson_lognormal.stan", data = list(N=2, y=c(1, 2)))

— Reply to this email directly, view it on GitHub https://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293965946, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALZZ4U63VKLV2XIE4RWF2BDZRZADDAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTHE3DKOJUGY . You are receiving this because you were mentioned.Message ID: @.***>

rstan::stan("poisson_lognormal.stan", data = list(N=2, y=c(1, 2)))

SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1). Chain 1: Chain 1: Gradient evaluation took 0.00046 seconds Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 4.6 seconds. Chain 1: Adjust your expectations accordingly! Chain 1: Chain 1: Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup) Chain 1: Iteration: 200 / 2000 [ 10%] (Warmup) Chain 1: Iteration: 400 / 2000 [ 20%] (Warmup) Chain 1: Iteration: 600 / 2000 [ 30%] (Warmup) Chain 1: Iteration: 800 / 2000 [ 40%] (Warmup) Chain 1: Iteration: 1000 / 2000 [ 50%] (Warmup) Chain 1: Iteration: 1001 / 2000 [ 50%] (Sampling) Chain 1: Iteration: 1200 / 2000 [ 60%] (Sampling) Chain 1: Iteration: 1400 / 2000 [ 70%] (Sampling) Chain 1: Iteration: 1600 / 2000 [ 80%] (Sampling) Chain 1: Iteration: 1800 / 2000 [ 90%] (Sampling) Chain 1: Iteration: 2000 / 2000 [100%] (Sampling) Chain 1: Chain 1: Elapsed Time: 0.014 seconds (Warm-up) Chain 1: 0.014 seconds (Sampling) Chain 1: 0.028 seconds (Total) Chain 1:

SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 2). Chain 2: Chain 2: Gradient evaluation took 6e-06 seconds Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds. Chain 2: Adjust your expectations accordingly! Chain 2: Chain 2: Chain 2: Iteration: 1 / 2000 [ 0%] (Warmup) Chain 2: Iteration: 200 / 2000 [ 10%] (Warmup) Chain 2: Iteration: 400 / 2000 [ 20%] (Warmup) Chain 2: Iteration: 600 / 2000 [ 30%] (Warmup) Chain 2: Iteration: 800 / 2000 [ 40%] (Warmup) Chain 2: Iteration: 1000 / 2000 [ 50%] (Warmup) Chain 2: Iteration: 1001 / 2000 [ 50%] (Sampling) Chain 2: Iteration: 1200 / 2000 [ 60%] (Sampling) Chain 2: Iteration: 1400 / 2000 [ 70%] (Sampling) Chain 2: Iteration: 1600 / 2000 [ 80%] (Sampling) Chain 2: Iteration: 1800 / 2000 [ 90%] (Sampling) Chain 2: Iteration: 2000 / 2000 [100%] (Sampling) Chain 2: Chain 2: Elapsed Time: 0.022 seconds (Warm-up) Chain 2: 0.017 seconds (Sampling) Chain 2: 0.039 seconds (Total) Chain 2:

SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 3). Chain 3: Chain 3: Gradient evaluation took 5e-06 seconds Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds. Chain 3: Adjust your expectations accordingly! Chain 3: Chain 3: Chain 3: Iteration: 1 / 2000 [ 0%] (Warmup) Chain 3: Iteration: 200 / 2000 [ 10%] (Warmup) Chain 3: Iteration: 400 / 2000 [ 20%] (Warmup) Chain 3: Iteration: 600 / 2000 [ 30%] (Warmup) Chain 3: Iteration: 800 / 2000 [ 40%] (Warmup) Chain 3: Iteration: 1000 / 2000 [ 50%] (Warmup) Chain 3: Iteration: 1001 / 2000 [ 50%] (Sampling) Chain 3: Iteration: 1200 / 2000 [ 60%] (Sampling) Chain 3: Iteration: 1400 / 2000 [ 70%] (Sampling) Chain 3: Iteration: 1600 / 2000 [ 80%] (Sampling) Chain 3: Iteration: 1800 / 2000 [ 90%] (Sampling) Chain 3: Iteration: 2000 / 2000 [100%] (Sampling) Chain 3: Chain 3: Elapsed Time: 0.021 seconds (Warm-up) Chain 3: 0.012 seconds (Sampling) Chain 3: 0.033 seconds (Total) Chain 3:

SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 4). Chain 4: Chain 4: Gradient evaluation took 5e-06 seconds Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds. Chain 4: Adjust your expectations accordingly! Chain 4: Chain 4: Chain 4: Iteration: 1 / 2000 [ 0%] (Warmup) Chain 4: Iteration: 200 / 2000 [ 10%] (Warmup) Chain 4: Iteration: 400 / 2000 [ 20%] (Warmup) Chain 4: Iteration: 600 / 2000 [ 30%] (Warmup) Chain 4: Iteration: 800 / 2000 [ 40%] (Warmup) Chain 4: Iteration: 1000 / 2000 [ 50%] (Warmup) Chain 4: Iteration: 1001 / 2000 [ 50%] (Sampling) Chain 4: Iteration: 1200 / 2000 [ 60%] (Sampling) Chain 4: Iteration: 1400 / 2000 [ 70%] (Sampling) Chain 4: Iteration: 1600 / 2000 [ 80%] (Sampling) Chain 4: Iteration: 1800 / 2000 [ 90%] (Sampling) Chain 4: Iteration: 2000 / 2000 [100%] (Sampling) Chain 4: Chain 4: Elapsed Time: 0.02 seconds (Warm-up) Chain 4: 0.017 seconds (Sampling) Chain 4: 0.037 seconds (Total) Chain 4: Inference for Stan model: anon_model. 4 chains, each with iter=2000; warmup=1000; thin=1; post-warmup draws per chain=1000, total post-warmup draws=4000.

    mean se_mean   sd  2.5%   25%   50%   75% 97.5% n_eff Rhat

lambda 1.45 0.02 0.72 0.44 0.93 1.31 1.82 3.24 1796 1 lp__ -3.23 0.02 0.69 -5.22 -3.35 -2.97 -2.81 -2.76 1524 1

Samples were drawn using NUTS(diag_e) at Fri Aug 16 21:29:01 2024. For each parameter, n_eff is a crude measure of effective sample size, and Rhat is the potential scale reduction factor on split chains (at convergence, Rhat=1).

andrjohns commented 4 weeks ago

So it looks like both parsing and sampling from your Stan model is working without issue. What R code are you running that is giving the error still?

tuulam commented 4 weeks ago

RStudio 2024.04.2+764 "Chocolate Cosmos" Release (e4392fc9ddc21961fd1d0efd47484b43f07a4177, 2024-06-05) for windows Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2024.04.2+764 Chrome/120.0.6099.291 Electron/28.3.1 Safari/537.36, Quarto 1.4.555


From: Andrew Johnson @.> Sent: Friday, August 16, 2024 9:33 PM To: stan-dev/stanc3 @.> Cc: tuulam @.>; Mention @.> Subject: Re: [stan-dev/stanc3] Internal compiler error: TypeError: a.charCodeAt is not a function (Issue #1446)

So it looks like both parsing and sampling from your Stan model is working without issue. What R code are you running that is giving the error still?

— Reply to this email directly, view it on GitHubhttps://github.com/stan-dev/stanc3/issues/1446#issuecomment-2293973955, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ALZZ4U5PZXJAVTSU6A53VFTZRZAZHAVCNFSM6AAAAABMTUEG2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJTHE3TGOJVGU. You are receiving this because you were mentioned.Message ID: @.***>