Skip to content

Commit

Permalink
muladd! with adjoints/transposes (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty authored May 20, 2024
1 parent f9fd686 commit fbc7d72
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ArrayLayouts"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
authors = ["Sheehan Olver <[email protected]>"]
version = "1.9.2"
version = "1.9.3"

[deps]
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand Down
4 changes: 4 additions & 0 deletions src/ArrayLayouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ Base.permutedims(D::Diagonal{<:Any,<:LayoutVector}) = D

zero!(A) = zero!(MemoryLayout(A), A)
zero!(_, A) = fill!(A,zero(eltype(A)))
function zero!(::DualLayout, A)
zero!(parent(A))
A
end
function zero!(_, A::AbstractArray{<:AbstractArray})
for a in A
zero!(a)
Expand Down
2 changes: 1 addition & 1 deletion src/muladd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ materialize(M::MulAdd) = copy(instantiate(M))
copy(M::MulAdd) = copyto!(similar(M), M)

_fill_copyto!(dest, C) = copyto!(dest, C)
_fill_copyto!(dest, C::Zeros) = zero!(dest) # exploit special fill! overload
_fill_copyto!(dest, C::Union{Zeros,AdjOrTrans{<:Any,<:Zeros}}) = zero!(dest) # exploit special fill! overload

@inline copyto!(dest::AbstractArray{T}, M::MulAdd) where T =
muladd!(M.α, unalias(dest,M.A), unalias(dest,M.B), M.β, _fill_copyto!(dest, M.C); Czero = M.Czero)
Expand Down
8 changes: 8 additions & 0 deletions test/test_muladd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,14 @@ Random.seed!(0)
@test copy(M) b * D * α + c * β
end
end

@testset "dual" begin
a = randn(5)
X = randn(5,6)
@test copyto!(similar(a,6)', MulAdd(2.0, a', X, 3.0, Zeros(6)')) 2a'*X
@test copyto!(transpose(similar(a,6)), MulAdd(2.0, a', X, 3.0, Zeros(6)')) 2a'*X
@test copyto!(transpose(similar(a,6)), MulAdd(2.0, transpose(a), X, 3.0, transpose(Zeros(6)))) 2a'*X
end
end

end

2 comments on commit fbc7d72

@dlfivefifty
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/107222

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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 v1.9.3 -m "<description of version>" fbc7d72c9e5caafc14bd8dada4a291b4e2fa5121
git push origin v1.9.3

Please sign in to comment.