Exemplo n.º 1
0
    def test_empty_fsa(self):
        array_size = k2host.IntArray2Size(0, 0)
        fsa = k2host.Fsa.create_fsa_with_size(array_size)
        arc_map = k2host.IntArray1.create_array_with_size(fsa.size2)
        k2host.arc_sort(fsa, arc_map)
        self.assertTrue(k2host.is_empty(fsa))
        self.assertTrue(arc_map.empty())

        # test without arc_map
        k2host.arc_sort(fsa)
        self.assertTrue(k2host.is_empty(fsa))
Exemplo n.º 2
0
    def test_empty_fsa(self):
        array_size = k2host.IntArray2Size(0, 0)
        fsa = k2host.Fsa.create_fsa_with_size(array_size)
        sorter = k2host.ArcSorter(fsa)
        array_size = k2host.IntArray2Size()
        sorter.get_sizes(array_size)
        fsa_out = k2host.Fsa.create_fsa_with_size(array_size)
        arc_map = k2host.IntArray1.create_array_with_size(array_size.size2)
        sorter.get_output(fsa_out, arc_map)
        self.assertTrue(k2host.is_empty(fsa))

        # test without arc_map
        sorter.get_output(fsa_out)
        self.assertTrue(k2host.is_empty(fsa_out))
Exemplo n.º 3
0
 def test_bad_case1(self):
     s = r'''
     0 1 2 0
     1
     '''
     fsa = k2host.str_to_fsa(s)
     self.assertFalse(k2host.is_empty(fsa))
Exemplo n.º 4
0
 def test_good_case_2(self):
     s_a = r'''
     0 1 1 0
     1 2 3 0
     2 3 4 0
     3 4 -1 0
     4
     '''
     fsa = k2host.str_to_fsa(s_a)
     rand_path = k2host.RandPath(fsa, False)
     array_size = k2host.IntArray2Size()
     rand_path.get_sizes(array_size)
     path = k2host.Fsa.create_fsa_with_size(array_size)
     arc_map = k2host.IntArray1.create_array_with_size(array_size.size2)
     status = rand_path.get_output(path, arc_map)
     self.assertTrue(status)
     self.assertFalse(k2host.is_empty(path))
     self.assertFalse(arc_map.empty())
     expected_arc_indexes = torch.IntTensor([0, 1, 2, 3, 4, 4])
     expected_arcs = torch.IntTensor([[0, 1, 1, 0], [1, 2, 3, 0],
                                      [2, 3, 4, 0], [3, 4, -1, 0]])
     expected_arc_map = torch.IntTensor([0, 1, 2, 3])
     self.assertTrue(torch.equal(path.indexes, expected_arc_indexes))
     self.assertTrue(torch.equal(path.data, expected_arcs))
     self.assertTrue(torch.equal(arc_map.data, expected_arc_map))
Exemplo n.º 5
0
 def test_case_2(self):
     # a cyclic input fsa
     # after trimming, the cycle is removed;
     # so the output fsa should be topsorted.
     s = r'''
     0 1 1 0
     0 2 2 1
     1 3 3 -2
     1 6 6 -3
     2 4 2 4
     2 6 3 5
     2 6 -1 6
     5 0 1 7
     5 7 -1 8
     7
     '''
     fsa = k2host.str_to_fsa(s)
     connection = k2host.Connection(fsa)
     array_size = k2host.IntArray2Size()
     connection.get_sizes(array_size)
     fsa_out = k2host.Fsa.create_fsa_with_size(array_size)
     arc_map = k2host.IntArray1.create_array_with_size(array_size.size2)
     status = connection.get_output(fsa_out, arc_map)
     self.assertTrue(status)
     self.assertTrue(k2host.is_empty(fsa_out))
     self.assertTrue(arc_map.empty())
Exemplo n.º 6
0
    def test_case_1(self):
        # empty fsa
        array_size = k2host.IntArray2Size(0, 0)
        fsa = k2host.Fsa.create_fsa_with_size(array_size)
        sorter = k2host.TopSorter(fsa)
        array_size = k2host.IntArray2Size()
        sorter.get_sizes(array_size)
        fsa_out = k2host.Fsa.create_fsa_with_size(array_size)
        arc_map = k2host.IntArray1.create_array_with_size(array_size.size2)
        status = sorter.get_output(fsa_out, arc_map)
        self.assertTrue(status)
        self.assertTrue(k2host.is_empty(fsa_out))
        self.assertTrue(arc_map.empty())

        # test without arc_map
        sorter.get_output(fsa_out)
        self.assertTrue(k2host.is_empty(fsa_out))
Exemplo n.º 7
0
    def test_case_1(self):
        # empty fsa
        array_size = k2host.IntArray2Size(0, 0)
        fsa_a = k2host.Fsa.create_fsa_with_size(array_size)
        fsa_b = k2host.Fsa.create_fsa_with_size(array_size)
        intersection = k2host.Intersection(fsa_a, fsa_b)
        array_size = k2host.IntArray2Size()
        intersection.get_sizes(array_size)
        fsa_out = k2host.Fsa.create_fsa_with_size(array_size)
        arc_map_a = k2host.IntArray1.create_array_with_size(array_size.size2)
        arc_map_b = k2host.IntArray1.create_array_with_size(array_size.size2)
        status = intersection.get_output(fsa_out, arc_map_a, arc_map_b)
        self.assertTrue(status)
        self.assertTrue(k2host.is_empty(fsa_out))
        self.assertTrue(arc_map_a.empty())
        self.assertTrue(arc_map_b.empty())

        # test without arc_map
        status = intersection.get_output(fsa_out)
        self.assertTrue(status)
        self.assertTrue(k2host.is_empty(fsa_out))
