Skip to content

Commit

Permalink
Extend kron support (#1458)
Browse files Browse the repository at this point in the history
* Bump patch

* Generalise kron implementation
  • Loading branch information
willtebbutt committed Sep 27, 2023
1 parent 415ec0a commit cf7f7d0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Zygote"
uuid = "e88e6eb3-aa80-5325-afca-941959d7151f"
version = "0.6.64"
version = "0.6.65"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
8 changes: 3 additions & 5 deletions src/lib/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,10 @@ function _kron(mat1::AbstractMatrix,mat2::AbstractMatrix)
return reshape(mat1_rsh.*mat2_rsh, (m1*m2,n1*n2))
end
_kron(a::AbstractVector, b::AbstractVector) = vec(_kron(reshape(a, :, 1), reshape(b, :, 1)))
_kron(a::AbstractVector, b::AbstractMatrix) = _kron(reshape(a, :, 1), b)
_kron(a::AbstractMatrix, b::AbstractVector) = _kron(a, reshape(b, :, 1))

function _pullback(cx::AContext, ::typeof(kron), a::AbstractVector, b::AbstractVector)
res, back = _pullback(cx, _kron, a, b)
return res, back unthunk_tangent
end
function _pullback(cx::AContext, ::typeof(kron), a::AbstractMatrix, b::AbstractMatrix)
function _pullback(cx::AContext, ::typeof(kron), a::AbstractVecOrMat, b::AbstractVecOrMat)
res, back = _pullback(cx, _kron, a, b)
return res, back unthunk_tangent
end
Expand Down
2 changes: 2 additions & 0 deletions test/gradcheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ end
@test gradtest(kron, rand(5,1), rand(3,1))
@test gradtest(kron, rand(5,1), rand(3,1), rand(8,1))
@test gradtest(kron, rand(5,2), rand(3,2), rand(8,2))
@test gradtest(kron, rand(5), rand(3, 2))
@test gradtest(kron, rand(3, 2), rand(5))

for mapfunc in [map,pmap]
@testset "$mapfunc" begin
Expand Down

2 comments on commit cf7f7d0

@willtebbutt
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/92295

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.6.65 -m "<description of version>" cf7f7d08705d2787fa31bcf45bcca5447fd9a9a7
git push origin v0.6.65

Please sign in to comment.