Skip to content

no method matching promote_vtype(::Type{SVec{8,Float64}}, ::Type{SVec{4,Float64}}), etc. #150

@mcabbott

Description

@mcabbott

I was trying things which keep only the first match, related to this thread. And I get some errors I don't understand, seemingly mixing SVec of different lengths. Are these bugs or am I doing something too weird?

using LoopVectorization # LoopVectorization v0.8.24
using LoopVectorization.VectorizationBase: SVec, Mask, prevpow2

@inline onlyone(cond::Bool, seen::Union{Int,SVec}) = cond && allzero(seen)
@inline onlyone(cond::Mask{W}, seen::Union{Int,SVec}) where {W} =
    allzero(seen) ? Mask(prevpow2(cond.u)) : zero(cond) 

@inline allzero(seen::Int) = iszero(seen)
@inline allzero(seen::SVec{N,Int}) where {N} = iszero((!iszero(seen)).u)

sv = SVec{4,Int}(1,2,3,4) # SVec{4,Int64}<1, 2, 3, 4>
ms = Mask(0x03) # Mask{8,Bool}<1, 1, 0, 0, 0, 0, 0, 0>
onlyone(ms, 0) == Mask(0x02)
onlyone(ms, sv) == Mask(0x00)
onlyone(ms, zero(sv)) == Mask(0x02)

function match!(y, x, res, zed)
    seen = 0
    @avx for i in 1:4
        flag = onlyone(res == x[i], seen)
        y[i] = ifelse(flag, zed, 0.0)
        seen += any(flag)
    end
    y
end
match!(rand(4), 1:4, 3, 5.6) # ERROR: MethodError: no method matching vstore!(::Ptr{Float64}, ::NTuple{8,VecElement{Float64}}, ::VectorizationBase._MM{4,Int64})

function grad1!(𝛥x, 𝛥ℛ::AbstractArray{𝒯}, ℛ, x) where {𝒯}
    seen = 0
    @avx for i = 1:4
        flag = onlyone(ℛ[1] == x[i], seen)
        𝛥x[i] += ifelse(flag, 𝛥ℛ[1], zero(𝒯))
        seen += any(flag)
    end
    𝛥x
end
grad1!(zeros(4), [5.6], [3], [1,2,3,3]) # MethodError: no method matching promote_vtype(::Type{SVec{8,Float64}}, ::Type{SVec{4,Float64}})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions