deepy/core/tensor_conversion.py
def convert_to_neural_var(obj):
    """
    Convert object and a test object into neural var.
    :param obj: tensor or list or dict or tuple
    :param test_obj: NeuralVar or list or dict or tuple
    :return:
    """
    from theano.tensor.var import TensorVariable
    from deepy.core.neural_var import NeuralVariable
    if type(obj) == list:
        return [convert_to_neural_var(item) for item in obj]
    elif type(obj) == tuple:
        return tuple(convert_to_neural_var(list(obj)))
    elif type(obj) == dict:
        merged_map = {}
        for key in obj:
            merged_map[key] = convert_to_neural_var(obj[key])
        return merged_map
    elif type(obj) == MapDict:
        merged_map = {}
        for key in obj:
            merged_map[key] = convert_to_neural_var(obj[key])
        return MapDict(merged_map)
    elif type(obj) == TensorVariable:
        deepy_var = NeuralVariable(obj)
        if hasattr(obj, 'tag') and hasattr(obj.tag, 'last_dim'):
            deepy_var.output_dim = obj.tag.last_dim
        return deepy_var
    else:
        return obj
def convert_to_neural_var(obj):
    """
    Convert object and a test object into neural var.
    :param obj: tensor or list or dict or tuple
    :param test_obj: NeuralVar or list or dict or tuple
    :return:
    """
    from theano.tensor.var import TensorVariable
    from deepy.core.neural_var import NeuralVariable
    if type(obj) == list:
        return [convert_to_neural_var(item) for item in obj]
    elif type(obj) == tuple:
        return tuple(convert_to_neural_var(list(obj)))
    elif type(obj) == dict:
        merged_map = {}
        for key in obj:
            merged_map[key] = convert_to_neural_var(obj[key])
        return merged_map
    elif type(obj) == MapDict:
        merged_map = {}
        for key in obj:
            merged_map[key] = convert_to_neural_var(obj[key])
        return MapDict(merged_map)
    elif type(obj) == TensorVariable:
        deepy_var = NeuralVariable(obj)
        if hasattr(obj, 'tag') and hasattr(obj.tag, 'last_dim'):
            deepy_var.output_dim = obj.tag.last_dim
        return deepy_var
    else:
        return obj
Convert object and a test object into neural var.
    :param obj: tensor or list or dict or tuple
    :param test_obj: NeuralVar or list or dict or tuple
    :return: