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

Let muladd accept arrays #37065

Merged
merged 7 commits into from
Oct 29, 2020
Merged
Changes from 1 commit
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
Next Next commit
muladd for arrays
  • Loading branch information
Michael Abbott committed Oct 5, 2020
commit 805eae98324e17d870c4f61711a06ef4414390cf
31 changes: 31 additions & 0 deletions stdlib/LinearAlgebra/src/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,37 @@ for elty in (Float32,Float64)
end
end

"""
muladd(A, y, z)

Combined multiply-add, `A*y .+ z`, for either matrix-matrix multiplication or
matrix-vector multiplication. The result is always the size of `A*y`, although
`z` have fewer dimensions.

# Examples
```jldoctest
julia> A=[1.0 2.0; 3.0 4.0]; B=[1.0 1.0; 1.0 1.0]; C=[0, 100];

julia> muladd(A, B, C)
2×2 Matrix{Float64}:
3.0 3.0
107.0 107.0
```
"""
function Base.muladd(A::AbstractMatrix{TA}, y::AbstractVector{Ty}, z::AbstractVector{Tz}) where {TA, Ty, Tz}
T = promote_type(TA, Ty, Tz)
C = similar(A, T, size(A,1))
C .= z
mul!(C, A, y, true, true)
end

function Base.muladd(A::AbstractMatrix{TA}, y::AbstractMatrix{Ty}, z::AbstractVecOrMat{Tz}) where {TA, Ty, Tz}
T = promote_type(TA, Ty, Tz)
C = similar(A, T, size(A,1), size(y,2))
C .= z
mul!(C, A, y, true, true)
end

"""
mul!(Y, A, B) -> Y

Expand Down