Skip to content

Commit

Permalink
Conflict resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
shinaoka committed Nov 17, 2024
2 parents 393d1d6 + a610813 commit daa802a
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 9 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ concurrency:
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
Expand All @@ -19,7 +23,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- 'lts'
- '1'
- 'nightly'
os:
Expand Down
216 changes: 208 additions & 8 deletions test/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ isdefined(Main, :sve_logistic) || include("_conftest.jl")
data = rand(rng, 3, 3)
knots = rand(rng, size(data, 2) + 1) |> sort
@test data == [
0.8177021060277301 0.7085670484724618 0.5033588232863977;
0.3804323567786363 0.7911959541742282 0.8268504271915096;
0.8177021060277301 0.7085670484724618 0.5033588232863977;
0.3804323567786363 0.7911959541742282 0.8268504271915096;
0.5425813266814807 0.38397463704084633 0.21626598379927042
]
@test knots == [
Expand All @@ -27,8 +27,8 @@ isdefined(Main, :sve_logistic) || include("_conftest.jl")
randsymm == 9
ddata = rand(drng, 3, 3)
ddata == [
0.5328437345518631 0.8443074122979211 0.6722336389122814;
0.1799506228788046 0.6805545318460489 0.17641780726469292;
0.5328437345518631 0.8443074122979211 0.6722336389122814;
0.1799506228788046 0.6805545318460489 0.17641780726469292;
0.13124858727993338 0.2193663343416914 0.7756615110113394
]
end
Expand Down Expand Up @@ -70,7 +70,7 @@ isdefined(Main, :sve_logistic) || include("_conftest.jl")
randsymm = rand(drng, Int)
ddata = rand(drng, 3, 3)
ddata_pwlp = SparseIR.PiecewiseLegendrePoly(ddata, pwlp; symm=randsymm)

@test ddata_pwlp.data == ddata
@test ddata_pwlp.symm == randsymm
for n in fieldnames(SparseIR.PiecewiseLegendrePoly)
Expand All @@ -80,11 +80,211 @@ isdefined(Main, :sve_logistic) || include("_conftest.jl")
end
end

@testset "PiecewiseLegendrePolyVector" begin
#=
julia> # The following data and knots are generated by
julia> using SparseIR
julia> sve_result = SparseIR.SVEResult(LogisticKernel(1.0))
julia> data1 = sve_result.u[1].data
julia> data2 = sve_result.u[2].data
julia> data3 = sve_result.u[3].data
julia> knots1 = sve_result.u[1].knots
julia> knots2 = sve_result.u[2].knots
julia> knots3 = sve_result.u[3].knots
julia> l1 = sve_result.u[1].l
julia> l2 = sve_result.u[2].l
julia> l3 = sve_result.u[3].l
=#
begin
data1 = reshape(
[
0.49996553669802485
-0.009838135710548356
0.003315915376286483
-2.4035906967802686e-5
3.4824832610792906e-6
-1.6818592059096e-8
1.5530850593697272e-9
-5.67191158452736e-12
3.8438802553084145e-13
-1.12861464373688e-15
-1.4028528586225198e-16
5.199431653846204e-18
-3.490774002228127e-16
4.339342349553959e-18
-8.247505551908268e-17
7.379549188001237e-19
0.49996553669802485
0.009838135710548356
0.003315915376286483
2.4035906967802686e-5
3.4824832610792906e-6
1.6818592059096e-8
1.5530850593697272e-9
5.67191158452736e-12
3.8438802553084145e-13
1.12861464373688e-15
-1.4028528586225198e-16
-5.199431653846204e-18
-3.490774002228127e-16
-4.339342349553959e-18
-8.247505551908268e-17
-7.379549188001237e-19
],
16,
2,
)

knots1 = [-1.0, 0.0, 1.0]
l1 = 0
end

begin
data2 = reshape(
[
-0.43195475509329695
0.436151579050162
-0.005257007544885257
0.0010660519696441624
-6.611545612452212e-6
7.461310619506964e-7
-3.2179499894475862e-9
2.5166526274315926e-10
-8.387341925898803e-13
5.008268649326024e-14
3.7750894390998034e-17
-2.304983535459561e-16
3.0252856483620636e-16
-1.923751082183687e-16
7.201014354168769e-17
-3.2715804561902326e-17
0.43195475509329695
0.436151579050162
0.005257007544885257
0.0010660519696441624
6.611545612452212e-6
7.461310619506964e-7
3.2179499894475862e-9
2.5166526274315926e-10
8.387341925898803e-13
5.008268649326024e-14
-3.7750894390998034e-17
-2.304983535459561e-16
-3.0252856483620636e-16
-1.923751082183687e-16
-7.201014354168769e-17
-3.2715804561902326e-17
],
16,
2,
)

knots2 = [-1.0, 0.0, 1.0]
l2 = 1
end

begin
data3 = reshape(
[
-0.005870438661638806
-0.8376202388555938
0.28368166184926036
-0.0029450618222246236
0.0004277118923277169
-2.4101642603229184e-6
2.2287962786878678e-7
-8.875091544426018e-10
6.021488924175155e-11
-1.8705305570705647e-13
9.924398482443944e-15
4.299521053905097e-16
-1.0697019178666955e-16
3.6972269778329906e-16
-8.848885164903329e-17
6.327687614609368e-17
-0.005870438661638806
0.8376202388555938
0.28368166184926036
0.0029450618222246236
0.0004277118923277169
2.4101642603229184e-6
2.2287962786878678e-7
8.875091544426018e-10
6.021488924175155e-11
1.8705305570705647e-13
9.924398482443944e-15
-4.299521053905097e-16
-1.0697019178666955e-16
-3.6972269778329906e-16
-8.848885164903329e-17
-6.327687614609368e-17
],
16,
2,
)

knots3 = [-1.0, 0.0, 1.0]
l3 = 2
end

pwlp1 = SparseIR.PiecewiseLegendrePoly(data1, knots1, l1)
pwlp2 = SparseIR.PiecewiseLegendrePoly(data2, knots2, l2)
pwlp3 = SparseIR.PiecewiseLegendrePoly(data3, knots3, l3)

polys = SparseIR.PiecewiseLegendrePolyVector([pwlp1, pwlp2, pwlp3])

@test length(polys) == 3

polys = SparseIR.PiecewiseLegendrePolyVector(
[
SparseIR.PiecewiseLegendrePoly(data1, knots1, l1)
SparseIR.PiecewiseLegendrePoly(data2, knots2, l2)
SparseIR.PiecewiseLegendrePoly(data3, knots3, l3)
],
)

@test SparseIR.xmin(polys) == SparseIR.xmin(pwlp1)
@test SparseIR.xmax(polys) == SparseIR.xmax(pwlp1)
@test SparseIR.knots(polys) == SparseIR.knots(pwlp1)
@test SparseIR.Δx(polys) == SparseIR.Δx(pwlp1)
@test SparseIR.polyorder(polys) == SparseIR.polyorder(pwlp1)
@test SparseIR.norms(polys) == SparseIR.norms(pwlp1)
@test SparseIR.symm(polys) == SparseIR.symm.([pwlp1, pwlp2, pwlp3])

@testset "polys(x::Float64)" begin
x = rand(StableRNG(42))
@test polys(x) == [pwlp1(x), pwlp2(x), pwlp3(x)]
@test SparseIR.data(polys) ==
cat(SparseIR.data.([pwlp1, pwlp2, pwlp3])..., dims = 3)
end

@testset "polys(x::Array)" begin
x = rand(StableRNG(42), 2, 1, 4)
tar = polys(x)
@test size(tar) == (3, 2, 1, 4)
ref = reshape(vcat([[pwlp1(e), pwlp2(e), pwlp3(e)] for e in x]...), 3, 2, 1, 4)
@test tar == ref
end

@testset "PiecewiseLegendrePolyVector(polys::PiecewiseLegendrePolyVector, knots::AbstractVector)" begin
new_knots = [-1.0, 0.0, 1.0]

new_polys = SparseIR.PiecewiseLegendrePolyVector(
polys, new_knots,
symm=zeros(Int, size(SparseIR.data(polys), 3)),
)

@test SparseIR.data(new_polys) == SparseIR.data(polys)
@test SparseIR.knots(new_polys) == SparseIR.knots(new_polys)
@test SparseIR.Δx(new_polys) == diff(new_knots)
end
end

@testset "deriv" begin
# independent from sve.jl
# https://github.com/SpM-lab/SparseIR.jl/issues/51
rng = StableRNG(2024)

data = rand(rng, 3, 3)
knots = rand(rng, size(data, 2) + 1) |> sort
l = 3
Expand Down Expand Up @@ -181,7 +381,7 @@ isdefined(Main, :sve_logistic) || include("_conftest.jl")
else
∫pwlp, ∫pwlp_err = (0.4934184996836403, 2.7755575615628914e-17)
end

@test overlap(pwlp, identity) ∫pwlp
@test all(overlap(pwlp, identity, return_error=true) .≈ (∫pwlp, ∫pwlp_err))
end
Expand All @@ -196,7 +396,7 @@ isdefined(Main, :sve_logistic) || include("_conftest.jl")
julia> sve_result = SparseIR.SVEResult(SparseIR.LogisticKernel(Λ))
julia> basis = SparseIR.FiniteTempBasis{SparseIR.Fermionic}(1, Λ; sve_result)
=#

data = reshape([
0.16774734206553019
0.49223680914312595
Expand Down

0 comments on commit daa802a

Please sign in to comment.