diff --git a/.gitignore b/.gitignore index 49541d3..a174b0a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.jl.mem deps/deps.jl Manifest.toml +Manifest-v*.toml diff --git a/src/RegisterWorkerShell.jl b/src/RegisterWorkerShell.jl index b30e0e8..573048c 100644 --- a/src/RegisterWorkerShell.jl +++ b/src/RegisterWorkerShell.jl @@ -20,10 +20,10 @@ See `RegisterWorkerShell` for an overview of the API supported by abstract type AbstractWorker end # Not sure about this next type... -struct ArrayDecl{A<:AbstractArray,N} - arraysize::NTuple{N,Int} +struct ArrayDecl{A <: AbstractArray, N} + arraysize::NTuple{N, Int} end -ArrayDecl(::Type{A}, sz) where {A<:AbstractArray} = ArrayDecl{A,ndims(A)}(sz) +ArrayDecl(::Type{A}, sz) where {A <: AbstractArray} = ArrayDecl{A, ndims(A)}(sz) Base.eltype(::ArrayDecl{A}) where {A} = eltype(A) @@ -60,19 +60,19 @@ the values into `mon`, and `monitor!(mon, :var3, var3)` for an internal variable `var3` that is not taken from `algorithm`. See `monitor!` for more detail. """ -function monitor(algorithm::AbstractWorker, fields::Union{NTuple{N,Symbol},Vector{Symbol}}, morevars::Dict{Symbol} = Dict{Symbol,Any}()) where N - mon = Dict{Symbol,Any}() +function monitor(algorithm::AbstractWorker, fields::Union{NTuple{N, Symbol}, Vector{Symbol}}, morevars::Dict{Symbol} = Dict{Symbol, Any}()) where {N} + mon = Dict{Symbol, Any}() for f in fields isdefined(algorithm, f) || continue mon[f] = getfield(algorithm, f) end - for (k,v) in morevars + for (k, v) in morevars mon[k] = v end - mon + return mon end -monitor(algorithms::Vector{W}, fields, morevars::Dict{Symbol} = Dict{Symbol,Any}()) where {W<:AbstractWorker} = - map(alg->monitor(alg, fields, morevars), algorithms) # for multi-thread +monitor(algorithms::Vector{W}, fields, morevars::Dict{Symbol} = Dict{Symbol, Any}()) where {W <: AbstractWorker} = + map(alg -> monitor(alg, fields, morevars), algorithms) # for multi-thread """ `monitor!(mon, algorithm)` updates `mon` with the current values of @@ -90,7 +90,7 @@ function monitor!(mon::Dict{Symbol}, algorithm::AbstractWorker) for f in fieldnames(typeof(algorithm)) monitor!(mon, f, getfield(algorithm, f)) end - mon + return mon end function monitor!(mon, fn::Symbol, v::AbstractArray) @@ -101,14 +101,14 @@ function monitor!(mon, fn::Symbol, v::AbstractArray) mon[fn] = v end end - mon + return mon end function monitor!(mon, fn::Symbol, v) if haskey(mon, fn) mon[fn] = v end - mon + return mon end """ @@ -162,26 +162,26 @@ load_mm_package(rr::RemoteChannel, args...) = load_mm_package(fetch(rr), args... ## Utility functions -function maybe_sharedarray(A::AbstractArray, pid::Int=myid()) +function maybe_sharedarray(A::AbstractArray, pid::Int = myid()) if pid != myid() && isbitstype(eltype(A)) - S = SharedArray{eltype(A)}(size(A), pids=union(myid(), pid)) + S = SharedArray{eltype(A)}(size(A), pids = union(myid(), pid)) copyto!(S, A) else S = A end - S + return S end -function maybe_sharedarray(::Type{T}, sz::Dims, pid=myid()) where T +function maybe_sharedarray(::Type{T}, sz::Dims, pid = myid()) where {T} if isbitstype(T) - S = SharedArray{T}(sz, pids=union(myid(), pid)) + S = SharedArray{T}(sz, pids = union(myid(), pid)) else S = Array{T}(undef, sz) end - S + return S end -maybe_sharedarray(adcl::ArrayDecl, pid::Int=myid()) = +maybe_sharedarray(adcl::ArrayDecl, pid::Int = myid()) = maybe_sharedarray(eltype(adcl), adcl.arraysize, pid) maybe_sharedarray(obj, pid::Int = myid()) = obj diff --git a/test/runtests.jl b/test/runtests.jl index faa6a9f..c17d40e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -13,11 +13,11 @@ end @testset "RegisterWorkerShell" begin @testset "ArrayDecl" begin - adcl = ArrayDecl(Array{Float64,2}, (3, 4)) + adcl = ArrayDecl(Array{Float64, 2}, (3, 4)) @test adcl.arraysize == (3, 4) @test eltype(adcl) == Float64 - adcl3 = ArrayDecl(Array{Int32,3}, (2, 3, 4)) + adcl3 = ArrayDecl(Array{Int32, 3}, (2, 3, 4)) @test adcl3.arraysize == (2, 3, 4) @test eltype(adcl3) == Int32 end @@ -31,7 +31,7 @@ end @test !haskey(mon, :param_string) # monitor with extra variables - mon2 = monitor(w, (:param_scalar,), Dict{Symbol,Any}(:extra => 42)) + mon2 = monitor(w, (:param_scalar,), Dict{Symbol, Any}(:extra => 42)) @test mon2[:param_scalar] == 3.14 @test mon2[:extra] == 42 @@ -52,7 +52,7 @@ end w = TestWorker(1, 2.71, [4, 5], "world") # monitor! updates all monitored fields - mon = Dict{Symbol,Any}(:param_scalar => 0.0, :param_array => [0, 0]) + mon = Dict{Symbol, Any}(:param_scalar => 0.0, :param_array => [0, 0]) monitor!(mon, w) @test mon[:param_scalar] == 2.71 @test mon[:param_array] == [4, 5] @@ -90,7 +90,7 @@ end @testset "worker (unimplemented)" begin w = TestWorker(1, 1.0, [1], "test") - @test_throws ErrorException worker(w, nothing, 1, Dict{Symbol,Any}()) + @test_throws ErrorException worker(w, nothing, 1, Dict{Symbol, Any}()) end @testset "workertid" begin @@ -119,7 +119,7 @@ end @test size(R) == (2, 3) # ArrayDecl with bits eltype: creates SharedArray - adcl = ArrayDecl(Array{Float32,2}, (5, 6)) + adcl = ArrayDecl(Array{Float32, 2}, (5, 6)) Sa = maybe_sharedarray(adcl) @test Sa isa SharedArray{Float32} @test size(Sa) == (5, 6) @@ -136,10 +136,12 @@ end # AxisArray with time axis: return view at tindex data = rand(3, 4, 5) - img_t = AxisArray(data, + img_t = AxisArray( + data, Axis{:x}(1:3), Axis{:y}(1:4), - Axis{:time}(1:5)) + Axis{:time}(1:5) + ) slice = getindex_t(img_t, 3) @test size(slice) == (3, 4) @test slice == view(data, :, :, 3)