Can map_rect return more than log probability?

I am integrating different operations in one map_rect, and I am calculating a “generated quantity” that now it can’t be exported to the fit object.

When I try to retrieve more complex object from map_rect, doing something like this I get error

transformed parameters{
 x = map_rect(function(){
   vector[]  v = ...;
   lp = ditribution(.., ..)

    return(append_row(lp, v))

my_variable = x[2:rows(x)]
   target += x[1];

map_rect allows your function to return a column vector of arbitrary length, but not a row vector.

EDIT: Sorry… to quick… that’s what you do. So this should work; could you post the actual code and the error message?

I think I got where the mistake is. I was thinking map_rect could output

vector[arbitrary_columns] m[shards];

But Actually just outputs (?)

vector[arbitrary_columns] m;

That if only lp is returned is

vector[shards] m;

Am I correct?

No… map_rect can return a ragged array. Say you have 5 shards defined and the number of rows returned per shard is {1,2,1,5,1}… then you will get a vector of length 1+2+1+5+1 = 10.


EDIT: Ah, you edited… so I think you are correct and this is aligned with what I am telling you above, right?

Eheh sorry for the mess. Ok let me ask a simple question, can map_rect return an array or vectors?

(My understanding is no, it flats it out to a vector)

No. map_rect only allows the user function to return row-vectors which are concatenated together. So the final return is always a long row-vector.