|
24 | 24 | differentiable_mean_function_tests(rng, m, x) |
25 | 25 | end |
26 | 26 | end |
| 27 | + |
| 28 | + @testset "ColVecs & RowVecs" begin |
| 29 | + m = custom_mean_testcase.mean_function |
| 30 | + |
| 31 | + @test mean_vector(m, xD_colvecs) == map(foo_mean, eachcol(xD_colvecs.X)) |
| 32 | + @test mean_vector(m, xD_rowvecs) == map(foo_mean, eachrow(xD_rowvecs.X)) |
| 33 | + end |
| 34 | + |
| 35 | + # This test fails without the specialized methods |
| 36 | + # `mean_vector(m::CustomMean, x::ColVecs)` |
| 37 | + # `mean_vector(m::CustomMean, x::RowVecs)` |
| 38 | + @testset "Zygote gradients" begin |
| 39 | + X = [1.;; 2.;; 3.;;] |
| 40 | + y = [1., 2., 3.] |
| 41 | + foo_mean = x -> sum(abs2, x) |
| 42 | + |
| 43 | + function construct_finite_gp(X, lengthscale, noise) |
| 44 | + mean = CustomMean(foo_mean) |
| 45 | + kernel = with_lengthscale(Matern52Kernel(), lengthscale) |
| 46 | + return GP(mean, kernel)(X, noise) |
| 47 | + end |
| 48 | + |
| 49 | + function loglike(lengthscale, noise) |
| 50 | + gp = construct_finite_gp(X, lengthscale, noise) |
| 51 | + return logpdf(gp, y) |
| 52 | + end |
| 53 | + |
| 54 | + @test Zygote.gradient(n -> loglike(1., n), 1.)[1] isa Real |
| 55 | + @test Zygote.gradient(l -> loglike(l, 1.), 1.)[1] isa Real |
| 56 | + end |
27 | 57 | end |
0 commit comments