def test_axis_insertion_should_raise_error_if_pixels_is_not_a_subset_of_extended_pixels(
         self):
     a = np.ones(shape=(2, 2))
     indices = [5, 10, 12]
     indices_ext = [7, 10, 11, 12, 13, 14]
     self.assertRaises(AssertionError,
                       lambda: add_axis(a, indices, indices_ext))
def pass_message(edge, node):
    """ Pass seperator potential to clique graph.
    This just computes the conditional entropy p(clique | seperator).
    Thus the probability tables are divided taking care of the proper index structure.
    """
    extended_sep_pot = add_axis(edge['seperator_potential'],
                                edge['intersection'], node['nodes'])
    clique_pot = node['clique_potential']
    default = np.zeros_like(clique_pot)
    msg = "After extension clique and seperator potentials differ in dimensions"
    assert len(clique_pot.shape) == len(extended_sep_pot.shape), msg
    return np.divide(clique_pot,
                     extended_sep_pot,
                     out=default,
                     where=extended_sep_pot != 0)
 def test_add_one_axis_add_the_end_of_2d_array(self):
     a = np.ones(shape=(2, 2))
     indices = [10, 12]
     indices_ext = [10, 12, 14]
     self.assertEqual(add_axis(a, indices, indices_ext).shape, (2, 2, 1))
 def test_some_crazy_axis_insertions(self):
     a = np.ones(shape=(2, 2))
     indices = [10, 12]
     indices_ext = [7, 10, 11, 12, 13, 14]
     self.assertEqual(
         add_axis(a, indices, indices_ext).shape, (1, 2, 1, 2, 1, 1))
 def test_add_two_axis_at_beginning_of_2d_array(self):
     a = np.ones(shape=(2, 2))
     indices = [10, 12]
     indices_ext = [5, 7, 10, 12]
     self.assertEqual(add_axis(a, indices, indices_ext).shape, (1, 1, 2, 2))
 def test_add_one_axis_in_the_middle_of_2d_array(self):
     a = np.ones(shape=(2, 2))
     indices = [10, 12]
     indices_ext = [10, 11, 12]
     self.assertEqual(add_axis(a, indices, indices_ext).shape, (2, 1, 2))