Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv committed Oct 30, 2023
1 parent b53e4e1 commit bd7f76f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/field/gaussian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ include("gaussian/lu.jl")
include("gaussian/fft.jl")
include("gaussian/seq.jl")

defaultmethod(::GaussianProcess) = LUMethod()
defaultmethod(::GaussianProcess, ::RandSetup) = LUMethod()
24 changes: 13 additions & 11 deletions src/processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ abstract type RandMethod end
struct DefaultRandMethod <: RandMethod end

"""
defaultmethod(process::FieldProcess) -> RandMethod
defaultmethod(process::FieldProcess, setup) -> RandMethod
Returns the default method for the corresponding field `process`.
"""
defaultmethod(::FieldProcess) = DefaultRandMethod()
defaultmethod(::FieldProcess, setup) = DefaultRandMethod()

#-----------------
# FIELD PROCESSES
Expand All @@ -61,25 +61,26 @@ julia> rand(process, domain, [:z => Float64])
julia> rand(process, domain, geotable, 3)
```
"""
Base.rand(process::FieldProcess, domain::Domain, data, method=defaultmethod(process); kwargs...) =
Base.rand(process::FieldProcess, domain::Domain, data, method=nothing; kwargs...) =
rand(Random.default_rng(), process, domain, data, method; kwargs...)

function Base.rand(
rng::AbstractRNG,
process::FieldProcess,
domain::Domain,
data,
method=defaultmethod(process);
method=nothing;
threads=cpucores()
)
setup = randsetup(domain, data, threads)
prep = randprep(rng, process, method, setup)
real = randsingle(rng, process, method, setup, prep)
rmethod = isnothing(method) ? defaultmethod(process, setup) : method
prep = randprep(rng, process, rmethod, setup)
real = randsingle(rng, process, rmethod, setup, prep)
table = (; (var => real[var] for var in setup.varnames)...)
georef(table, domain)
end

Base.rand(process::FieldProcess, domain::Domain, data, nreals::Integer, method=defaultmethod(process); kwargs...) =
Base.rand(process::FieldProcess, domain::Domain, data, nreals::Integer, method=nothing; kwargs...) =
rand(Random.default_rng(), process, domain, data, nreals, method; kwargs...)

function Base.rand(
Expand All @@ -88,13 +89,14 @@ function Base.rand(
domain::Domain,
data,
nreals::Integer,
method=defaultmethod(process);
method=nothing;
pool=[myid()],
threads=cpucores(),
progress=true
)
setup = randsetup(domain, data, threads)
prep = randprep(rng, process, method, setup)
rmethod = isnothing(method) ? defaultmethod(process, setup) : method
prep = randprep(rng, process, rmethod, setup)

# pool of worker processes
pool = CachingPool(pool)
Expand All @@ -103,11 +105,11 @@ function Base.rand(
reals = if progress
message = "Simulating $(join(setup.varnames, " ,", " and ")):"
@showprogress desc = message pmap(pool, 1:nreals) do _
randsingle(rng, process, method, setup, prep)
randsingle(rng, process, rmethod, setup, prep)
end
else
pmap(pool, 1:nreals) do _
randsingle(rng, process, method, setup, prep)
randsingle(rng, process, rmethod, setup, prep)
end
end

Expand Down

0 comments on commit bd7f76f

Please sign in to comment.