Skip to content

Commit

Permalink
Export SplitLayer (#41)
Browse files Browse the repository at this point in the history
also fix constructors and add tests
  • Loading branch information
nmheim authored Oct 26, 2020
1 parent 5dce6c6 commit 0e64e9c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ConditionalDists"
uuid = "c648c4dd-c1e0-49a6-84b9-144ae7fd2468"
authors = ["Niklas Heim <[email protected]>"]
version = "0.4.4"
version = "0.4.5"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
6 changes: 6 additions & 0 deletions src/ConditionalDists.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export condition

export ConditionalDistribution
export ConditionalMvNormal
export SplitLayer

include("cond_dist.jl")

Expand All @@ -25,6 +26,11 @@ function __init__()
function SplitLayer(in::Int, outs::Vector{Int}, acts::Vector)
SplitLayer(Tuple(Dense(in,o,a) for (o,a) in zip(outs,acts)))
end

function SplitLayer(in::Int, outs::Vector{Int}, act=identity)
acts = [act for _ in 1:length(outs)]
SplitLayer(in, outs, acts)
end
end
end

Expand Down
9 changes: 3 additions & 6 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
struct SplitLayer
layers::Tuple
struct SplitLayer{T<:Tuple}
layers::T
end

function SplitLayer(in::Int, outs::Vector{Int}, act=identity)
acts = [act for _ in 1:length(outs)]
SplitLayer(in, outs, acts)
end
SplitLayer(xs...) = SplitLayer(xs)

function (m::SplitLayer)(x)
Tuple(layer(x) for layer in m.layers)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ using ConditionalDists: BatchMvNormal, SplitLayer

include("cond_dist.jl")
include("cond_mvnormal.jl")
include("utils.jl")

# for the BatchMvNormal tests to work BatchMvNormals have to be functors!
include("batch_mvnormal.jl")
12 changes: 12 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@testset "SplitLayer" begin
l = SplitLayer(x->x .+ 1, _->1)
x = rand(3)
(a,b) = l(x)
@test all(a .≈ x .+ 1)
@test b == 1

l = SplitLayer(3,[2,4])
(a,b) = l(x)
@test size(a) == (2,)
@test size(b) == (4,)
end

2 comments on commit 0e64e9c

@nmheim
Copy link
Member Author

@nmheim nmheim commented on 0e64e9c Oct 26, 2020

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/23671

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.4.5 -m "<description of version>" 0e64e9cdd5a3d33a16afa92f9006bb4759236d35
git push origin v0.4.5

Please sign in to comment.