Esempio n. 1
0
def test_kernel_design():
    """
    Every kernel must be
    1. must have a name defined
    2. must be callable with two samples
    3. returns a number

    """

    for kernel in SupportedKernels:

        # must be callable with 2 args
        check_callable(kernel, min_num_args=2)

        if not hasattr(kernel, 'name'):
            raise TypeError('{} does not have name attribute!'.format(kernel))

        # only numeric data is accepted and other dtypes must raise an error
        for non_catg in [(True, False, True), [1.0, 2.4], [object, object]]:
            with raises(TypeError):
                _ = kernel(non_catg, non_catg)
def test_kernel_design():
    """
    Every kernel must be
    1. must have a name defined
    2. must be callable with two samples
    3. returns a number

    """

    for kernel in DEFINED_KERNEL_FUNCS:

        # must be callable with 2 args
        check_callable(kernel, min_num_args=2)

        if not hasattr(kernel, 'name'):
            raise TypeError('{} does not have name attribute!'.format(kernel))

        # only numeric data is accepted and other dtypes must raise an error
        for non_num in ['string', [object, object]]:
            with raises(ValueError):
                _ = kernel(non_num, non_num)
Esempio n. 3
0
def test_misc():

    _ = get_callable_name(test_ensure_array_dim, 'test')
    _ = get_callable_name('test_ensure_array_dim', None)

    with raises(TypeError):
        check_callable('kdjkj')

    def func_with_less_than_min_args(): return None

    with raises(TypeError):
        check_callable(func_with_less_than_min_args)

    with raises(TypeError):
        check_callable(func_with_less_than_min_args, 1)

    with raises(TypeError):
        check_callable(func_with_less_than_min_args, 3)

    assert not_symmetric(np.array([[1, 2], [1, 2]])) is True
Esempio n. 4
0
    def __init__(self, input_func, name=None, **func_params):
        """
        Constructor.

        Parameters
        ----------
        input_func : callable
            A callable that can accept atleast 2 args
            Must not be builtin or C function.
            If func is a C or builtin func, wrap it in a python def

        name : str
            A name to identify this kernel in a human readable way

        func_params : dict
            Parameters to func

        """

        self.func = check_callable(input_func, min_num_args=2)
        self.params = func_params

        super().__init__(name=get_callable_name(input_func, name))