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
6 changes: 3 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end
flush_info_and_warnings()


Logging.disable_logging(Logging.Warn)
# Logging.disable_logging(Logging.Warn)

# Make the docs, without running the tests again
# We need to explicitly add all the extensions here
Expand Down Expand Up @@ -51,7 +51,7 @@ doc = makedocs(
)

# Enable logging to console again
Logging.disable_logging(Logging.BelowMinLevel)
# Logging.disable_logging(Logging.BelowMinLevel)

DocumenterVitepress.deploydocs(; repo="github.com/rafaqz/Rasters.jl",
branch = "gh-pages",
Expand All @@ -61,4 +61,4 @@ DocumenterVitepress.deploydocs(; repo="github.com/rafaqz/Rasters.jl",

if !isempty(doc.internal.errors)
error("Documentation build failed with errors:\n$(collect(doc.internal.errors))")
end
end
25 changes: 18 additions & 7 deletions src/methods/rasterize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ _reduce_op(::typeof(prod)) = Base.mul_prod
_reduce_op(::typeof(minimum)) = min
_reduce_op(::typeof(maximum)) = max
_reduce_op(::typeof(last)) = _take_last
_reduce_op(::typeof(any)) = |
_reduce_op(::typeof(all)) = &
_reduce_op(f, missingval) = _reduce_op(f)
_reduce_op(::typeof(first), missingval) = _TakeFirst(missingval)
_reduce_op(x) = nothing

_is_op_threadsafe(::typeof(sum)) = true
_is_op_threadsafe(::typeof(prod)) = true
_is_op_threadsafe(::typeof(minimum)) = true
_is_op_threadsafe(::typeof(maximum)) = true
# Identical to Base.PermutedDimsArrays.CommutativeOps but define here to avoid
# using base internals
const CommutativeOps = Union{
typeof(&),
typeof(+),
typeof(Base._extrema_rf),
typeof(Base.add_sum),
typeof(max),
typeof(min),
typeof(|),
typeof(Base.mul_prod), # these are not in Base.PermutedDimsArrays.CommutativeOps but should be safe?
typeof(*)
}

_is_op_threadsafe(::CommutativeOps) = true
_is_op_threadsafe(f) = false

_reduce_init(reducer, st::AbstractRasterStack, missingval) = map(A -> _reduce_init(reducer, A, missingval), st)
Expand Down Expand Up @@ -103,7 +116,7 @@ struct Rasterizer{T,G,F,R,O,I,M}
end
function Rasterizer(geom, fill, fillitr;
reducer=nothing,
op=nothing,
op=_reduce_op(reducer),
missingval=nothing,
shape=nothing,
eltype=nothing,
Expand All @@ -121,8 +134,6 @@ function Rasterizer(geom, fill, fillitr;
isnothing(reducer) && isnothing(op) && !(fill isa Function) && throw(ArgumentError("either reducer, op or fill must be a function"))
end

op = isnothing(op) ? _reduce_op(reducer) : op

threadsafe_op = isnothing(threadsafe) ? _is_op_threadsafe(op) : threadsafe

shape = if isnothing(shape)
Expand Down
21 changes: 20 additions & 1 deletion test/rasterize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,23 @@ end
@test count(x -> x == [2], result) == 12
@test count(x -> x == [1, 2], result) == 12
end
end
end


@testset "threaded reduction warnings" begin
commutative_fs = (sum, prod, maximum, minimum, any, all, mean)
geom = GI.GeometryCollection([polygon,polygon,polygon])

for f in commutative_fs
@test_logs rasterize(f, geom; to=A1, fill=true, missingval = false, threaded=true)
end
@test_logs rasterize(count, geom; to=A1, threaded=true) # count has no fill or missingval

other_fs = (median, first, last, x -> sum(x))

for f in other_fs
@test_logs (:warn, "if `op` is not threadsafe, `threaded=true` may be slower than `threaded=false`") rasterize(
f, geom; to=A1, fill=true, missingval = false, threaded=true)
@test_logs rasterize(f, geom; to=A1, fill=true, missingval = false, threaded=false)
end
end
Loading