Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierHnt committed Nov 14, 2023
1 parent 5e3db13 commit 7af362f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
10 changes: 5 additions & 5 deletions src/sequence_spaces/arithmetic/action.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# fallback methods

(A::LinearOperator)(b::Sequence) = *(A, b)
(A::LinearOperator)(b::AbstractSequence) = *(A, b)

function Base.:*(A::LinearOperator, b::Sequence)
function Base.:*(A::LinearOperator, b::AbstractSequence)
domain_A, codomain_A = domain(A), codomain(A)
space_b = space(b)
_iscompatible(domain_A, space_b) || return throw(ArgumentError("spaces must be compatible: A has domain $domain_A, b has space $space_b"))
Expand All @@ -12,13 +12,13 @@ function Base.:*(A::LinearOperator, b::Sequence)
return c
end

function mul!(c::Sequence, A::LinearOperator, b::Sequence, α::Number, β::Number)
function mul!(c::Sequence, A::LinearOperator, b::AbstractSequence, α::Number, β::Number)
_iscompatible(space(c), codomain(A)) & _iscompatible(domain(A), space(b)) || return throw(ArgumentError("spaces must be compatible"))
_mul!(c, A, b, α, β)
return c
end

function _mul!(c::Sequence, A::LinearOperator, b::Sequence, α::Number, β::Number)
function _mul!(c::Sequence, A::LinearOperator, b::AbstractSequence, α::Number, β::Number)
domain_A, codomain_A = domain(A), codomain(A)
space_b = space(b)
space_c = space(c)
Expand Down Expand Up @@ -51,7 +51,7 @@ function _mul!(c::Sequence, A::LinearOperator, b::Sequence, α::Number, β::Numb
return c
end

function Base.:\(A::LinearOperator, b::Sequence)
function Base.:\(A::LinearOperator, b::AbstractSequence)
codomain_A = codomain(A)
space_b = space(b)
_iscompatible(codomain_A, space_b) || return throw(ArgumentError("spaces must be compatible: A has codomain $codomain_A, b has space $space_b"))
Expand Down
14 changes: 7 additions & 7 deletions src/sequence_spaces/arithmetic/fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ fft_size(s₁::TensorSpace{<:NTuple{N,BaseSpace}}, s₂::TensorSpace{<:NTuple{N,
fft_size(s₁::TensorSpace{<:NTuple{N,BaseSpace}}, s₂::TensorSpace{<:NTuple{N,BaseSpace}}, s₃::TensorSpace{<:NTuple{N,BaseSpace}}...) where {N} =
ntuple(i -> nextpow(2, _dfs_dimension(s₁, i) + _dfs_dimension(s₂, i) + mapreduce(s₃_ -> _dfs_dimension(s₃_, i), +, s₃)), Val(N))

fft_size(s::BaseSpace, n::Int) = (_fft_length(s, n),)
fft_size(s::BaseSpace, n::Integer) = (_fft_length(s, n),)

fft_size(s::TensorSpace, n::Int) = map(sᵢ -> _fft_length(sᵢ, n), spaces(s))
fft_size(s::TensorSpace, n::Integer) = map(sᵢ -> _fft_length(sᵢ, n), spaces(s))

_fft_length(s₁::BaseSpace, s₂::BaseSpace) =
nextpow(2, _dfs_dimension(s₁) + _dfs_dimension(s₂))

_fft_length(s₁::BaseSpace, s₂::BaseSpace, s₃::BaseSpace...) =
nextpow(2, _dfs_dimension(s₁) + _dfs_dimension(s₂) + mapreduce(_dfs_dimension, +, s₃))

_fft_length(s::BaseSpace, n::Int) = nextpow(2, n * _dfs_dimension(s))
_fft_length(s::BaseSpace, n::Integer) = nextpow(2, n * _dfs_dimension(s))

#

_dfs_dimensions(s::TensorSpace) = map(_dfs_dimension, spaces(s))

_dfs_dimension(s::TensorSpace, i::Int) = _dfs_dimension(s[i])
_dfs_dimension(s::TensorSpace, i::Integer) = _dfs_dimension(s[i])

# Taylor
_dfs_dimension(s::Taylor) = dimension(s)
Expand All @@ -37,9 +37,9 @@ _dfs_dimension(s::Chebyshev) = 2order(s)+1

# sequence to discrete Fourier series

fft(a::Sequence{<:BaseSpace}, n::Tuple{Int}) = @inbounds fft(a, n[1])
fft(a::Sequence{<:BaseSpace}, n::Tuple{Integer}) = @inbounds fft(a, n[1])

function fft(a::Sequence{<:BaseSpace}, n::Int)
function fft(a::Sequence{<:BaseSpace}, n::Integer)
space_a = space(a)
_is_fft_size_compatible(n, space_a) || return throw(DimensionMismatch)
CoefType = complex(eltype(a))
Expand All @@ -62,7 +62,7 @@ function fft!(C::AbstractVector, a::Sequence{<:BaseSpace})
return _fft_pow2!(C)
end

function fft(a::Sequence{TensorSpace{T}}, n::NTuple{N,Int}) where {N,T<:NTuple{N,BaseSpace}}
function fft(a::Sequence{TensorSpace{T}}, n::NTuple{N,Integer}) where {N,T<:NTuple{N,BaseSpace}}
space_a = space(a)
_is_fft_size_compatible(n, space_a) || return throw(DimensionMismatch)
CoefType = complex(eltype(a))
Expand Down
2 changes: 1 addition & 1 deletion src/sequence_spaces/arithmetic/linear_operator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function lmul!(A::LinearOperator, B::LinearOperator)
return LinearOperator(domain(B), codomain(A), lmul!(coefficients(A), coefficients(B)))
end

function Base.:^(A::LinearOperator, n::Int)
function Base.:^(A::LinearOperator, n::Integer)
if n < 0
return ^(inv(A), -n)
elseif n == 0
Expand Down
30 changes: 15 additions & 15 deletions src/sequence_spaces/special_operators/calculus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,24 @@ Integral(order::Int...) = Integral(order)
order(ℐ::Integral) =.order

"""
*(𝒟::Derivative, a::Sequence)
*(𝒟::Derivative, a::AbstractSequence)
Compute the `order(𝒟)`-th derivative of `a`; equivalent to `differentiate(a, order(𝒟))`.
See also: [`(::Derivative)(::Sequence)`](@ref), [`Derivative`](@ref),
See also: [`(::Derivative)(::AbstractSequence)`](@ref), [`Derivative`](@ref),
[`differentiate`](@ref) and [`differentiate!`](@ref).
"""
Base.:*(𝒟::Derivative, a::Sequence) = differentiate(a, order(𝒟))
Base.:*(𝒟::Derivative, a::AbstractSequence) = differentiate(a, order(𝒟))

"""
(𝒟::Derivative)(a::Sequence)
(𝒟::Derivative)(a::AbstractSequence)
Compute the `order(𝒟)`-th derivative of `a`; equivalent to `differentiate(a, order(𝒟))`.
See also: [`*(::Derivative, ::Sequence)`](@ref), [`Derivative`](@ref),
See also: [`*(::Derivative, ::AbstractSequence)`](@ref), [`Derivative`](@ref),
[`differentiate`](@ref) and [`differentiate!`](@ref).
"""
(𝒟::Derivative)(a::Sequence) = *(𝒟, a)
(𝒟::Derivative)(a::AbstractSequence) = *(𝒟, a)

"""
differentiate(a::Sequence, α=1)
Expand Down Expand Up @@ -179,24 +179,24 @@ function project!(C::LinearOperator, 𝒟::Derivative)
end

"""
*(ℐ::Integral, a::Sequence)
*(ℐ::Integral, a::AbstractSequence)
Compute the `order(ℐ)`-th integral of `a`; equivalent to `integrate(a, order(ℐ))`.
See also: [`(::Integral)(::Sequence)`](@ref), [`Integral`](@ref),
See also: [`(::Integral)(::AbstractSequence)`](@ref), [`Integral`](@ref),
[`integrate`](@ref) and [`integrate!`](@ref).
"""
Base.:*(ℐ::Integral, a::Sequence) = integrate(a, order(ℐ))
Base.:*(ℐ::Integral, a::AbstractSequence) = integrate(a, order(ℐ))

"""
(ℐ::Integral)(a::Sequence)
(ℐ::Integral)(a::AbstractSequence)
Compute the `order(ℐ)`-th integral of `a`; equivalent to `integrate(a, order(ℐ))`.
See also: [`*(::Integral, ::Sequence)`](@ref), [`Integral`](@ref),
See also: [`*(::Integral, ::AbstractSequence)`](@ref), [`Integral`](@ref),
[`integrate`](@ref) and [`integrate!`](@ref).
"""
(ℐ::Integral)(a::Sequence) = *(ℐ, a)
(ℐ::Integral)(a::AbstractSequence) = *(ℐ, a)

"""
integrate(a::Sequence, α=1)
Expand Down Expand Up @@ -273,9 +273,9 @@ for (F, f) ∈ ((:Derivative, :differentiate), (:Integral, :integrate))
Base.:*(ℱ₁::$F{Int}, ℱ₂::$F{Int}) = $F(order(ℱ₁) + order(ℱ₂))
Base.:*(ℱ₁::$F{NTuple{N,Int}}, ℱ₂::$F{NTuple{N,Int}}) where {N} = $F(map(+, order(ℱ₁), order(ℱ₂)))

Base.:^(ℱ::$F{Int}, n::Int) = $F(order(ℱ) * n)
Base.:^(ℱ::$F{<:Tuple{Vararg{Int}}}, n::Int) = $F(map(αᵢ -> *(αᵢ, n), order(ℱ)))
Base.:^(ℱ::$F{NTuple{N,Int}}, n::NTuple{N,Int}) where {N} = $F(map(*, order(ℱ), n))
Base.:^(ℱ::$F{Int}, n::Integer) = $F(order(ℱ) * n)
Base.:^(ℱ::$F{<:Tuple{Vararg{Int}}}, n::Integer) = $F(map(αᵢ -> *(αᵢ, n), order(ℱ)))
Base.:^(ℱ::$F{NTuple{N,Int}}, n::NTuple{N,Integer}) where {N} = $F(map(*, order(ℱ), n))

_findposition_nzind_domain(ℱ::$F, domain, codomain) =
_findposition(_nzind_domain(ℱ, domain, codomain), domain)
Expand Down
24 changes: 12 additions & 12 deletions src/sequence_spaces/special_operators/evaluation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,36 @@ Evaluation(value::Union{Number,Nothing}...) = Evaluation(value)
value(ℰ::Evaluation) =.value

"""
*(ℰ::Evaluation, a::Sequence)
*(ℰ::Evaluation, a::AbstractSequence)
Evaluate `a` at `value(ℰ)`; equivalent to `evaluate(a, value(ℰ))`.
See also: [`(::Evaluation)(::Sequence)`](@ref), [`Evaluation`](@ref),
[`(::Sequence)(::Any, ::Vararg)`](@ref), [`evaluate`](@ref) and [`evaluate!`](@ref).
See also: [`(::Evaluation)(::AbstractSequence)`](@ref), [`Evaluation`](@ref),
[`(::AbstractSequence)(::Any, ::Vararg)`](@ref), [`evaluate`](@ref) and [`evaluate!`](@ref).
"""
Base.:*(ℰ::Evaluation, a::Sequence) = evaluate(a, value(ℰ))
Base.:*(ℰ::Evaluation, a::AbstractSequence) = evaluate(a, value(ℰ))

"""
(ℰ::Evaluation)(a::Sequence)
(ℰ::Evaluation)(a::AbstractSequence)
Evaluate `a` at `value(ℰ)`; equivalent to `evaluate(a, value(ℰ))`.
See also: [`*(::Evaluation, ::Sequence)`](@ref), [`Evaluation`](@ref),
[`(::Sequence)(::Any, ::Vararg)`](@ref), [`evaluate`](@ref) and [`evaluate!`](@ref).
See also: [`*(::Evaluation, ::AbstractSequence)`](@ref), [`Evaluation`](@ref),
[`(::AbstractSequence)(::Any, ::Vararg)`](@ref), [`evaluate`](@ref) and [`evaluate!`](@ref).
"""
(ℰ::Evaluation)(a::Sequence) = *(ℰ, a)
(ℰ::Evaluation)(a::AbstractSequence) = *(ℰ, a)

"""
(a::Sequence)(x, y...)
(a::AbstractSequence)(x, y...)
Evaluate `a` at `(x, y...)`; equivalent to `evaluate(a, (x, y...))` or
`evaluate(a, x)` if `y` is not provided.
See also: [`evaluate`](@ref), [`evaluate!`](@ref), [`Evaluation`](@ref),
[`*(::Evaluation, ::Sequence)`](@ref) and [`(::Evaluation)(::Sequence)`](@ref).
[`*(::Evaluation, ::AbstractSequence)`](@ref) and [`(::Evaluation)(::AbstractSequence)`](@ref).
"""
(a::Sequence)(x, y...) = evaluate(a, (x, y...))
(a::Sequence)(x) = evaluate(a, x)
(a::AbstractSequence)(x, y...) = evaluate(a, (x, y...))
(a::AbstractSequence)(x) = evaluate(a, x)

"""
evaluate(a::Sequence, x)
Expand Down
2 changes: 1 addition & 1 deletion src/sequence_spaces/special_operators/multiplication.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ and [`^(::Sequence{<:SequenceSpace}, ::Int)`](@ref).

Base.:+(ℳ::Multiplication) = Multiplication(+(sequence(ℳ)))
Base.:-(ℳ::Multiplication) = Multiplication(-(sequence(ℳ)))
Base.:^(ℳ::Multiplication, n::Int) = Multiplication(sequence(ℳ) ^ n)
Base.:^(ℳ::Multiplication, n::Integer) = Multiplication(sequence(ℳ) ^ n)

for f (:+, :-, :*)
@eval begin
Expand Down
18 changes: 9 additions & 9 deletions src/sequence_spaces/special_operators/shift.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ value(𝒮::Shift) = 𝒮.value
Base.:*(𝒮₁::Shift{<:Number}, 𝒮₂::Shift{<:Number}) = Shift(value(𝒮₁) + value(𝒮₂))
Base.:*(𝒮₁::Shift{<:NTuple{N,Number}}, 𝒮₂::Shift{<:NTuple{N,Number}}) where {N} = Shift(map(+, value(𝒮₁), value(𝒮₂)))

Base.:^(𝒮::Shift{<:Number}, n::Int) = Shift(value(𝒮) * n)
Base.:^(𝒮::Shift{<:Tuple{Vararg{Number}}}, n::Int) = Shift(map(τᵢ -> *(τᵢ, n), value(𝒮)))
Base.:^(𝒮::Shift{<:NTuple{N,Number}}, n::NTuple{N,Int}) where {N} = Shift(map(*, value(𝒮), n))
Base.:^(𝒮::Shift{<:Number}, n::Integer) = Shift(value(𝒮) * n)
Base.:^(𝒮::Shift{<:Tuple{Vararg{Number}}}, n::Integer) = Shift(map(τᵢ -> *(τᵢ, n), value(𝒮)))
Base.:^(𝒮::Shift{<:NTuple{N,Number}}, n::NTuple{N,Integer}) where {N} = Shift(map(*, value(𝒮), n))

"""
*(𝒮::Shift, a::Sequence)
*(𝒮::Shift, a::AbstractSequence)
Shift `a` by `value(𝒮)`; equivalent to `shift(a, value(𝒮))`.
See also: [`(::Shift)(::Sequence)`](@ref), [`Shift`](@ref), [`shift`](@ref) and
See also: [`(::Shift)(::AbstractSequence)`](@ref), [`Shift`](@ref), [`shift`](@ref) and
[`shift!`](@ref).
"""
Base.:*(𝒮::Shift, a::Sequence) = shift(a, value(𝒮))
Base.:*(𝒮::Shift, a::AbstractSequence) = shift(a, value(𝒮))

"""
(𝒮::Shift)(a::Sequence)
(𝒮::Shift)(a::AbstractSequence)
Shift `a` by `value(𝒮)`; equivalent to `shift(a, value(𝒮))`.
See also: [`*(::Shift, ::Sequence)`](@ref), [`Shift`](@ref), [`shift`](@ref) and
See also: [`*(::Shift, ::AbstractSequence)`](@ref), [`Shift`](@ref), [`shift`](@ref) and
[`shift!`](@ref).
"""
(𝒮::Shift)(a::Sequence) = *(𝒮, a)
(𝒮::Shift)(a::AbstractSequence) = *(𝒮, a)

"""
shift(a::Sequence, τ)
Expand Down

0 comments on commit 7af362f

Please sign in to comment.