multiple index question

227 views
Skip to first unread message

Sebastian Weber

unread,
Jul 19, 2016, 6:02:05 AM7/19/16
to Stan users mailing list
Hi!

I wonder if the following is possible with the multi-index notation in Stan: I have a matrix of O lines with 3 columns, so

matrix[O, 3] obs;

Now, I have an integer index vector of length O

int idx[O];

and idx has elements 1, 2 or 3. The idx codes which element I want out of obs (per row of obs). So what I tried, but does not work is

vector[O] res;
res <- obs[1:O,idx];

Doing so creates a huge object on the RHS. So can this be done in Stan or do I have to loop?

Thanks.

Best,
Sebastian

Daniel Lee

unread,
Jul 19, 2016, 9:01:15 AM7/19/16
to stan-...@googlegroups.com
Hi Sebastian,

Look at Ch 5 in the section on multiple indexing. I think you want an int idc[O, 2].


Daniel
--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sebastian Weber

unread,
Jul 19, 2016, 11:10:31 AM7/19/16
to Stan users mailing list
Hi Daniel,

yeah, this could be what I want, but then I get from the parser this:

index must be integer or 1D integer array; found number of dimensions=2

Maybe, this is not yet supported?

Sebastian

Bob Carpenter

unread,
Jul 19, 2016, 5:21:53 PM7/19/16
to stan-...@googlegroups.com
That's a bug. I created an issue to explain what's going
on:

https://github.com/stan-dev/stan/issues/1960

For now, hopefully rep_array(0, 0) will work if you need
a size zero index.

For the second issue, only 1D arrays are allowed for
indexing. It'd make sense to generalize this into the future
for any dimensionality array as long as the number of index
dimensions is less than or equal to the container dimensions.

- Bob
Reply all
Reply to author
Forward
0 new messages