diff --git a/src/Plots.jl b/src/Plots.jl index d17af86a..bb554bcf 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -106,9 +106,10 @@ export # --------------------------------------------------------- +import NaNMath # define functions (e.g. `_extrema`, that ignores NaNs, when the type is applicable. To overcome the destructive effects of https://github.com/JuliaLang/julia/pull/12563 for fun in (:extrema, :minimum, :maximum) - @eval $(Symbol(string("_",fun))){F<:AbstractFloat}(x::AbstractArray{F}) = Base.$(fun)(filter(!isnan,x)) + @eval $(Symbol(string("_",fun))){F<:AbstractFloat}(x::AbstractArray{F}) = NaNMath.$(fun)(x) @eval $(Symbol(string("_",fun)))(x) = Base.$(fun)(x) end diff --git a/src/axes.jl b/src/axes.jl index 54fe0c6d..64adc90f 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -260,8 +260,8 @@ end function expand_extrema!(ex::Extrema, v::Number) - ex.emin = _min(v, ex.emin) - ex.emax = _max(v, ex.emax) + ex.emin = NaNMath.min(v, ex.emin) + ex.emax = NaNMath.max(v, ex.emax) ex end @@ -276,8 +276,8 @@ expand_extrema!(axis::Axis, ::Bool) = axis[:extrema] function expand_extrema!{MIN<:Number,MAX<:Number}(axis::Axis, v::Tuple{MIN,MAX}) ex = axis[:extrema] - ex.emin = _min(v[1], ex.emin) - ex.emax = _max(v[2], ex.emax) + ex.emin = NaNMath.min(v[1], ex.emin) + ex.emax = NaNMath.max(v[2], ex.emax) ex end function expand_extrema!{N<:Number}(axis::Axis, v::AVec{N}) @@ -368,8 +368,8 @@ end # push the limits out slightly function widen(lmin, lmax) span = lmax - lmin - # eps = _max(1e-16, min(1e-2span, 1e-10)) - eps = _max(1e-16, 0.03span) + # eps = NaNMath.max(1e-16, min(1e-2span, 1e-10)) + eps = NaNMath.max(1e-16, 0.03span) lmin-eps, lmax+eps end @@ -425,7 +425,7 @@ function discrete_value!(axis::Axis, dv) # @show axis[:discrete_map], axis[:discrete_values], dv if cv_idx == -1 ex = axis[:extrema] - cv = _max(0.5, ex.emax + 1.0) + cv = NaNMath.max(0.5, ex.emax + 1.0) expand_extrema!(axis, cv) push!(axis[:discrete_values], dv) push!(axis[:continuous_values], cv) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index 6feba2e3..b9f8006f 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -367,14 +367,14 @@ end dist(a, b) = abs(a-b) -mindist(x, a, b) = _min(dist(a, x), dist(b, x)) +mindist(x, a, b) = NaNMath.min(dist(a, x), dist(b, x)) function gappy(x, ps) n = length(ps) x <= first(ps) && return first(ps) - x for j=1:(n-1) p0 = ps[j] - p1 = ps[_min(j+1, n)] + p1 = ps[NaNMath.min(j+1, n)] if p0 <= x && p1 >= x return mindist(x, p0, p1) * (isodd(j) ? 1 : -1) end diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 3016808c..c381ba3b 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -341,7 +341,7 @@ end function gr_set_line(lw, style, c) #, a) GR.setlinetype(gr_linetype[style]) w, h = gr_plot_size - GR.setlinewidth(_max(0, lw / ((w + h) * 0.001))) + GR.setlinewidth(NaNMath.max(0, lw / ((w + h) * 0.001))) gr_set_linecolor(c) #, a) end @@ -394,7 +394,7 @@ function gr_viewport_from_bbox(sp::Subplot{GRBackend}, bb::BoundingBox, w, h, vi viewport[4] = viewport_canvas[4] * (1.0 - top(bb) / h) if is3d(sp) vp = viewport[:] - extent = _min(vp[2] - vp[1], vp[4] - vp[3]) + extent = NaNMath.min(vp[2] - vp[1], vp[4] - vp[3]) viewport[1] = 0.5 * (vp[1] + vp[2] - extent) viewport[2] = 0.5 * (vp[1] + vp[2] + extent) viewport[3] = 0.5 * (vp[3] + vp[4] - extent) @@ -428,7 +428,7 @@ function gr_set_viewport_polar() ymax -= 0.05 * (xmax - xmin) xcenter = 0.5 * (xmin + xmax) ycenter = 0.5 * (ymin + ymax) - r = 0.5 * _min(xmax - xmin, ymax - ymin) + r = 0.5 * NaNMath.min(xmax - xmin, ymax - ymin) GR.setviewport(xcenter -r, xcenter + r, ycenter - r, ycenter + r) GR.setwindow(-1, 1, -1, 1) r diff --git a/src/backends/inspectdr.jl b/src/backends/inspectdr.jl index 85dd9c11..18b5b541 100644 --- a/src/backends/inspectdr.jl +++ b/src/backends/inspectdr.jl @@ -349,7 +349,7 @@ function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend}) ymin, ymax = axis_limits(yaxis) if ispolar(sp) #Plots.jl appears to give (xmin,xmax) ≜ (Θmin,Θmax) & (ymin,ymax) ≜ (rmin,rmax) - rmax = _max(abs(ymin), abs(ymax)) + rmax = NaNMath.max(abs(ymin), abs(ymax)) xmin, xmax = -rmax, rmax ymin, ymax = -rmax, rmax end diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 8bacb99e..124871e5 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -926,14 +926,14 @@ function py_compute_axis_minval(axis::Axis) for series in series_list(sp) v = series.d[axis[:letter]] if !isempty(v) - minval = _min(minval, _minimum(abs(v))) + minval = NaNMath.min(minval, _minimum(abs(v))) end end end # now if the axis limits go to a smaller abs value, use that instead vmin, vmax = axis_limits(axis) - minval = _min(minval, abs(vmin), abs(vmax)) + minval = NaNMath.min(minval, abs(vmin), abs(vmax)) minval end @@ -954,7 +954,7 @@ function py_set_scale(ax, axis::Axis) elseif scale == :log10 10 end - kw[Symbol(:linthresh,letter)] = _max(1e-16, py_compute_axis_minval(axis)) + kw[Symbol(:linthresh,letter)] = NaNMath.max(1e-16, py_compute_axis_minval(axis)) "symlog" end func(arg; kw...) @@ -1096,10 +1096,10 @@ function _update_min_padding!(sp::Subplot{PyPlotBackend}) bottompad = 0mm for bb in (py_bbox_axis(ax, "x"), py_bbox_axis(ax, "y"), py_bbox_title(ax)) if ispositive(width(bb)) && ispositive(height(bb)) - leftpad = _max(leftpad, left(plotbb) - left(bb)) - toppad = _max(toppad, top(plotbb) - top(bb)) - rightpad = _max(rightpad, right(bb) - right(plotbb)) - bottompad = _max(bottompad, bottom(bb) - bottom(plotbb)) + leftpad = NaNMath.max(leftpad, left(plotbb) - left(bb)) + toppad = NaNMath.max(toppad, top(plotbb) - top(bb)) + rightpad = NaNMath.max(rightpad, right(bb) - right(plotbb)) + bottompad = NaNMath.max(bottompad, bottom(bb) - bottom(plotbb)) end end diff --git a/src/layouts.jl b/src/layouts.jl index afd4e851..654b81f2 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -55,10 +55,10 @@ function Base.:+(bb1::BoundingBox, bb2::BoundingBox) ispositive(width(bb2)) || return bb1 ispositive(height(bb2)) || return bb1 - l = _min(left(bb1), left(bb2)) - t = _min(top(bb1), top(bb2)) - r = _max(right(bb1), right(bb2)) - b = _max(bottom(bb1), bottom(bb2)) + l = NaNMath.min(left(bb1), left(bb2)) + t = NaNMath.min(top(bb1), top(bb2)) + r = NaNMath.max(right(bb1), right(bb2)) + b = NaNMath.max(bottom(bb1), bottom(bb2)) BoundingBox(l, t, r-l, b-t) end diff --git a/src/recipes.jl b/src/recipes.jl index 82473795..2d52e21a 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -225,7 +225,7 @@ end fr = if yaxis[:scale] == :identity 0.0 else - _min(axis_limits(yaxis)[1], _minimum(y)) + NaNMath.min(axis_limits(yaxis)[1], _minimum(y)) end end newx, newy = zeros(3n), zeros(3n) @@ -548,7 +548,7 @@ Plots.@deps stepbins path function _auto_binning_nbins{N}(vs::NTuple{N,AbstractVector}, dim::Integer; mode::Symbol = :auto) - _cl(x) = _max(ceil(Int, x), 1) + _cl(x) = NaNMath.max(ceil(Int, x), 1) _iqr(v) = quantile(v, 0.75) - quantile(v, 0.25) _span(v) = _maximum(v) - _minimum(v) diff --git a/src/utils.jl b/src/utils.jl index 802b28e5..82fec6aa 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -6,7 +6,7 @@ function binData(data, nbins) lo, hi = _extrema(data) edges = collect(linspace(lo, hi, nbins+1)) midpoints = calcMidpoints(edges) - buckets = Int[_max(2, _min(searchsortedfirst(edges, x), length(edges)))-1 for x in data] + buckets = Int[NaNMath.max(2, NaNMath.min(searchsortedfirst(edges, x), length(edges)))-1 for x in data] counts = zeros(Int, length(midpoints)) for b in buckets counts[b] += 1 @@ -284,8 +284,8 @@ unzip{T}(xyuv::FixedSizeArrays.Vec{4,T}) = T[xyuv[1]], T[xyuv[2]], T[xyuv[ function _expand_limits(lims, x) try e1, e2 = _extrema(x) - lims[1] = _min(lims[1], e1) - lims[2] = _max(lims[2], e2) + lims[1] = NaNMath.min(lims[1], e1) + lims[2] = NaNMath.max(lims[2], e2) # catch err # warn(err) end @@ -343,7 +343,7 @@ end function calc_r_extrema(x, y) xmin, xmax = _extrema(x) ymin, ymax = _extrema(y) - r = 0.5 * _min(xmax - xmin, ymax - ymin) + r = 0.5 * NaNMath.min(xmax - xmin, ymax - ymin) _extrema(r) end