Skip to content

Commit

Permalink
update version to 1.1.0 and store handle to basis in Sampling objects
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelBadr committed Dec 6, 2024
1 parent 35f6721 commit 8fbff17
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SparseIR"
uuid = "4fe2279e-80f0-4adb-8463-ee114ff56b7d"
authors = ["Samuel Badr <[email protected]>", "Hiroshi Shinaoka <[email protected]>", "Markus Wallerberger <[email protected]>"]
version = "1.0.19"
version = "1.1.0"

[deps]
Bessels = "0e736298-9ec6-45e8-9647-e4fc86a2fe38"
Expand Down
7 changes: 7 additions & 0 deletions src/abstract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ Return sampling points.
"""
sampling_points(sampling::AbstractSampling) = sampling.sampling_points

"""
basis(sampling::AbstractSampling)
Return the IR basis associated with `sampling`.
"""
basis(sampling::AbstractSampling) = sampling.basis

function Base.show(io::IO, ::MIME"text/plain", smpl::S) where {S<:AbstractSampling}
println(io, "$S with sampling points:")
for p in sampling_points(smpl)[begin:(end - 1)]
Expand Down
11 changes: 7 additions & 4 deletions src/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ Sparse sampling in imaginary time.
Allows the transformation between the IR basis and a set of sampling points
in (scaled/unscaled) imaginary time.
"""
struct TauSampling{T,TMAT,F} <: AbstractSampling{T,TMAT,F}
struct TauSampling{T,TMAT,F,B} <: AbstractSampling{T,TMAT,F}
sampling_points :: Vector{T}
matrix :: Matrix{TMAT}
matrix_svd :: F
basis :: B
end

"""
Expand All @@ -24,7 +25,7 @@ function TauSampling(basis::AbstractBasis;
sampling_points=default_tau_sampling_points(basis), factorize=true)
matrix = eval_matrix(TauSampling, basis, sampling_points)
matrix_svd = factorize ? svd(matrix) : nothing
sampling = TauSampling(sampling_points, matrix, matrix_svd)
sampling = TauSampling(sampling_points, matrix, matrix_svd, basis)
if factorize && iswellconditioned(basis) && cond(sampling) > 1e8
@warn "Sampling matrix is poorly conditioned (cond = $(cond(sampling)))."
end
Expand All @@ -41,11 +42,13 @@ Sparse sampling in Matsubara frequencies.
Allows the transformation between the IR basis and a set of sampling points
in (scaled/unscaled) imaginary frequencies.
"""
struct MatsubaraSampling{T<:MatsubaraFreq,TMAT,F} <: AbstractSampling{T,TMAT,F}
struct MatsubaraSampling{T<:MatsubaraFreq,TMAT,F,B<:AbstractBasis} <:
AbstractSampling{T,TMAT,F}
sampling_points :: Vector{T}
matrix :: Matrix{TMAT}
matrix_svd :: F
positive_only :: Bool
basis :: B
end

"""
Expand Down Expand Up @@ -82,7 +85,7 @@ function MatsubaraSampling(basis::AbstractBasis; positive_only=false,
else
svd_matrix = nothing
end
sampling = MatsubaraSampling(sampling_points, matrix, svd_matrix, positive_only)
sampling = MatsubaraSampling(sampling_points, matrix, svd_matrix, positive_only, basis)
if factorize && iswellconditioned(basis) && cond(sampling) > 1e8
@warn "Sampling matrix is poorly conditioned (cond = $(cond(sampling)))."
end
Expand Down
2 changes: 2 additions & 0 deletions test/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ isdefined(Main, :sve_logistic) || include("_conftest.jl")

basis = FiniteTempBasis(stat, 1, Λ; sve_result=sve_logistic[Λ])
smpl = TauSampling(basis)
@test basis === SparseIR.basis(smpl)
@test issorted(smpl.sampling_points)
Random.seed!(5318008)

Expand Down Expand Up @@ -109,6 +110,7 @@ isdefined(Main, :sve_logistic) || include("_conftest.jl")

basis = FiniteTempBasis(stat, 1, Λ; sve_result=sve_logistic[Λ])
smpl = MatsubaraSampling(basis; positive_only)
@test basis === SparseIR.basis(smpl)
if !positive_only
@test smpl isa
(stat == Fermionic() ? MatsubaraSampling64F : MatsubaraSampling64B)
Expand Down

0 comments on commit 8fbff17

Please sign in to comment.