Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Strided"
uuid = "5e0ebb24-38b0-5f93-81fe-25c709ecae67"
version = "2.6.4"
version = "2.6.5"
authors = ["Lukas Devos <lukas.devos@ugent.be>", "Maarten Van Damme <maartenvd1994@gmail.com>", "Jutho Haegeman <jutho.haegeman@ugent.be>"]

[deps]
Expand Down
7 changes: 7 additions & 0 deletions src/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions test/othertests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading