Skip to content

Commit ef309a6

Browse files
committed
Move checks to within norm_x_minus_y method for Arrays
1 parent 35c5dd3 commit ef309a6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/generic.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,12 +2004,7 @@ function isapprox(x::AbstractArray, y::AbstractArray;
20042004
atol::Real=0,
20052005
rtol::Real=Base.rtoldefault(promote_leaf_eltypes(x),promote_leaf_eltypes(y),atol),
20062006
nans::Bool=false, norm::Function=norm)
2007-
Base.promote_shape(size(x), size(y)) # ensure compatible size
2008-
d = if isempty(x) && isempty(y)
2009-
norm(zero(eltype(x)) - zero(eltype(y)))
2010-
else
2011-
norm_x_minus_y(x, y)
2012-
end
2007+
d = norm_x_minus_y(x, y)
20132008
if isfinite(d)
20142009
return iszero(rtol) ? d <= atol : d <= max(atol, rtol*max(norm(x), norm(y)))
20152010
else
@@ -2023,7 +2018,12 @@ norm_x_minus_y(x, y) = norm(x - y)
20232018
FastContiguousArrayView{T,N,P<:Array,I<:Tuple{AbstractUnitRange, Vararg{Any}}} = Base.SubArray{T,N,P,I,true}
20242019
const ArrayOrFastContiguousArrayView = Union{Array, FastContiguousArrayView}
20252020
function norm_x_minus_y(x::ArrayOrFastContiguousArrayView, y::ArrayOrFastContiguousArrayView)
2026-
norm(Iterators.map(splat(-), zip(x,y)))
2021+
Base.promote_shape(size(x), size(y)) # ensure compatible size
2022+
if isempty(x) && isempty(y)
2023+
norm(zero(eltype(x)) - zero(eltype(y)))
2024+
else
2025+
norm(Iterators.map(splat(-), zip(x,y)))
2026+
end
20272027
end
20282028

20292029
"""

0 commit comments

Comments
 (0)