These are called "ragged arrays", searching the list for this term will
show you attempts and issues, in particular
https://github.com/JuliaLang/julia/issues/10064
https://github.com/ReidAtcheson/RaggedArrays.jl
For the moment you could just use a either
a) a vector of vectors,
b) a single vector which contains all vectors, and a vector of indexes
that provides the positions.
(a) is preferred when you want to grow the rows dynamically, or don't
want to do too much programming. (b) is nice when the rows don't change,
and/or you know something special about the structure (banded linear
operators suggests this), or you want to pass it to routines which
require this format (for example, this is the idiom for ragged arrays in
Stan).
Finally, if you want to use this matrix for linear algebra computations,
look into the representation that those routines (eg in LAPACK) would
use. If you do a lot of these operations and require conversion each
time, it may not be worth it, then just go with the structure that is
natively supported, maybe storing info on raggedness in a wrapper.
Best,
Tamas
On Wed, Feb 24 2016, Sheehan Olver wrote:
> I'm wondering if there's a natural data structure for a matrix whose rows
> are of different length, in my case strictly growing. The usage is e.g.
> representing coefficients in a 2D monomial expansion:
>
> f_00 + f_10 x + f_01 y + f_20 x^2 + f_11 xy + f_02 y^2 + …
>
>
> So I want to do the following:
>
> F=TreeMatrix(Float64,1:n,n)
>
> F[1,1] # return f_00
> F[1,2] # out of bounds error
> F[1,1] # returns f_10
> F[1,2] # returns f_01
> F[1,3] # out of bounds error
>
>
> It's easy to implement myself I suppose (probably more efficient to wrap a
> Vector{Float64} than a Vector{Vector{Float64}}), but I was just curious if
> such a thing exists.
>
> The next step on top of this is a data structure for banded linear
> operators on trees.