From 493f680b24dc494b49cdedee626686c94103ece2 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Sat, 5 Apr 2025 23:17:05 +0530 Subject: [PATCH 1/3] Explicit loop in _iszero for strided views --- src/generic.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/generic.jl b/src/generic.jl index 2b03b249..25964ee6 100644 --- a/src/generic.jl +++ b/src/generic.jl @@ -1359,7 +1359,13 @@ _iszero(V) = iszero(V) # A Base.FastContiguousSubArray view of a StridedArray FastContiguousSubArrayStrided{T,N,P<:StridedArray,I<:Tuple{AbstractUnitRange, Vararg{Any}}} = Base.SubArray{T,N,P,I,true} # using mapreduce instead of all permits vectorization -_iszero(V::FastContiguousSubArrayStrided) = mapreduce(iszero, &, V, init=true) +function _iszero(V::FastContiguousSubArrayStrided) + ret = true + for i in eachindex(V) + ret &= iszero(@inbounds V[i]) + end + ret +end """ istriu(A::AbstractMatrix, k::Integer = 0) -> Bool From 2cc7547598c26dcbde5fe038a7f353ca60c13728 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Sun, 6 Apr 2025 09:34:30 +0530 Subject: [PATCH 2/3] Update comment --- src/generic.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/generic.jl b/src/generic.jl index 25964ee6..2d467622 100644 --- a/src/generic.jl +++ b/src/generic.jl @@ -1358,7 +1358,8 @@ ishermitian(x::Number) = (x == conj(x)) _iszero(V) = iszero(V) # A Base.FastContiguousSubArray view of a StridedArray FastContiguousSubArrayStrided{T,N,P<:StridedArray,I<:Tuple{AbstractUnitRange, Vararg{Any}}} = Base.SubArray{T,N,P,I,true} -# using mapreduce instead of all permits vectorization +# Reducing over the entire array instead of all permits vectorization +# The loop is equivalent to a mapreduce, but is faster to compile function _iszero(V::FastContiguousSubArrayStrided) ret = true for i in eachindex(V) From 41fb9531fc1e82a3f32c36623d41924b325a479d Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Sun, 6 Apr 2025 09:36:05 +0530 Subject: [PATCH 3/3] Minor update to comment --- src/generic.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generic.jl b/src/generic.jl index 2d467622..de37f081 100644 --- a/src/generic.jl +++ b/src/generic.jl @@ -1358,7 +1358,7 @@ ishermitian(x::Number) = (x == conj(x)) _iszero(V) = iszero(V) # A Base.FastContiguousSubArray view of a StridedArray FastContiguousSubArrayStrided{T,N,P<:StridedArray,I<:Tuple{AbstractUnitRange, Vararg{Any}}} = Base.SubArray{T,N,P,I,true} -# Reducing over the entire array instead of all permits vectorization +# Reducing over the entire array instead of calling `all` within `iszero` permits vectorization # The loop is equivalent to a mapreduce, but is faster to compile function _iszero(V::FastContiguousSubArrayStrided) ret = true