From 171465aca9c1f40efce18af41b79f58dc904f3ea Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Mon, 8 Jul 2024 21:49:24 +0100 Subject: [PATCH] Promote types of transforms (#186) * promote types of transforms * Create downstream.yml * move downstream * Update bases.jl * add test --- .github/workflows/downstream.yml | 80 ++++++++++++++++++++++++++++++++ Project.toml | 2 +- src/ContinuumArrays.jl | 1 + src/bases/bases.jl | 8 +++- src/bases/basisconcat.jl | 2 +- src/bases/splines.jl | 5 ++ test/test_splines.jl | 19 ++++++++ 7 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/downstream.yml diff --git a/.github/workflows/downstream.yml b/.github/workflows/downstream.yml new file mode 100644 index 0000000..ef1e7e3 --- /dev/null +++ b/.github/workflows/downstream.yml @@ -0,0 +1,80 @@ +name: IntegrationTest +on: + push: + branches: [master] + tags: [v*] + paths-ignore: + - 'LICENSE' + - 'README.md' + - '.github/workflows/TagBot.yml' + pull_request: + paths-ignore: + - '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: ${{ matrix.package.group }}/${{ matrix.package.repo }}/${{ matrix.julia-version }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + julia-version: ['1'] + os: [ubuntu-latest] + package: + - {repo: ClassicalOrthogonalPolynomials.jl, group: JuliaApproximation} + - {repo: HarmonicOrthogonalPolynomials.jl, group: JuliaApproximation} + - {repo: MultivariateOrthogonalPolynomials.jl, group: JuliaApproximation} + - {repo: PiecewiseOrthogonalPolynomials.jl, group: JuliaApproximation} + - {repo: SemiclassicalOrthogonalPolynomials.jl, group: JuliaApproximation} + + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: ${{ matrix.julia-version }} + arch: x64 + - uses: julia-actions/julia-buildpkg@latest + - name: Clone Downstream + uses: actions/checkout@v4 + with: + repository: ${{ matrix.package.group }}/${{ matrix.package.repo }} + path: downstream + - name: Load this and run the downstream tests + shell: julia --color=yes --project=downstream {0} + run: | + using Pkg + try + # force it to use this PR's version of the package + Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps + Pkg.update() + Pkg.test(; coverage = true) # resolver may fail with test time deps + catch err + err isa Pkg.Resolve.ResolverError || rethrow() + # If we can't resolve that means this is incompatible by SemVer and this is fine + # It means we marked this as a breaking change, so we don't need to worry about + # Mistakenly introducing a breaking change, as we have intentionally made one + @info "Not compatible with this release. No problem." exception=err + exit(0) # Exit immediately, as a success + end + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: lcov.info diff --git a/Project.toml b/Project.toml index 76ee1c4..2b4234e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ContinuumArrays" uuid = "7ae1f121-cc2c-504b-ac30-9b923412ae5c" -version = "0.18.2" +version = "0.18.3" [deps] AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c" diff --git a/src/ContinuumArrays.jl b/src/ContinuumArrays.jl index fd2e248..0c3d19f 100644 --- a/src/ContinuumArrays.jl +++ b/src/ContinuumArrays.jl @@ -55,6 +55,7 @@ include("maps.jl") const QInfAxes = Union{Inclusion,AbstractAffineQuasiVector} +# TODO: the following break some tests in QuasiArrays.jl when loaded, when `QInfAxes` are finite dimensional sub_materialize(_, V::AbstractQuasiArray, ::Tuple{QInfAxes}) = V sub_materialize(_, V::AbstractQuasiArray, ::Tuple{QInfAxes,QInfAxes}) = V diff --git a/src/bases/bases.jl b/src/bases/bases.jl index 760d56e..b1bdf50 100644 --- a/src/bases/bases.jl +++ b/src/bases/bases.jl @@ -272,8 +272,12 @@ function _factorize(::MappedBasisLayout, L, dims...; kws...) MappedFactorization(factorize(view(P,:,jr), dims...; kws...), invmap(parentindices(L)[1])) end -plan_ldiv(A, B::AbstractQuasiVector) = factorize(A) -plan_ldiv(A, B::AbstractQuasiMatrix) = factorize(A, size(B,2)) + +_any_eltype(B::AbstractQuasiArray{Any}) = typeof(first(B)) # assume types are same +_any_eltype(B) = eltype(B) + +plan_ldiv(A, B::AbstractQuasiVector) = factorize(convert(AbstractQuasiMatrix{promote_type(eltype(A), _any_eltype(B))}, A)) +plan_ldiv(A, B::AbstractQuasiMatrix) = factorize(convert(AbstractQuasiMatrix{promote_type(eltype(A), _any_eltype(B))}, A), size(B,2)) transform_ldiv_size(_, A::AbstractQuasiArray{T}, B::AbstractQuasiArray{V}) where {T,V} = plan_ldiv(A, B) \ B transform_ldiv(A, B) = transform_ldiv_size(size(A), A, B) diff --git a/src/bases/basisconcat.jl b/src/bases/basisconcat.jl index 8e9809e..448c02f 100644 --- a/src/bases/basisconcat.jl +++ b/src/bases/basisconcat.jl @@ -112,4 +112,4 @@ function QuasiArrays._getindex(::Type{IND}, A::HvcatBasis{T}, (x,j)::IND) where end -diff(H::ApplyQuasiMatrix{<:Any,typeof(hcat)}; dims::Integer) = hcat((diff.(H.args; dims=dims))...) \ No newline at end of file +diff(H::ApplyQuasiMatrix{<:Any,typeof(hcat)}; dims::Integer=1) = hcat((diff.(H.args; dims=dims))...) \ No newline at end of file diff --git a/src/bases/splines.jl b/src/bases/splines.jl index 26777d4..9f99a9c 100644 --- a/src/bases/splines.jl +++ b/src/bases/splines.jl @@ -9,6 +9,11 @@ const HeavisideSpline = Spline{0} Spline{o}(pts::AbstractVector{T}) where {o,T} = Spline{o,float(T)}(pts) Spline{o}(S::Spline) where {o} = Spline{o}(S.points) +convert(::Type{AbstractQuasiArray{T}}, S::Spline{λ,T}) where {λ,T} = S +convert(::Type{AbstractQuasiMatrix{T}}, S::Spline{λ,T}) where {λ,T} = S +convert(::Type{AbstractQuasiArray{T}}, S::Spline{λ}) where {λ,T} = Spline{λ,T}(S.points) +convert(::Type{AbstractQuasiMatrix{T}}, S::Spline{λ}) where {λ,T} = convert(AbstractQuasiArray{T}, S) + for Typ in (:LinearSpline, :HeavisideSpline) STyp = string(Typ) @eval function show(io::IO, L::$Typ) diff --git a/test/test_splines.jl b/test/test_splines.jl index ede1f20..67c5c5f 100644 --- a/test/test_splines.jl +++ b/test/test_splines.jl @@ -609,4 +609,23 @@ import ContinuumArrays: basis, AdjointBasisLayout, ExpansionLayout, BasisLayout, @test sum(u) == 10 @test cumsum(u)[5-4eps()] == 10 end + + @testset "complex" begin + L = LinearSpline([1,2,3]) + x = axes(L,1) + @test L \ exp.(im*x) == LinearSpline{ComplexF64}([1,2,3]) \ exp.(im*x) == transform(L, x -> exp(im*x)) + @test expand(L, x -> exp(im*x))[2.0] ≈ exp(im*2.0) + end + + @testset "convert" begin + L = LinearSpline([1,2,3]) + @test L ≡ convert(AbstractQuasiArray{Float64}, L) ≡ convert(AbstractQuasiMatrix{Float64}, L) + @test convert(AbstractQuasiArray{ComplexF64}, L) == convert(AbstractQuasiMatrix{ComplexF64}, L) == LinearSpline{ComplexF64}([1,2,3]) + end + + @testset "any eltype" begin + L = LinearSpline([-1,0,1]) + f = x -> abs(x) ≤ 1 ? 1 : "hi" + @test expand(L,f)[0.1] ≈ 1 + end end