• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JoshuaLampert / KernelInterpolation.jl / 8952363003

04 May 2024 06:10PM UTC coverage: 98.715% (-0.01%) from 98.728%
8952363003

Pull #44

github

web-flow
Merge 0dd8e4ecb into 497084185
Pull Request #44: Add `SaveSolutionCallback`

70 of 70 new or added lines in 4 files covered. (100.0%)

1 existing line in 1 file now uncovered.

922 of 934 relevant lines covered (98.72%)

3073717.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/src/visualization.jl
1
@recipe function f(kernel::AbstractKernel{Dim}; x_min = -1.0, x_max = 1.0,
×
2
                   N = 50) where {Dim}
3
    if Dim == 1
18✔
4
        x = LinRange(x_min, x_max, N)
6✔
5
        title --> get_name(kernel)
12✔
6
        x, kernel.(Ref(0.0), x)
6✔
7
    elseif Dim == 2
12✔
8
        nodeset = homogeneous_hypercube(N, x_min, x_max; dim = 2)
12✔
9
        x = unique(values_along_dim(nodeset, 1))
12✔
10
        y = unique(values_along_dim(nodeset, 2))
12✔
11
        z = reshape(kernel.(Ref([0.0, 0.0]), nodeset), (N, N))
24✔
12
        seriestype --> :heatmap # :contourf
24✔
13
        title --> get_name(kernel)
24✔
14
        x, y, z
12✔
15
    else
UNCOV
16
        @error("Plotting a kernel is only supported for dimension up to 2, but the kernel has dimension $Dim")
×
17
    end
18
end
19

20
@recipe function f(x::AbstractVector, kernel::AbstractKernel)
×
21
    xguide --> "r"
6✔
22
    title --> get_name(kernel)
6✔
23
    x, kernel.(Ref(0.0), x)
3✔
24
end
25

26
@recipe function f(nodeset::NodeSet, kernel::AbstractKernel)
×
27
    if dim(nodeset) == 1
12✔
28
        x = values_along_dim(nodeset, 1)
3✔
29
        title --> get_name(kernel)
6✔
30
        x, kernel.(Ref(0.0), x)
3✔
31
    elseif dim(nodeset) == 2
9✔
32
        x = values_along_dim(nodeset, 1)
9✔
33
        y = values_along_dim(nodeset, 2)
9✔
34
        seriestype --> :scatter
15✔
35
        label --> "nodes"
18✔
36
        title --> get_name(kernel)
18✔
37
        x, y, kernel.(Ref([0.0, 0.0]), nodeset)
18✔
38
    else
39
        @error("Plotting a kernel is only supported for dimension up to 2, but the set has dimension $(dim(nodeset))")
21✔
40
    end
41
end
42

43
@recipe function f(nodeset::NodeSet)
×
44
    if dim(nodeset) == 1
15✔
45
        x = values_along_dim(nodeset, 1)
3✔
46
        seriestype := :scatter
3✔
47
        label --> "nodes"
6✔
48
        xguide --> "x"
6✔
49
        ylim --> (-0.1, 0.1)
6✔
50
        yticks --> []
6✔
51
        x, zero(x)
3✔
52
    elseif dim(nodeset) == 2
12✔
53
        x = values_along_dim(nodeset, 1)
9✔
54
        y = values_along_dim(nodeset, 2)
9✔
55
        seriestype --> :scatter
18✔
56
        label --> "nodes"
18✔
57
        xguide --> "x"
18✔
58
        yguide --> "y"
18✔
59
        # Dirty hack to have different behavior depending on there already exists a 3D plot that the nodes should be
60
        # plotted into or not. If not, the nodes are plotted in the 2D plane, otherwise inside the 3D with z = 0.
61
        # This can, e.g., be useful when the error of an inteprolation is plotted (in 3D) and then the original training
62
        # nodes should be plotted in the same 3D plot.
63
        if length(plotattributes[:plot_object].series_list) > 0
9✔
64
            if !isnothing(plotattributes[:plot_object].series_list[1][:z])
3✔
65
                x, y, zero(x)
3✔
66
            else
67
                x, y
3✔
68
            end
69
        else
70
            x, y
15✔
71
        end
72
    elseif dim(nodeset) == 3
3✔
73
        x = values_along_dim(nodeset, 1)
3✔
74
        y = values_along_dim(nodeset, 2)
3✔
75
        z = values_along_dim(nodeset, 3)
3✔
76
        seriestype --> :scatter
6✔
77
        label --> "nodes"
