# Path: anypytools/tools.py
# def define2str(key, value=None):
#     if isinstance(value, str):
#         if value.startswith('"') and value.endswith('"'):
#             defstr = '-def %s=---"\\"%s\\""' % (key, value[1:-1].replace("\\", "\\\\"))
#         else:
#             defstr = '-def %s="%s"' % (key, value)
#     elif value is None:
#         defstr = '-def %s=""' % (key)
#     elif isinstance(value, float):
#         defstr = '-def %s="%g"' % (key, value)
#     else:
#         defstr = '-def %s="%d"' % (key, value)
#     return defstr
# 
# def path2str(key, path="."):
#     return '-p %s=---"%s"' % (key, path.replace("\\", "\\\\"))
# 
# def array2anyscript(arr):
#     """Format a numpy array as an anyscript variable."""
# 
#     def tostr(v):
#         # pylint: disable=no-member
#         if np.isreal(v):
#             return "{:.12g}".format(v)
#         elif isinstance(v, (str, np.str_)):
#             return '"{}"'.format(v)
# 
#     def createsubarr(arr):
#         outstr = ""
#         if isinstance(arr, np.ndarray):
#             if len(arr) == 1 and not isinstance(arr[0], np.ndarray):
#                 return "{" + tostr(arr[0]) + "},"
#             outstr += "{"
#             for row in arr:
#                 outstr += createsubarr(row)
#             outstr = outstr.strip(",") + "},"
#             return outstr
#         else:
#             return outstr + tostr(arr) + ","
# 
#     if isinstance(arr, np.ndarray) and not arr.shape:
#         return tostr(arr.tolist())
#     elif isinstance(arr, np.ndarray):
#         return createsubarr(arr).strip(",")
#     elif isinstance(arr, float):
#         return tostr(arr)
#     else:
#         return str(arr)


import types
import logging
import numpy as np
            import pyDOE
    import pytest
from pprint import pprint, pformat  # noqa
from copy import deepcopy
from collections.abc import MutableSequence
from scipy.stats import distributions
from anypytools.tools import define2str, path2str, array2anyscript
      'operation Main.Study.InverseDynamics',
      'run'],
     ['load "MyModel.main.any"',
      'classoperation Main.Study.myvar1 "Set Value" --value="2"',
      'operation Main.Study.InverseDynamics',
      'run']]

    """

    def __init__(self, var, value):
        self.var = var
        self.value = value

    def __repr__(self):
        if isinstance(self.value, list):
            n_elem = len(self.value)
        else:
            n_elem = 1

        return "\n".join([self.get_macro(i) for i in range(n_elem)])

    def get_macro(self, index, **kwarg):
        if isinstance(self.value, list):
            val = self.value[index % len(self.value)]
        else:
            val = self.value
        return self._format_macro(val)

    def _format_macro(self, val):
        if isinstance(val, np.ndarray):

# Path: anypytools/tools.py
# def define2str(key, value=None):
#     if isinstance(value, str):
#         if value.startswith('"') and value.endswith('"'):
#             defstr = '-def %s=---"\\"%s\\""' % (key, value[1:-1].replace("\\", "\\\\"))
#         else:
#             defstr = '-def %s="%s"' % (key, value)
#     elif value is None:
#         defstr = '-def %s=""' % (key)
#     elif isinstance(value, float):
#         defstr = '-def %s="%g"' % (key, value)
#     else:
#         defstr = '-def %s="%d"' % (key, value)
#     return defstr
# 
# def path2str(key, path="."):
#     return '-p %s=---"%s"' % (key, path.replace("\\", "\\\\"))
# 
# def array2anyscript(arr):
#     """Format a numpy array as an anyscript variable."""
# 
#     def tostr(v):
#         # pylint: disable=no-member
#         if np.isreal(v):
#             return "{:.12g}".format(v)
#         elif isinstance(v, (str, np.str_)):
#             return '"{}"'.format(v)
# 
#     def createsubarr(arr):
#         outstr = ""
#         if isinstance(arr, np.ndarray):
#             if len(arr) == 1 and not isinstance(arr[0], np.ndarray):
#                 return "{" + tostr(arr[0]) + "},"
#             outstr += "{"
#             for row in arr:
#                 outstr += createsubarr(row)
#             outstr = outstr.strip(",") + "},"
#             return outstr
#         else:
#             return outstr + tostr(arr) + ","
# 
#     if isinstance(arr, np.ndarray) and not arr.shape:
#         return tostr(arr.tolist())
#     elif isinstance(arr, np.ndarray):
#         return createsubarr(arr).strip(",")
#     elif isinstance(arr, float):
#         return tostr(arr)
#     else:
#         return str(arr)


# Path: anypytools/macroutils.py
import types
import logging
import numpy as np
            import pyDOE
    import pytest
from pprint import pprint, pformat  # noqa
from copy import deepcopy
from collections.abc import MutableSequence
from scipy.stats import distributions
from anypytools.tools import define2str, path2str, array2anyscript

      'operation Main.Study.InverseDynamics',
      'run'],
     ['load "MyModel.main.any"',
      'classoperation Main.Study.myvar1 "Set Value" --value="2"',
      'operation Main.Study.InverseDynamics',
      'run']]

    """

    def __init__(self, var, value):
        self.var = var
        self.value = value

    def __repr__(self):
        if isinstance(self.value, list):
            n_elem = len(self.value)
        else:
            n_elem = 1

        return "\n".join([self.get_macro(i) for i in range(n_elem)])

    def get_macro(self, index, **kwarg):
        if isinstance(self.value, list):
            val = self.value[index % len(self.value)]
        else:
            val = self.value
        return self._format_macro(val)

    def _format_macro(self, val):
        if isinstance(val, np.ndarray):

            val = array2anyscript(val)