Skip to content
Snippets Groups Projects
Commit 7acdc31c authored by Martin Bauer's avatar Martin Bauer
Browse files

More tests

parent 65698934
No related branches found
No related tags found
No related merge requests found
......@@ -72,10 +72,11 @@ import numpy as np
from appdirs import user_config_dir, user_cache_dir
from ctypes import cdll
from pystencils.backends.cbackend import generate_c, get_headers
from collections import OrderedDict, Mapping
from collections import OrderedDict
from pystencils.transformations import symbol_name_to_variable_name
from pystencils.data_types import to_ctypes, get_base_type, StructType
from pystencils.field import FieldType
from pystencils.utils import recursive_dict_update
def make_python_function(kernel_function_node, argument_dict={}):
......@@ -133,16 +134,6 @@ def set_compiler_config(config):
_config = config.copy()
def _recursive_dict_update(d, u):
for k, v in u.items():
if isinstance(v, Mapping):
r = _recursive_dict_update(d.get(k, {}), v)
d[k] = r
else:
d[k] = u[k]
return d
def get_configuration_file_path():
config_path_in_home = os.path.join(user_config_dir('pystencils'), 'config.json')
......@@ -200,7 +191,7 @@ def read_config():
if config_exists:
with open(config_path, 'r') as jsonConfigFile:
loaded_config = json.load(jsonConfigFile)
config = _recursive_dict_update(config, loaded_config)
config = recursive_dict_update(config, loaded_config)
else:
create_folder(config_path, True)
json.dump(config, open(config_path, 'w'), indent=4)
......
from typing import Mapping
class DotDict(dict):
"""Normal dict with additional dot access for all keys"""
......@@ -13,3 +15,22 @@ def all_equal(iterator):
except StopIteration:
return True
return all(first == rest for rest in iterator)
def recursive_dict_update(d, u):
"""Updates the first dict argument, using second dictionary recursively.
Examples:
>>> d = {'sub_dict': {'a': 1, 'b': 2}, 'outer': 42}
>>> u = {'sub_dict': {'a': 5, 'c': 10}, 'outer': 41, 'outer2': 43}
>>> recursive_dict_update(d, u)
{'sub_dict': {'a': 5, 'b': 2, 'c': 10}, 'outer': 41, 'outer2': 43}
"""
d = d.copy()
for k, v in u.items():
if isinstance(v, Mapping):
r = recursive_dict_update(d.get(k, {}), v)
d[k] = r
else:
d[k] = u[k]
return d
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment