Skip to content

Commit

Permalink
Fix Vararg deprecation warnings (#26) (#27)
Browse files Browse the repository at this point in the history
* Fix Vararg deprecation warnings (#26)

* Bump patch version

---------

Co-authored-by: George Datseris <[email protected]>
  • Loading branch information
dhanak and Datseris authored Apr 25, 2024
1 parent 593c782 commit 8ff0bd1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "StateSpaceSets"
uuid = "40b095a5-5852-4c12-98c7-d43bf788e795"
authors = ["George Datseris <[email protected]>"]
repo = "https://github.com/JuliaDynamics/StateSpaceSets.jl.git"
version = "1.4.5"
version = "1.4.6"

[deps]
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
Expand Down
8 changes: 4 additions & 4 deletions src/statespaceset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ function Base.hcat(x::Vector{<:Real}, d::AbstractStateSpaceSet{D, T}) where {D,
return StateSpaceSet(data)
end

function Base.hcat(ds::Vararg{AbstractStateSpaceSet{D, T} where {D}, N}) where {T, N}
function Base.hcat(ds::AbstractStateSpaceSet{<: Any, T}...) where {T}
Ls = length.(ds)
maxlen = maximum(Ls)
all(Ls .== maxlen) || error("Datasets must be of same length")
newdim = sum(dimension.(ds))
v = Vector{SVector{newdim, T}}(undef, maxlen)
for i = 1:maxlen
v[i] = SVector{newdim, T}(Iterators.flatten(ds[d][i] for d = 1:N)...,)
v[i] = SVector{newdim, T}(Iterators.flatten(d[i] for d in ds)...,)
end
return StateSpaceSet(v)
end
Expand All @@ -125,7 +125,7 @@ end
# converts every input to a dataset first and promotes everything to a common type.
# It's not optimal, because it allocates unnecessarily, but it works.
# If this method is made more efficient, the method above can be dropped.
function hcat(xs::Vararg{Union{AbstractVector{<:Real}, AbstractStateSpaceSet{D, T} where {D, T}}, N}) where {N}
function hcat(xs::Union{AbstractVector{<:Real}, AbstractStateSpaceSet}...)
ds = StateSpaceSet.(xs)
Ls = length.(ds)
maxlen = maximum(Ls)
Expand All @@ -134,7 +134,7 @@ function hcat(xs::Vararg{Union{AbstractVector{<:Real}, AbstractStateSpaceSet{D,
T = promote_type(eltype.(ds)...)
v = Vector{SVector{newdim, T}}(undef, maxlen)
for i = 1:maxlen
v[i] = SVector{newdim, T}(Iterators.flatten(ds[d][i] for d = 1:N)...,)
v[i] = SVector{newdim, T}(Iterators.flatten(d[i] for d in xs)...,)
end
return StateSpaceSet(v)
end
Expand Down
7 changes: 4 additions & 3 deletions src/statespaceset_concrete.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ function StateSpaceSet(v::Vector{<:AbstractArray{T}}) where {T<:Number}
return StateSpaceSet{D, T}(data)
end

@generated function _dataset(vecs::Vararg{<:AbstractVector{T},D}) where {D, T}
@generated function _dataset(vecs::AbstractVector{T}...) where {T}
D = length(vecs)
gens = [:(vecs[$k][i]) for k=1:D]
quote
L = typemax(Int)
Expand All @@ -84,11 +85,11 @@ end
end
end

function StateSpaceSet(vecs::Vararg{<:AbstractVector{T}}) where {T}
function StateSpaceSet(vecs::AbstractVector{T}...) where {T}
return StateSpaceSet(_dataset(vecs...))
end

StateSpaceSet(xs::Vararg{Union{AbstractVector, AbstractStateSpaceSet}}) = hcat(xs...)
StateSpaceSet(xs::Union{AbstractVector, AbstractStateSpaceSet}...) = hcat(xs...)
StateSpaceSet(x::Vector{<:Real}, y::AbstractStateSpaceSet{D, T}) where {D, T} = hcat(x, y)
StateSpaceSet(x::AbstractStateSpaceSet{D, T}, y::Vector{<:Real}) where {D, T} = hcat(x, y)

Expand Down

0 comments on commit 8ff0bd1

Please sign in to comment.