<commit_before>import numpy as np
from Space import Space


class Field(Space):

    def __init__(self, name, field_type):
        self.type = str(field_type)
        super(Field, self).__init__(name, coordinate_system=None)

    def __str__(self):
        return 'Field: %s (%s)' % (self.name, self.type)

    def add_element(self, element):
        print 'No element could be added to Field'
        pass

    def remove_element(self, element):
        print 'No element could be added to or removed from Field'
        pass

    def scalar_field(self, xyz):
        """
        Calculates scalar field value at points xyz
        :param xyz: array of one or more points
        :return: scalar values array
        """
        xyz = np.array(xyz, dtype=np.float)
        if xyz.size == 3:
            field = 0
        elif xyz.size > 3:
            if len(xyz.shape) == 2 and xyz.shape[1] == 3:
                field = np.zeros_like(xyz.shape[0])
            else:
                raise ValueError('N-points array shape must be (N, 3)')
        else:
            raise ValueError('at least 3 coordinates are needed for point')
        return field

    def vector_field(self, xyz):
        """
        Calculates vector field value at points xyz
        :param xyz: array of one or more points
        :return: vector field values array
        """
        xyz = np.array(xyz, dtype=np.float)
        if xyz.size == 3:
            field = np.array([0, 0, 0])
        elif xyz.size > 3:
            if len(xyz.shape) == 2 and xyz.shape[1] == 3:
                field = np.zeros_like(xyz)
            else:
                raise ValueError('N-points array shape must be (N, 3)')
        else:
            raise ValueError('at least 3 coordinates are needed for point')
        return field


class SuperposedField(Field):

    def __init__(self, name, fields):
        self.fields = None
        self.type = None
        self._set_fields(fields)
        super(SuperposedField, self).__init__(name, self.type)

    def _set_fields(self, fields):
        for field in fields:
            if not isinstance(field, Field):
                raise ValueError('Fields must be iterable of Field class instances')
            if self.type is None:
                self.type = field.type
            if self.type != field.type:
                raise ValueError('All fields must be iterable of Field class instances')

        self.fields = fields

    def scalar_field(self, xyz):
        """
        Calculates superposed scalar field value at points xyz
        :param xyz: array of one or more points in global coordinate system
        :return: scalar values array
        """
        xyz = np.array(xyz, dtype=np.float)
        if xyz.size == 3:
            total_field = 0
        elif xyz.size > 3:
            if len(xyz.shape) == 2 and xyz.shape[1] == 3:
                total_field = np.zeros_like(xyz.shape[0])
            else:
                raise ValueError('N-points array shape must be (N, 3)')
        else:
            raise ValueError('at least 3 coordinates are needed for point')
        for field in self.fields:
            total_field += field.scalar_field(field.to_local_coordinate_system(xyz))
        return total_field

    def vector_field(self, xyz):
        """
        Calculates superposed vector field value at points xyz
        :param xyz: array of one or more points in global coordinate system
        :return: vector values array
        """
        xyz = np.array(xyz, dtype=np.float)
        if xyz.size == 3:
            total_field = np.array([0, 0, 0])
        elif xyz.size > 3:
            if len(xyz.shape) == 2 and xyz.shape[1] == 3:
                total_field = np.zeros_like(xyz)
            else:
                raise ValueError('N-points array shape must be (N, 3)')
        else:
            raise ValueError('at least 3 coordinates are needed for point')
        for field in self.fields:
            total_field += field.vector_field(field.to_local_coordinate_system(xyz))
        return total_field
<commit_msg>minor fixes<commit_after>import numpy as np
from Space import Space


class Field(Space):

    def __init__(self, name, field_type):
        self.type = str(field_type)
        super(Field, self).__init__(name, coordinate_system=None)

    def __str__(self):
        return 'Field: %s (%s)' % (self.name, self.type)

    def add_element(self, element):
        print 'No element could be added to Field'
        pass

    def remove_element(self, element):
        print 'No element could be added to or removed from Field'
        pass

    def scalar_field(self, xyz):
        """
        Calculates scalar field value at points xyz
        :param xyz: array of one or more points
        :return: scalar values array
        """
        xyz = np.array(xyz, dtype=np.float)
        if xyz.size == 3:
            field = 0
        elif xyz.size > 3:
            if len(xyz.shape) == 2 and xyz.shape[1] == 3:
                field = np.zeros_like(xyz.shape[0])
            else:
                raise ValueError('N-points array shape must be (N, 3)')
        else:
            raise ValueError('at least 3 coordinates are needed for point')
        return field

    def vector_field(self, xyz):
        """
        Calculates vector field value at points xyz
        :param xyz: array of one or more points
        :return: vector field values array
        """
        xyz = np.array(xyz, dtype=np.float)
        if xyz.size == 3:
            field = np.array([0, 0, 0])
        elif xyz.size > 3:
            if len(xyz.shape) == 2 and xyz.shape[1] == 3:
                field = np.zeros_like(xyz)
            else:
                raise ValueError('N-points array shape must be (N, 3)')
        else:
            raise ValueError('at least 3 coordinates are needed for point')
        return field


class SuperposedField(Field):

    def __init__(self, name, fields):
        self.fields = None
        self.type = None
        self._set_fields(fields)
        super(SuperposedField, self).__init__(name, self.type)

    def _set_fields(self, fields):
        for field in fields:
            if not isinstance(field, Field):
                raise ValueError('Fields must be iterable of Field class instances')
            if self.type is None:
                self.type = field.type
            if self.type != field.type:
                raise ValueError('All fields must be iterable of Field class instances')

        self.fields = fields

    def scalar_field(self, xyz):
        """
        Calculates superposed scalar field value at points xyz
        :param xyz: array of one or more points in global coordinate system
        :return: scalar values array
        """
        xyz = np.array(xyz, dtype=np.float)
        if xyz.size == 3:
            total_field = 0
        elif xyz.size > 3:
            if len(xyz.shape) == 2 and xyz.shape[1] == 3:
                total_field = np.zeros((xyz.shape[0],))
            else:
                raise ValueError('N-points array shape must be (N, 3)')
        else:
            raise ValueError('at least 3 coordinates are needed for point')
        for field in self.fields:
            total_field += field.scalar_field(field.to_local_coordinate_system(xyz))
        return total_field

    def vector_field(self, xyz):
        """
        Calculates superposed vector field value at points xyz
        :param xyz: array of one or more points in global coordinate system
        :return: vector values array
        """
        xyz = np.array(xyz, dtype=np.float)
        if xyz.size == 3:
            total_field = np.array([0, 0, 0])
        elif xyz.size > 3:
            if len(xyz.shape) == 2 and xyz.shape[1] == 3:
                total_field = np.zeros_like(xyz)
            else:
                raise ValueError('N-points array shape must be (N, 3)')
        else:
            raise ValueError('at least 3 coordinates are needed for point')
        for field in self.fields:
            total_field += field.vector_field(field.to_local_coordinate_system(xyz))
        return total_field

{'fraction_non_alphanumeric': 0.09275683665927568, 'fraction_numerical': 0.009361911800936191, 'mean_word_length': 1.8790780141843972, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7021995', 'n_tokens_mistral': 2437, 'n_tokens_neox': 2250, 'n_words': 769}