-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInfiniteLinearAlgebraDSPExt.jl
More file actions
83 lines (65 loc) · 2.78 KB
/
InfiniteLinearAlgebraDSPExt.jl
File metadata and controls
83 lines (65 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
module InfiniteLinearAlgebraDSPExt
using InfiniteLinearAlgebra
using InfiniteArrays
using InfiniteArrays: InfRanges, OneToInf
using FillArrays
using FillArrays: AbstractFill, getindex_value
using LazyArrays
import DSP: conv
##
# conv
# This is useful for determining polynomial dimensions
##
conv(a::AbstractFill, b::AbstractFill) = conv(collect(a), collect(b))
conv(a::Vector, b::AbstractFill) = conv(a, collect(b))
conv(a::AbstractFill, b::Vector) = conv(collect(a), b)
conv(::Ones{T,1,<:Tuple{<:OneToInf}}, ::Ones{V,1,<:Tuple{<:OneToInf}}) where {T<:Integer,V<:Integer} =
OneToInf{promote_type(T,V)}()
conv(::Ones{Bool,1,<:Tuple{<:OneToInf}}, ::Ones{Bool,1,<:Tuple{<:OneToInf}}) =
OneToInf()
conv(::Ones{T,1,<:Tuple{<:OneToInf}}, ::Ones{V,1,<:Tuple{<:OneToInf}}) where {T,V} =
one(promote_type(T,V)):∞
function conv(::Ones{T,1,<:Tuple{<:OneToInf}}, a::AbstractVector{V}) where {T,V}
cs = cumsum(convert(AbstractVector{promote_type(T,V)}, a))
Vcat(cs, Fill(last(cs), ∞))
end
function conv(::Ones{T,1,<:Tuple{<:OneToInf}}, a::Vector{V}) where {T,V}
cs = cumsum(convert(AbstractVector{promote_type(T,V)}, a))
Vcat(cs, Fill(last(cs), ∞))
end
function conv(a::AbstractVector{V}, ::Ones{T,1,<:Tuple{<:OneToInf}}) where {T,V}
cs = cumsum(convert(AbstractVector{promote_type(T,V)}, a))
Vcat(cs, Fill(last(cs), ∞))
end
function conv(a::Vector{V}, ::Ones{T,1,<:Tuple{<:OneToInf}}) where {T,V}
cs = cumsum(convert(AbstractVector{promote_type(T,V)}, a))
Vcat(cs, Fill(last(cs), ∞))
end
function conv(r::InfRanges, x::AbstractVector)
length(x) ≠ 1 && throw(ArgumentError("conv(::$(typeof(r)), ::$(typeof(x))) not implemented"))
first(x)*r
end
function conv(x::AbstractVector, r::InfRanges)
length(x) ≠ 1 && throw(ArgumentError("conv(::$(typeof(r)), ::$(typeof(x))) not implemented"))
first(x)*r
end
conv(r1::InfRanges, r2::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}}) =
cumsum(r1*getindex_value(r2))
conv(r2::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}}, r1::InfRanges) =
cumsum(getindex_value(r2)*r1)
conv(r1::InfRanges, r2::Ones{<:Any,1,<:Tuple{<:OneToInf}}) = cumsum(r1)
conv(r2::Ones{<:Any,1,<:Tuple{<:OneToInf}}, r1::InfRanges) = cumsum(r1)
conv(r1::InfRanges, r2::InfRanges) = throw(ArgumentError("conv(::$(typeof(r1)), ::$(typeof(r2))) not implemented"))
function conv(r1::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}}, r2::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}})
a = getindex_value(r1) * getindex_value(r2)
a:a:∞
end
function conv(r1::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}}, r2::Ones{<:Any,1,<:Tuple{<:OneToInf}})
a = getindex_value(r1) * getindex_value(r2)
a:a:∞
end
function conv(r1::Ones{<:Any,1,<:Tuple{<:OneToInf}}, r2::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}})
a = getindex_value(r1) * getindex_value(r2)
a:a:∞
end
end