|
| 1 | +real_rep(a::AbstractArray{Complex{T}, N}) where {T, N} = reinterpret(reshape, T, a) |
| 2 | +#PtrArray(Ptr{T}(pointer(a)), (StaticInt(2), size(a)...)) |
| 3 | + |
| 4 | +@inline function _matmul!(_C::AbstractMatrix{Complex{T}}, _A::AbstractMatrix{Complex{U}}, _B::AbstractMatrix{Complex{V}}, |
| 5 | + α=One(), β=Zero(), nthread::Nothing=nothing, MKN=nothing, contig_axis=nothing) where {T,U,V} |
| 6 | + C, A, B = real_rep.((_C, _A, _B)) |
| 7 | + |
| 8 | + η = ifelse(ArrayInterface.is_lazy_conjugate(_A), StaticInt(-1), StaticInt(1)) |
| 9 | + θ = ifelse(ArrayInterface.is_lazy_conjugate(_B), StaticInt(-1), StaticInt(1)) |
| 10 | + (+ᶻ, -ᶻ) = ifelse(ArrayInterface.is_lazy_conjugate(_C), (-, +), (+, -)) |
| 11 | + ηθ = η*θ |
| 12 | + |
| 13 | + @avxt for n ∈ indices((C, B), 3), m ∈ indices((C, A), 2) |
| 14 | + Cmn_re = zero(T) |
| 15 | + Cmn_im = zero(T) |
| 16 | + for k ∈ indices((A, B), (3, 2)) |
| 17 | + Cmn_re += A[1, m, k] * B[1, k, n] - ηθ * A[2, m, k] * B[2, k, n] |
| 18 | + Cmn_im += θ * A[1, m, k] * B[2, k, n] + η * A[2, m, k] * B[1, k, n] |
| 19 | + end |
| 20 | + C[1,m,n] = (real(α) * Cmn_re -ᶻ imag(α) * Cmn_im) + (real(β) * C[1,m,n] -ᶻ imag(β) * C[2,m,n]) |
| 21 | + C[2,m,n] = (imag(α) * Cmn_re +ᶻ real(α) * Cmn_im) + (imag(β) * C[1,m,n] +ᶻ real(β) * C[2,m,n]) |
| 22 | + end |
| 23 | + _C |
| 24 | +end |
| 25 | + |
| 26 | +@inline function _matmul!(_C::AbstractMatrix{Complex{T}}, A::AbstractMatrix{U}, _B::AbstractMatrix{Complex{V}}, |
| 27 | + α=One(), β=Zero(), nthread::Nothing=nothing, MKN=nothing, contig_axis=nothing) where {T,U,V} |
| 28 | + C, B = real_rep.((_C, _B)) |
| 29 | + |
| 30 | + θ = ifelse(ArrayInterface.is_lazy_conjugate(_B), StaticInt(-1), StaticInt(1)) |
| 31 | + (+ᶻ, -ᶻ) = ifelse(ArrayInterface.is_lazy_conjugate(_C), (-, +), (+, -)) |
| 32 | + |
| 33 | + @avxt for n ∈ indices((C, B), 3), m ∈ indices((C, A), (2, 1)) |
| 34 | + Cmn_re = zero(T) |
| 35 | + Cmn_im = zero(T) |
| 36 | + for k ∈ indices((A, B), (2, 2)) |
| 37 | + Cmn_re += A[m, k] * B[1, k, n] |
| 38 | + Cmn_im += θ * A[m, k] * B[2, k, n] |
| 39 | + end |
| 40 | + C[1,m,n] = (real(α) * Cmn_re -ᶻ imag(α) * Cmn_im) + (real(β) * C[1,m,n] -ᶻ imag(β) * C[2,m,n]) |
| 41 | + C[2,m,n] = (imag(α) * Cmn_re +ᶻ real(α) * Cmn_im) + (imag(β) * C[1,m,n] +ᶻ real(β) * C[2,m,n]) |
| 42 | + end |
| 43 | + _C |
| 44 | +end |
| 45 | + |
| 46 | +@inline function _matmul!(_C::AbstractMatrix{Complex{T}}, _A::AbstractMatrix{Complex{U}}, B::AbstractMatrix{V}, |
| 47 | + α=One(), β=Zero(), nthread::Nothing=nothing, MKN=nothing, contig_axis=nothing) where {T,U,V} |
| 48 | + C, A = real_rep.((_C, _A)) |
| 49 | + |
| 50 | + η = ifelse(ArrayInterface.is_lazy_conjugate(_A), StaticInt(-1), StaticInt(1)) |
| 51 | + (+ᶻ, -ᶻ) = ifelse(ArrayInterface.is_lazy_conjugate(_C), (-, +), (+, -)) |
| 52 | + |
| 53 | + @avxt for n ∈ indices((C, B), (3, 2)), m ∈ indices((C, A), 2) |
| 54 | + Cmn_re = zero(T) |
| 55 | + Cmn_im = zero(T) |
| 56 | + for k ∈ indices((A, B), (3, 1)) |
| 57 | + Cmn_re += A[1, m, k] * B[k, n] |
| 58 | + Cmn_im += η * A[2, m, k] * B[k, n] |
| 59 | + end |
| 60 | + C[1,m,n] = (real(α) * Cmn_re -ᶻ imag(α) * Cmn_im) + (real(β) * C[1,m,n] -ᶻ imag(β) * C[2,m,n]) |
| 61 | + C[2,m,n] = (imag(α) * Cmn_re +ᶻ real(α) * Cmn_im) + (imag(β) * C[1,m,n] +ᶻ real(β) * C[2,m,n]) |
| 62 | + end |
| 63 | + _C |
| 64 | +end |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +@inline function _matmul_serial!(_C::AbstractMatrix{Complex{T}}, _A::AbstractMatrix{Complex{U}}, _B::AbstractMatrix{Complex{V}}, |
| 71 | + α=One(), β=Zero(), MKN=nothing, contig_axis=nothing) where {T,U,V} |
| 72 | + C, A, B = real_rep.((_C, _A, _B)) |
| 73 | + |
| 74 | + η = ifelse(ArrayInterface.is_lazy_conjugate(_A), StaticInt(-1), StaticInt(1)) |
| 75 | + θ = ifelse(ArrayInterface.is_lazy_conjugate(_B), StaticInt(-1), StaticInt(1)) |
| 76 | + (+ᶻ, -ᶻ) = ifelse(ArrayInterface.is_lazy_conjugate(_C), (-, +), (+, -)) |
| 77 | + ηθ = η*θ |
| 78 | + @avxt for n ∈ indices((C, B), 3), m ∈ indices((C, A), 2) |
| 79 | + Cmn_re = zero(T) |
| 80 | + Cmn_im = zero(T) |
| 81 | + for k ∈ indices((A, B), (3, 2)) |
| 82 | + Cmn_re += A[1, m, k] * B[1, k, n] - ηθ * A[2, m, k] * B[2, k, n] |
| 83 | + Cmn_im += θ * A[1, m, k] * B[2, k, n] + η * A[2, m, k] * B[1, k, n] |
| 84 | + end |
| 85 | + C[1,m,n] = (real(α) * Cmn_re -ᶻ imag(α) * Cmn_im) + (real(β) * C[1,m,n] -ᶻ imag(β) * C[2,m,n]) |
| 86 | + C[2,m,n] = (imag(α) * Cmn_re +ᶻ real(α) * Cmn_im) + (imag(β) * C[1,m,n] +ᶻ real(β) * C[2,m,n]) |
| 87 | + end |
| 88 | + _C |
| 89 | +end |
| 90 | + |
| 91 | +@inline function _matmul_serial!(_C::AbstractMatrix{Complex{T}}, A::AbstractMatrix{U}, _B::AbstractMatrix{Complex{V}}, |
| 92 | + α=One(), β=Zero(), MKN=nothing, contig_axis=nothing) where {T,U,V} |
| 93 | + C, B = real_rep.((_C, _B)) |
| 94 | + |
| 95 | + θ = ifelse(ArrayInterface.is_lazy_conjugate(_B), StaticInt(-1), StaticInt(1)) |
| 96 | + (+ᶻ, -ᶻ) = ifelse(ArrayInterface.is_lazy_conjugate(_C), (-, +), (+, -)) |
| 97 | + |
| 98 | + @avx for n ∈ indices((C, B), 3), m ∈ indices((C, A), (2, 1)) |
| 99 | + Cmn_re = zero(T) |
| 100 | + Cmn_im = zero(T) |
| 101 | + for k ∈ indices((A, B), (2, 2)) |
| 102 | + Cmn_re += A[m, k] * B[1, k, n] |
| 103 | + Cmn_im += θ * A[m, k] * B[2, k, n] |
| 104 | + end |
| 105 | + C[1,m,n] = (real(α) * Cmn_re -ᶻ imag(α) * Cmn_im) + (real(β) * C[1,m,n] -ᶻ imag(β) * C[2,m,n]) |
| 106 | + C[2,m,n] = (imag(α) * Cmn_re +ᶻ real(α) * Cmn_im) + (imag(β) * C[1,m,n] +ᶻ real(β) * C[2,m,n]) |
| 107 | + end |
| 108 | + _C |
| 109 | +end |
| 110 | + |
| 111 | +@inline function _matmul_serial!(_C::AbstractMatrix{Complex{T}}, _A::AbstractMatrix{Complex{U}}, B::AbstractMatrix{V}, |
| 112 | + α=One(), β=Zero(), MKN=nothing, contig_axis=nothing) where {T,U,V} |
| 113 | + C, A = real_rep.((_C, _A)) |
| 114 | + |
| 115 | + η = ifelse(ArrayInterface.is_lazy_conjugate(_A), StaticInt(-1), StaticInt(1)) |
| 116 | + (+ᶻ, -ᶻ) = ifelse(ArrayInterface.is_lazy_conjugate(_C), (-, +), (+, -)) |
| 117 | + |
| 118 | + @avx for n ∈ indices((C, B), (3, 2)), m ∈ indices((C, A), 2) |
| 119 | + Cmn_re = zero(T) |
| 120 | + Cmn_im = zero(T) |
| 121 | + for k ∈ indices((A, B), (3, 1)) |
| 122 | + Cmn_re += A[1, m, k] * B[k, n] |
| 123 | + Cmn_im += η * A[2, m, k] * B[k, n] |
| 124 | + end |
| 125 | + C[1,m,n] = (real(α) * Cmn_re -ᶻ imag(α) * Cmn_im) + (real(β) * C[1,m,n] -ᶻ imag(β) * C[2,m,n]) |
| 126 | + C[2,m,n] = (imag(α) * Cmn_re +ᶻ real(α) * Cmn_im) + (imag(β) * C[1,m,n] +ᶻ real(β) * C[2,m,n]) |
| 127 | + end |
| 128 | + _C |
| 129 | +end |
0 commit comments