-
Notifications
You must be signed in to change notification settings - Fork 53
/
memory.jl
134 lines (127 loc) · 4.41 KB
/
memory.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
module TestMemory
using Test, GaussianProcesses
using GaussianProcesses: EmptyData, init_precompute
@testset "Memory Allocation" begin
@testset "simple" begin
k = SEIso(0.0, 0.0)
dim = 5
nobs = 1000
X = randn(dim, nobs)
y = randn(nobs)
logNoise = 0.1
m = MeanZero()
gp = GP(X, y, m, k, logNoise)
mem = @allocated GP(X, y, m, k, logNoise)
# there should be 1 allocation of an n×x matrix for the covariance
# one for its Cholesky decomposition, and one for KernelData
matrix_bytes = (nobs^2)*64/8
@test mem/matrix_bytes < 3.1
buf = init_precompute(gp)
GaussianProcesses.update_mll_and_dmll!(gp, buf)
mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
@test mem/matrix_bytes < 0.1
end
@testset "sum kernel" begin
k = SEIso(0.0, 0.0) + RQIso(1.0, 1.0, 1.0) + SEIso(1.0, 1.0)
dim = 5
nobs = 1000
X = randn(dim, nobs)
y = randn(nobs)
logNoise = 0.1
m = MeanZero()
gp = GP(X, y, m, k, logNoise)
mem = @allocated GP(X, y, m, k, logNoise)
matrix_bytes = (nobs^2)*64/8
@test mem/matrix_bytes < 3.1
buf = init_precompute(gp)
GaussianProcesses.update_mll_and_dmll!(gp, buf)
mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
@test mem/matrix_bytes < 0.1
end
@testset "sum noise" begin
k = SEIso(0.0, 0.0) + Noise(1.0)
dim = 5
nobs = 1000
X = randn(dim, nobs)
y = randn(nobs)
logNoise = 0.1
m = MeanZero()
gp = GP(X, y, m, k, logNoise)
mem = @allocated GP(X, y, m, k, logNoise)
matrix_bytes = (nobs^2)*64/8
@test mem/matrix_bytes < 3.1
buf = init_precompute(gp)
GaussianProcesses.update_mll_and_dmll!(gp, buf)
mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
@test mem/matrix_bytes < 0.1
end
@testset "masked kernel" begin
k = Masked(SEIso(0.0, 0.0), [2,3])
dim = 5
nobs = 1000
X = randn(dim, nobs)
y = randn(nobs)
logNoise = 0.1
m = MeanZero()
gp = GP(X, y, m, k, logNoise)
mem = @allocated GP(X, y, m, k, logNoise)
matrix_bytes = (nobs^2)*64/8
@test mem/matrix_bytes < 3.1
buf = init_precompute(gp)
GaussianProcesses.update_mll_and_dmll!(gp, buf)
mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
@test mem/matrix_bytes < 0.1
end
@testset "prod kernel" begin
k = Mat12Iso(0.0, 0.0) * SEIso(0.0, 0.0) + RQIso(1.0, 1.0, 1.0) * Mat32Iso(1.0, 1.0)
dim = 5
nobs = 1000
X = randn(dim, nobs)
y = randn(nobs)
logNoise = 0.1
m = MeanZero()
gp = GP(X, y, m, k, logNoise)
mem = @allocated GP(X, y, m, k, logNoise)
matrix_bytes = (nobs^2)*64/8
@test mem/matrix_bytes < 4.1
buf = init_precompute(gp)
GaussianProcesses.update_mll_and_dmll!(gp, buf)
mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
@test mem/matrix_bytes < 0.1
end
@testset "EmptyData" begin
k = SEIso(0.0, 0.0) + RQIso(1.0, 1.0, 1.0)
dim = 5
nobs = 1000
X = randn(dim, nobs)
y = randn(nobs)
logNoise = 0.1
m = MeanZero()
gp = GPE(X, y, m, k, logNoise, EmptyData())
mem = @allocated GPE(X, y, m, k, logNoise, EmptyData())
matrix_bytes = (nobs^2)*64/8
@test mem/matrix_bytes < 2.1
buf = init_precompute(gp)
GaussianProcesses.update_mll_and_dmll!(gp, buf)
mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
@test mem/matrix_bytes < 0.1
end
@testset "EmptyData prod kernel" begin
k = (SEIso(0.0, 0.0) + RQIso(1.0, 1.0, 1.0)) * SEIso(1.0, 1.0)
dim = 5
nobs = 1000
X = randn(dim, nobs)
y = randn(nobs)
logNoise = 0.1
m = MeanZero()
gp = GPE(X, y, m, k, logNoise, EmptyData())
mem = @allocated GPE(X, y, m, k, logNoise, EmptyData())
matrix_bytes = (nobs^2)*64/8
@test mem/matrix_bytes < 2.1
buf = init_precompute(gp)
GaussianProcesses.update_mll_and_dmll!(gp, buf)
mem = @allocated GaussianProcesses.update_mll_and_dmll!(gp, buf)
@test mem/matrix_bytes < 0.1
end
end
end