Exemple #1
0
        def test_load_map(self):
            save_map(self.dsp, self.tmp)
            dsp = Dispatcher(default_values=self.dsp.default_values)
            load_map(dsp, self.tmp)

            self.assertEqual(dsp.dmap.degree(self.fun_id),
                             self.dsp.dmap.degree(self.fun_id))
            self.assertEqual(dsp.dmap.node[self.fun_id]['function'](1), 2)
            self.assertEqual(dsp.dispatch()['b'], 6)
Exemple #2
0
    def test_replicate_function(self):
        dsp = Dispatcher()

        def fun(a):
            return a + 1, a - 1

        dsp.add_function('fun', ReplicateFunction(fun), ['a', 'b'], ['c', 'd'])

        o = dsp.dispatch(inputs={'a': 3, 'b': 4})

        self.assertEqual(o, {'a': 3, 'b': 4, 'c': (4, 2), 'd': (5, 3)})
Exemple #3
0
    def setUp(self):
        ss_dsp = Dispatcher()

        fun = lambda a: (a + 1, 5, a - 1)
        c = '|!"£$%&/()=?^*+éè[]#¶ù§çò@:;-_.,<>'
        ss_dsp.add_function(function=fun, inputs=['a'], outputs=['b', SINK, c])

        sub_dispatch = SubDispatch(ss_dsp, ['a', 'b', c], output_type='list')
        s_dsp = Dispatcher()

        s_dsp.add_function('sub_dispatch', sub_dispatch, ['a'],
                           ['b', 'c', 'd'])

        dispatch = SubDispatch(s_dsp, ['b', 'c', 'd'], output_type='list')
        dsp = Dispatcher()
        dsp.add_data('input', default_value={'a': {'a': 3, 'funcs': fun}})

        dsp.add_function('dispatch', dispatch, ['input'], [SINK, 'h', 'i'])

        dsp.dispatch()
        self.dsp = dsp
Exemple #4
0
    def setUp(self):
        ss_dsp = Dispatcher()

        fun = lambda a: (a + 1, 5, a - 1)
        dom = lambda kw: True
        c = '|!"£$%&/()=?^*+éè[]#¶ù§çò@:;-_.,<>'
        ss_dsp.add_function(function=fun,
                            inputs=['a'],
                            outputs=['b', SINK, c],
                            input_domain=dom,
                            weight=1)

        def raise_fun(a):
            raise ValueError('Error')

        ss_dsp.add_function(function=raise_fun, inputs=['a'], outputs=['b'])

        sdspfunc = SubDispatchFunction(ss_dsp, 'SubDispatchFunction', ['a'],
                                       ['b', c])

        sdsppipe = SubDispatchPipe(ss_dsp, 'SubDispatchPipe', ['a'], ['b', c])

        sdsp = SubDispatch(ss_dsp, ['b', c], output_type='list')

        s_dsp = Dispatcher()
        s_dsp.add_function(None, sdspfunc, ['a'], ['b', 'c'], weight=2)
        s_dsp.add_function(None,
                           sdsppipe, ['a'], ['b', 'c'],
                           out_weight={'c': 5})
        s_dsp.add_function('SubDispatch', sdsp, ['d'], ['e', 'f'])

        dsp = Dispatcher()
        import numpy as np
        dsp.add_data('A', default_value=np.zeros(1000))
        dsp.add_data('D', default_value={'a': 3})

        dsp.add_dispatcher(dsp=s_dsp,
                           inputs={
                               'A': 'a',
                               'D': 'd'
                           },
                           outputs={
                               'b': 'B',
                               'c': 'C',
                               'e': 'E',
                               'f': 'F'
                           },
                           inp_weight={'A': 3})
        self.sol = dsp.dispatch()
        self.dsp = dsp
Exemple #5
0
 def test_load_default_values(self):
     save_default_values(self.dsp, self.tmp)
     dsp = Dispatcher(dmap=self.dsp.dmap)
     load_default_values(dsp, self.tmp)
     self.assertEqual(dsp.default_values, self.dsp.default_values)
     self.assertEqual(dsp.dispatch()['b'], 6)