From da0cb90fa0fc3b92de7b8c769b9e1eff378d33b1 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Tue, 26 Sep 2023 22:54:39 +0200 Subject: [PATCH 1/2] update ambiguity tests now they dont fail erroneously --- src/Dimensions/format.jl | 1 + src/Dimensions/primitives.jl | 10 ++++++---- src/LookupArrays/selector.jl | 6 +++--- src/LookupArrays/set.jl | 2 ++ src/array/array.jl | 38 ++++++++++++++++++++++++++++++++++-- src/array/indexing.jl | 5 ++++- src/array/matmul.jl | 1 + src/array/methods.jl | 13 ++++++++---- src/dimindices.jl | 6 +++++- test/runtests.jl | 3 +-- 10 files changed, 68 insertions(+), 17 deletions(-) diff --git a/src/Dimensions/format.jl b/src/Dimensions/format.jl index 17b3708e6..9bc2e9ef2 100644 --- a/src/Dimensions/format.jl +++ b/src/Dimensions/format.jl @@ -86,6 +86,7 @@ _format(span::AutoSpan, D::Type, index::Union{AbstractArray,Val}) = _format(Irregular(), D, index) _format(span::AutoSpan, D::Type, index::AbstractRange) = Regular(step(index)) _format(span::Regular{AutoStep}, D::Type, index::Union{AbstractArray,Val}) = _arraynosteperror() +_format(span::Regular{AutoStep}, D::Type, index::LinRange) = Regular(step(index)) _format(span::Regular{AutoStep}, D::Type, index::AbstractRange) = Regular(step(index)) _format(span::Regular, D::Type, index::Union{AbstractArray,Val}) = span function _format(span::Regular, D::Type, index::AbstractRange) diff --git a/src/Dimensions/primitives.jl b/src/Dimensions/primitives.jl index ba16c6d3a..27083f9dd 100644 --- a/src/Dimensions/primitives.jl +++ b/src/Dimensions/primitives.jl @@ -505,13 +505,14 @@ function comparedims end @inline comparedims(args...; kw...) = _comparedims(_Throw, args...; kw...) @inline comparedims(T::Type, args...; kw...) = _comparedims(T, args...; kw...) -@inline _comparedims(T::Type, ds::Dimension...; kw...) = - map(d -> _comparedims(T, first(ds), d; kw...), ds) +@inline _comparedims(T::Type, d1::Dimension, ds::Dimension...; kw...) = + map(d -> _comparedims(T, d1, d; kw...), (d1, ds...)) @inline _comparedims(T::Type, A::Tuple; kw...) = _comparedims(T, map(dims, A)...; kw...) @inline _comparedims(T::Type, A...; kw...) = _comparedims(T, map(dims, A)...; kw...) @inline _comparedims(T::Type, dims::Vararg{Tuple{Vararg{Dimension}}}; kw...) = map(d -> _comparedims(T, first(dims), d; kw...), dims) +@inline _comparedims(T::Type{_Throw}; kw...) = () @inline _comparedims(T::Type{_Throw}, a::DimTuple, b::DimTuple; kw...) = (_comparedims(T, first(a), first(b); kw...), _comparedims(T, tail(a), tail(b); kw...)...) @inline _comparedims(::Type{_Throw}, a::DimTupleOrEmpty, ::Nothing; kw...) = a @@ -537,8 +538,9 @@ function comparedims end return a end -@inline _comparedims(T::Type{Bool}, ds::Dimension...; kw...) = - all(map(d -> _comparedims(T, first(ds), d; kw...), ds)) +@inline _comparedims(T::Type; kw...) = true +@inline _comparedims(T::Type{Bool}, d1::Dimension, ds::Dimension...; kw...) = + all(map(d -> _comparedims(T, d1, d; kw...), ds)) @inline _comparedims(T::Type{Bool}, dims::Vararg{Tuple{Vararg{Dimension}}}; kw...) = all(map(d -> _comparedims(T, first(dims), d; kw...), dims)) @inline _comparedims(T::Type{Bool}, a::DimTuple, b::DimTuple; kw...) = diff --git a/src/LookupArrays/selector.jl b/src/LookupArrays/selector.jl index ee8d1a238..b7f249a8b 100644 --- a/src/LookupArrays/selector.jl +++ b/src/LookupArrays/selector.jl @@ -940,9 +940,9 @@ function select_unalligned_indices(lookups::LookupArrayTuple, sel::Tuple{Selecto throw(ArgumentError("only `Near`, `At` or `Contains` selectors currently work on `Unalligned` lookups")) end -_transform2int(lookup, ::Near, x) = min(max(round(Int, x), firstindex(lookup)), lastindex(lookup)) -_transform2int(lookup, ::Contains, x) = round(Int, x) -_transform2int(lookup, sel::At, x) = _transform2int(sel, x, atol(sel)) +_transform2int(lookup::AbstractArray, ::Near, x) = min(max(round(Int, x), firstindex(lookup)), lastindex(lookup)) +_transform2int(lookup::AbstractArray, ::Contains, x) = round(Int, x) +_transform2int(lookup::AbstractArray, sel::At, x) = _transform2int(sel, x, atol(sel)) _transform2int(::At, x, atol::Nothing) = convert(Int, x) function _transform2int(::At, x, atol) i = round(Int, x) diff --git a/src/LookupArrays/set.jl b/src/LookupArrays/set.jl index 54a8e33d1..88e726c13 100644 --- a/src/LookupArrays/set.jl +++ b/src/LookupArrays/set.jl @@ -40,7 +40,9 @@ _set(lookup::LookupArray, newlookup::NoLookup) = newlookup # Set the index _set(lookup::LookupArray, index::Val) = rebuild(lookup; data=index) _set(lookup::LookupArray, index::Colon) = lookup +_set(lookup::LookupArray, index::AutoLookup) = lookup _set(lookup::LookupArray, index::AbstractArray) = rebuild(lookup; data=index) + _set(lookup::LookupArray, index::AutoIndex) = lookup _set(lookup::LookupArray, index::AbstractRange) = rebuild(lookup; data=_set(parent(lookup), index), order=orderof(index)) diff --git a/src/array/array.jl b/src/array/array.jl index db1d36101..807735629 100644 --- a/src/array/array.jl +++ b/src/array/array.jl @@ -251,7 +251,34 @@ for (d, s) in ((:AbstractDimArray, :AbstractDimArray), copyto!(_maybeunwrap(dst), Rdst, _maybeunwrap(src), Rsrc) end end -Base.copy!(dst::SparseArrays.SparseVector, src::AbstractDimArray{T,1}) where T = copy!(dst, parent(src)) +# Ambiguity +Base.copyto!(dst::AbstractDimArray{T,2}, src::SparseArrays.CHOLMOD.Dense{T}) where T<:Union{Float64,ComplexF64} = + copyto!(parent(dst), src) +Base.copyto!(dst::AbstractDimArray{T}, src::SparseArrays.CHOLMOD.Dense{T}) where T<:Union{Float64,ComplexF64} = + copyto!(parent(dst), src) +Base.copyto!(::DimensionalData.AbstractDimArray, ::SparseArrays.CHOLMOD.Dense) = + copyto!(parent(dst), src) +Base.copyto!(dst::AbstractDimArray{T,2} where T, src::SparseArrays.AbstractSparseMatrixCSC) = + copyto!(parent(dst), src) +Base.copyto!(dst::AbstractDimArray{T,2} where T, src::LinearAlgebra.AbstractQ) = + copyto!(parent(dst), src) +Base.copyto!(dst::SparseArrays.AbstractCompressedVector, src::AbstractDimArray{T, 1} where T) = + copyto!(dst, parent(src)) +Base.copyto!(dst::PermutedDimsArray, src::AbstractDimArray) = + copyto!(dst, parent(src)) +function Base.copyto!( + dst::AbstractDimArray{<:Any,2}, + dst_i::CartesianIndices{2, R} where R<:Tuple{OrdinalRange{Int64, Int64}, OrdinalRange{Int64, Int64}}, + src::SparseArrays.AbstractSparseMatrixCSC{<:Any}, + src_i::CartesianIndices{2, R} where R<:Tuple{OrdinalRange{Int64, Int64}, OrdinalRange{Int64, Int64}} +) + copyto!(parent(dst), dst_i, src, src_i) +end + +Base.copy!(dst::SparseArrays.SparseVector, src::AbstractDimArray{T,1}) where T = + copy!(dst, parent(src)) +Base.copy!(dst::SparseArrays.AbstractCompressedVector{T}, src::AbstractDimArray{T, 1}) where T = + copy!(dst, parent(src)) ArrayInterface.parent_type(::Type{<:AbstractDimArray{T,N,D,A}}) where {T,N,D,A} = A @@ -550,9 +577,16 @@ function Base.rand(r::AbstractRNG, x, dims::DimTuple; kw...) C = dimconstructor(dims) C(rand(r, x, _dimlength(dims)), _maybestripval(dims); kw...) end +function Base.rand(r::AbstractRNG, d1::Dimension, dims::Dimension...; kw...) + rand(r, (d1, dims...); kw...) +end function Base.rand(r::AbstractRNG, ::Type{T}, d1::Dimension, dims::Dimension...; kw...) where T rand(r, T, (d1, dims...); kw...) end +function Base.rand(r::AbstractRNG, dims::DimTuple; kw...) + C = dimconstructor(dims) + C(rand(r, _dimlength(dims)), _maybestripval(dims); kw...) +end function Base.rand(r::AbstractRNG, ::Type{T}, dims::DimTuple; kw...) where T C = dimconstructor(dims) C(rand(r, T, _dimlength(dims)), _maybestripval(dims); kw...) @@ -692,4 +726,4 @@ _unmergedims(all_dims, dim_pairs::Pair...) = _cat_tuples(replace(all_dims, dim_p _cat_tuples(tuples...) = mapreduce(_astuple, (x, y) -> (x..., y...), tuples) -_filter_dims(alldims, dims) = filter(dim -> hasdim(alldims, dim), dims) \ No newline at end of file +_filter_dims(alldims, dims) = filter(dim -> hasdim(alldims, dim), dims) diff --git a/src/array/indexing.jl b/src/array/indexing.jl index c0adfc7ec..5f44ff60f 100644 --- a/src/array/indexing.jl +++ b/src/array/indexing.jl @@ -82,4 +82,7 @@ end setindex!(parent(A), x, i1, I...) # For @views macro to work with keywords -Base.maybeview(A::AbstractDimArray, args...; kw...) = view(A, args...; kw...) +Base.maybeview(A::AbstractDimArray, args...; kw...) = + view(A, args...; kw...) +Base.maybeview(A::AbstractDimArray, args::Vararg{Union{Number,Base.AbstractCartesianIndex}}) = + view(A, args...; kw...) diff --git a/src/array/matmul.jl b/src/array/matmul.jl index b210a8457..c959ec721 100644 --- a/src/array/matmul.jl +++ b/src/array/matmul.jl @@ -48,6 +48,7 @@ for (a, b) in ( @eval Base.:*(A::$a, B::$b) = _rebuildmul(A, B) end + Base.:*(A::AbstractDimVector, B::Adjoint{T,<:AbstractRotation}) where T = _rebuildmul(A, B) Base.:*(A::Adjoint{T,<:AbstractRotation}, B::AbstractDimMatrix) where T = _rebuildmul(A, B) Base.:*(A::Transpose{<:Any,<:AbstractMatrix{T}}, B::AbstractDimArray{S,1}) where {T,S} = _rebuildmul(A, B) diff --git a/src/array/methods.jl b/src/array/methods.jl index 3479ec555..95a2392a2 100644 --- a/src/array/methods.jl +++ b/src/array/methods.jl @@ -64,6 +64,10 @@ end function Base._mapreduce_dim(f, op, nt, A::AbstractDimArray, dims) rebuild(A, Base._mapreduce_dim(f, op, nt, parent(A), dimnum(A, dims)), reducedims(A, dims)) end +function Base._mapreduce_dim(f, op, nt, A::AbstractDimArray, dims::Colon) + rebuild(A, Base._mapreduce_dim(f, op, nt, parent(A), dimnum(A, dims)), reducedims(A, dims)) +end + @static if VERSION >= v"1.6" function Base._mapreduce_dim(f, op, nt::Base._InitialValue, A::AbstractDimArray, dims) rebuild(A, Base._mapreduce_dim(f, op, nt, parent(A), dimnum(A, dims)), reducedims(A, dims)) @@ -344,10 +348,10 @@ check_cat_lookups(dims::Dimension...) = # LookupArrays may need adjustment for `cat` _check_cat_lookups(D, lookups::LookupArray...) = _check_cat_lookup_order(D, lookups...) -_check_cat_lookups(D, lookups::NoLookup...) = true -function _check_cat_lookups(D, lookups::AbstractSampled...) - _check_cat_lookup_order(D, lookups...) || return false - _check_cat_lookups(D, span(first(lookups)), lookups...) +_check_cat_lookups(D, l1::NoLookup, lookups::NoLookup...) = true +function _check_cat_lookups(D, l1::AbstractSampled, lookups::AbstractSampled...) + _check_cat_lookup_order(D, l1, lookups...) || return false + _check_cat_lookups(D, span(l1), l1, lookups...) end function _check_cat_lookups(D, ::Regular, lookups...) length(lookups) > 1 || return true @@ -541,3 +545,4 @@ _reverse(dim::Dimension) = reverse(dim) Base.reverse(dim::Dimension) = rebuild(dim, reverse(lookup(dim))) Base.dataids(A::AbstractDimArray) = Base.dataids(parent(A)) + diff --git a/src/dimindices.jl b/src/dimindices.jl index d8c6ce9fa..c4a2108e6 100644 --- a/src/dimindices.jl +++ b/src/dimindices.jl @@ -16,7 +16,7 @@ for f in (:getindex, :view, :dotview) end end -(::Type{<:AbstractDimIndices})(::Nothing; kw...) = throw(ArgumentError("Object has no `dims` method")) +(::Type{T})(::Nothing; kw...) where T<:AbstractDimIndices = throw(ArgumentError("Object has no `dims` method")) (::Type{T})(x; kw...) where T<:AbstractDimIndices = T(dims(x); kw...) (::Type{T})(dim::Dimension; kw...) where T<:AbstractDimIndices = T((dim,); kw...) @@ -42,6 +42,10 @@ indices of unknown dimension. """ struct DimIndices{T,N,D<:Tuple{Vararg{Dimension}}} <: AbstractDimIndices{T,N} dims::D + # Manual inner constructor for ambiguity only + function DimIndices{T,N,D}(dims::Tuple{Vararg{Dimension}}) where {T,N,D<:Tuple{Vararg{Dimension}}} + new{T,N,D}(dims) + end end function DimIndices(dims::D) where {D<:Tuple{Vararg{Dimension}}} T = typeof(map(d -> rebuild(d, 1), dims)) diff --git a/test/runtests.jl b/test/runtests.jl index 7543f6ec5..88e6a6d32 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,7 @@ using DimensionalData, Aqua, SafeTestsets if VERSION >= v"1.5.0" - # This is catching some unambiguous constructors for T<:Metadata. - # Aqua.test_ambiguities([DimensionalData, Base, Core]) + Aqua.test_ambiguities([DimensionalData, Base, Core]) Aqua.test_unbound_args(DimensionalData) Aqua.test_undefined_exports(DimensionalData) Aqua.test_project_extras(DimensionalData) From 7baea2c6fa447d27e995ca1ffcb5146eb4cb6343 Mon Sep 17 00:00:00 2001 From: Rafael Schouten Date: Tue, 26 Sep 2023 23:59:24 +0200 Subject: [PATCH 2/2] bugfix with JET --- src/Dimensions/Dimensions.jl | 2 ++ src/Dimensions/primitives.jl | 15 +++++++-------- src/array/array.jl | 7 +++++-- src/array/indexing.jl | 2 +- src/array/methods.jl | 2 +- src/plotrecipes.jl | 22 +++++++++++----------- src/utils.jl | 6 +++--- 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/Dimensions/Dimensions.jl b/src/Dimensions/Dimensions.jl index 8eaebc6ce..21a08adb9 100644 --- a/src/Dimensions/Dimensions.jl +++ b/src/Dimensions/Dimensions.jl @@ -20,6 +20,8 @@ include("../LookupArrays/LookupArrays.jl") using .LookupArrays +const LA = LookupArrays + import .LookupArrays: rebuild, order, span, sampling, locus, val, index, set, _set, metadata, bounds, intervalbounds, units, basetypeof, unwrap, selectindices, hasselection, shiftlocus, maybeshiftlocus, SelectorOrInterval, Interval diff --git a/src/Dimensions/primitives.jl b/src/Dimensions/primitives.jl index 27083f9dd..d96b38b6f 100644 --- a/src/Dimensions/primitives.jl +++ b/src/Dimensions/primitives.jl @@ -140,6 +140,7 @@ X, Y ``` """ @inline dims(a1, args...) = _call_primitive(_dims, MaybeFirst(), a1, args...) +@inline dims(::Tuple{}, ::Tuple{}) = () @inline _dims(f, dims, query) = _remove_nothing(_sortdims(f, dims, query)) @@ -530,7 +531,7 @@ function comparedims end type && basetypeof(a) != basetypeof(b) && _dimsmismatcherror(a, b) valtype && typeof(parent(a)) != typeof(parent(b)) && _valtypeerror(a, b) val && parent(a) != parent(b) && _valerror(a, b) - order && order(a) != order(b) && _ordererror(a, b) + order && LA.order(a) != LA.order(b) && _ordererror(a, b) if ignore_length_one && (Base.length(a) == 1 || Base.length(b) == 1) return Base.length(b) == 1 ? a : b end @@ -555,16 +556,12 @@ end @inline _comparedims(T::Type{Bool}, a::Dimension, b::AnonDim; kw...) = true @inline _comparedims(T::Type{Bool}, a::AnonDim, b::Dimension; kw...) = true @inline function _comparedims(::Type{Bool}, a::Dimension, b::Dimension; - type=true, lookuptype=false, valtype=false, val=false, length=true, order=false, ignore_length_one=false, warn=nothing, + type=true, valtype=false, val=false, length=true, order=false, ignore_length_one=false, warn=nothing, ) if type && basetypeof(a) != basetypeof(b) isnothing(warn) || _dimsmismatchwarn(a, b, warn) return false end - if lookuptype && basetypeof(lookup(a)) != basetypeof(lookup(b)) - isnothing(warn) || _typewarn(lookup(a), lookup(b), warn) - return false - end if valtype && typeof(parent(a)) != typeof(parent(b)) isnothing(warn) || _valtypewarn(a, b, warn) return false @@ -728,7 +725,8 @@ _valtypemsg(a, b) = "Lookup for $(basetypeof(a)) of $(lookup(a)) and $(lookup(b) _extradimsmsg(extradims) = "$(map(basetypeof, extradims)) dims were not found in object." _extradimsmsg(::Tuple{}) = "Some dims were not found in object." _metadatamsg(a, b) = "Metadata $(metadata(a)) and $(metadata(b)) do not match." -_dimordermsg(a, b) = "Lookups do not all have the same order: $(order(a)), $(order(b))." +_ordermsg(a, b) = "Lookups do not all have the same order: $(order(a)), $(order(b))." +_typemsg(a, b) = "Lookups do not all have the same type: $(order(a)), $(order(b))." # Warning: @noinline to avoid allocations when it isn't used @noinline _dimsmismatchwarn(a, b, msg="") = @warn _dimsmismatchmsg(a, b) * msg @@ -736,13 +734,14 @@ _dimordermsg(a, b) = "Lookups do not all have the same order: $(order(a)), $(ord @noinline _dimsizewarn(a, b, msg="") = @warn _dimsizemsg(a, b) * msg @noinline _valtypewarn(a, b, msg="") = @warn _valtypemsg(a, b) * msg @noinline _extradimswarn(dims, msg="") = @warn _extradimsmsg(dims) * msg +@noinline _orderwarn(a, b, msg="") = @warn _ordermsg(a, b) * msg # Error @noinline _dimsmismatcherror(a, b) = throw(DimensionMismatch(_dimsmismatchmsg(a, b))) -@noinline _dimordererror(a, b) = throw(DimensionMismatch(_dimsizemsg(a, b))) @noinline _dimsizeerror(a, b) = throw(DimensionMismatch(_dimsizemsg(a, b))) @noinline _valtypeerror(a, b) = throw(DimensionMismatch(_valtypemsg(a, b))) @noinline _valerror(a, b) = throw(DimensionMismatch(_valmsg(a, b))) +@noinline _ordererror(a, b) = throw(DimensionMismatch(_ordermsg(a, b))) @noinline _metadataerror(a, b) = throw(DimensionMismatch(_metadatamsg(a, b))) @noinline _extradimserror(args...) = throw(ArgumentError(_extradimsmsg(args))) @noinline _dimsnotdefinederror() = throw(ArgumentError("Object does not define a `dims` method")) diff --git a/src/array/array.jl b/src/array/array.jl index 807735629..7e32b7bb9 100644 --- a/src/array/array.jl +++ b/src/array/array.jl @@ -100,10 +100,13 @@ function Base.NamedTuple(A1::AbstractDimArray, As::AbstractDimArray...) end # undef constructor for all AbstractDimArray -(::Type{A})(x::UndefInitializer, dims::Dimension...; kw...) where {A<:AbstractDimArray} = A(x, dims; kw...) +(::Type{A})(x::UndefInitializer, dims::Dimension...; kw...) where {A<:AbstractDimArray{<:Any}} = A(x, dims; kw...) function (::Type{A})(x::UndefInitializer, dims::DimTuple; kw...) where {A<:AbstractDimArray{T}} where T basetypeof(A)(Array{T}(undef, size(dims)), dims; kw...) end +function (::Type{A})(x::UndefInitializer, dims::Tuple{}; kw...) where {A<:AbstractDimArray{T}} where T + basetypeof(A)(Array{T}(undef, ()), dims; kw...) +end # Dummy `read` methods that does nothing. # This can be used to actually read `AbstractDimArray` subtypes that dont hold in-memory Arrays. @@ -256,7 +259,7 @@ Base.copyto!(dst::AbstractDimArray{T,2}, src::SparseArrays.CHOLMOD.Dense{T}) whe copyto!(parent(dst), src) Base.copyto!(dst::AbstractDimArray{T}, src::SparseArrays.CHOLMOD.Dense{T}) where T<:Union{Float64,ComplexF64} = copyto!(parent(dst), src) -Base.copyto!(::DimensionalData.AbstractDimArray, ::SparseArrays.CHOLMOD.Dense) = +Base.copyto!(dst::DimensionalData.AbstractDimArray, src::SparseArrays.CHOLMOD.Dense) = copyto!(parent(dst), src) Base.copyto!(dst::AbstractDimArray{T,2} where T, src::SparseArrays.AbstractSparseMatrixCSC) = copyto!(parent(dst), src) diff --git a/src/array/indexing.jl b/src/array/indexing.jl index 5f44ff60f..68103710c 100644 --- a/src/array/indexing.jl +++ b/src/array/indexing.jl @@ -84,5 +84,5 @@ end # For @views macro to work with keywords Base.maybeview(A::AbstractDimArray, args...; kw...) = view(A, args...; kw...) -Base.maybeview(A::AbstractDimArray, args::Vararg{Union{Number,Base.AbstractCartesianIndex}}) = +Base.maybeview(A::AbstractDimArray, args::Vararg{Union{Number,Base.AbstractCartesianIndex}}; kw...) = view(A, args...; kw...) diff --git a/src/array/methods.jl b/src/array/methods.jl index 95a2392a2..eb31c0131 100644 --- a/src/array/methods.jl +++ b/src/array/methods.jl @@ -487,7 +487,7 @@ end @noinline _cat_lookup_overlap_warn(D, x1, x2) = @warn _cat_warn_string(D, "`Ordered` lookups are misaligned at $x2 and $x1") @noinline _cat_lookup_intersect_warn(D, intr) = @warn _cat_warn_string(D, "`Unorderd` lookups share values: $intr") -@noinline _mixed_span_error(D, S, span) = throw(DimensionMismatch(_span_string(T, span))) +@noinline _mixed_span_error(D, S, span) = throw(DimensionMismatch(_span_string(D, S, span))) @noinline function _mixed_span_warn(D, S, span) @warn _span_string(D, S, span) return false diff --git a/src/plotrecipes.jl b/src/plotrecipes.jl index 16d7e9220..44ae7c53b 100644 --- a/src/plotrecipes.jl +++ b/src/plotrecipes.jl @@ -14,7 +14,7 @@ struct DimensionalPlot end DimensionalPlot(), A end -@recipe function f(::DimensionalPlot, A::AbstractArray) +@recipe function f(::DimensionalPlot, A::AbstractDimArray) A_fwd = reorder(A, ForwardOrdered()) sertype = get(plotattributes, :seriestype, :none)::Symbol if !(sertype in (:marginalhist,)) @@ -44,7 +44,7 @@ end end end -@recipe function f(s::SeriesLike, A::AbstractArray{T,1}) where T +@recipe function f(s::SeriesLike, A::AbstractDimArray{T,1}) where T dim = dims(A, 1) :xguide --> label(dim) :yguide --> label(A) @@ -52,7 +52,7 @@ end _xticks!(plotattributes, s, dim) _withaxes(dim, A) end -@recipe function f(s::SeriesLike, A::AbstractArray{T,2}) where T +@recipe function f(s::SeriesLike, A::AbstractDimArray{T,2}) where T A = permutedims(A, forward_order_plot_dims(A)) ind, dep = dims(A) :xguide --> label(ind) @@ -64,12 +64,12 @@ end _withaxes(ind, A) end -@recipe function f(s::HistogramLike, A::AbstractArray{T,1}) where T +@recipe function f(s::HistogramLike, A::AbstractDimArray{T,1}) where T dim = dims(A, 1) :xguide --> label(A) _withaxes(dim, A) end -@recipe function f(s::HistogramLike, A::AbstractArray{T,2}) where T +@recipe function f(s::HistogramLike, A::AbstractDimArray{T,2}) where T ds = reverse_order_plot_dims(A) A = permutedims(A, ds) ind, dep = dims(A) @@ -79,12 +79,12 @@ end _withaxes(ind, A) end -@recipe function f(::ViolinLike, A::AbstractArray{T,1}) where T +@recipe function f(::ViolinLike, A::AbstractDimArray{T,1}) where T dim = dims(A, 1) :yguide --> label(A) parent(A) end -@recipe function f(s::ViolinLike, A::AbstractArray{T,2}) where T +@recipe function f(s::ViolinLike, A::AbstractDimArray{T,2}) where T ds = reverse_order_plot_dims(A) A = permutedims(A, ds) dep, ind = dims(A) @@ -95,7 +95,7 @@ end _xticks!(plotattributes, s, ind) parent(A) end -@recipe function f(s::ViolinLike, A::AbstractArray{T,3}) where T +@recipe function f(s::ViolinLike, A::AbstractDimArray{T,3}) where T ds = reverse_order_plot_dims(A) A = permutedims(A, ds) dep2, dep1, ind = dims(A) @@ -107,14 +107,14 @@ end parent(A) end -@recipe function f(s::HeatMapLike, A::AbstractArray{T,1}) where T +@recipe function f(s::HeatMapLike, A::AbstractDimArray{T,1}) where T dim = dims(A, 1) :xguide --> label(dim) :yguide --> label(A) _xticks!(plotattributes, s, dim) parent(A) end -@recipe function f(s::HeatMapLike, A::AbstractArray{T,2}) where T +@recipe function f(s::HeatMapLike, A::AbstractDimArray{T,2}) where T ds = reverse_order_plot_dims(A) A = permutedims(A, ds) y, x = dims(A) @@ -126,7 +126,7 @@ end _yticks!(plotattributes, s, y) _withaxes(x, y, A) end -@recipe function f(x::DimPlotMode, A::AbstractArray{T,N}) where {T,N} +@recipe function f(x::DimPlotMode, A::AbstractDimArray{T,N}) where {T,N} throw(ArgumentError("$(x.seriestype) not implemented in $N dimensions")) end diff --git a/src/utils.jl b/src/utils.jl index 58ef31e1d..c0016aa77 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -28,11 +28,11 @@ _reorder(x, orderdims::Tuple{}) = x reorder(x, orderdim::Dimension) = _reorder(val(orderdim), x, dims(x, orderdim)) -_reorder(neworder::Order, x, dim::DimOrDimType) = _reorder(basetypeof(neworder), x, dim) +_reorder(neworder::Order, x, dim::Dimension) = _reorder(basetypeof(neworder), x, dim) # Reverse the dimension index -_reorder(::Type{O}, x, dim::DimOrDimType) where O<:Ordered = +_reorder(::Type{O}, x, dim::Dimension) where O<:Ordered = order(dim) isa O ? x : reverse(x; dims=dim) -_reorder(ot::Type{Unordered}, x, dim::DimOrDimType) = x +_reorder(ot::Type{Unordered}, x, dim::Dimension) = x """ modify(f, A::AbstractDimArray) => AbstractDimArray