Skip to content

Commit

Permalink
allow arbitrary eltype (#33)
Browse files Browse the repository at this point in the history
cc @kahaaga in complexutymeasures we need this. I am updating the whole ecosystem to SSSets v2, which takes my whole sunday. GODDAMNIT
  • Loading branch information
Datseris authored Sep 22, 2024
1 parent 0725f5c commit b49066b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
Changelog for StateSpaceSets.jl is kept w.r.t. version 1.3

# 2.1

It is allowed to make `StateSpaceSet` with points of arbitrary `eltype` now.
Please don't use `Complex` numbers as the `eltype`!

# 2.0

- `StateSpaceSet` now subtypes `AbstractVector`, in particular `StateSpaceSet{V<:AbstractVector} <: AbstractVector{V}`. This leads to the breaking change that `size(ssset) = (length(ssset), )` while before `size` was `length(ssset), dimension(ssset)`. Now you have to use `dimension(ssset)` exclusively to get the "number of columns" in the state space set.
- `StateSpaceSet` now subtypes `AbstractVector`, in particular `StateSpaceSet{V<:AbstractVector} <: AbstractVector{V}`. This leads to the breaking change that `size(ssset) = (length(ssset), )` while before `size` was `(length(ssset), dimension(ssset))`. Now you have to use `dimension(ssset)` exclusively to get the "number of columns" in the state space set.
- `StateSpaceSet` now supports arbitrary inner vectors as state space points.
The keyword `container` can be given to all functions that make state space sets
and sets the type of the container of the inner vectors. This is the abstract type
Expand Down
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 = "2.0.1"
version = "2.1.0"

[deps]
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
Expand Down
2 changes: 1 addition & 1 deletion src/statespaceset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export cov, cor, mean_and_cov
# D = dimension, T = element type, V = container type
# note that the container type is given as keyword `container` to
# all functions that somehow end up making a state space set.
abstract type AbstractStateSpaceSet{D, T<:Real, V} <: AbstractVector{V} end
abstract type AbstractStateSpaceSet{D, T, V} <: AbstractVector{V} end

# Core extensions and functions:
"""
Expand Down
8 changes: 4 additions & 4 deletions src/statespaceset_concrete.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export StateSpaceSet

"""
StateSpaceSet{D, T<:Real, V} <: AbstractVector{V}
StateSpaceSet{D, T, V} <: AbstractVector{V}
A dedicated interface for sets in a state space.
It is an **ordered container of equally-sized points** of length `D`,
with element type `T<:Real`,
with element type `T`,
represented by a vector of type `V`. Typically `V` is `SVector{D,T}` or `Vector{T}`
and the data are always stored internally as `Vector{V}`.
Expand Down Expand Up @@ -86,7 +86,7 @@ end
###########################################################################
# StateSpaceSet(Vectors of stuff)
###########################################################################
function StateSpaceSet(vecs::AbstractVector{T}...; container = SVector) where {T<:Real}
function StateSpaceSet(vecs::AbstractVector{T}...; container = SVector) where {T}
data = _ssset(vecs...)
if container != SVector
data = container.(data)
Expand All @@ -96,7 +96,7 @@ function StateSpaceSet(vecs::AbstractVector{T}...; container = SVector) where {T
return StateSpaceSet{D,T,V}(data)
end

@generated function _ssset(vecs::AbstractVector{T}...) where {T<:Real}
@generated function _ssset(vecs::AbstractVector{T}...) where {T}
D = length(vecs)
gens = [:(vecs[$k][i]) for k=1:D]
quote
Expand Down
10 changes: 6 additions & 4 deletions test/ssset_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ s = StateSpaceSet(o)
@test m3[1] isa MVector
end

@testset "not reals" begin
q = fill("a", 10)
@test_throws MethodError StateSpaceSet(q)
@testset "nonreal element" begin
ff = fill("ff", 10)
tt = fill("tt", 10)
ss = StateSpaceSet(ff, tt)
@test dimension(ss) == 2
@test eltype(ss) == String
end

end


Expand Down

0 comments on commit b49066b

Please sign in to comment.