Skip to content

Commit

Permalink
fix: update invert to work like connect
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Aug 16, 2024
1 parent 19594b6 commit 3001991
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion rustfst-python/rustfst/algorithms/inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
from rustfst.fst.vector_fst import VectorFst


def invert(fst: VectorFst):
def invert(fst: VectorFst) -> VectorFst:
"""
Invert the transduction corresponding to an FST by exchanging the
FST's input and output labels in-place.
Args:
fst: FST to be inverted.
Returns:
self
"""

ret_code = lib.fst_invert(fst.ptr)
err_msg = "Error during invert"
check_ffi_error(ret_code, err_msg)

return fst
7 changes: 7 additions & 0 deletions rustfst-python/rustfst/fst/vector_fst.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,13 @@ def isomorphic(self, other: VectorFst) -> bool:
return isomorphic(self, other)

def invert(self) -> VectorFst:
"""
Invert the transduction corresponding to an FST by exchanging the
FST's input and output labels in-place.
Returns:
self
"""
from rustfst.algorithms.inversion import invert

return invert(self)
Expand Down
2 changes: 1 addition & 1 deletion rustfst-python/tests/algorithms/test_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_invert():
tr1_4 = Tr(3, 5, 1.0, s3)
fst1.add_tr(s2, tr1_4)

fst1.invert()
fst1 = fst1.invert()

# Expected FST
expected_fst = VectorFst()
Expand Down

0 comments on commit 3001991

Please sign in to comment.