Sure
On Aug 13, 2014, at 9:10 AM, Marco Inacio <
marcoig...@gmail.com> wrote:
>
> On 14-08-13 01:08 AM, Bob Carpenter wrote:
>> You should be able to do just this:
>>
>> for (r in 1:R)
>> orderedbla[r] <- sort_asc(bla[r]);
>>
>> I worked hard to get row assignment working :-)
>>
> That's pretty cool, is assignment also possible for columns of matrices?
No --- assignment to columns isn't allowed yet.
I want to do a generalization of indexing so that we
can create lvalues (what can be assigned to) of expressions
like you'd see in R/JAGS: alpha[1:3,2,4] to take a 3D array
and return a 1D array.
> Also, this was pretty hard to find in page 20, may I suggest that we add it the description of the row function in the manual?
OK --- I added a comment in the manual issue to update:
https://github.com/stan-dev/stan/issues/786#issuecomment-52063212
>> Now having said that, it's not efficient either way because
>> matrices are stored column-major. So it's better if
>> you take an array of vectors:
>>
>> vector[C] bla[R];
>>
>> or to make it more like a matrix, row vectors:
>>
>> row_vector[C] bla[R];
>>
> Or he could just use 2d arrays as in his initial code?
>
> real bla[R, C];
>
> real orderedbla[R,C];
>
> for (r in 1:R) {
> orderedbla[r] <- sort_asc(bla[r]);
> }
>
> (this at least parses)
Yes, 2D arrays will work --- the only issue is that you can't
use their rows for vector operations.
>
> Since arrays are stored in row-major order, this one will be efficient, right? It's hard to believe that it was just a matter of removing two commas.
Either an array of vectors or an array of arrays (aka 2D array) is most efficient
in terms of access time. Matrices are a bit tighter in memory, but I doubt that
will even be measurable as it's only order o(n) overhead for an n x n matrix.
- Bob