From ca22df5855dccaba2d1d12ac71bbf8fbc00466bd Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 13 May 2025 22:55:09 +0530 Subject: [PATCH] Specialize `map!(f, array)` --- src/mapreduce.jl | 6 ++++++ test/mapreduce.jl | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/mapreduce.jl b/src/mapreduce.jl index 2df6cd04..1e0e6e1b 100644 --- a/src/mapreduce.jl +++ b/src/mapreduce.jl @@ -110,6 +110,12 @@ enumerate_static(a::StaticArray) = StaticEnumerate(a) end end +if VERSION >= v"1.12.0-beta3" + @inline function map!(f, dest::StaticArray) + _map!(f, dest, Size(dest), dest) + end +end + @inline function map!(f, dest::StaticArray, a::StaticArray...) _map!(f, dest, same_size(dest, a...), a...) end diff --git a/test/mapreduce.jl b/test/mapreduce.jl index 902aa0ac..5fb3775a 100644 --- a/test/mapreduce.jl +++ b/test/mapreduce.jl @@ -31,6 +31,14 @@ using Statistics: mean map!(+, mv3, v1, v2, v3) @test mv3 == @MVector [7, 9, 11, 13] + if VERSION >= v"1.12.0-beta3" + @testset "map!(function, array)" begin + local mv = MVector(1,2,3) + map!(x->x^2, mv) + @test mv == SA[1,4,9] + end + end + # Output eltype for empty cases #528 @test @inferred(map(/, SVector{0,Int}(), SVector{0,Int}())) === SVector{0,Float64}() @test @inferred(map(+, SVector{0,Int}(), SVector{0,Float32}())) === SVector{0,Float32}()