6✔
78
        xguide --> "x"
6✔
79
        yguide --> "y"
6✔
80
        zguide --> "z"
6✔
81
        x, y, z
3✔
82
    else
83
        @error("Plotting a NodeSet is only supported for dimension up to 3, but the set has dimension $(dim(nodeset))")
30✔
84
    end
85
end
86

87
@recipe function f(nodeset::NodeSet, itp::Interpolation; training_nodes = true)
×
88
    if dim(nodeset) == 1
51✔
89
        if training_nodes
9✔
90
            @series begin
18✔
91
                x = values_along_dim(itp.nodeset, 1)
9✔
92
                seriestype := :scatter
9✔
93
                markershape --> :star
18✔
94
                label --> "training nodes"
18✔
95
                x, itp.(x)
9✔
96
            end
97
        end
98
        @series begin
9✔
99
            x = values_along_dim(nodeset, 1)
9✔
100
            perm = sortperm(x)
9✔
101
            label --> "interpolation"
18✔
102
            xguide --> "x"
18✔
103
            yguide --> "f"
18✔
104
            x[perm], itp.(x[perm])
9✔
105
        end
106
    elseif dim(nodeset) == 2
42✔
107
        if training_nodes
42✔
108
            @series begin
84✔
109
                x = values_along_dim(itp.nodeset, 1)
42✔
110
                y = values_along_dim(itp.nodeset, 2)
42✔
111
                seriestype := :scatter
42✔
112
                markershape --> :star
84✔
113
                markersize --> 10
84✔
114
                label --> "training nodes"
84✔
115
                x, y, itp.(itp.nodeset)
42✔
116
            end
117
        end
118
        @series begin
84✔
119
            x = values_along_dim(nodeset, 1)
42✔
120
            y = values_along_dim(nodeset, 2)
42✔
121
            seriestype --> :scatter
84✔
122
            label --> "interpolation"
84✔
123
            xguide --> "x"
84✔
124
            yguide --> "y"
84✔
125
            zguide --> "f"
84✔
126
            x, y, itp.(nodeset)
42✔
127
        end
128
    else
129
        @error("Plotting an interpolation is only supported for dimension up to 2, but the interpolation has dimension $(dim(nodeset))")
93✔
130
    end
131
end
132

133
@recipe function f(itp::Interpolation; x_min = 0.0, x_max = 1.0, N = 50)
×
134
    if dim(itp) == 1
12✔
135
        x = LinRange(x_min, x_max, N)
3✔
136
        x, itp.(x)
3✔
137
    elseif dim(itp) == 2
9✔
138
        nodeset = homogeneous_hypercube(N, x_min, x_max; dim = 2)
9✔
139
        x = unique(values_along_dim(nodeset, 1))
9✔
140
        y = unique(values_along_dim(nodeset, 2))
9✔
141
        z = reshape(itp.(nodeset), (N, N))'
9✔
142
        xguide --> "x"
18✔
143
        yguide --> "y"
18✔
144
        seriestype --> :heatmap # :contourf
12✔
145
        x, y, z
9✔
146
    else
147
        @error("Plotting an interpolation is only supported for dimension up to 2, but the interpolation has dimension $(dim(itp))")
21✔
148
    end
149
end
150

151
@recipe function f(nodeset::NodeSet, vals::AbstractVector)
×
152
    if dim(nodeset) == 1
42✔
153
        @series begin
6✔
154
            x = values_along_dim(nodeset, 1)
6✔
155
            perm = sortperm(x)
6✔
156
            label --> "f"
12✔
157
            xguide --> "x"
12✔
158
            yguide --> "f"
12✔
159
            x[perm], vals[perm]
6✔
160
        end
161
    elseif dim(nodeset) == 2
36✔
162
        @series begin
72✔
163
            x = values_along_dim(nodeset, 1)
36✔
164
            y = values_along_dim(nodeset, 2)
36✔
165
            seriestype --> :scatter
66✔
166
            label --> "f"
72✔
167
            xguide --> "x"
72✔
168
            yguide --> "y"
72✔
169
            zguide --> "f"
72✔
170
            x, y, vals
36✔
171
        end
172
    else
173
        @error("Plotting an interpolation is only supported for dimension up to 2, but the interpolation has dimension $(dim(nodeset))")
78✔
174
    end
175
end
176

177
@recipe function f(nodeset::NodeSet, f::Function)
×
178
    nodeset, f.(nodeset)
42✔
179
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2024 Coveralls, Inc