Skip to content

Commit 763abf4

Browse files
authored
Yet more CoreBoxes fixes. (#1878)
1 parent ac79b5d commit 763abf4

7 files changed

Lines changed: 20 additions & 13 deletions

File tree

src/beziers.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,20 @@ function bezier(p::Matrix{<:Real}; t=nothing, np::Int=0, pure=false, firstcurve=
114114
end
115115

116116
function helper_bezier_cb(o::Matrix{Float64}, p::Matrix{Float64}, t, firstcurve::Bool)::Matrix{Float64}
117-
# Made this function barrier to restrict the Core.box. For some incomprehensible reason, 'o' becomes
118-
# a Core.box and that happens due to the appending (the 'vcats' below). Both Cthulhu and the debugger
119-
# show that 'o' is no longer a Core.box when it lands on the calling function.
120117
# This function is not efficient due to the matrix concatenations, but it's not expeced to cat much data.
121118
for k = 5:size(p, 1)
122119
oo = bezier(p[k-3,:], p[k-2,:], p[k-1,:], p[k,:]; t=t)
120+
d = Vector{Float64}(undef, size(oo, 1))
123121
if (firstcurve)
124122
xn = o[end,1]; yn = o[end,2]; zn = o[end,3]
125-
d::Vector{Float64} = [(oo[n,1] - xn)^2 + (oo[n,2] - yn)^2 + (oo[n,3] - zn)^2 for n = 1:size(oo, 1)]
123+
@inbounds for n = 1:size(oo, 1)
124+
d[n] = (oo[n,1] - xn)^2 + (oo[n,2] - yn)^2 + (oo[n,3] - zn)^2
125+
end
126126
else
127127
xn = oo[1,1]; yn = oo[1,2]; zn = oo[1,3]
128-
d = [(o[n,1] - xn)^2 + (o[n,2] - yn)^2 + (o[n,3] - zn)^2 for n = 1:size(oo, 1)]
128+
@inbounds for n = 1:size(oo, 1)
129+
d[n] = (o[n,1] - xn)^2 + (o[n,2] - yn)^2 + (o[n,3] - zn)^2
130+
end
129131
end
130132
m = argmin(d)
131133
o = firstcurve ? vcat(o, oo[m+1:end,:]) : vcat(o[1:m,:], oo)

src/gdal_utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function gd2gmt_helper_scalefac(mat::Array{<:Real}, scale_factor, add_offset, go
157157
if (eltype(mat) <: Integer)
158158
mat = mat .* scale_factor .+ add_offset # Also promotes (and pay) the array to float32
159159
else
160-
@inbounds Threads.@threads for k = 1:lastindex(mat) mat[k] = mat[k] * scale_factor + add_offset end
160+
@inbounds for k = 1:lastindex(mat) mat[k] = mat[k] * scale_factor + add_offset end
161161
end
162162
end
163163
(got_fill_val) && (mat[nodata] .= NaN)

src/img_funs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function helper_rgb2ycbcr(I::GMTimage{UInt8,3}, c1, c2, c3, add)
249249
end
250250
else
251251
i = 0
252-
@inbounds Threads.@threads for ij = 1:3:3nxy
252+
@inbounds for ij = 1:3:3nxy
253253
img[i+=1] = round(UInt8, add + c1 * _Img[ij] + c2 * _Img[ij+1] + c3 * _Img[ij+2])
254254
end
255255
end

src/plot.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,11 @@ function piechart(x::VecOrMat; first::Bool=true, kw...)
19931993
data[k, 4] = data[k-1, 3]
19941994
end
19951995

1996-
mid_angs = [(data[k, 3] + data[k, 4]) / 2 for k = 1:numel(x)] # Compute the bissections angles
1996+
#mid_angs = [(data[k, 3] + data[k, 4]) / 2 for k = 1:numel(x)] # Compute the bissections angles
1997+
mid_angs = Vector{Float64}(undef, length(x))
1998+
@inbounds for k = 1:numel(x) # Compute the bissections angles
1999+
mid_angs[k] = (data[k, 3] + data[k, 4]) / 2
2000+
end
19972001

19982002
do_explode = false
19992003
non_exploded = ones(Bool, length(X)) # Default to no explosion

src/remotegrids.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function remotegrid(name, res_p::String=""; res::String="", reg::String="", info
209209
end
210210
(info == 1 && n_under > 1) && (@warn("No information for $(name) available when resolution was also specified"); return "")
211211

212-
function check_reg(name, grdtype, reg, ind)
212+
function check_reg(name, grdtype, reg, ind, res)
213213
# Check if 'reg' is valid for 'name' and 'grdtype' and set 'name' accordingly
214214
_reg = lowercase(reg[1])
215215
(_reg != 'p' && _reg != 'g') && error("Bad registration code $(reg). Must be one of 'grid' or 'pixel'")
@@ -225,15 +225,15 @@ function remotegrid(name, res_p::String=""; res::String="", reg::String="", info
225225
ind::Int = _ind # Fck Anys
226226
(res != "5m") ? (res = thisgrid_res[ind]) : (res = "05m") # 5m is an exception because it may be miscatch by 15m
227227
name *= "_" * res
228-
(reg != "") && (name = check_reg(name, thisgrid, reg, ind))
228+
(reg != "") && (name = check_reg(name, thisgrid, reg, ind, res))
229229
elseif (n_under == 2 && reg != "") # name & type & res
230230
ind_res::Int = findlast(name, '_')
231231
thisgrid = eval(Symbol(name[1:ind_res-1]))
232232
res = name[ind_res+1:end]
233233
length(res) == 2 && (res = "0" * res) # To allow both 01d and 1d
234234
((_ind = findfirst(contains.(thisgrid_res, res))) === nothing) && error("Bad resolution code $(res). Must be one of $thisgrid_res.")
235235
ind = _ind
236-
name = check_reg(name, thisgrid, reg, ind)
236+
name = check_reg(name, thisgrid, reg, ind, res)
237237
end
238238

239239
return "@" * name

src/solids.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ Create a torus mesh with radius `r`.
349349
- `ny`: the number of vertices in the yy direction.
350350
"""
351351
function torus(; r=2.0, R=5.0, center=(0.0, 0.0, 0.0), nx=100, ny=50)::GMTfv
352-
if (R < r) R, r = r, R end
352+
_r = (r < R) ? r : R # Can't simply do this because of CoreBoxes: #if (R < r) R, r = r, R end
353+
_R = (r < R) ? R : r
353354
Θ, ϕ = range(-pi,pi,nx), range(-pi,pi,ny)
354355
x = [(R + cos(v)) * cos(u) + center[1] for u in Θ, v in ϕ]
355356
y = [(R + cos(v)) * sin(u) + center[2] for u in Θ, v in ϕ]

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ function isnodata(array::AbstractArray, val=0)
606606
else indNaN = fill(false, nrows, ncols)
607607
end
608608
@inbounds Threads.@threads for k = 1:nrows * ncols * nlayers # 5x faster than: indNaN = (I.image .== 0)
609-
(array[k] == val) && (indNaN[k] = true)
609+
(array[k] == val) && (indNaN[k] = true) # With Threads.@threads it insists indNaN is a CoreBox but it's 2x faster
610610
end
611611
indNaN
612612
end

0 commit comments

Comments
 (0)