Exemplo n.º 8
0
 def test_bad_case_1(self):
     # empty fsa
     array_size = k2host.IntArray2Size(0, 0)
     fsa = k2host.Fsa.create_fsa_with_size(array_size)
     rand_path = k2host.RandPath(fsa, False)
     array_size = k2host.IntArray2Size()
     rand_path.get_sizes(array_size)
     path = k2host.Fsa.create_fsa_with_size(array_size)
     arc_map = k2host.IntArray1.create_array_with_size(array_size.size2)
     status = rand_path.get_output(path, arc_map)
     self.assertFalse(status)
     self.assertTrue(k2host.is_empty(path))
     self.assertTrue(arc_map.empty())
Exemplo n.º 9
0
 def test_bad_case_2(self):
     # non-connected fsa
     s_a = r'''
     0 1 1 0
     0 2 2 0
     1 3 4 0
     4
     '''
     fsa = k2host.str_to_fsa(s_a)
     rand_path = k2host.RandPath(fsa, False)
     array_size = k2host.IntArray2Size()
     rand_path.get_sizes(array_size)
     path = k2host.Fsa.create_fsa_with_size(array_size)
     arc_map = k2host.IntArray1.create_array_with_size(array_size.size2)
     status = rand_path.get_output(path, arc_map)
     self.assertFalse(status)
     self.assertTrue(k2host.is_empty(path))
     self.assertTrue(arc_map.empty())
Exemplo n.º 10
0
 def test_case_1(self):
     # empty fsa
     array_size = k2host.IntArray2Size(0, 0)
     fsa_in = k2host.Fsa.create_fsa_with_size(array_size)
     indexes = torch.IntTensor([0, 1, 3, 6, 7])
     data = torch.IntTensor([1, 2, 3, 4, 5, 6, 7])
     labels_in = k2host.AuxLabels(indexes, data)
     inverter = k2host.FstInverter(fsa_in, labels_in)
     fsa_size = k2host.IntArray2Size()
     aux_size = k2host.IntArray2Size()
     inverter.get_sizes(fsa_size, aux_size)
     self.assertEqual(aux_size.size1, 0)
     self.assertEqual(aux_size.size2, 0)
     fsa_out = k2host.Fsa.create_fsa_with_size(fsa_size)
     labels_out = k2host.AuxLabels.create_array_with_size(aux_size)
     inverter.get_output(fsa_out, labels_out)
     self.assertTrue(k2host.is_empty(fsa_out))
     self.assertTrue(labels_out.empty())
Exemplo n.º 11
0
 def test_case_3(self):
     # non-connected fsa (not accessible)
     s = r'''
     0 2 -1 0
     1 0 1 0
     1 2 0 0
     2
     '''
     fsa = k2host.str_to_fsa(s)
     sorter = k2host.TopSorter(fsa)
     array_size = k2host.IntArray2Size()
     sorter.get_sizes(array_size)
     fsa_out = k2host.Fsa.create_fsa_with_size(array_size)
     state_map = k2host.IntArray1.create_array_with_size(array_size.size1)
     status = sorter.get_output(fsa_out, state_map)
     self.assertFalse(status)
     self.assertTrue(k2host.is_empty(fsa_out))
     self.assertTrue(state_map.empty())
Exemplo n.º 12
0
 def test_good_case_1(self):
     s_a = r'''
     0 1 1 0
     0 2 2 0
     1 2 3 0
     2 3 4 0
     2 4 5 0
     3 4 7 0
     4 5 9 0
     5
     '''
     fsa = k2host.str_to_fsa(s_a)
     rand_path = k2host.RandPath(fsa, False)
     array_size = k2host.IntArray2Size()
     rand_path.get_sizes(array_size)
     path = k2host.Fsa.create_fsa_with_size(array_size)
     status = rand_path.get_output(path)
     self.assertTrue(status)
     self.assertFalse(k2host.is_empty(path))
Exemplo n.º 13
0
 def test_case_3(self):
     # non-connected fsa (not accessible)
     s = r'''
     0 2 -1 0
     1 0 1 0
     1 2 0 0
     2
     '''
     fsa = k2host.str_to_fsa(s)
     sorter = k2host.TopSorter(fsa)
     array_size = k2host.IntArray2Size()
     sorter.get_sizes(array_size)
     fsa_out = k2host.Fsa.create_fsa_with_size(array_size)
     arc_map = k2host.IntArray1.create_array_with_size(array_size.size2)
     status = sorter.get_output(fsa_out, arc_map)
     self.assertTrue(status)
     self.assertFalse(k2host.is_empty(fsa_out))
     expected_arc_map = torch.IntTensor([0])
     self.assertTrue(torch.equal(arc_map.data, expected_arc_map))
Exemplo n.º 14
0
 def test_eps_arc_1(self):
     s_a = r'''
     0 1 1 0
     0 2 0 0
     1 2 3 0
     2 3 0 0
     2 4 5 0
     3 4 7 0
     4 5 9 0
     5
     '''
     fsa = k2host.str_to_fsa(s_a)
     rand_path = k2host.RandPath(fsa, True)
     array_size = k2host.IntArray2Size()
     rand_path.get_sizes(array_size)
     path = k2host.Fsa.create_fsa_with_size(array_size)
     arc_map = k2host.IntArray1.create_array_with_size(array_size.size2)
     status = rand_path.get_output(path, arc_map)
     self.assertTrue(status)
     self.assertFalse(k2host.is_empty(path))
     self.assertFalse(arc_map.empty())
Exemplo n.º 15
0
 def test_good_cases1(self):
     array_size = k2host.IntArray2Size(0, 0)
     fsa = k2host.Fsa.create_fsa_with_size(array_size)
     self.assertTrue(k2host.is_empty(fsa))