Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/ode_pso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@set! particle.velocity = updated_velocity
@set! particle.position = particle.position + particle.velocity

update_pos = max(particle.position, lb)
update_pos = min(update_pos, ub)
update_pos = max.(particle.position, lb)
update_pos = min.(update_pos, ub)

@set! particle.position = update_pos
@inbounds gpu_particles[i] = particle
Expand Down
21 changes: 21 additions & 0 deletions test/ode_pso.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using ParallelParticleSwarms, KernelAbstractions, StaticArrays, Test

include("./utils.jl")

@testset "parameter_estim_ode! particle update clamps each coordinate to the box" begin
lb = SVector(-10.0f0, -10.0f0)
ub = SVector(10.0f0, 10.0f0)
positions = [SVector(5.0f0, -20.0f0), SVector(-20.0f0, 5.0f0), SVector(20.0f0, -20.0f0)]
update! = ParallelParticleSwarms.ode_update_particle_states!(backend)
for x in positions
particle = ParallelParticleSwarms.SPSOParticle(x, zero(x), Inf32, x, Inf32)
single = KernelAbstractions.allocate(backend, typeof(particle), 1)
copyto!(single, [particle])
update!(
single, lb, ub, ParallelParticleSwarms.SPSOGBest(x, Inf32), 0.0f0;
ndrange = 1
)
KernelAbstractions.synchronize(backend)
@test Array(single)[1].position == clamp.(x, lb, ub)
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ run_tests(;
#TODO: Current throws warning for redefinition with the use of @testset multiple times. Migrate to TestItemRunners.jl
return @testset for BACKEND in unique(("CPU", CI_GROUP))
global GROUP = BACKEND
@testset "$(BACKEND) ODE parameter estimation particle update" include("./ode_pso.jl")
@testset "$(BACKEND) optimizers tests" include("./gpu.jl")
GC.gc(true)
@testset "$(BACKEND) optimizers with constraints tests" include("./constraints.jl")
Expand Down
Loading