Skip to content

Commit 3f5bfea

Browse files
committed
🤖 Format .jl files
1 parent 0d76c9c commit 3f5bfea

File tree

2 files changed

+50
-51
lines changed

2 files changed

+50
-51
lines changed

src/ReadFiles.jl

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,41 @@ Expected file structure:
1818
- 3D points: 3 lines per point
1919
"""
2020
function readfile(filename::String; T::Type = Float64)
21-
open(filename) do io
22-
f = Bzip2DecompressorStream(io)
23-
24-
# First line: number of cameras, points, and observations
25-
ncams, npnts, nobs = map(x -> parse(Int, x), split(readline(f)))
26-
@debug "$filename: reading $ncams cameras, $npnts points, $nobs observations"
27-
28-
# Preallocate vectors
29-
cam_indices = Vector{Int}(undef, nobs)
30-
pnt_indices = Vector{Int}(undef, nobs)
31-
pt2d = Vector{T}(undef, 2 * nobs)
32-
x0 = Vector{T}(undef, 3 * npnts + 9 * ncams)
33-
34-
# Read observations
35-
for i = 1:nobs
36-
cam, pnt, x, y = split(readline(f))
37-
cam_indices[i] = parse(Int, cam) + 1 # Convert to 1-based indexing
38-
pnt_indices[i] = parse(Int, pnt) + 1
39-
pt2d[2 * i - 1] = parse(T, x)
40-
pt2d[2 * i] = parse(T, y)
41-
end
42-
43-
# Read camera parameters (9 values per camera)
44-
for i = 1:ncams
45-
offset = 3 * npnts + 9 * (i - 1)
46-
for j = 1:9
47-
x0[offset + j] = parse(T, readline(f))
48-
end
49-
end
50-
51-
# Read 3D points (3 coordinates per point)
52-
for k = 1:(3 * npnts)
53-
x0[k] = parse(T, readline(f))
54-
end
55-
56-
return cam_indices, pnt_indices, pt2d, x0, ncams, npnts, nobs
21+
open(filename) do io
22+
f = Bzip2DecompressorStream(io)
23+
24+
# First line: number of cameras, points, and observations
25+
ncams, npnts, nobs = map(x -> parse(Int, x), split(readline(f)))
26+
@debug "$filename: reading $ncams cameras, $npnts points, $nobs observations"
27+
28+
# Preallocate vectors
29+
cam_indices = Vector{Int}(undef, nobs)
30+
pnt_indices = Vector{Int}(undef, nobs)
31+
pt2d = Vector{T}(undef, 2 * nobs)
32+
x0 = Vector{T}(undef, 3 * npnts + 9 * ncams)
33+
34+
# Read observations
35+
for i = 1:nobs
36+
cam, pnt, x, y = split(readline(f))
37+
cam_indices[i] = parse(Int, cam) + 1 # Convert to 1-based indexing
38+
pnt_indices[i] = parse(Int, pnt) + 1
39+
pt2d[2 * i - 1] = parse(T, x)
40+
pt2d[2 * i] = parse(T, y)
5741
end
42+
43+
# Read camera parameters (9 values per camera)
44+
for i = 1:ncams
45+
offset = 3 * npnts + 9 * (i - 1)
46+
for j = 1:9
47+
x0[offset + j] = parse(T, readline(f))
48+
end
49+
end
50+
51+
# Read 3D points (3 coordinates per point)
52+
for k = 1:(3 * npnts)
53+
x0[k] = parse(T, readline(f))
54+
end
55+
56+
return cam_indices, pnt_indices, pt2d, x0, ncams, npnts, nobs
57+
end
5858
end

test/testBundleAdjustmentAllocations.jl

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,27 @@ meta_nls = nls_meta(model)
66
S = typeof(model.meta.x0)
77

88
@testset "residual allocations" begin
9-
F = S(undef, meta_nls.nequ)
9+
F = S(undef, meta_nls.nequ)
1010

11-
residual!(model, model.meta.x0, F)
12-
residual_alloc(model) = @allocated residual!(model, model.meta.x0, F)
13-
@test residual_alloc(model) == 0
11+
residual!(model, model.meta.x0, F)
12+
residual_alloc(model) = @allocated residual!(model, model.meta.x0, F)
13+
@test residual_alloc(model) == 0
1414
end
1515

1616
@testset "jac_structure_residual allocations" begin
17-
rows = Vector{Int}(undef, meta_nls.nnzj)
18-
cols = Vector{Int}(undef, meta_nls.nnzj)
17+
rows = Vector{Int}(undef, meta_nls.nnzj)
18+
cols = Vector{Int}(undef, meta_nls.nnzj)
1919

20-
jac_structure_residual!(model, rows, cols)
21-
jac_structure_residual_alloc(model, rows, cols) =
22-
@allocated jac_structure_residual!(model, rows, cols)
23-
@test jac_structure_residual_alloc(model, rows, cols) == 0
20+
jac_structure_residual!(model, rows, cols)
21+
jac_structure_residual_alloc(model, rows, cols) =
22+
@allocated jac_structure_residual!(model, rows, cols)
23+
@test jac_structure_residual_alloc(model, rows, cols) == 0
2424
end
2525

2626
@testset "jac_coord_residual allocations" begin
27-
vals = S(undef, meta_nls.nnzj)
27+
vals = S(undef, meta_nls.nnzj)
2828

29-
jac_coord_residual!(model, model.meta.x0, vals)
30-
jac_coord_residual_alloc(model, vals) =
31-
@allocated jac_coord_residual!(model, model.meta.x0, vals)
32-
@test jac_coord_residual_alloc(model, vals) == 0
29+
jac_coord_residual!(model, model.meta.x0, vals)
30+
jac_coord_residual_alloc(model, vals) = @allocated jac_coord_residual!(model, model.meta.x0, vals)
31+
@test jac_coord_residual_alloc(model, vals) == 0
3332
end

0 commit comments

Comments
 (0)