Skip to content

Commit

Permalink
Make minimum/maximum generic for Frequencies (#54)
Browse files Browse the repository at this point in the history
Co-authored-by: Pawel Latawiec <pawel@metalenz.com>
  • Loading branch information
platawiec and Pawel Latawiec authored Mar 1, 2021
1 parent 193d035 commit 5fb4b43
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ julia = "^1.0"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[targets]
test = ["Test"]
test = ["Test", "Unitful"]
4 changes: 2 additions & 2 deletions src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ Broadcast.broadcasted(::typeof(*), x::Number, f::Frequencies) = Broadcast.broadc
Broadcast.broadcasted(::typeof(/), f::Frequencies, x::Number) = Frequencies(f.n_nonnegative, f.n, f.multiplier / x)
Broadcast.broadcasted(::typeof(\), x::Number, f::Frequencies) = Broadcast.broadcasted(/, f, x)

Base.maximum(f::Frequencies) = (f.n_nonnegative - ifelse(f.multiplier >= 0, 1, f.n)) * f.multiplier
Base.minimum(f::Frequencies) = (f.n_nonnegative - ifelse(f.multiplier >= 0, f.n, 1)) * f.multiplier
Base.maximum(f::Frequencies{T}) where T = (f.n_nonnegative - ifelse(f.multiplier >= zero(T), 1, f.n)) * f.multiplier
Base.minimum(f::Frequencies{T}) where T = (f.n_nonnegative - ifelse(f.multiplier >= zero(T), f.n, 1)) * f.multiplier
Base.extrema(f::Frequencies) = (minimum(f), maximum(f))

"""
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ using AbstractFFTs: Plan
using LinearAlgebra
using Test

import Unitful

@testset "rfft sizes" begin
A = rand(11, 10)
@test @inferred(AbstractFFTs.rfft_output_size(A, 1)) == (6, 10)
Expand Down Expand Up @@ -131,7 +133,7 @@ end
@test f(freqs) == f(collect(freqs)) == f(fftshift(freqs))
end
end
for f in (fftfreq, rfftfreq), n in (8, 9), multiplier in (2, 1/3, -1/7)
for f in (fftfreq, rfftfreq), n in (8, 9), multiplier in (2, 1/3, -1/7, 1.0*Unitful.mm)
freqs = f(n, multiplier)
check_extrema(freqs)
end
Expand Down

0 comments on commit 5fb4b43

Please sign in to comment.