toolbox/nt/database/chime5/__init__.py
def recursive_transform(func, dict_list_val, start, end, list2array=False):
    """
    Applies a function func to all leaf values in a dict or list or directly to
    a value. The hierarchy of dict_list_val is inherited. Lists are stacked
    to numpy arrays. This function can e.g. be used to recursively apply a
    transformation (e.g. audioread) to all audio paths in an example dict
    (see top of this file).
    :param func: a transformation function to be applied to the leaf values
    :param dict_list_val: dict list or value
    :param start: start time of example
    :param end: end time of example
    :param list2array:
    :return: dict, list or value with transformed elements
    """
    if isinstance(dict_list_val, dict):
        # Recursively call itself
        return {
            key: recursive_transform(
                func,
                val,
                start=start[key],
                end=end[key],
                list2array=list2array,
            )
            for key, val in dict_list_val.items()
        }
    elif isinstance(dict_list_val, (list, tuple)):
        if type(start) == type(dict_list_val):
            # Recursively call itself
            l = [
                recursive_transform(
                    func,
                    l,
                    start=s,
                    end=e,
                    list2array=list2array,
                )
                for l, s, e in zip(dict_list_val, start, end)
            ]
        else:
            # Broadcast start and end for the array channels
            assert isinstance(start, numbers.Integral) and isinstance(end, numbers.Integral), (start, end, type(start), type(end))
            l = [
                recursive_transform(
                    func,
                    l,
                    start=start,
                    end=end,
                    list2array=list2array,
                )
                for l in dict_list_val
            ]
        if list2array:
            return np.array(l)
        return l
    elif isinstance(dict_list_val, (list, tuple)):
        assert False, \
            'CB: This branch is unreachable. ' \
            'This branch has no valid code. Fix the code.'
        l = start
        if list2array:
            return np.array(l)
        return l
    else:
        # applies function to a leaf value which is not a dict or list
        return func(dict_list_val, start=start, stop=end)

    Applies a function func to all leaf values in a dict or list or directly to
    a value. The hierarchy of dict_list_val is inherited. Lists are stacked
    to numpy arrays. This function can e.g. be used to recursively apply a
    transformation (e.g. audioread) to all audio paths in an example dict
    (see top of this file).
    :param func: a transformation function to be applied to the leaf values
    :param dict_list_val: dict list or value
    :param start: start time of example
    :param end: end time of example
    :param list2array:
    :return: dict, list or value with transformed elements
    
Applies a function func to all leaf values in a dict or list or directly to
a value. The hierarchy of dict_list_val is inherited. Lists are stacked
to numpy arrays.
Applies a function func to all leaf values in a dict or list or directly to a value . The hierarchy of dict_list_val is inherited . Lists are stacked to numpy arrays .
def recursive_transform(func, dict_list_val, start, end, list2array=False):
    if isinstance(dict_list_val, dict):
        return {
            key: recursive_transform(
                func,
                val,
                start=start[key],
                end=end[key],
                list2array=list2array,
            )
            for key, val in dict_list_val.items()
        }
    elif isinstance(dict_list_val, (list, tuple)):
        if type(start) == type(dict_list_val):
            l = [
                recursive_transform(
                    func,
                    l,
                    start=s,
                    end=e,
                    list2array=list2array,
                )
                for l, s, e in zip(dict_list_val, start, end)
            ]
        else:
            assert isinstance(start, numbers.Integral) and isinstance(end, numbers.Integral), (start, end, type(start), type(end))
            l = [
                recursive_transform(
                    func,
                    l,
                    start=start,
                    end=end,
                    list2array=list2array,
                )
                for l in dict_list_val
            ]
        if list2array:
            return np.array(l)
        return l
    elif isinstance(dict_list_val, (list, tuple)):
        assert False, \
            'CB: This branch is unreachable. ' \
            'This branch has no valid code. Fix the code.'
        l = start
        if list2array:
            return np.array(l)
        return l
    else:
        return func(dict_list_val, start=start, stop=end)
def recursive_transform ( func , dict_list_val , start , end , list2array = False ) : if isinstance ( dict_list_val , dict ) : return { key : recursive_transform ( func , val , start = start [ key ] , end = end [ key ] , list2array = list2array , ) for key , val in dict_list_val . items ( ) } elif isinstance ( dict_list_val , ( list , tuple ) ) : if type ( start ) == type ( dict_list_val ) : l = [ recursive_transform ( func , l , start = s , end = e , list2array = list2array , ) for l , s , e in zip ( dict_list_val , start , end ) ] else : assert isinstance ( start , numbers . Integral ) and isinstance ( end , numbers . Integral ) , ( start , end , type ( start ) , type ( end ) ) l = [ recursive_transform ( func , l , start = start , end = end , list2array = list2array , ) for l in dict_list_val ] if list2array : return np . array ( l ) return l elif isinstance ( dict_list_val , ( list , tuple ) ) : assert False , 'CB: This branch is unreachable. ' 'This branch has no valid code. Fix the code.' l = start if list2array : return np . array ( l ) return l else : return func ( dict_list_val , start = start , stop = end )
Applies a function func to all leaf values in a dict or list or directly to
a value.
Applies a function func to all leaf values in a dict or list or directly to a value .
"""
    Applies a function func to all leaf values in a dict or list or directly to
    a value. The hierarchy of dict_list_val is inherited. Lists are stacked
    to numpy arrays. This function can e.g. be used to recursively apply a
    transformation (e.g. audioread) to all audio paths in an example dict
    (see top of this file).
    :param func: a transformation function to be applied to the leaf values
    :param dict_list_val: dict list or value
    :param start: start time of example
    :param end: end time of example
    :param list2array:
    :return: dict, list or value with transformed elements
    """ # Recursively call itself # Recursively call itself # Broadcast start and end for the array channels # applies function to a leaf value which is not a dict or list
dict, list or value with transformed elements
dict list or value with transformed elements
func
a transformation function to be applied to the leaf values
a transformation function to be applied to the leaf values
dict_list_val
dict list or value
dict list or value
start
start time of example
start time of example
end
end time of example
end time of example
list2array
None