Skip to content

Please enable CartesianIndices for VectorOfArray #98

@bionicles

Description

@bionicles

To escape "AI Shape Hell" and map across shapes like a cthulu-esque ameboid monstrosity, I hacked a way to use CartesianIndices with VectorOfArray. Here's the code. It's pretty lame since I've only been doing julia for less than a week but perhaps could be useful for this module

Test Case:

v = VectorOfArray([rand(20), rand(10,10), rand(3,3,3)])

function voa_indices(voa)
    CI = []
    for array_number in 1:length(voa)
        for ci in CartesianIndices(voa[array_number])
            ci = CartesianIndex(array_number, Tuple(ci)...)
            push!(CI, ci)
        end
    end
    return CI
end

for i in voa_indices(v)
    @show i
    @show v[i]
    println()
end

Fix so test case passes:

@inline Base.getindex(VA::AbstractVectorOfArray{T,N}, I::CartesianIndex) where {T, N} = VA.u[Tuple(I)[1]][Tuple(I)[2:end]...]

Thanks for your work, julia definitely seems more powerful than python

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions