# 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
        """
        if not isinstance(wrt, list):
            wrt = [wrt]
            if val is not None:
                val = [val]

        elem_root = self._elem_root

        x_of = "/partials/of[uid='{}']".format(of)
        elem_of = self._tree.xpath(x_of)

        if not len(elem_of):
            elem_of = etree.SubElement(elem_root, 'of')
            etree.SubElement(elem_of, 'uid').text = of
        else:
            elem_of = elem_of[0]

        for i, _wrt in enumerate(wrt):
            x_wrt = x_of + "/wrt[uid='{}']".format(_wrt)
            elem_wrt = self._tree.xpath(x_wrt)

            if not len(elem_wrt):
                elem_wrt = etree.SubElement(elem_of, 'wrt')
                etree.SubElement(elem_wrt, 'uid').text = _wrt
                if val is not None:
                    value_to_xml(etree.SubElement(elem_wrt, 'value'), val[i])
            else:
                warnings.warn(
                    'Partial from {} to {} is defined more than once. Last occurrence take precedence.'
                        .format(of, _wrt))

# 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

        """
        if not isinstance(wrt, list):
            wrt = [wrt]
            if val is not None:
                val = [val]

        elem_root = self._elem_root

        x_of = "/partials/of[uid='{}']".format(of)
        elem_of = self._tree.xpath(x_of)

        if not len(elem_of):
            elem_of = etree.SubElement(elem_root, 'of')
            etree.SubElement(elem_of, 'uid').text = of
        else:
            elem_of = elem_of[0]

        for i, _wrt in enumerate(wrt):
            x_wrt = x_of + "/wrt[uid='{}']".format(_wrt)
            elem_wrt = self._tree.xpath(x_wrt)

            if not len(elem_wrt):
                elem_wrt = etree.SubElement(elem_of, 'wrt')
                etree.SubElement(elem_wrt, 'uid').text = _wrt
                if val is not None:
                    value_to_xml(etree.SubElement(elem_wrt, 'value'), val[i])
            else:
                warnings.warn(
                    'Partial from {} to {} is defined more than once. Last occurrence take precedence.'
                        .format(of, _wrt))

                value_to_xml(elem_wrt[0][1], val[i])