Skip to content

Commit

Permalink
Fix for unstructured grids with Cholsky/Spectral
Browse files Browse the repository at this point in the history
  • Loading branch information
PieterjanRobbe committed Sep 15, 2021
1 parent 4303db9 commit 28202a7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GaussianRandomFields"
uuid = "e4b2fa32-6e09-5554-b718-106ed5adafe9"
version = "2.1.3"
version = "2.1.4"

[deps]
Arpack = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"
Expand Down
3 changes: 3 additions & 0 deletions src/covariance_functions/covariance_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ function apply(cov::CovarianceStructure, tx::NTuple{2,AbstractMatrix},
Symmetric(C, :U)
end

# evaluate for unstructured grids
apply(cov::CovarianceFunction{d}, x::AbstractMatrix{T}, y::AbstractMatrix{N}) where {d, T, N} = apply(cov.cov, (x,x), (x,x))

# evaluate for KL eigenfunctions
function apply(cov::CovarianceStructure, tx::NTuple{2,AbstractMatrix}, y::Tuple)
x = first(tx) # select FE nodes
Expand Down
2 changes: 1 addition & 1 deletion src/fem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function GaussianRandomField(mean::Vector{<:Real}, cov::CovarianceFunction{d}, m
size(pts, 2) == d || throw(DimensionMismatch("second dimension of points must be equal to $(d)"))
method isa CirculantEmbedding && throw(ArgumentError("cannot use circulant embedding with an unstructured grid"))

_GaussianRandomField(mean, cov, method, pts', Matrix{Int}(undef,0,0); kwargs...)
_GaussianRandomField(mean, cov, method, copy(pts'), Matrix{Int}(undef,0,0); kwargs...)
end

GaussianRandomField(cov::CovarianceFunction, method::GaussianRandomFieldGenerator,
Expand Down
4 changes: 4 additions & 0 deletions test/test_unstructured.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@
grf = GaussianRandomField(cov, KarhunenLoeve(128), pts)
z = sample(grf)
@test isa(grf,GaussianRandomField{KarhunenLoeve{128}})
grf = GaussianRandomField(cov, Spectral(), pts)
@test isa(grf,GaussianRandomField{Spectral})
grf = GaussianRandomField(cov, Cholesky(), pts)
@test isa(grf,GaussianRandomField{Cholesky})

end

0 comments on commit 28202a7

Please sign in to comment.