Stream: helpdesk (published)

Topic: Denser storage in StructArrays


view this post on Zulip Kyle Daruwalla (Mar 14 2021 at 15:18):

Let's say I have the following:

struct Foo{T<:AbstractVector}
    x::T
end
Foo(n::Integer) = Foo(zeros(n))

struct Bar{T<:Foo}
    foos::Matrix{T}
end
Bar(foo, m, n) = Bar(StructArray(foo() for _ in 1:m, _ in 1:n; unwrap = t -> t <: Foo))

Currently this will make it so that I get bar.foos.x[i, j][t]. I am wondering how I can get it to be bar.foos.x[i, j, t] (i.e. a dense array with three dimensions instead of a matrix of vectors).


Last updated: Oct 02 2023 at 04:34 UTC