Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ AlgebraOfGraphics = "0.8, 0.9, 0.10"
Aqua = "0.8"
ArrayInterface = "7"
BenchmarkTools = "1"
CairoMakie = "0.10, 0.11, 0.12"
CairoMakie = "0.10, 0.11, 0.12, 0.13"
CategoricalArrays = "0.10"
ColorTypes = "0.11"
Combinatorics = "1"
Expand Down
2 changes: 1 addition & 1 deletion src/Dimensions/Dimensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const LU = Lookups
const LookupArrays = Lookups

import .Lookups: rebuild, order, span, sampling, locus, val, index, set, _set,
metadata, bounds, intervalbounds, units, basetypeof, unwrap, selectindices, hasselection,
metadata, bounds, intervalbounds, units, basetypeof, unwrap, selectindices, hasselection, hasmultipledimensions,
shiftlocus, maybeshiftlocus, ordered_first, ordered_last, ordered_firstindex, ordered_lastindex,
promote_first, _remove
using .Lookups: StandardIndices, SelTuple, CategoricalEltypes,
Expand Down
1 change: 1 addition & 0 deletions src/Dimensions/coord.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct CoordLookup{T,A<:AbstractVector{T},D,Me} <: MultiDimensionalLookup{T}
metadata::Me
end
CoordLookup(data, dims; metadata=NoMetadata()) = CoordLookup(data, dims, metadata)
hasmultipledimensions(::CoordLookup) = true

dims(m::CoordLookup) = m.dims
order(m::CoordLookup) = Unordered()
Expand Down
15 changes: 9 additions & 6 deletions src/Dimensions/dimension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,22 +303,25 @@ Base.size(dims::DimTuple) = map(length, dims)
Base.CartesianIndices(dims::DimTuple) = CartesianIndices(map(d -> axes(d, 1), dims))

# Extents.jl
#=
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this commented out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that we still had the old version to refer back to, mainly

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can just remove it, but we probably need an explanation for the new complexity

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, now that it works I'll do that

function Extents.extent(ds::DimTuple, args...)
extent_dims = _astuple(dims(ds, args...))
extent_bounds = bounds(extent_dims)
return Extents.Extent{name(extent_dims)}(extent_bounds)
end
=#

function _experimental_extent(ds::DimTuple)
regulardims = dims(ds, x -> !(lookup(x) isa MultiDimensionalLookup))
regular_bounds = bounds.(regulardims)
function Extents.extent(ids::DimTuple, args...)
ds = _astuple(dims(ids, args...))
regulardims = dims(ds, x -> !hasmultipledimensions(lookup(x)))
regular_bounds = map(bounds, regulardims)
regular_bounds_nt = NamedTuple{map(name, regulardims)}(regular_bounds)

multidims = otherdims(ds, regulardims)
multidim_raw_bounds = bounds.(multidims) # we trust that bounds will give us a tuple of bounds one for each enclosed dimension
multidim_raw_bounds = map(bounds, multidims) # we trust that bounds will give us a tuple of bounds one for each enclosed dimension
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be made into a contract, perhaps in the docs of hasmultipledimensions and MultiDimensionalLookup

multidim_dims = combinedims(map(dims, multidims)...; length = false)
multidim_bounds = map(multidim_dims) do outdim
foldl(zip(multidims, multidim_raw_bounds); init = (nothing, nothing)) do (minval, maxval), (dim, bounds)
foldl(map(tuple, multidims, multidim_raw_bounds); init = (nothing, nothing)) do (minval, maxval), (dim, bounds)
if hasdim(dim, outdim)
if isnothing(minval) && isnothing(maxval)
bounds[dimnum(dim, outdim)]
Expand All @@ -332,7 +335,7 @@ function _experimental_extent(ds::DimTuple)
end
end
multidim_bounds_nt = NamedTuple{map(name, multidim_dims)}(multidim_bounds)
return merge(regular_bounds_nt, multidim_bounds_nt)
return Extents.Extent(merge(regular_bounds_nt, multidim_bounds_nt))
end

dims(extent::Extents.Extent{K}) where K = map(rebuild, name2dim(K), values(extent))
Expand Down
2 changes: 1 addition & 1 deletion src/Dimensions/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Convert a `Dimension` or `Selector` `I` to indices of `Int`, `AbstractArray` or
@inline function dims2indices(dims::DimTuple, I::DimTuple)
extradims = otherdims(I, dims) # extra dims in the query, I
# Extract "multi dimensional" lookups like MergedLookup or Rasters' GeometryLookup
multidims = Dimensions.dims(otherdims(dims, I), x -> lookup(x) isa MultiDimensionalLookup && !isempty(Dimensions.dims(x, I)))
multidims = Dimensions.dims(otherdims(dims, I), x -> hasmultipledimensions(lookup(x)) && !isempty(Dimensions.dims(x, I)))
# Warn if any dims from I were not picked up by multidims
actuallyextradims = otherdims(extradims, x -> any(y -> hasdim(y, x), multidims)) # one way setdiff(extradims, multidims) essentially
length(actuallyextradims) > 0 && _extradimswarn(actuallyextradims)
Expand Down
2 changes: 2 additions & 0 deletions src/Dimensions/merged.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
abstract type MultiDimensionalLookup{T} <: Lookup{T,1} end
hasmultipledimensions(::MultiDimensionalLookup) = true

"""
MergedLookup <: MultiDimensionalLookup <: Lookup
Expand Down Expand Up @@ -63,6 +64,7 @@ struct MergedLookup{T,A<:AbstractVector{T},D,Me} <: MultiDimensionalLookup{T}
end
MergedLookup(data, dims; metadata=NoMetadata()) = MergedLookup(data, dims, metadata)

hasmultipledimensions(::MergedLookup) = true
order(m::MergedLookup) = Unordered()
dims(m::MergedLookup) = m.dims
dims(d::Dimension{<:MergedLookup}) = dims(val(d))
Expand Down
2 changes: 1 addition & 1 deletion src/Lookups/Lookups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export reducelookup, shiftlocus, maybeshiftlocus, promote_first
export index

export issampled, iscategorical, iscyclic, isnolookup, isintervals, ispoints, isregular,
isexplicit, isstart, iscenter, isend, isordered, isforward, isreverse
isexplicit, isstart, iscenter, isend, isordered, isforward, isreverse, hasmultipledimensions

export Selector
export At, Between, Touches, Contains, Near, Where, All
Expand Down
1 change: 1 addition & 0 deletions src/Lookups/predicates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ isintervals(::Intervals) = true
isintervals(::Points) = false
ispoints(::Points) = true
ispoints(::Intervals) = false
hasmultipledimensions(::Lookup) = false

# Forward them from lookups
for f in (:isregular, :isexplicit)
Expand Down
Loading