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

Add check in error hint #199

Merged
merged 2 commits into from
Jan 25, 2024
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
16 changes: 14 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ImageCore"
uuid = "a09fc81d-aa75-5fe9-8630-4744c3626534"
version = "0.10.1"
version = "0.10.2"

[deps]
ColorVectorSpace = "c3611d14-8923-5661-9e6a-0046d554d3a4"
Expand All @@ -14,15 +14,26 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
Aqua = "0.8"
BlockArrays = "0.16"
ColorVectorSpace = "0.10"
Colors = "0.12"
Documenter = "1"
FFTW = "1"
FixedPointNumbers = "0.8"
ImageIO = "0.6"
ImageInTerminal = "0.5"
Logging = "1"
MappedArrays = "0.2, 0.3, 0.4"
MosaicViews = "0.3.3"
OffsetArrays = "0.8, 0.9, 0.10, 0.11, 1.0.1"
PaddedViews = "0.5.8"
PrecompileTools = "1"
Random = "1"
Reexport = "0.2, 1.0"
ReferenceTests = "0.10"
Statistics = "1"
Test = "1"
julia = "1.6"

[extras]
Expand All @@ -32,10 +43,11 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "BlockArrays", "Documenter", "FFTW", "ImageIO", "ImageInTerminal", "Random", "ReferenceTests", "Statistics", "Test"]
test = ["Aqua", "BlockArrays", "Documenter", "FFTW", "ImageIO", "ImageInTerminal", "Logging", "Random", "ReferenceTests", "Statistics", "Test"]
3 changes: 2 additions & 1 deletion src/ImageCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ end

function __init__()
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, kwargs
if nameof(exc.f) ∈ (:fft, :rfft, :plan_fft, :plan_rfft, :realfloat) && argtypes[1] <: AbstractArray{<:Colorant}
f = exc.f
if isa(f, Function) && nameof(f) ∈ (:fft, :rfft, :plan_fft, :plan_rfft, :realfloat) && argtypes[1] <: AbstractArray{<:Colorant}
throw_ffterror(io, exc.f, exc.args...)
end
end
Expand Down
12 changes: 10 additions & 2 deletions test/functions.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using ImageCore
using FFTW
using Logging
using Test

@testset "functions" begin
ag = rand(Gray{Float32}, 4, 5)
Expand All @@ -8,14 +11,19 @@ using FFTW
(fft, (ac,)), (fft, (ac, 1:2)), (plan_fft, (ac,)),
(rfft, (ac,)), (rfft, (ac, 1:2)), (plan_rfft, (ac,)))
dims_str = eltype(args[1])<:Gray ? "1:2" : "2:3"
ret = @test_throws "channelview, and likely $dims_str" f(args...)
@test_throws "channelview, and likely $dims_str" f(args...)
end
for (a, dims) in ((ag, 1:2), (ac, 2:3))
@test ifft(fft(channelview(a), dims), dims) ≈ channelview(a)
ret = @test_throws "channelview, and likely $dims" rfft(a)
@test irfft(rfft(channelview(a), dims), 4, dims) ≈ channelview(a)
end

# Ensure that the hint doesn't error
@test_logs min_level=Logging.Warn try
[3](1, 2)
catch err
showerror(devnull, err)
end

a = [RGB(1,0,0), RGB(0,1,0), RGB(0,0,1)]
@test a' == [RGB(1,0,0) RGB(0,1,0) RGB(0,0,1)]
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ using Aqua, Documenter # for meta quality checks
deps_compat=true,
stale_deps=true,
# FIXME? re-enable the `piracy` test
piracy=false, # currently just `float` and `paddedviews`
project_toml_formatting=true,
piracies=false, # currently just `float` and `paddedviews`
unbound_args=true,
)
DocMeta.setdocmeta!(ImageCore, :DocTestSetup, :(using ImageCore); recursive=true)
Expand Down
Loading