Skip to content

Commit

Permalink
add unit tests for single-point posterior evals
Browse files Browse the repository at this point in the history
  • Loading branch information
soldasim committed Nov 5, 2024
1 parent 45b1602 commit dd72220
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
12 changes: 11 additions & 1 deletion test/unit/test/models/gaussian_process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ end
isapprox.(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][1,1,:], out([1., 1.])[2] .^ 2; atol=1e-8) |> all,
isapprox.(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][2,2,:], out([2., 2.])[2] .^ 2; atol=1e-8) |> all,
isapprox.(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][3,3,:], out([3., 3.])[2] .^ 2; atol=1e-8) |> all,

# single-element matrix
out([1.;1.;;]) isa Tuple{<:AbstractMatrix{<:Real}, <:AbstractArray{<:Real, 3}},
size(out([1.;1.;;])[1]) == (1, 2),
size(out([1.;1.;;])[2]) == (1, 1, 2),
)
end
end
Expand Down Expand Up @@ -170,14 +175,19 @@ end

# matrix
out([1.;1.;; 2.;2.;; 3.;3.;;]) isa Tuple{<:AbstractVector{<:Real}, <:AbstractMatrix{<:Real}},
length(out([1.;1.;; 2.;2.;; 3.;3.;;])[1]) == 3,
size(out([1.;1.;; 2.;2.;; 3.;3.;;])[1]) == (3,),
size(out([1.;1.;; 2.;2.;; 3.;3.;;])[2]) == (3, 3),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[1][1], out([1., 1.])[1]; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[1][2], out([2., 2.])[1]; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[1][3], out([3., 3.])[1]; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][1,1], out([1., 1.])[2] ^ 2; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][2,2], out([2., 2.])[2] ^ 2; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][3,3], out([3., 3.])[2] ^ 2; atol=1e-8),

# single-element matrix
out([1.;1.;;]) isa Tuple{<:AbstractVector{<:Real}, <:AbstractMatrix{<:Real}},
size(out([1.;1.;;])[1]) == (1,),
size(out([1.;1.;;])[2]) == (1, 1),
)
end
end
Expand Down
12 changes: 11 additions & 1 deletion test/unit/test/models/parametric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ end
isapprox.(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][1,1,:], out([1., 1.])[2] .^ 2; atol=1e-8) |> all,
isapprox.(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][2,2,:], out([2., 2.])[2] .^ 2; atol=1e-8) |> all,
isapprox.(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][3,3,:], out([3., 3.])[2] .^ 2; atol=1e-8) |> all,

# single-element matrix
out([1.;1.;;]) isa Tuple{<:AbstractMatrix{<:Real}, <:AbstractArray{<:Real, 3}},
size(out([1.;1.;;])[1]) == (1, 2),
size(out([1.;1.;;])[2]) == (1, 1, 2),
)
end
end
Expand Down Expand Up @@ -273,14 +278,19 @@ end

# matrix
out([1.;1.;; 2.;2.;; 3.;3.;;]) isa Tuple{<:AbstractVector{<:Real}, <:AbstractMatrix{<:Real}},
length(out([1.;1.;; 2.;2.;; 3.;3.;;])[1]) == 3,
size(out([1.;1.;; 2.;2.;; 3.;3.;;])[1]) == (3,),
size(out([1.;1.;; 2.;2.;; 3.;3.;;])[2]) == (3, 3),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[1][1], out([1., 1.])[1]; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[1][2], out([2., 2.])[1]; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[1][3], out([3., 3.])[1]; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][1,1], out([1., 1.])[2] ^ 2; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][2,2], out([2., 2.])[2] ^ 2; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][3,3], out([3., 3.])[2] ^ 2; atol=1e-8),

# single-element matrix
out([1.;1.;;]) isa Tuple{<:AbstractVector{<:Real}, <:AbstractMatrix{<:Real}},
size(out([1.;1.;;])[1]) == (1,),
size(out([1.;1.;;])[2]) == (1, 1),
)
end
end
Expand Down
12 changes: 11 additions & 1 deletion test/unit/test/models/semiparametric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
isapprox.(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][1,1,:], out([1., 1.])[2] .^ 2; atol=1e-8) |> all,
isapprox.(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][2,2,:], out([2., 2.])[2] .^ 2; atol=1e-8) |> all,
isapprox.(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][3,3,:], out([3., 3.])[2] .^ 2; atol=1e-8) |> all,

# single-element matrix
out([1.;1.;;]) isa Tuple{<:AbstractMatrix{<:Real}, <:AbstractArray{<:Real, 3}},
size(out([1.;1.;;])[1]) == (1, 2),
size(out([1.;1.;;])[2]) == (1, 1, 2),
)
end
end
Expand Down Expand Up @@ -92,14 +97,19 @@ end

# matrix
out([1.;1.;; 2.;2.;; 3.;3.;;]) isa Tuple{<:AbstractVector{<:Real}, <:AbstractMatrix{<:Real}},
length(out([1.;1.;; 2.;2.;; 3.;3.;;])[1]) == 3,
size(out([1.;1.;; 2.;2.;; 3.;3.;;])[1]) == (3,),
size(out([1.;1.;; 2.;2.;; 3.;3.;;])[2]) == (3, 3),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[1][1], out([1., 1.])[1]; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[1][2], out([2., 2.])[1]; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[1][3], out([3., 3.])[1]; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][1,1], out([1., 1.])[2] ^ 2; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][2,2], out([2., 2.])[2] ^ 2; atol=1e-8),
isapprox(out([1.;1.;; 2.;2.;; 3.;3.;;])[2][3,3], out([3., 3.])[2] ^ 2; atol=1e-8),

# single-element matrix
out([1.;1.;;]) isa Tuple{<:AbstractVector{<:Real}, <:AbstractMatrix{<:Real}},
size(out([1.;1.;;])[1]) == (1,),
size(out([1.;1.;;])[2]) == (1, 1),
)
end
end
Expand Down

0 comments on commit dd72220

Please sign in to comment.