# Path: openlego/utils/general_utils.py
# def parse_string(s):
#     # type: (str) -> Union[str, np.ndarray, float]
#     """Convert a string to a numpy array of floats or float if possible.
# 
#     The string is returned unchanged if it cannot be converted to a numpy array of floats or float.
# 
#     Parameters
#     ----------
#         s : str
#             String to be converted.
# 
#     Returns
#     -------
#         str or np.ndarray or float
#             Parsed string or the string itself.
#     """
#     v = re.sub(r'[\[\]]', '', s)
# 
#     if ',' in v:
#         v = v.split(',')
#     elif ';' in v:
#         v = v.split(';')
# 
#     try:
#         v = np.atleast_1d(np.array(v, dtype=float))
#         if v.size == 1:
#             v = v[0]
#         return v
#     except ValueError:
#         return s
# 
# Path: openlego/utils/xml_utils.py
# def value_to_xml(elem, value):
#     if isinstance(value, np.ndarray):
#         value = np.atleast_1d(value).flatten()
# 
#     if isinstance(value, np.ndarray):
#         if value.size == 1:
#             try:
#                 elem.text = str('{:.24e}'.format(value[0]))
#             except ValueError:
#                 elem.text = str(value[0])
#         else:
#             try:
#                 elem.text = ';'.join([str('{:.24e}'.format(v)) for v in value[:]])
#             except ValueError:
#                 elem.text = ';'.join([str(v) for v in value[:]])
#             elem.attrib.update({'mapType': 'vector'})
#     elif isinstance(value, float):
#         elem.text = str('{:.24e}'.format(value))
#     else:
#         elem.text = str(value)


import os
import warnings
from lxml import etree
from typing import Union, List, Optional, Any
from six import binary_type
from openlego.utils.general_utils import parse_string
from openlego.utils.xml_utils import value_to_xml
        ----------
            of : str, optional
                Name of the parameter to get the partials of

        Returns
        -------
            dict
                In the form partials['from_param_name']['wrt_param_name'] = sensitivity_value if no `of` is given, or
                in the form partials['wrt_param_name'] = sensitivity_value if `of` is given.
        """
        partials = dict()

        if of is not None:
            elem_of = self._tree.xpath('/partials/of[@uid="{}"]'.format(of))
            if len(elem_of):
                for elem_wrt in elem_of:
                    wrt_uid = elem_wrt.get('uid')
                    value = parse_string(elem_wrt.text)
                    partials.update({wrt_uid: value})
        else:
            for elem_of in self._elem_root:
                of_uid = elem_of[0].text

                if of_uid not in partials:
                    partials.update({of_uid: dict()})

                for elem_wrt in elem_of[1:]:
                    wrt_uid = elem_wrt[0].text

                    if len(elem_wrt) == 2:

# Path: openlego/utils/general_utils.py
# def parse_string(s):
#     # type: (str) -> Union[str, np.ndarray, float]
#     """Convert a string to a numpy array of floats or float if possible.
# 
#     The string is returned unchanged if it cannot be converted to a numpy array of floats or float.
# 
#     Parameters
#     ----------
#         s : str
#             String to be converted.
# 
#     Returns
#     -------
#         str or np.ndarray or float
#             Parsed string or the string itself.
#     """
#     v = re.sub(r'[\[\]]', '', s)
# 
#     if ',' in v:
#         v = v.split(',')
#     elif ';' in v:
#         v = v.split(';')
# 
#     try:
#         v = np.atleast_1d(np.array(v, dtype=float))
#         if v.size == 1:
#             v = v[0]
#         return v
#     except ValueError:
#         return s
# 
# Path: openlego/utils/xml_utils.py
# def value_to_xml(elem, value):
#     if isinstance(value, np.ndarray):
#         value = np.atleast_1d(value).flatten()
# 
#     if isinstance(value, np.ndarray):
#         if value.size == 1:
#             try:
#                 elem.text = str('{:.24e}'.format(value[0]))
#             except ValueError:
#                 elem.text = str(value[0])
#         else:
#             try:
#                 elem.text = ';'.join([str('{:.24e}'.format(v)) for v in value[:]])
#             except ValueError:
#                 elem.text = ';'.join([str(v) for v in value[:]])
#             elem.attrib.update({'mapType': 'vector'})
#     elif isinstance(value, float):
#         elem.text = str('{:.24e}'.format(value))
#     else:
#         elem.text = str(value)


# Path: openlego/partials/partials.py
import os
import warnings
from lxml import etree
from typing import Union, List, Optional, Any
from six import binary_type
from openlego.utils.general_utils import parse_string
from openlego.utils.xml_utils import value_to_xml

        ----------
            of : str, optional
                Name of the parameter to get the partials of

        Returns
        -------
            dict
                In the form partials['from_param_name']['wrt_param_name'] = sensitivity_value if no `of` is given, or
                in the form partials['wrt_param_name'] = sensitivity_value if `of` is given.
        """
        partials = dict()

        if of is not None:
            elem_of = self._tree.xpath('/partials/of[@uid="{}"]'.format(of))
            if len(elem_of):
                for elem_wrt in elem_of:
                    wrt_uid = elem_wrt.get('uid')
                    value = parse_string(elem_wrt.text)
                    partials.update({wrt_uid: value})
        else:
            for elem_of in self._elem_root:
                of_uid = elem_of[0].text

                if of_uid not in partials:
                    partials.update({of_uid: dict()})

                for elem_wrt in elem_of[1:]:
                    wrt_uid = elem_wrt[0].text

                    if len(elem_wrt) == 2:

                        value = parse_string(elem_wrt[1].text)