Skip to content
Snippets Groups Projects

added the possbility to parse an PetscOptionIntArray String

Merged Christoph Alt requested to merge devel/optionintarray into main
Compare and
2 files
+ 31
2
Preferences
Compare changes
Files
2
+ 22
1
@@ -2,17 +2,38 @@ import logging
@@ -2,17 +2,38 @@ import logging
import operator
import operator
import os
import os
import time
import time
 
import re
from datetime import datetime
from datetime import datetime
from functools import reduce
from functools import reduce
from pathlib import Path
from pathlib import Path
from typing import Tuple, Union
from typing import Tuple, Union, List
import git
import git
logger = logging.getLogger(__file__)
logger = logging.getLogger(__file__)
 
def parse_option_int_array(specification: str):
 
""" Parses the specification from Petsc PetscOptionGetIntarray.
 
"""
 
elements = specification.split(',')
 
for element in elements:
 
if (match := re.match(r"(\d+)-(\d+)(:(\d+))?", element)):
 
lower = int(match.group(1))
 
upper = int(match.group(2))
 
step = 1
 
if match.lastindex == 3:
 
step = int(match.group(4))
 
yield from range(lower, upper, step)
 
else:
 
yield int(element)
 
 
 
def get_option_int_array(specification: str) -> List:
 
return sorted(set(parse_option_int_array(specification)))
 
 
def remove_none(old_dict: dict) -> dict:
def remove_none(old_dict: dict) -> dict:
"""Remove all entries with None as value. """
"""Remove all entries with None as value. """
return {k: v for k, v in old_dict.items() if v is not None}
return {k: v for k, v in old_dict.items() if v is not None}