Skip to content

Commit

Permalink
Merge branch 'master' into patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
putianyi889 authored Nov 5, 2023
2 parents d523448 + 7343893 commit e0ad2e8
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 28 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,24 @@ on:
- 'LICENSE'
- 'README.md'
- '.github/workflows/TagBot.yml'

concurrency:
group: build-${{ github.event.pull_request.number || github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
pre_job:
# continue-on-error: true # Uncomment once integration is finished
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5
test:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -22,15 +38,14 @@ jobs:
version:
- '1.6'
- '1'
- '^1.9.0-0'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
Expand Down
20 changes: 17 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
name = "InfiniteArrays"
uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
version = "0.12.13"
version = "0.13.3"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[weakdeps]
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[extensions]
InfiniteArraysDSPExt = "DSP"
InfiniteArraysStatisticsExt = "Statistics"

[compat]
Aqua = "0.6"
ArrayLayouts = "1.0"
BandedMatrices = "0.17.18"
DSP = "0.7"
FillArrays = "1.0"
Infinities = "0.1.1"
LazyArrays = "1.0"
LazyBandedMatrices = "0.8.9"
LazyBandedMatrices = "0.8.9, 0.9"
LinearAlgebra = "1.6"
Statistics = "1.6"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
LazyBandedMatrices = "d7e5e226-e90b-4449-9968-0f923699bf6f"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test", "BandedMatrices", "LazyBandedMatrices", "SparseArrays", "Base64"]
test = ["Aqua", "Test", "BandedMatrices", "LazyBandedMatrices", "Statistics", "SparseArrays", "Base64", "DSP"]
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# InfiniteArrays.jl


[pkgeval-img]: https://juliaci.github.io/NanosoldierReports/pkgeval_badges/I/InfiniteArrays.svg
[pkgeval-url]: https://juliaci.github.io/NanosoldierReports/pkgeval_badges/report.html

[![Build Status](https://github.com/JuliaArrays/InfiniteArrays.jl/workflows/CI/badge.svg)](https://github.com/JuliaArrays/InfiniteArrays.jl/actions)
[![codecov](https://codecov.io/gh/JuliaArrays/InfiniteArrays.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaArrays/InfiniteArrays.jl)
[![PkgEval][pkgeval-img]][pkgeval-url]


A Julia package for representing arrays with infinite dimension sizes, designed to work
Expand All @@ -17,7 +21,7 @@ and QR decompositions.
Here are some examples of current functionality:

```julia
julia> using InfiniteArrays, LinearAlgebra
julia> using InfiniteArrays, LinearAlgebra, FillArrays

julia> x = Ones(∞) # infinite vector of all ones
Ones{Float64,1,Tuple{InfiniteArrays.OneToInf{Int64}}} with indices OneToInf():
Expand Down
79 changes: 79 additions & 0 deletions ext/InfiniteArraysDSPExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
module InfiniteArraysDSPExt

using InfiniteArrays
using InfiniteArrays: InfRanges, OneToInf
# Specifying the full namespace is necessary because of https://github.com/JuliaLang/julia/issues/48533
# See https://github.com/JuliaStats/LogExpFunctions.jl/pull/63
using InfiniteArrays.FillArrays
using InfiniteArrays.FillArrays: AbstractFill, getindex_value
using InfiniteArrays.LazyArrays
import DSP: conv


##
# conv
# This is useful for determining polynomial dimensions
##

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
10 changes: 10 additions & 0 deletions ext/InfiniteArraysStatisticsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module InfiniteArraysStatisticsExt

using InfiniteArrays
using InfiniteArrays: InfRanges
using Statistics

Statistics.mean(r::InfRanges{<:Real}) = last(r)
Statistics.median(r::InfRanges{<:Real}) = last(r)

end
38 changes: 26 additions & 12 deletions src/InfiniteArrays.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module InfiniteArrays
using ArrayLayouts: LayoutVecOrMat
using Base, Statistics, LinearAlgebra, FillArrays, Infinities, LazyArrays, ArrayLayouts
using LinearAlgebra, FillArrays, Infinities, LazyArrays, ArrayLayouts

import Base: *, +, -, /, \, ==, isinf, isfinite, sign, signbit, angle, show, isless,
fld, cld, div, min, max, minimum, maximum, mod,
Expand Down Expand Up @@ -33,6 +32,16 @@ if VERSION < v"1.8-"
else
import Base: range_start_step_length
end
if VERSION v"1.11.0-DEV.21"
using LinearAlgebra: UpperOrLowerTriangular
else
const UpperOrLowerTriangular{T,S} = Union{LinearAlgebra.UpperTriangular{T,S},
LinearAlgebra.UnitUpperTriangular{T,S},
LinearAlgebra.LowerTriangular{T,S},
LinearAlgebra.UnitLowerTriangular{T,S}}
end


using Base.Broadcast
import Base.Broadcast: BroadcastStyle, AbstractArrayStyle, Broadcasted, broadcasted,
@nexprs, @ncall, combine_eltypes, DefaultArrayStyle, instantiate, axistype
Expand All @@ -41,15 +50,17 @@ import LinearAlgebra: BlasInt, BlasFloat, norm, diag, diagm, ishermitian, issymm
det, logdet, istriu, istril, adjoint, tr, AbstractTriangular,
norm2, norm1, normp, AdjOrTrans, HermOrSym

import Statistics: mean, median

import FillArrays: AbstractFill, getindex_value, fill_reshape, RectDiagonal, Fill, Ones, Zeros, Eye, elconvert
import LazyArrays: LazyArrayStyle, AbstractBandedLayout, MemoryLayout, LazyLayout, UnknownLayout,
ZerosLayout, AbstractCachedVector, CachedArray, CachedVector, ApplyLayout, LazyMatrix,
reshapedlayout, sub_materialize, sublayout, LayoutMatrix, LayoutVector, _padded_sub_materialize, PaddedLayout,

import LazyArrays: LazyArrayStyle, LazyLayout,
AbstractCachedVector, CachedArray, CachedVector, ApplyLayout, LazyMatrix,
_padded_sub_materialize, PaddedLayout,
AbstractCachedMatrix, sub_paddeddata, InvColumnLayout

import ArrayLayouts: RangeCumsum, LayoutVecOrMat, LayoutVecOrMats
import ArrayLayouts: RangeCumsum, LayoutVecOrMat, LayoutVecOrMats, LayoutMatrix, LayoutVector,
AbstractBandedLayout, MemoryLayout, UnknownLayout, reshapedlayout,
sub_materialize, sublayout, ZerosLayout, LayoutVecOrMat

import Infinities: ∞, Infinity, InfiniteCardinal

export ∞, ℵ₀, Hcat, Vcat, Zeros, Ones, Fill, Eye, BroadcastArray, cache
Expand Down Expand Up @@ -150,7 +161,7 @@ axistype(::OneToInf{V}, ::OneTo{T}) where {T,V} = OneToInf{promote_type(T,V)}()
# returns the range of indices of v equal to x
# if v does not contain x, returns a 0-length range
# indicating the insertion point of x
function searchsorted(v::AbstractVector, x, ilo::Int, ::PosInfinity, o::Ordering)
function searchsorted(v::AbstractVector, x, ilo::Integer, ::PosInfinity, o::Ordering)
lo = ilo-1
hi = ℵ₀
@inbounds while lo < hi-1
Expand All @@ -171,7 +182,7 @@ end

# index of the first value of vector a that is greater than or equal to x;
# returns length(v)+1 if x is greater than all values in v.
function searchsortedfirst(v::AbstractVector, x, lo::Int, hi::PosInfinity, o::Ordering)
function searchsortedfirst(v::AbstractVector, x, lo::Integer, hi::PosInfinity, o::Ordering)
u = 1
lo = lo - u
hi = ℵ₀
Expand All @@ -188,7 +199,7 @@ end

# index of the last value of vector a that is less than or equal to x;
# returns 0 if x is less than all values of v.
function searchsortedlast(v::AbstractVector, x, lo::Int, hi::PosInfinity, o::Ordering)
function searchsortedlast(v::AbstractVector, x, lo::Integer, hi::PosInfinity, o::Ordering)
u = 1
lo = lo - u
hi = ℵ₀
Expand All @@ -211,7 +222,10 @@ end
return LazyArrays.searchsortedlast_recursive(n, x, args...)
end


if !isdefined(Base, :get_extension)
include("../ext/InfiniteArraysStatisticsExt.jl")
include("../ext/InfiniteArraysDSPExt.jl")
end


end # module
10 changes: 5 additions & 5 deletions src/infarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ fill(x, nm::Tuple{PosInfinity, PosInfinity}) = cache(Fill(x,nm...))



# This gets called when infinit number of columns
# This gets called when infinite number of columns
axes_print_matrix_row(_, io, X, A, i, ::AbstractVector{<:PosInfinity}, sep) = nothing
print_matrix_row(io::IO, X::AbstractVecOrMat, A::Vector, i::Integer, cols::AbstractVector{<:PosInfinity}, sep::AbstractString, idxlast::Integer=last(axes(X, 2))) = nothing
print_matrix_row(io::IO, X::AbstractVecOrMat, A::Vector, i::Integer, cols::AbstractVector, sep::AbstractString, idxlast::Union{RealInfinity,Infinity}) = print_matrix_row(io, X, A, i, cols, sep, ℵ₀)
print_matrix_row(io::IO,
X::Union{LayoutMatrix,
LayoutVector,
AbstractTriangular{<:Any,<:LayoutMatrix},
UpperOrLowerTriangular{<:Any,<:LayoutMatrix},
AdjOrTrans{<:Any,<:LayoutMatrix},
AdjOrTrans{<:Any,<:LayoutVector},
HermOrSym{<:Any,<:LayoutMatrix},
Expand All @@ -101,7 +101,7 @@ print_matrix_row(io::IO,
AbstractFill{<:Any,2},
Diagonal{<:Any,<:AbstractFill{<:Any,1}},
RectDiagonal,
AbstractTriangular{<:Any,<:AbstractFill{<:Any,2}}
UpperOrLowerTriangular{<:Any,<:AbstractFill{<:Any,2}}
}, A::Vector,
i::Integer, cols::AbstractVector{<:PosInfinity}, sep::AbstractString, idxlast::Integer=last(axes(X, 2))) =
axes_print_matrix_row(axes(X), io, X, A, i, cols, sep)
Expand Down Expand Up @@ -164,7 +164,7 @@ end
#####


# Lazy Broadacasting
# Lazy Broadcasting
for typ in (:Ones, :Zeros, :Fill)
@eval begin
BroadcastStyle(::Type{$typ{T,N,NTuple{N,<:OneToInf}}}) where {T,N} = LazyArrayStyle{N}()
Expand Down Expand Up @@ -335,7 +335,7 @@ _vcat(a, b, c...) = Vcat(a, b, c...)
getindex(A::Vcat, r::InfUnitRange) = Base.invoke(getindex, Tuple{AbstractArray, Any}, A, r)
_unsafe_getindex(::IndexLinear, A::Vcat, r::InfUnitRange) = _vcat(_gettail(first(r), A.args...)...)

# some common cases not catched by LayoutArrays + ambiguities
# some common cases not caught by LayoutArrays + ambiguities
for InfColMatrix in (:(SubArray{<:Any,2,<:Any,<:Tuple{Any,InfIndexRanges}}),
:(SubArray{<:Any,2,<:LayoutVecOrMat,<:Tuple{Any,InfIndexRanges}}),
:(AbstractFill{<:Any,2,Tuple{OneTo{Int},OneToInf{Int}}}))
Expand Down
20 changes: 18 additions & 2 deletions src/infrange.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ AbstractVector{T}(a::OneToInf) where T<:Real = InfStepRange(one(T),one(T))
## interface implementations

size(r::InfRanges) = (ℵ₀,)
axes(r::InfRanges{<:Integer}) = (OneToInf{promote_type(Int,eltype(r))}(),)
axes(r::InfRanges) = (OneToInf(),)

isempty(r::InfRanges) = false

Expand Down Expand Up @@ -440,8 +442,6 @@ InfStepRange(r::InfUnitRange{T}) where {T} =
## sorting ##

sum(r::InfRanges{<:Real}) = last(r)
mean(r::InfRanges{<:Real}) = last(r)
median(r::InfRanges{<:Real}) = last(r)

in(x::Union{Infinity,RealInfinity}, r::InfRanges) = false # never reach it...
in(x::Infinity, r::InfRanges{<:Integer}) = false # never reach it...
Expand Down Expand Up @@ -514,6 +514,22 @@ diff(r::OneToInf{T}) where T = Ones{T}(∞)
Base.@propagate_inbounds getindex(c::RangeCumsum, kr::OneToInf) = RangeCumsum(c.range[kr])
getindex(c::RangeCumsum{<:Any,<:OneToInf}, k::Integer) = k * (k+1) ÷ 2

# vcat

vcat(a::Number, r::InfRanges) = Vcat(a, r)

throw_inferror() = throw(ArgumentError("vcat is undefined with a leading infinite range"))
vcat(r::InfRanges) = r
vcat(r::InfRanges{T}, args::InfRanges{T}...) where {T} = throw_inferror()
vcat(r::InfRanges, args::InfRanges...) = throw_inferror()
vcat(r::InfRanges{T}, args::AbstractRange{T}...) where {T} = throw_inferror()
vcat(r::InfRanges, args::AbstractRange...) = throw_inferror()
vcat(r::InfRanges{T}, args::AbstractVector{T}...) where {T} = throw_inferror()
vcat(r::InfRanges, args::AbstractVector...) = throw_inferror()
vcat(r::InfRanges, ::Union{Number, AbstractVector}...) = throw_inferror()
vcat(r::AbstractRange{T}, infr::InfRanges{T}) where {T} = Vcat(r, infr)
vcat(r::AbstractRange, infr::InfRanges) = Vcat(r, infr)
vcat(v::AbstractVector, infr::InfRanges) = Vcat(v, infr)

###
# MemoryLayout
Expand Down
Loading

0 comments on commit e0ad2e8

Please sign in to comment.