Skip to content

Commit

Permalink
Added missing impl of output_size for ComposedFunction (#296)
Browse files Browse the repository at this point in the history
* add `output_size` for `ComposedFunction`

* add tests for `output_size` for `ComposedFunction`

* bump patch version

* Update test/bijectors/stacked.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
torfjelde and github-actions[bot] authored Dec 4, 2023
1 parent 04b79dd commit 75b5d15
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Bijectors"
uuid = "76274a88-744f-5084-9051-94815aaf08c4"
version = "0.13.7"
version = "0.13.8"

[deps]
ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197"
Expand Down
1 change: 1 addition & 0 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ with_logabsdet_jacobian(f::Columnwise, x::AbstractMatrix) = (f(x), logabsdetjac(
Returns the output size of `f` given the input size `sz`.
"""
output_size(f, sz) = sz
output_size(f::ComposedFunction, sz) = output_size(f.outer, output_size(f.inner, sz))

"""
output_length(f, len::Int)
Expand Down
40 changes: 40 additions & 0 deletions test/bijectors/stacked.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,44 @@ end
@test y == [exp(1.0), 2.0]
@test binv(y) == [1.0, 2.0, 0.0]
end

@testset "composition" begin
# Composition with one dimension reduction.
b = Stacked((elementwise(exp), ProjectionBijector() identity), [1:1, 2:3])
binv = inverse(b)
x = [1.0, 2.0, 3.0]
y = b(x)
x_ = binv(y)

# Are the values of correct size?
@test size(y) == (2,)
@test size(x_) == (3,)
# Can we determine the sizes correctly?
@test Bijectors.output_size(b, size(x)) == (2,)
@test Bijectors.output_size(binv, size(y)) == (3,)

# Are values correct?
@test y == [exp(1.0), 2.0]
@test binv(y) == [1.0, 2.0, 0.0]

# Composition with two dimension reductions.
b = Stacked(
(elementwise(exp), ProjectionBijector() ProjectionBijector()), [1:1, 2:4]
)
binv = inverse(b)
x = [1.0, 2.0, 3.0, 4.0]
y = b(x)
x_ = binv(y)

# Are the values of correct size?
@test size(y) == (2,)
@test size(x_) == (4,)
# Can we determine the sizes correctly?
@test Bijectors.output_size(b, size(x)) == (2,)
@test Bijectors.output_size(binv, size(y)) == (4,)

# Are values correct?
@test y == [exp(1.0), 2.0]
@test binv(y) == [1.0, 2.0, 0.0, 0.0]
end
end

2 comments on commit 75b5d15

@torfjelde
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/96456

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 v0.13.8 -m "<description of version>" 75b5d1556449fa66e2aa4a17943dc10e772b22b5
git push origin v0.13.8

Please sign in to comment.