def __map_tensors(self, mapper, elem):
    if isinstance(elem, dict):
        for k in elem.keys():
            elem[k] = self.__map_tensors(mapper, elem[k])
        return elem
    if isinstance(elem, tuple):
        return new_tuple(type(elem), (self.__map_tensors(mapper, part) for part in elem))
    return mapper(elem)
def __map_tensors(self, mapper, elem):
    if isinstance(elem, dict):
        for k in elem.keys():
            elem[k] = self.__map_tensors(mapper, elem[k])
        return elem
    if isinstance(elem, tuple):
        return new_tuple(type(elem), (self.__map_tensors(mapper, part) for part in elem))
    return mapper(elem)