Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pairwise! for Covariance types #5

Merged
merged 5 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/covariance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ Evaluate covariance `cov` between all elements of `domain₁` and `domain₂`.
"""
pairwise(cov::Covariance, args...) = sill(cov.γ) .- pairwise(cov.γ, args...)

"""
pairwise!(C, cov, domain)

Evaluates covariance `cov` between all elements in the `domain` in-place, filling the matrix `C`.

pairwise!(C, cov, domain₁, domain₂)

Evaluates covariance `cov` between all elements of `domain₁` and `domain₂` in-place, filling the matrix `C`.
"""
function pairwise!(C, cov::Covariance, args...)
pairwise!(C, cov.γ, args...)
for i in eachindex(Γ)
C[i] = sill(cov.γ) - C[i]
end
C
end

# -----------
# IO METHODS
# -----------
Expand Down
10 changes: 10 additions & 0 deletions src/variogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ function pairwise(γ::Variogram, domain)
pairwise!(Γ, γ, domain)
end

"""
pairwise!(Γ, γ, domain)

Evaluates covariance `γ` between all elements in the `domain` in-place, filling the matrix `Γ`.
"""
function pairwise!(Γ, γ::Variogram, domain)
n = length(domain)
@inbounds for j in 1:n
Expand Down Expand Up @@ -185,6 +190,11 @@ function pairwise(γ::Variogram, domain₁, domain₂)
pairwise!(Γ, γ, domain₁, domain₂)
end

"""
pairwise!(Γ, γ, domain₁, domain₂)

Evaluates covariance `γ` between all elements of `domain₁` and `domain₂` in-place, filling the matrix `Γ`.
"""
function pairwise!(Γ, γ::Variogram, domain₁, domain₂)
m = length(domain₁)
n = length(domain₂)
Expand Down
Loading