Skip to content

Commit

Permalink
add pairwise! for Covariance types (#5)
Browse files Browse the repository at this point in the history
* add pairwise! for Covariance types

* add pairwise! covariance test and update function

* Minor adjustments

* Update src/variogram.jl

---------

Co-authored-by: Mark Baum <>
Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
  • Loading branch information
markmbaum and juliohm authored Mar 26, 2024
1 parent 21785f2 commit 7842431
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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

0 comments on commit 7842431

Please sign in to comment.