diff --git a/Project.toml b/Project.toml index c483aaa..bba7c4f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Strided" uuid = "5e0ebb24-38b0-5f93-81fe-25c709ecae67" -version = "2.6.4" +version = "2.6.5" authors = ["Lukas Devos ", "Maarten Van Damme ", "Jutho Haegeman "] [deps] diff --git a/src/mapreduce.jl b/src/mapreduce.jl index 45e3980..be02584 100644 --- a/src/mapreduce.jl +++ b/src/mapreduce.jl @@ -6,6 +6,13 @@ LinearAlgebra.adjoint!(dst::StridedView, src::StridedView) = copy!(dst, adjoint( LinearAlgebra.transpose!(C::StridedView, A::StridedView) = copy!(C, transpose(A)) Base.permutedims!(dst::StridedView, src::StridedView, p) = copy!(dst, permutedims(src, p)) Base.fill!(A::StridedView, val) = map!(Returns(val), A, A) +function Base.fill!( + A::StridedView{<:Union{BigFloat, Complex{BigFloat}, BigInt, Complex{BigInt}}}, val + ) + isempty(A) && return A + _mapreduce_order!(Returns(val), nothing, nothing, size(A), (A,)) + return A +end # This is a wrapper function intended to allow us to # intercept "conj" and rewrite it in cases where the diff --git a/test/othertests.jl b/test/othertests.jl index 556b860..ba873b1 100644 --- a/test/othertests.jl +++ b/test/othertests.jl @@ -155,6 +155,37 @@ end end end +@testset "fill! and reductions with undef-initialized BigFloat/BigInt storage" begin + @testset for T in (BigFloat, Complex{BigFloat}, BigInt, Complex{BigInt}) + # test the specific path in src/mapreduce here that avoids undefined + # reference errors + @test collect(fill!(StridedView(Vector{T}(undef, 5)), one(T))) == ones(T, 5) + + A = StridedView(Vector{T}(undef, 12), (2, 3), (1, 4), 0) + @test collect(fill!(A, T(3))) == fill(T(3), 2, 3) + + B = StridedView(Vector{T}(undef, 6), (2, 3), (-1, 2), 1) + @test collect(fill!(B, T(5))) == fill(T(5), 2, 3) + + @test fill!(StridedView(Vector{T}(undef, 0), (0,), (1,), 0), one(T)) |> isempty + + S = StridedView(Vector{T}(undef, 1), (), (), 0) + @test fill!(S, T(7))[] == T(7) + + R = T[1, 4, 2, 3, 5, 6] + V, M = StridedView(copy(R), (2, 3), (1, 2), 0), reshape(copy(R), 2, 3) + @test norm(V) == norm(M) + @test sum(V) == sum(M) + @test prod(V) == prod(M) + @test maximum(abs, V) == maximum(abs, M) + @test minimum(abs, V) == minimum(abs, M) + + # large enough to reach the threaded reduction path + L = StridedView(Vector{T}(undef, 1 << 17)) + @test sum(fill!(L, T(2))) == T(2) * (1 << 17) + end +end + @testset "0-dimensional (scalar) StridedView" begin @testset for T in (Float32, Float64, ComplexF32, ComplexF64) R = fill(rand(T)) # 0-dimensional Array