Skip to content

Specialised issubset for CartesianIndices #41598

@andreasKroepelin

Description

@andreasKroepelin

It seems like there is currently no specialised implementation of issubset for CartesianIndices, while there is one for AbstractUnitRange. This means that what could be a constant-time task (check if lower/upper bounds of potential subset are greater/less than lower/upper bounds of potential superset) instead checks every value individually and even allocates.

I think something like this could solve this issue quite easily:

function issubset(l::CartesianIndices{N, <: NTuple{N, AbstractUnitRange{Int}}}, r::CartesianIndices{N, <: NTuple{N, AbstractUnitRange{Int}}}) where N
    all(issubset.(l.indices, r.indices))
end

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