Skip to content

Commit 219e430

Browse files
authored
add precompile statements - SnoopPrecompile (#10)
1 parent fa3e135 commit 219e430

6 files changed

Lines changed: 74 additions & 58 deletions

File tree

.JuliaFormatter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
annotate_untyped_fields_with_any = false
22
short_to_long_function_def = false
3+
long_to_short_function_def = true
34
whitespace_ops_in_indices = true
45
remove_extra_newlines = true
56
whitespace_in_kwargs = true

.github/workflows/CI.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,15 @@ jobs:
3030
version: '1'
3131
arch: x64
3232
steps:
33-
- uses: actions/checkout@v2
34-
- uses: julia-actions/setup-julia@v1
33+
- uses: actions/checkout@v3
34+
- uses: julia-actions/setup-julia@latest
3535
with:
3636
version: ${{ matrix.version }}
3737
arch: ${{ matrix.arch }}
38-
- uses: actions/cache@v2
39-
env:
40-
cache-name: cache-artifacts
41-
with:
42-
path: ~/.julia/artifacts
43-
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
44-
restore-keys: |
45-
${{ runner.os }}-test-${{ env.cache-name }}-
46-
${{ runner.os }}-test-
47-
${{ runner.os }}-
48-
- uses: julia-actions/julia-buildpkg@v1
49-
- uses: julia-actions/julia-runtest@v1
50-
- uses: julia-actions/julia-processcoverage@v1
51-
- uses: codecov/codecov-action@v1
38+
- uses: julia-actions/cache@v1
39+
- uses: julia-actions/julia-buildpkg@latest
40+
- uses: julia-actions/julia-runtest@latest
41+
- uses: julia-actions/julia-processcoverage@latest
42+
- uses: codecov/codecov-action@v3
5243
with:
5344
file: lcov.info

Project.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ uuid = "299715c1-40a9-479a-aaf9-4a633d36f717"
33
version = "0.1.3"
44

55
[deps]
6+
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
67
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
78

9+
[compat]
10+
StaticArrays = "0.12, 1"
11+
SnoopPrecompile = "1"
12+
julia = "1.6"
13+
814
[extras]
915
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
1016
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
1117
PlyIO = "42171d58-473b-503a-8d5f-782019eb09ec"
1218
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1319

14-
[compat]
15-
StaticArrays = "0.12, 1"
16-
julia = "1"
17-
1820
[targets]
1921
test = ["BenchmarkTools", "Meshes", "PlyIO", "Test"]

src/MarchingCubes.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ Adapted to `Julia` by T Bltg (github.com/t-bltg).
1919

2020
module MarchingCubes
2121

22-
import Base: RefValue
22+
using SnoopPrecompile
2323
using StaticArrays
2424

25+
import Base: RefValue
26+
2527
export MC, march, march_legacy
2628

2729
include("lut.jl")
@@ -690,4 +692,10 @@ end
690692

691693
include("example.jl")
692694

695+
@precompile_setup begin
696+
@precompile_all_calls begin
697+
march(MarchingCubes.scenario(4, 4, 4; F = Float64, I = Int))
698+
end
699+
end
700+
693701
end

src/example.jl

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
scenario(nx = 60, ny = 60, nz = 60; case = :torus2) = begin
2-
F = Float32
1+
scenario(nx = 60, ny = 60, nz = 60; F = Float32, I = Int32, case = :torus2) = begin
32
vol = zeros(F, nx, ny, nz)
43

54
sx, sy, sz = size(vol) ./ F(16)
@@ -10,46 +9,37 @@ scenario(nx = 60, ny = 60, nz = 60; case = :torus2) = begin
109
r = F(1.85)
1110
R = F(4)
1211

13-
cushin(x, y, z) =
14-
z^2 * x^2 - z^4 - 2z * x^2 + 2z^3 + x^2 - z^2 - (x^2 - z)^2 - y^4 - 2x^2 * y^2 -
15-
y^2 * z^2 +
16-
2y^2 * z +
17-
y^2
18-
19-
torus2(x, y, z) =
20-
((x^2 + y^2 + z^2 + R^2 - r^2)^2 - 4R^2 * (x^2 + y^2)) *
21-
((x^2 + (y + R)^2 + z^2 + R^2 - r^2)^2 - 4R^2 * ((y + R)^2 + z^2))
22-
23-
sphere(x, y, z) = (
24-
((x - 2)^2 + (y - 2)^2 + (z - 2)^2 - 1) *
25-
((x + 2)^2 + (y - 2)^2 + (z - 2)^2 - 1) *
26-
((x - 2)^2 + (y + 2)^2 + (z - 2)^2 - 1)
27-
)
28-
29-
plane(x, y, z) = x + y + z - 3
30-
31-
cassini(x, y, z) =
32-
(x^2 + y^2 + z^2 + F(0.45)^2)^2 - 16 * F(0.45)^2 * (x^2 + z^2) - F(0.5)^2
33-
34-
blooby(x, y, z) = x^4 - 5x^2 + y^4 - 5y^2 + z^4 - 5z^2 + F(11.8)
35-
36-
hyperboloid(x, y, z) = x^2 + y^2 - z^2 - 1
37-
38-
callback = (;
39-
cushin = cushin,
40-
torus2 = torus2,
41-
sphere = sphere,
42-
plane = plane,
43-
cassini = cassini,
44-
blooby = blooby,
45-
hyperboloid = hyperboloid,
46-
)[case]
12+
callback = if case :cushin
13+
(x, y, z) ->
14+
z^2 * x^2 - z^4 - 2z * x^2 + 2z^3 + x^2 - z^2 - (x^2 - z)^2 - y^4 - 2x^2 * y^2 - y^2 * z^2 +
15+
2y^2 * z +
16+
y^2
17+
elseif case :torus2
18+
(x, y, z) ->
19+
((x^2 + y^2 + z^2 + R^2 - r^2)^2 - 4R^2 * (x^2 + y^2)) *
20+
((x^2 + (y + R)^2 + z^2 + R^2 - r^2)^2 - 4R^2 * ((y + R)^2 + z^2))
21+
elseif case :sphere
22+
(x, y, z) -> (
23+
((x - 2)^2 + (y - 2)^2 + (z - 2)^2 - 1) *
24+
((x + 2)^2 + (y - 2)^2 + (z - 2)^2 - 1) *
25+
((x - 2)^2 + (y + 2)^2 + (z - 2)^2 - 1)
26+
)
27+
elseif case :plane
28+
(x, y, z) -> x + y + z - 3
29+
elseif case :cassini
30+
(x, y, z) ->
31+
(x^2 + y^2 + z^2 + F(0.45)^2)^2 - 16 * F(0.45)^2 * (x^2 + z^2) - F(0.5)^2
32+
elseif case :blooby
33+
(x, y, z) -> x^4 - 5x^2 + y^4 - 5y^2 + z^4 - 5z^2 + F(11.8)
34+
elseif case :hyperboloid
35+
(x, y, z) -> x^2 + y^2 - z^2 - 1
36+
end
4737

4838
for k 1:nz, j 1:ny, i 1:nx
4939
vol[i, j, k] = callback((i - 1) / sx - tx, (j - 1) / sy - ty, (k - 1) / sz - tz)
5040
end
5141

52-
MC(vol, Int32)
42+
MC(vol, I)
5343
end
5444

5545
output(PlyIO::Module, m::MC, fn::AbstractString = "test.ply") = begin

test/runtests.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ end
6262
@test length(mc.triangles) == 24_118
6363
end
6464

65+
@testset "cushin" begin
66+
mc = MarchingCubes.scenario(case = :cushin)
67+
bytes = @allocated march(mc)
68+
@test bytes == 0
69+
@test length(mc.vertices) == 302
70+
@test length(mc.triangles) == 600
71+
end
72+
73+
@testset "cassini" begin
74+
mc = MarchingCubes.scenario(case = :cassini)
75+
bytes = @allocated march(mc)
76+
@test bytes == 0
77+
@test length(mc.vertices) == 554
78+
@test length(mc.triangles) == 1_104
79+
end
80+
81+
@testset "blooby" begin
82+
mc = MarchingCubes.scenario(case = :blooby)
83+
bytes = @allocated march(mc)
84+
@test bytes == 0
85+
@test length(mc.vertices) == 2_168
86+
@test length(mc.triangles) == 4_352
87+
end
88+
6589
@testset "isovalue" begin
6690
dat = Float32[(x - 3)^2 + (y - 3)^2 + (z - 3)^2 for x 1:5, y 1:5, z 1:5]
6791

0 commit comments

Comments
 (0)