Skip to content

Commit

Permalink
fix generator SVector problems (#22)
Browse files Browse the repository at this point in the history
* fix generator SVector problems

* add SVector tests
  • Loading branch information
Datseris authored Sep 27, 2023
1 parent cbab97a commit 5b9be60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 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.3"
version = "1.4.4"

[deps]
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
Expand Down
14 changes: 7 additions & 7 deletions src/sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ end
function sphereregion(r, center, rng, inside)
@assert r 0
dim = length(center)
dummies = [zeros(dim) for _ in 1:Threads.nthreads()]
dummies = [zeros(typeof(r), dim) for _ in 1:Threads.nthreads()]
generator = SphereGenerator(r, center, dummies, inside, rng, length(center))
if inside
isinside = (x) -> norm(x .- center) < r
Expand All @@ -93,10 +93,10 @@ function sphereregion(r, center, rng, inside)
end
return generator, isinside
end
struct SphereGenerator{T, R} <: Function
struct SphereGenerator{T, V<:AbstractVector{T}, R} <: Function
radius::T
center::Vector{T}
dummies::Vector{Vector{Float64}}
center::V
dummies::Vector{Vector{T}}
inside::Bool
rng::R
D::Int
Expand All @@ -122,9 +122,9 @@ function statespace_sampler(region::HRectangle, seed = abs(rand(Int)))
isinside(x) = all(i -> as[i] x[i] < bs[i], eachindex(x))
return gen, isinside
end
struct RectangleGenerator{T, R} <: Function
mins::Vector{T}
difs::Vector{T}
struct RectangleGenerator{T, V <: AbstractVector{T}, R} <: Function
mins::V
difs::V
dummies::Vector{Vector{T}}
rng::R
end
Expand Down
7 changes: 6 additions & 1 deletion test/sampler_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ using LinearAlgebra, Random, Statistics, Test
@test isinside(x)
end
end
@test HRectangle(SVector(0,0), SVector(1,1)) isa HRectangle
rect = HRectangle(SVector(0,0), SVector(1,1))
gen, isinside = statespace_sampler(rect, 1)
@test gen() isa Vector
end

@testset "sphere" begin
Expand Down Expand Up @@ -50,4 +52,7 @@ end
end
end
end
rect = HSphere(0.1, SVector(0.1, 0.1))
gen, isinside = statespace_sampler(rect, 1)
@test gen() isa Vector
end

0 comments on commit 5b9be60

Please sign in to comment.