<commit_before># -*- coding: utf-8 -*-


"""
This module contains the functions and classes for the computation of
dynamic models (inverse and direct).
"""


from sympy import sign

from pysymoro.screw import Screw
from pysymoro.screw6 import Screw6
from symoroutil.tools import skew


class DynModel(object):
    """
    Data structure:
        Hold the various components obtained during the computation of
        dynamic models (inverse and direct).
    """
    def __init__(self, joints):
        """
        Constructor period.

        Args:
            joints: An iterative object containing all the joint
                numbers. This is usually the `joint_nums` attribute in
                `Robot` class.
        """
        # link velocity
        self.vels = list(None for j in joints)
        # gyroscopic acceleration
        self.gammas = list(None for j in joints)
        # wrench - external+coriolis+centrifugal
        self.betas = list(None for j in joints)
        # relative acceleration
        self.zetas = list(None for j in joints)
        # composite spatial inertia matrix
        self.composite_inertias = list(None for j in joints)
        # composite wrench
        self.composite_betas = list(None for j in joints)
        # link acceleration
        self.accels = list(None for j in joints)
        # reaction wrench
        self.wrenchs = list(None for j in joints)
        # joint torque
        self.torques = list(None for j in joints)

    def __str__(self):
        str_format = ""
        # add header
        str_format = str_format + "DynModel:\n"
        str_format = str_format + "---------\n"
        # add link velocity
        str_format = str_format + "vels: \n"
        str_format = str_format + self._str_items(self.vels)
        # add gyroscopic acceleration
        str_format = str_format + "gammas: \n"
        str_format = str_format + self._str_items(self.gammas)
        # add wrench - external + coriolis + centrifugal
        str_format = str_format + "betas: \n"
        str_format = str_format + self._str_items(self.betas)
        # add relative acceleration
        str_format = str_format + "zetas: \n"
        str_format = str_format + self._str_items(self.zetas)
        return str_format

    def __repr__(self):
        return str(self)

    def _str_items(self, items):
        """
        Create a string representation for a given attribute.

        Args:
            items: An attribute of the class which is a list

        Returns:
            A string representation of the attribute.
        """
        row_format = '\t' + ('{0:^6} : {1}') + '\n'
        str_format = ""
        for idx, item in enumerate(items):
            str_format = str_format + row_format.format(*(
                str(idx), str(item)
            ))
        return str_format


def _init_composite_inertia(model, robo, j):<commit_msg>Refactor `__str__()` in `DynModel` class<commit_after># -*- coding: utf-8 -*-


"""
This module contains the functions and classes for the computation of
dynamic models (inverse and direct).
"""


from sympy import sign

from pysymoro.screw import Screw
from pysymoro.screw6 import Screw6
from symoroutils.tools import skew


class DynModel(object):
    """
    Data structure:
        Hold the various components obtained during the computation of
        dynamic models (inverse and direct).
    """
    def __init__(self, joints):
        """
        Constructor period.

        Args:
            joints: An iterative object containing all the joint
                numbers. This is usually the `joint_nums` attribute in
                `Robot` class.
        """
        # link velocity
        self.vels = list(None for j in joints)
        # gyroscopic acceleration
        self.gammas = list(None for j in joints)
        # wrench - external+coriolis+centrifugal
        self.betas = list(None for j in joints)
        # relative acceleration
        self.zetas = list(None for j in joints)
        # composite spatial inertia matrix
        self.composite_inertias = list(None for j in joints)
        # composite wrench
        self.composite_betas = list(None for j in joints)
        # link acceleration
        self.accels = list(None for j in joints)
        # reaction wrench
        self.wrenchs = list(None for j in joints)
        # joint torque
        self.torques = list(None for j in joints)

    def __str__(self):
        str_format = ""
        # add header
        str_format = str_format + "DynModel:\n"
        str_format = str_format + "---------\n"
        # get all the attributes currently in the class
        attrs = [attr for attr in dir(self) if not attr.startswith('_')]
        # add each attribute
        for attr in attrs:
            items = getattr(self, attr)
            if hasattr(items, '__iter__'):
                attr_str = self._str_items(items)
            else:
                attr_str = str(items) + '\n'
            str_format = str_format + str(attr) + ": \n"
            str_format = str_format + attr_str
        return str_format

    def __repr__(self):
        return str(self)

    def _str_items(self, items):
        """
        Create a string representation for a given attribute.

        Args:
            items: An attribute of the class which is a list

        Returns:
            A string representation of the attribute.
        """
        row_format = '\t' + ('{0:^6} : {1}') + '\n'
        str_format = ""
        for idx, item in enumerate(items):
            str_format = str_format + row_format.format(*(
                str(idx), str(item)
            ))
        return str_format


def _init_composite_inertia(model, robo, j):
{'fraction_non_alphanumeric': 0.08760533707865169, 'fraction_numerical': 0.002106741573033708, 'mean_word_length': 2.0095087163232965, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3058459', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1578, 'n_words': 526}