Skip to content

Commit

Permalink
Add inv for SequentialTransform
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Jul 26, 2023
1 parent 81f50c2 commit 49c5439
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/sequential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,12 @@ struct SequentialTransform <: Transform
transforms::Vector{Transform}
end

# AbstractTrees interface
AbstractTrees.nodevalue(::SequentialTransform) = SequentialTransform
AbstractTrees.children(s::SequentialTransform) = s.transforms

Base.show(io::IO, s::SequentialTransform) =
print(io, join(s.transforms, ""))

function Base.show(io::IO, ::MIME"text/plain", s::SequentialTransform)
tree = AbstractTrees.repr_tree(s, context=io)
print(io, tree[begin:end-1]) # remove \n at end
end

isrevertible(s::SequentialTransform) = all(isrevertible, s.transforms)

isinvertible(s::SequentialTransform) = all(isinvertible, s.transforms)

Base.inv(s::SequentialTransform) = SequentialTransform([inv(t) for t in reverse(s.transforms)])

function apply(s::SequentialTransform, table)
allcache = []
current = table
Expand Down Expand Up @@ -80,3 +70,15 @@ Create a [`SequentialTransform`](@ref) transform with
(t1::Identity, t2::Identity) = Identity()
(t1::Transform, t2::Identity) = t1
(t1::Identity, t2::Transform) = t2

# AbstractTrees interface
AbstractTrees.nodevalue(::SequentialTransform) = SequentialTransform
AbstractTrees.children(s::SequentialTransform) = s.transforms

Base.show(io::IO, s::SequentialTransform) =
print(io, join(s.transforms, ""))

function Base.show(io::IO, ::MIME"text/plain", s::SequentialTransform)
tree = AbstractTrees.repr_tree(s, context=io)
print(io, tree[begin:end-1]) # remove \n at end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ using Test
@test TransformsBase.isrevertible(Identity())
@test TransformsBase.isinvertible(Identity())
@test inv(Identity()) == Identity()
@test inv(Identity() Identity()) == Identity()
@test (Identity() Identity()) == Identity()
end

2 comments on commit 49c5439

@juliohm
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 updated: JuliaRegistries/General/88391

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.1.0 -m "<description of version>" 49c54392beaea4e5a8f53e12b9dde7415a89e145
git push origin v1.1.0

Please sign in to comment.