Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow empty arrays in maximum/minimum #391

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FillArrays"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "1.13.0"
version = "1.13.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
6 changes: 5 additions & 1 deletion src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,11 @@
#########

for op in (:maximum, :minimum)
@eval $op(x::AbstractFill) = getindex_value(x)
@eval function $op(x::AbstractFill)
length(x) == 0 && throw(ArgumentError(

Check warning on line 588 in src/FillArrays.jl

View check run for this annotation

Codecov / codecov/patch

src/FillArrays.jl#L587-L588

Added lines #L587 - L588 were not covered by tests
"reducing over an empty collection is not allowed; consider supplying `init` to the reducer"))
getindex_value(x)

Check warning on line 590 in src/FillArrays.jl

View check run for this annotation

Codecov / codecov/patch

src/FillArrays.jl#L590

Added line #L590 was not covered by tests
end
end


Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,9 @@ end
@test_throws MethodError issorted(Fill(im, 2))
@test_throws MethodError sort(Fill(im, 2))
@test_throws MethodError sort!(Fill(im, 2))

@test_throws ArgumentError maximum(Fill(3, 0))
@test_throws ArgumentError minimum(Fill(3, 0))
end

@testset "Cumsum, accumulate and diff" begin
Expand Down
Loading