Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix broadcast issue #55 #60

Merged
merged 3 commits into from
Dec 1, 2022
Merged
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: 2 additions & 0 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ end
::Base.Broadcast.DefaultArrayStyle{N2},
) where {S,N1,N2} = N2 > N1 ? Base.Broadcast.Unknown() : CartesianStyle{S,N1}()
Base.BroadcastStyle(a::CartesianStyle{S,N}, ::AbstractStrideStyle{S,N}) where {S,N} = a
Base.BroadcastStyle(::AbstractStrideStyle{S,N}, a::CartesianStyle{S,N}) where {S,N} = a
Base.BroadcastStyle(a::CartesianStyle{S,N}, ::CartesianStyle{S,N}) where {S,N} = a # resolve ambiguities
Base.BroadcastStyle(a::LinearStyle{S,N,R}, ::LinearStyle{S,N,R}) where {S,N,R} = a # ranks match
Base.BroadcastStyle(::LinearStyle{S,N}, ::LinearStyle{S,N}) where {S,N} =
CartesianStyle{S,N}() # ranks don't match
Expand Down
20 changes: 17 additions & 3 deletions test/broadcast_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using StrideArrays, Test
A .= zero(eltype(A))
@test all(==(0), A)



u1 = StrideArray(ones(1, 10), (static(1), 10));
u2 = StrideArray(collect(2:2:20)', (static(1), 10));
Expand All @@ -31,14 +31,28 @@ using StrideArrays, Test
@test u3[1,1] == 2
@test u3[2,1] == 2
@test all(isone, @view(u3[:,2:end]))

@views u1[:, 1] .= u4[:, 1]
@views u3[:, 1] .= u4[:, 1]
@test u1[1] == 0
@test all(isone, @view(u1[1,2:end]))
@test u3[1,1] == 0
@test u3[2,1] == 0
@test all(isone, @view(u3[:,2:end]))

# end

@testset "issue #55" begin
src1 = rand(10)
src2 = rand(length(src1))
dst = zero(src1)

src1_ptr = PtrArray(src1)
src2_ptr = PtrArray(src2)
dst_ptr = PtrArray(dst)

@test_nowarn @. dst_ptr = muladd(1, src1_ptr, 2 * src2_ptr)
@. dst = muladd(1, src1, 2 * src2)
@test dst_ptr ≈ dst
end
end
13 changes: 8 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ const START_TIME = time()

@time @testset "StrideArrays.jl" begin
@test isempty(Test.detect_unbound_args(StrideArrays))

@time Aqua.test_all(StrideArrays, ambiguities = false, project_toml_formatting = false, deps_compat = VERSION <= v"1.8" || isempty(VERSION.prerelease))
# Currently, there is one method ambiguity:
# - map(f::F, A::AbstractStrideArray, args::Vararg{Any, K}) where {F, K} in StrideArrays at StrideArrays/src/miscellaneous.jl:22
# - map(f, a1::AbstractArray, a2::StaticArrays.StaticArray, as::AbstractArray...) in StaticArrays at StaticArrays/0bweZ/src/mapreduce.jl:33
@time @test length(Test.detect_ambiguities(StrideArrays)) <= 1
# Currently, there are five method ambiguities:
# (rand!(A::AbstractStrideArray, args::Vararg{Any, K}) where K in StrideArrays at StrideArrays/src/rand.jl:3, rand!(f::F, rng::VectorizedRNG.AbstractVRNG, x::AbstractArray{T}, α::Number, β, γ) where {T<:Union{Float32, Float64}, F} in VectorizedRNG at VectorizedRNG/L3orR/src/api.jl:242)
# (map(f::F, A::AbstractStrideArray, args::Vararg{Any, K}) where {F, K} in StrideArrays at StrideArrays/src/miscellaneous.jl:37, map(f, a1::AbstractArray, a2::StaticArraysCore.StaticArray, as::AbstractArray...) in StaticArrays at StaticArrays/B0HhH/src/mapreduce.jl:33)
# (rand!(A::AbstractStrideArray, args::Vararg{Any, K}) where K in StrideArrays at StrideArrays/src/rand.jl:3, rand!(f::F, rng::VectorizedRNG.AbstractVRNG, x::AbstractArray{T}, α::Number, β) where {T<:Union{Float32, Float64}, F} in VectorizedRNG at VectorizedRNG/L3orR/src/api.jl:242)
# (rand!(A::AbstractStrideArray, args::Vararg{Any, K}) where K in StrideArrays at StrideArrays/src/rand.jl:3, rand!(f::F, rng::VectorizedRNG.AbstractVRNG, x::AbstractArray{T}) where {T<:Union{Float32, Float64}, F} in VectorizedRNG at VectorizedRNG/L3orR/src/api.jl:242)
# (rand!(A::AbstractStrideArray, args::Vararg{Any, K}) where K in StrideArrays at StrideArrays/src/rand.jl:3, rand!(f::F, rng::VectorizedRNG.AbstractVRNG, x::AbstractArray{T}, α::Number) where {T<:Union{Float32, Float64}, F} in VectorizedRNG at VectorizedRNG/L3orR/src/api.jl:242)
@time @test length(Test.detect_ambiguities(StrideArrays)) <= 5
# @test isempty(detect_unbound_args(StrideArrays))
@time include("matmul_tests.jl")
@time include("misc.jl")
Expand Down