Perfect, thank you for the explanation. (I didn't see your response until 
now).

It doesn't seem as if the [A; B] syntax creates a vector of matrices 
though, it creates an Array{T, 2} here.

julia> A=[1. 2; 3 5]
2x2 Array{Float64,2}:
 1.0  2.0
 3.0  5.0

julia> B=[0. 0; 0 0]
2x2 Array{Float64,2}:
 0.0  0.0
 0.0  0.0

julia> C=[A;B]
4x2 Array{Float64,2}:
 1.0  2.0
 3.0  5.0
 0.0  0.0
 0.0  0.0

Currently I am initializing a 

C = Vector{Matrix}(2)
C[1] = A
C[2] = B

Is this the easiest way? Guess I could avoid the dimension and push!, but 
that doesn't really resolve the C  = Vector... part.

On Friday, September 18, 2015 at 8:00:08 AM UTC-4, Steven G. Johnson wrote:
>
>
>
> On Thursday, September 17, 2015 at 11:38:29 PM UTC-4, Patrick Kofod 
> Mogensen wrote:
>>
>> Yes, I did indeed just notice I had made a mistake with the ;.
>>
>> My state spaces typically have more than two values, so they're more 
>> likely hundreds-by-hundreds instead of 2-by-2.
>>
>> What does the "right dimensions for locality" mean? Are you referring to 
>> the memory addresses (to make sure I'm not jumping all over the place) or 
>> what does "locality" mean in this context? Sorry if this is basic stuff.
>>
>
> Suppose you are concatenating all of your little MxM matrices F1, F2, 
> etcetera into a single matrix F.  You can either concatenate vertically 
> into an (N*M)xM matrix Fv = [F1; F2; ...] or horizontally into an Mx(N*M) 
> matrix Fh = [F1 F2 ...].  Which one you do has a big effect on spatial 
> locality (see e.g. https://en.wikipedia.org/wiki/Locality_of_reference), 
> which affects how fast you can access the data because of cache lines.
>
> When you are accessing the n-th matrix Fm[i,j], in Fv you would do 
> Fv[n*M-1 + i, j] and in Fh you would do Fh[i, n*M-1 + j].
>
> Julia uses column-major order for its matrices, which means that matrices 
> are stored in memory with contiguous columns, one after another.   That 
> means Fh stores each matrix Fm as a contiguous block of M*M memory 
> elements, which is fast to access, whereas in Fv it is stored as 
> discontiguous chunks (each column of Fm is offset from the next column by 
> (N-1)*M memory items), which is slower to access.
>
> None of this affects you if you are using an array of arrays; in that case 
> each of the sub-arrays is stored contiguously.
>

Reply via email to