Skip to content

Commit

Permalink
Fix Zygote issues with FunctionTransform (#152)
Browse files Browse the repository at this point in the history
* Fix Zygote issues for functional transform

* Resolve tests

* Clean up

* Avoid splatting, use reduce instead

* Remove rrules for reduce(hcat)
  • Loading branch information
sharanry authored Aug 15, 2020
1 parent 0df9e83 commit f144045
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/transform/functiontransform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,21 @@ end
(t::FunctionTransform)(x) = t.f(x)

_map(t::FunctionTransform, x::AbstractVector{<:Real}) = map(t.f, x)
_map(t::FunctionTransform, x::ColVecs) = ColVecs(mapslices(t.f, x.X; dims=1))
_map(t::FunctionTransform, x::RowVecs) = RowVecs(mapslices(t.f, x.X; dims=2))


function _map(t::FunctionTransform, x::ColVecs)
vals = map(axes(x.X, 2)) do i
t.f(view(x.X, :, i))
end
return ColVecs(reduce(hcat, vals))
end

function _map(t::FunctionTransform, x::RowVecs)
vals = map(axes(x.X, 1)) do i
t.f(view(x.X, i, :))
end
return RowVecs(reduce(hcat, vals)')
end

duplicate(t::FunctionTransform,f) = FunctionTransform(f)

Expand Down
3 changes: 1 addition & 2 deletions test/transform/functiontransform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@

@test repr(FunctionTransform(sin)) == "Function Transform: $(sin)"
f(a, x) = sin.(a .* x)
test_ADs(x->transform(SEKernel(), FunctionTransform(y->f(x, y))), randn(rng, 3), ADs = [:ForwardDiff, :ReverseDiff])
@test_broken "Zygote is failing"
test_ADs(x->transform(SEKernel(), FunctionTransform(y->f(x, y))), randn(rng, 3))
end

0 comments on commit f144045

Please sign in to comment.