Skip to content

Commit

Permalink
Make array isapprox more generic by avoiding zip/explicit iteration (
Browse files Browse the repository at this point in the history
…#44893)

* Avoid explicit array iteration in isapprox

This is more generic and works for, e.g., gpu arrays
  • Loading branch information
danielwe authored Sep 30, 2022
1 parent 4db5ffa commit ec5fe69
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,8 @@ function isapprox(x::AbstractArray, y::AbstractArray;
return d <= max(atol, rtol*max(norm(x), norm(y)))
else
# Fall back to a component-wise approximate comparison
return all(ab -> isapprox(ab[1], ab[2]; rtol=rtol, atol=atol, nans=nans), zip(x, y))
# (mapreduce instead of all for greater generality [#44893])
return mapreduce((a, b) -> isapprox(a, b; rtol=rtol, atol=atol, nans=nans), &, x, y)
end
end

Expand Down

0 comments on commit ec5fe69

Please sign in to comment.