Skip to content
Snippets Groups Projects
Commit f890dc27 authored by Michael Zikeli's avatar Michael Zikeli
Browse files

Add an error to the parsing of precision and blending, to give the use a hint,...

Add an error to the parsing of precision and blending, to give the use a hint, what he actually wanted to do. And fix spacing.
parent b4d7e0cf
Branches
No related tags found
1 merge request!2Extend generator script by precision and blending
...@@ -3,7 +3,6 @@ from functools import partial ...@@ -3,7 +3,6 @@ from functools import partial
import os import os
import sys import sys
from typing import Any, Dict, List, Union from typing import Any, Dict, List, Union
from collections import defaultdict
if sys.version_info >= (3, 11): if sys.version_info >= (3, 11):
import tomllib import tomllib
...@@ -189,6 +188,20 @@ def generate_operator( ...@@ -189,6 +188,20 @@ def generate_operator(
"IcosahedralShellMap": hfg.blending.IcosahedralShellMap(), "IcosahedralShellMap": hfg.blending.IcosahedralShellMap(),
} }
def raise_exception(dict_key: Union[str, int]) -> None:
dict_arg = spec[f"{dict_key}"]
valid_options = []
if dict_key == "precision":
valid_options = [key for key in precisions.keys()]
elif dict_key == "blending":
valid_options = [key for key in blending_maps.keys()]
raise ValueError(
f"Something went wrong, "
f"the given value '{dict_arg}' is not a valid '{dict_key}'.\n"
f"{'' if not valid_options else str('Please choose one of these ' + str(valid_options) + '.')}"
)
try: try:
get_form = getattr(forms, form_str) get_form = getattr(forms, form_str)
except: except:
...@@ -211,15 +224,19 @@ def generate_operator( ...@@ -211,15 +224,19 @@ def generate_operator(
for opt in spec["optimizations"] for opt in spec["optimizations"]
} }
if "precision" not in spec: type_descriptor = precisions["fp64"] # set default precision
# set default precision if "precision" in spec:
spec["precision"] = "fp64" if spec["precision"] in precisions:
type_descriptor = precisions[spec["precision"]] type_descriptor = precisions[spec["precision"]]
else:
raise_exception("precision")
if "blending" not in spec: blending = blending_maps["IdentityMap"] # set default blending
# set default blending if "blending" in spec:
spec["blending"] = "IdentityMap" if spec["blending"] in blending_maps:
blending = blending_maps[spec["blending"]] blending = blending_maps[spec["blending"]]
else:
raise_exception("blending")
kernel_types = [ kernel_types = [
operator_generation.kernel_types.Apply( operator_generation.kernel_types.Apply(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment