# Path: veidt/utils/general_utils.py
# def deserialize_veidt_object(identifier, module_objects=None,
#                              printable_module_name='object'):
#     if isinstance(identifier, dict):
#         # dealing with configuration dictionary
#         config = identifier
#         if 'class_name' not in config or 'config' not in config:
#             raise ValueError('Improper config format: ' + str(config))
#         class_name = config['class_name']
#         module_objects = module_objects or {}
#         cls = module_objects.get(class_name)
#         if cls is None:
#             raise ValueError('Unknown ' + printable_module_name +
#                              ': ' + class_name)
#         return cls(**config['config'])
# 
#     elif isinstance(identifier, str):
#         function_name = identifier
#         fn = module_objects.get(function_name)
#         if fn is None:
#             raise ValueError('Unknown ' + printable_module_name +
#                              ':' + function_name)
#         return fn


import numpy as np
from veidt.utils.general_utils import deserialize_veidt_object


# now the kernels are defined as functions
# For future development the kernel should be class
# with tunable parameters, this is particular useful for Bayesian methods
def rbf(x1, x2, sigma):
    d_squared = np.sum((x1[:, None, :] - x2[None, :, :]) ** 2, axis=2)
    return np.exp(-d_squared / (2 * sigma ** 2))


def get_kernel(identifier):
    if isinstance(identifier, dict):
        config = {'class_name': identifier['class_name'], 'config': identifier['config']}

# Path: veidt/utils/general_utils.py
# def deserialize_veidt_object(identifier, module_objects=None,
#                              printable_module_name='object'):
#     if isinstance(identifier, dict):
#         # dealing with configuration dictionary
#         config = identifier
#         if 'class_name' not in config or 'config' not in config:
#             raise ValueError('Improper config format: ' + str(config))
#         class_name = config['class_name']
#         module_objects = module_objects or {}
#         cls = module_objects.get(class_name)
#         if cls is None:
#             raise ValueError('Unknown ' + printable_module_name +
#                              ': ' + class_name)
#         return cls(**config['config'])
# 
#     elif isinstance(identifier, str):
#         function_name = identifier
#         fn = module_objects.get(function_name)
#         if fn is None:
#             raise ValueError('Unknown ' + printable_module_name +
#                              ':' + function_name)
#         return fn


# Path: veidt/kernel.py
import numpy as np
from veidt.utils.general_utils import deserialize_veidt_object



# now the kernels are defined as functions
# For future development the kernel should be class
# with tunable parameters, this is particular useful for Bayesian methods
def rbf(x1, x2, sigma):
    d_squared = np.sum((x1[:, None, :] - x2[None, :, :]) ** 2, axis=2)
    return np.exp(-d_squared / (2 * sigma ** 2))


def get_kernel(identifier):
    if isinstance(identifier, dict):
        config = {'class_name': identifier['class_name'], 'config': identifier['config']}

        return deserialize_veidt_object(config, module_objects=globals())