Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
add compose (k2-fsa#543)
Browse files Browse the repository at this point in the history
* add compose.

* update doc.

* fix a typo.

* fix compose.

b_fsa.aux_labels can be a ragged tensor.

* add missing files for ragged shape doc.

* fix style issues.
  • Loading branch information
csukuangfj authored Dec 23, 2020
1 parent 013cba2 commit c29066a
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ exclude =
ignore =
# E127 continuation line over-indented for visual indent
E127,
# F401, import but not used
F401,
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cmake_minimum_required(VERSION 3.8 FATAL_ERROR)

project(k2 CUDA CXX)

set(K2_VERSION "0.1.1")
set(K2_VERSION "0.1.2")

# ----------------- Supported build types for K2 project -----------------
set(ALLOWABLE_BUILD_TYPES Debug Release RelWithDebInfo MinSizeRel)
Expand Down
15 changes: 13 additions & 2 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,26 @@ To run tests in parallel::

cd build
make -j
ctest --parallel <JOBNUM>
ctest --output-on-failure --parallel <JOBNUM>

If `valgrind` is installed, you can check heap corruptions and memory leaks by::

cd build
make -j
ctest -R <TESTNAME> -D ExperimentalMemCheck
ctest --output-on-failure -R <TESTNAME> -D ExperimentalMemCheck

.. HINT::

You can install `valgrind` with `sudo apt-get install valgrind`
on Ubuntu.

Reporting issues
----------------

If you encounter any errors while using k2 after installation, please
create an issue `on GitHub <https://github.com/k2-fsa/k2/issues/new>`_
and tell us your current environment by posting the output of the following
two commands::

python3 -m k2.version
python3 -m torch.utils.collect_env
15 changes: 15 additions & 0 deletions docs/source/python_api/fsa_algo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ connect

.. autofunction:: connect

compose
-------

.. autofunction:: compose

determinize
-----------

Expand All @@ -47,6 +52,11 @@ intersect_dense_pruned

.. autofunction:: intersect_dense_pruned

invert
------

.. autofunction:: invert

linear_fsa
----------

Expand All @@ -57,6 +67,11 @@ remove_epsilon

.. autofunction:: remove_epsilon

remove_epsilons_iterative_tropical
----------------------------------

.. autofunction:: remove_epsilons_iterative_tropical

shortest_path
-------------

Expand Down
1 change: 1 addition & 0 deletions docs/source/python_api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Python API Reference
version
ops
ragged_ops
ragged_shape
_k2
5 changes: 5 additions & 0 deletions docs/source/python_api/ragged_ops.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ index

.. autofunction:: index

remove_axis
-----------

.. autofunction:: remove_axis

remove_values_leq
------------------

Expand Down
15 changes: 15 additions & 0 deletions docs/source/python_api/ragged_shape.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ragged_shape
============

.. currentmodule:: k2.ragged

create_ragged_shape2
--------------------

.. autofunction:: create_ragged_shape2


compose_ragged_shapes
---------------------

.. autofunction:: compose_ragged_shapes
7 changes: 4 additions & 3 deletions k2/python/k2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
from . import utils

from .autograd import get_tot_scores
from .autograd import intersect_dense_pruned
from .autograd import intersect_dense
from .autograd import intersect_dense_pruned
from .autograd import union
from .dense_fsa_vec import DenseFsaVec
from .dense_fsa_vec import convert_dense_to_fsa_vec
from .fsa import Fsa
from .fsa_algo import add_epsilon_self_loops
from .fsa_algo import arc_sort
from .fsa_algo import closure
from .fsa_algo import compose
from .fsa_algo import connect
from .fsa_algo import determinize
from .fsa_algo import intersect
Expand Down Expand Up @@ -48,13 +49,14 @@
__all__ = [
'DenseFsaVec',
'Fsa',
'SymbolTable',
'RaggedInt',
'RaggedShape',
'SymbolTable',
'add_epsilon_self_loops',
'arc_sort',
'autograd_utils',
'closure',
'compose',
'connect',
'convert_dense_to_fsa_vec',
'create_fsa_vec',
Expand Down Expand Up @@ -83,5 +85,4 @@
'to_tensor',
'top_sort',
'union',
'use_cuda',
]
6 changes: 3 additions & 3 deletions k2/python/k2/fsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from _k2 import RaggedArc



class Fsa(object):
'''This class represents a single fsa or a vector of fsas.
Expand Down Expand Up @@ -436,7 +435,7 @@ def get_incoming_arcs(self) -> _k2.RaggedInt:
name, cache = 'incoming_arcs', self._cache
if name not in cache:
cache[name] = _k2.get_incoming_arcs(self.arcs,
self.get_dest_states())
self.get_dest_states())
return cache[name]

def get_entering_arc_batches(self) -> _k2.RaggedInt:
Expand Down Expand Up @@ -770,7 +769,8 @@ def __getitem__(self, i: int) -> 'Fsa':

# The following is a magic invocation to make sure
# the backprop on the scores happens.
k2.autograd_utils.phantom_set_scores_to(out_fsa, self.scores[start:end])
k2.autograd_utils.phantom_set_scores_to(out_fsa,
self.scores[start:end])

return out_fsa

Expand Down
Loading

0 comments on commit c29066a

Please sign in to comment.