Trouble with dimension mismatch after converting a real[] array to vector

490 views
Skip to first unread message

H. X.

unread,
Oct 27, 2016, 6:20:19 PM10/27/16
to stan-...@googlegroups.com
Hi,

I am trying to vectorize my code so that I can do something like

S_ratios_hat_vector ~ normal(S_ratios_vector, sigma);

for my likelihood.

So right now, I have a chunk in my code that goes something like this:

real C_hat[N_t,4]; // Predicted pool content
real S_hat[N_t]; // Container array for SOC solution
vector[N_t] S_hat_vector; // Container vector for SOC solution
vector[N_t] S_ratios_hat_vector; // Container vector of model ratios of S solution to S_0

...

C_hat = integrate_ode_rk45(AWB_ODE, C_t0, t0, ts, theta, x_r, x_i);
S_hat = (C_hat[:,1]);
S_hat_vector = to_vector(S_hat);

S_ratios_hat_vector = S_hat_vector / x_r[1];

return S_ratios_hat_vector;

When I run this, I get the following error message:
Mismatched array dimensions.Base type mismatch. Returned expression does not match return type
    LHS type = real[]; RHS type = vector
Improper return in body of function.


I am not quite sure where the type mismatch is occurring and would appreciate some clarification. Thanks.

H. X.

unread,
Oct 27, 2016, 7:22:16 PM10/27/16
to stan-...@googlegroups.com
Doh, answering my own question, I was re-reading the manual and saw this:
  1. Vectors and matrices cannot be typed to return integer values. They are restricted to real values.1

So, it looks like I will have to convert use to_vector after returning a real from the function.

Since I cannot divide real[]s by a real, what would be the most efficient way of handling division of arrays by a scalar value? I would prefer to write something more vectorized than a for loop.
Reply all
Reply to author
Forward
0 new messages