|
| 1 | + |
| 2 | +## |
| 3 | +# conv |
| 4 | +# This is useful for determining polynomial dimensions |
| 5 | +## |
| 6 | + |
| 7 | +conv(a::AbstractFill, b::AbstractFill) = conv(collect(a), collect(b)) |
| 8 | +conv(a::Vector, b::AbstractFill) = conv(a, collect(b)) |
| 9 | +conv(a::AbstractFill, b::Vector) = conv(collect(a), b) |
| 10 | + |
| 11 | + |
| 12 | +conv(::Ones{T,1,<:Tuple{<:OneToInf}}, ::Ones{V,1,<:Tuple{<:OneToInf}}) where {T<:Integer,V<:Integer} = |
| 13 | + OneToInf{promote_type(T,V)}() |
| 14 | +conv(::Ones{Bool,1,<:Tuple{<:OneToInf}}, ::Ones{Bool,1,<:Tuple{<:OneToInf}}) = |
| 15 | + OneToInf() |
| 16 | +conv(::Ones{T,1,<:Tuple{<:OneToInf}}, ::Ones{V,1,<:Tuple{<:OneToInf}}) where {T,V} = |
| 17 | + one(promote_type(T,V)):∞ |
| 18 | + |
| 19 | +function conv(::Ones{T,1,<:Tuple{<:OneToInf}}, a::AbstractVector{V}) where {T,V} |
| 20 | + cs = cumsum(convert(AbstractVector{promote_type(T,V)}, a)) |
| 21 | + Vcat(cs, Fill(last(cs), ∞)) |
| 22 | +end |
| 23 | + |
| 24 | +function conv(::Ones{T,1,<:Tuple{<:OneToInf}}, a::Vector{V}) where {T,V} |
| 25 | + cs = cumsum(convert(AbstractVector{promote_type(T,V)}, a)) |
| 26 | + Vcat(cs, Fill(last(cs), ∞)) |
| 27 | +end |
| 28 | + |
| 29 | +function conv(a::AbstractVector{V}, ::Ones{T,1,<:Tuple{<:OneToInf}}) where {T,V} |
| 30 | + cs = cumsum(convert(AbstractVector{promote_type(T,V)}, a)) |
| 31 | + Vcat(cs, Fill(last(cs), ∞)) |
| 32 | +end |
| 33 | + |
| 34 | +function conv(a::Vector{V}, ::Ones{T,1,<:Tuple{<:OneToInf}}) where {T,V} |
| 35 | + cs = cumsum(convert(AbstractVector{promote_type(T,V)}, a)) |
| 36 | + Vcat(cs, Fill(last(cs), ∞)) |
| 37 | +end |
| 38 | + |
| 39 | + |
| 40 | +function conv(r::InfRanges, x::AbstractVector) |
| 41 | + length(x) ≠ 1 && throw(ArgumentError("conv(::$(typeof(r)), ::$(typeof(x))) not implemented")) |
| 42 | + first(x)*r |
| 43 | +end |
| 44 | +function conv(x::AbstractVector, r::InfRanges) |
| 45 | + length(x) ≠ 1 && throw(ArgumentError("conv(::$(typeof(r)), ::$(typeof(x))) not implemented")) |
| 46 | + first(x)*r |
| 47 | +end |
| 48 | + |
| 49 | +conv(r1::InfRanges, r2::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}}) = |
| 50 | + cumsum(r1*getindex_value(r2)) |
| 51 | +conv(r2::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}}, r1::InfRanges) = |
| 52 | + cumsum(getindex_value(r2)*r1) |
| 53 | + |
| 54 | +conv(r1::InfRanges, r2::Ones{<:Any,1,<:Tuple{<:OneToInf}}) = cumsum(r1) |
| 55 | +conv(r2::Ones{<:Any,1,<:Tuple{<:OneToInf}}, r1::InfRanges) = cumsum(r1) |
| 56 | + |
| 57 | +conv(r1::InfRanges, r2::InfRanges) = throw(ArgumentError("conv(::$(typeof(r1)), ::$(typeof(r2))) not implemented")) |
| 58 | + |
| 59 | +function conv(r1::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}}, r2::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}}) |
| 60 | + a = getindex_value(r1) * getindex_value(r2) |
| 61 | + a:a:∞ |
| 62 | +end |
| 63 | +function conv(r1::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}}, r2::Ones{<:Any,1,<:Tuple{<:OneToInf}}) |
| 64 | + a = getindex_value(r1) * getindex_value(r2) |
| 65 | + a:a:∞ |
| 66 | +end |
| 67 | +function conv(r1::Ones{<:Any,1,<:Tuple{<:OneToInf}}, r2::AbstractFill{<:Any,1,<:Tuple{<:OneToInf}}) |
| 68 | + a = getindex_value(r1) * getindex_value(r2) |
| 69 | + a:a:∞ |
| 70 | +end |
0 commit comments