Skip to content

Commit

Permalink
specialize broadcast only for native types, fixes #77
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed Jul 21, 2023
1 parent 3a5f3d9 commit fcdc0cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StrideArrays"
uuid = "d1fa6d79-ef01-42a6-86c9-f7c551f8593b"
authors = ["Chris Elrod <[email protected]> and contributors"]
version = "0.1.25"
version = "0.1.26"

[deps]
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
Expand Down
30 changes: 3 additions & 27 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct LinearStyle{S,N,R} <: AbstractStrideStyle{S,N} end
struct CartesianStyle{S,N} <: AbstractStrideStyle{S,N} end
@generated function Base.BroadcastStyle(
::Type{A}
) where {T,N,R,S,X,A<:AbstractStrideArray{T,N,R,S,X}}
) where {T<:VectorizationBase.NativeTypes,N,R,S,X,A<:AbstractStrideArray{T,N,R,S,X}}
t = Expr(:curly, :Tuple)
for x X.parameters
x === nothing || return CartesianStyle{S,N}()
Expand All @@ -19,44 +19,20 @@ struct CartesianStyle{S,N} <: AbstractStrideStyle{S,N} end
end
:(LinearStyle{$t,$N,$R}())
end
# Base.BroadcastStyle(::Type{A}) where {S,T,N,X,SN,XN,A<:AbstractStrideArray{S,T,N,X,SN,XN,true}} = CartesianStyle{S,N}()
# function reverse_simplevec(S, N = length(S))
# Srev = Expr(:curly, :Tuple)
# for n ∈ 1:N
# push!(Srev.args, S.parameters[N + 1 - n])
# end
# if N == 1
# N += 1
# insert!(Srev.args, 2, 1)
# end
# Srev, N
# # end
# @generated function Base.BroadcastStyle(::Type{Adjoint{T,A}}) where {S,T,N,A<:AbstractStrideArray{S,T,N}}
# Srev, Nrev = reverse_simplevec(S, N)
# Expr(:call, Expr(:curly, :CartesianStyle, Srev, Nrev))
# end
# @generated function Base.BroadcastStyle(::Type{Transpose{T,A}}) where {S,T,N,A<:AbstractStrideArray{S,T,N}}
# Srev, Nrev = reverse_simplevec(S, N)
# Expr(:call, Expr(:curly, :CartesianStyle, Srev, Nrev))
# end

const StrideArrayProduct = Union{
LoopVectorization.Product{<:AbstractStrideArray},
LoopVectorization.Product{<:Any,<:AbstractStrideArray},
LoopVectorization.Product{<:AbstractStrideArray,<:AbstractStrideArray}
# LoopVectorization.Product{Adjoint{<:Any,<:AbstractFixedSizeArray}},
# LoopVectorization.Product{Transpose{<:Any,<:AbstractFixedSizeArray}},
# LoopVectorization.Product{<:Any,Adjoint{<:Any,<:AbstractFixedSizeArray}},
# LoopVectorization.Product{<:Any,Transpose{<:Any,<:AbstractFixedSizeArray}}
}

@generated function Base.BroadcastStyle(
::Type{P}
) where {
SA,
A<:AbstractStrideArray{<:Any,<:Any,<:Any,SA},
A<:AbstractStrideArray{<:VectorizationBase.NativeTypes,<:Any,<:Any,SA},
SB,
B<:AbstractStrideArray{<:Any,<:Any,<:Any,SB},
B<:AbstractStrideArray{<:VectorizationBase.NativeTypes,<:Any,<:Any,SB},
P<:LoopVectorization.Product{A,B}
}
t = Expr(:curly, :Tuple)
Expand Down

2 comments on commit fcdc0cc

@chriselrod
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/88074

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.26 -m "<description of version>" fcdc0cc3ae69b04723be156147e137d0203ff7a5
git push origin v0.1.26

Please sign in to comment.