示例#1
0
 def test_mia_compiler(self):
     """
     Test raising KeyError when missing compiler selected in
     :func:`~exa.compute.compilation.available_compilers`.
     """
     with self.assertRaises(KeyError):
         compile_function(lambda x: not x, (bool, ), compiler='__mia__')
示例#2
0
 def test_no_compilation(self):
     """
     Test no compilation in :func:`~exa.compute.compilation.compile_function`.
     """
     func = lambda x: not x
     sig, func1 = compile_function(func, bool, compiler='none')
     self.assertEqual(sig, ("cpu", "ram", "serial", bool))
     self.assertTrue(func1 is func)
示例#3
0
 def register(self, func, *itypes, **flags):
     """
     Register a new function signature.
     """
     nargs = get_nargs(func)
     ntyps = len(itypes)
     if nargs != ntyps:
         raise ValueError("Function has {} args but signature has {} entries!".format(nargs, ntyps))
     elif any(isinstance(typ, (tuple, list)) for typ in itypes):
         prod = []
         for typ in itypes:
             if isinstance(typ, (tuple, list)):
                 prod.append(typ)
             else:
                 prod.append(tuple([typ, ]))
         for typs in product(*prod):    # Recursive call to self.register
             self.register(func, *typs, **flags)
         return                         # Make sure to exit recursive calls
     # Begin registration process here, checking expanded arguments
     for typ in itypes:
         if not isinstance(typ, type):
             raise TypeError("Not a type: {}".format(typ))
     sig, func = compile_function(func, *itypes, **flags)
     self.functions[sig] = func