Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve ambiguities in https://github.com/jonniedie/ComponentArrays.jl/pull/231 #230

Merged
merged 15 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from 12 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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
- '1.6'
- '1.8'
- '1' # Leave this line unchanged. '1' will automatically expand to the latest stable 1.x release of Julia.
- '1.10.0-beta3'
vpuri3 marked this conversation as resolved.
Show resolved Hide resolved
os:
- ubuntu-latest
arch:
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ComponentArrays"
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
authors = ["Jonnie Diegelman <[email protected]>"]
version = "0.15.4"
version = "0.15.5"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
20 changes: 10 additions & 10 deletions src/array_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ second_axis(::ComponentVector) = FlatAxis()

# Are all these methods necessary?
# TODO: See what we can reduce down to without getting ambiguity errors
Base.vcat(x::ComponentVector, y::AbstractVector) = vcat(getdata(x), y)
Base.vcat(x::AbstractVector, y::ComponentVector) = vcat(x, getdata(y))
function Base.vcat(x::ComponentVector, y::ComponentVector)
Base.vcat(x::ComponentVector{<:Number}, y::AbstractVector{<:Number}) = vcat(getdata(x), y)
Base.vcat(x::AbstractVector{<:Number}, y::ComponentVector{<:Number}) = vcat(x, getdata(y))
function Base.vcat(x::ComponentVector{<:Number}, y::ComponentVector{<:Number})
if reduce((accum, key) -> accum || (key in keys(x)), keys(y); init=false)
return vcat(getdata(x), getdata(y))
else
Expand All @@ -46,7 +46,7 @@ function Base.vcat(x::ComponentVector, y::ComponentVector)
return ComponentArray(vcat(data_x, data_y), Axis((;idxmap_x..., idxmap_y...)))
end
end
function Base.vcat(x::AbstractComponentVecOrMat, y::AbstractComponentVecOrMat)
function Base.vcat(x::AbstractComponentVecOrMat{<:Number}, y::AbstractComponentVecOrMat{<:Number})
ax_x, ax_y = getindex.(getaxes.((x, y)), 1)
if reduce((accum, key) -> accum || (key in keys(ax_x)), keys(ax_y); init=false) || getaxes(x)[2:end] != getaxes(y)[2:end]
return vcat(getdata(x), getdata(y))
Expand All @@ -57,10 +57,10 @@ function Base.vcat(x::AbstractComponentVecOrMat, y::AbstractComponentVecOrMat)
return ComponentArray(vcat(data_x, data_y), Axis((;idxmap_x..., idxmap_y...)), getaxes(x)[2:end]...)
end
end
Base.vcat(x::CV...) where {CV<:AdjOrTransComponentArray} = ComponentArray(reduce(vcat, map(y->getdata(y.parent)', x)), getaxes(x[1]))
Base.vcat(x::ComponentVector, args...) = vcat(getdata(x), getdata.(args)...)
Base.vcat(x::ComponentVector, args::Vararg{Union{Number, UniformScaling, AbstractVecOrMat}}) = vcat(getdata(x), getdata.(args)...)
Base.vcat(x::ComponentVector, args::Vararg{AbstractVector{T}, N}) where {T,N} = vcat(getdata(x), getdata.(args)...)
Base.vcat(x::CV...) where {CV<:AdjOrTransComponentArray{<:Number}} = ComponentArray(reduce(vcat, map(y->getdata(y.parent)', x)), getaxes(x[1]))
Base.vcat(x::ComponentVector{<:Number}, args...) = vcat(getdata(x), getdata.(args)...)
Base.vcat(x::ComponentVector{<:Number}, args::Vararg{Union{Number, UniformScaling, AbstractVecOrMat{<:Number}}}) = vcat(getdata(x), getdata.(args)...)
Base.vcat(x::ComponentVector{<:Number}, args::Vararg{AbstractVector{T}, N}) where {T<:Number,N} = vcat(getdata(x), getdata.(args)...)

function Base.hvcat(row_lengths::NTuple{N,Int}, xs::Vararg{AbstractComponentVecOrMat}) where {N}
i = 1
Expand All @@ -84,7 +84,7 @@ Base.IndexStyle(::Type{<:ComponentArray{T,N,<:A,<:Axes}}) where {T,N,A,Axes} = I

# Since we aren't really using the standard approach to indexing, this will forward things to
# the correct methods
Base.to_indices(x::ComponentArray, i::Tuple) = i
Base.to_indices(x::ComponentArray, i::Tuple{Any}) = i
Base.to_indices(x::ComponentArray, i::NTuple{N,Union{Integer, CartesianIndex}}) where N = i
Base.to_indices(x::ComponentArray, i::NTuple{N,Int64}) where N = i
Base.to_index(x::ComponentArray, i) = i
Expand Down Expand Up @@ -147,4 +147,4 @@ end
Base.stride(x::ComponentArray, k) = stride(getdata(x), k)
Base.stride(x::ComponentArray, k::Int64) = stride(getdata(x), k)

ArrayInterface.parent_type(::Type{ComponentArray{T,N,A,Axes}}) where {T,N,A,Axes} = A
ArrayInterface.parent_type(::Type{ComponentArray{T,N,A,Axes}}) where {T,N,A,Axes} = A
12 changes: 6 additions & 6 deletions src/componentarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ const AdjOrTransComponentArray{T, A} = Union{Adjoint{T, A}, Transpose{T, A}} whe
const AdjOrTransComponentVector{T} = Union{Adjoint{T, A}, Transpose{T, A}} where A<:ComponentVector
const AdjOrTransComponentMatrix{T} = Union{Adjoint{T, A}, Transpose{T, A}} where A<:ComponentMatrix

const ComponentVecOrMat = Union{ComponentVector, ComponentMatrix}
const AdjOrTransComponentVecOrMat = AdjOrTrans{T, <:ComponentVecOrMat} where T
const AbstractComponentArray = Union{ComponentArray, AdjOrTransComponentArray}
const AbstractComponentVecOrMat = Union{ComponentVecOrMat, AdjOrTransComponentVecOrMat}
const AbstractComponentVector = Union{ComponentVector, AdjOrTransComponentVector}
const AbstractComponentMatrix = Union{ComponentMatrix, AdjOrTransComponentMatrix}
const ComponentVecOrMat{T} = Union{ComponentVector{T}, ComponentMatrix{T}} where{T}
vpuri3 marked this conversation as resolved.
Show resolved Hide resolved
const AdjOrTransComponentVecOrMat{T} = AdjOrTrans{T, <:ComponentVecOrMat} where {T}
const AbstractComponentArray{T} = Union{ComponentArray{T}, AdjOrTransComponentArray{T}} where{T}
const AbstractComponentVecOrMat{T} = Union{ComponentVecOrMat{T}, AdjOrTransComponentVecOrMat{T}} where{T}
const AbstractComponentVector{T} = Union{ComponentVector{T}, AdjOrTransComponentVector{T}} where{T}
const AbstractComponentMatrix{T} = Union{ComponentMatrix{T}, AdjOrTransComponentMatrix{T}} where{T}


## Constructor helpers
Expand Down
Loading