<commit_before>import numpy
import numpy.linalg

# Disable divide-by-zero warnings so that 1.0 / (1.0, 0.0, 0.0) returns (1.0, Inf, Inf) without complaining
numpy.seterr(divide='ignore')

import math

from copy import deepcopy

##  Simple 3D-vector class based on numpy arrays.
#
#   This class represents a 3-dimensional vector.
class Vector(object):
    Unit_X = None
    Unit_Y = None
    Unit_Z = None

    def __init__(self, *args, **kwargs):
        if len(args) == 3:
            self._data = numpy.array([args[0], args[1], args[2]],dtype=numpy.float32)
        elif 'data' in kwargs:
            self._data = kwargs['data'].copy()
        else:
            self._data = numpy.zeros(3, dtype=numpy.float32)
    
    ##  Set the data of the vector
    #   \param x X coordinate of vector.
    #   \param y Y coordinate of vector.
    #   \param z Z coordinate of vector.
    def setData(self, x = 0,y = 0,z = 0):
        self._data = numpy.array([x,y,z],dtype=numpy.float32)
    
    ##  Get numpy array with the data
    #   \returns numpy array of length 3 holding xyz data.
    def getData(self):
        return self._data

    ##  Return the x component of this vector
    @property
    def x(self):
        return self._data[0]

    ##  Set the x component of this vector
    #   \param value The value for the x component
    def setX(self, value):
        self._data[0] = value

    ##  Return the y component of this vector
    @property
    def y(self):
        return self._data[1]

    ##  Set the y component of this vector
    #   \param value The value for the y component
    def setY(self, value):
        self._data[1] = value

    ## Return the z component of this vector
    @property
    def z(self):
        return self._data[2]

    ##  Set the z component of this vector
    #   \param value The value for the z component
    def setZ(self, value):
        self._data[2] = value
    
    ##  Get the angle from this vector to another
    def angleToVector(self, vector,):
        v0 = numpy.array(self._data, dtype=numpy.float32, copy=False)
        v1 = numpy.array(vector.getData(), dtype = numpy.float32, copy=False)
        dot = numpy.sum(v0 * v1)
        dot /= self._normalizeVector(v0) * self._normalizeVector(v1)
        return numpy.arccos(numpy.fabs(dot))
    
    def normalize(self):
        l = self.length()
        if l != 0:
            self._data /= l
        return self

    def getNormalized(self):
        other = deepcopy(self)
        return other.normalize()
    
    ##  Return length, i.e. Euclidean norm, of ndarray along axis.
    def _normalizeVector(self, data):
        data = numpy.array(data, dtype=numpy.float32, copy=True)
        if data.ndim == 1:
            return math.sqrt(numpy.dot(data, data))
        data *= data
        out = numpy.atleast_1d(numpy.sum(data))
        numpy.sqrt(out, out)
        return out

    def length(self):
        return numpy.linalg.norm(self._data)

    def dot(self, other):
        return numpy.dot(self._data, other._data)

    def cross(self, other):
        result = numpy.cross(self._data, other._data)
        return Vector(result[0], result[1], result[2])

    def multiply(self, matrix):
        d = numpy.empty(4, dtype=numpy.float32)
        d[0] = self._data[0]
        d[1] = self._data[1]
        d[2] = self._data[2]
        d[3] = 1.0

        d = d.dot(matrix.getData())

        return Vector(d[0], d[1], d[2])

    def __eq__(self, other):
        return self._data[0] == other._data[0] and self._data[1] == other._data[1] and self._data[2] == other._data[2]

    def __add__(self, other):
        v = Vector(data = self._data)
        v += other
        return v

    def __iadd__(self, other):
        if type(other) is float:
            self._data[0] += other
            self._data[1] += other
            self._data[2] += other
        elif type(other) is Vector:
            self._data[0] += other._data[0]
            self._data[1] += other._data[1]
            self._data[2] += other._data[2]
        else:
            raise NotImplementedError()

        return self

    def __sub__(self, other):
        v = Vector(data = self._data)
        v -= other
        return v

    def __isub__(self, other):
        if type(other) is float:
            self._data[0] -= other
            self._data[1] -= other
            self._data[2] -= other
        elif type(other) is Vector:
            self._data[0] -= other._data[0]
            self._data[1] -= other._data[1]
            self._data[2] -= other._data[2]
        else:
            raise NotImplementedError()

        return self

    def __mul__(self, other):
        v = Vector(data = self._data)
        v *= other
        return v

    def __imul__(self, other):
        t = type(other)
        if t is float or t is numpy.float32 or t is numpy.float64 or t is int:
            self._data *= other
            return self
        else:
            raise NotImplementedError()

    def __truediv__(self, other):
        v = Vector(data = self._data)
        v /= other
        return v

    def __itruediv__(self, other):
        if type(other) is float:
            self._data /= other
            return self
        else:
            raise NotImplementedError()

    def __rtruediv__(self, other):
        if type(other) is float:
            v = numpy.float32(other) / self._data
            return Vector(v[0], v[1], v[2])<commit_msg>Add support for dividing Vector by int<commit_after>import numpy
import numpy.linalg

# Disable divide-by-zero warnings so that 1.0 / (1.0, 0.0, 0.0) returns (1.0, Inf, Inf) without complaining
numpy.seterr(divide='ignore')

import math

from copy import deepcopy

##  Simple 3D-vector class based on numpy arrays.
#
#   This class represents a 3-dimensional vector.
class Vector(object):
    Unit_X = None
    Unit_Y = None
    Unit_Z = None

    def __init__(self, *args, **kwargs):
        if len(args) == 3:
            self._data = numpy.array([args[0], args[1], args[2]],dtype=numpy.float32)
        elif 'data' in kwargs:
            self._data = kwargs['data'].copy()
        else:
            self._data = numpy.zeros(3, dtype=numpy.float32)
    
    ##  Set the data of the vector
    #   \param x X coordinate of vector.
    #   \param y Y coordinate of vector.
    #   \param z Z coordinate of vector.
    def setData(self, x = 0,y = 0,z = 0):
        self._data = numpy.array([x,y,z],dtype=numpy.float32)
    
    ##  Get numpy array with the data
    #   \returns numpy array of length 3 holding xyz data.
    def getData(self):
        return self._data

    ##  Return the x component of this vector
    @property
    def x(self):
        return self._data[0]

    ##  Set the x component of this vector
    #   \param value The value for the x component
    def setX(self, value):
        self._data[0] = value

    ##  Return the y component of this vector
    @property
    def y(self):
        return self._data[1]

    ##  Set the y component of this vector
    #   \param value The value for the y component
    def setY(self, value):
        self._data[1] = value

    ## Return the z component of this vector
    @property
    def z(self):
        return self._data[2]

    ##  Set the z component of this vector
    #   \param value The value for the z component
    def setZ(self, value):
        self._data[2] = value
    
    ##  Get the angle from this vector to another
    def angleToVector(self, vector,):
        v0 = numpy.array(self._data, dtype=numpy.float32, copy=False)
        v1 = numpy.array(vector.getData(), dtype = numpy.float32, copy=False)
        dot = numpy.sum(v0 * v1)
        dot /= self._normalizeVector(v0) * self._normalizeVector(v1)
        return numpy.arccos(numpy.fabs(dot))
    
    def normalize(self):
        l = self.length()
        if l != 0:
            self._data /= l
        return self

    def getNormalized(self):
        other = deepcopy(self)
        return other.normalize()
    
    ##  Return length, i.e. Euclidean norm, of ndarray along axis.
    def _normalizeVector(self, data):
        data = numpy.array(data, dtype=numpy.float32, copy=True)
        if data.ndim == 1:
            return math.sqrt(numpy.dot(data, data))
        data *= data
        out = numpy.atleast_1d(numpy.sum(data))
        numpy.sqrt(out, out)
        return out

    def length(self):
        return numpy.linalg.norm(self._data)

    def dot(self, other):
        return numpy.dot(self._data, other._data)

    def cross(self, other):
        result = numpy.cross(self._data, other._data)
        return Vector(result[0], result[1], result[2])

    def multiply(self, matrix):
        d = numpy.empty(4, dtype=numpy.float32)
        d[0] = self._data[0]
        d[1] = self._data[1]
        d[2] = self._data[2]
        d[3] = 1.0

        d = d.dot(matrix.getData())

        return Vector(d[0], d[1], d[2])

    def __eq__(self, other):
        return self._data[0] == other._data[0] and self._data[1] == other._data[1] and self._data[2] == other._data[2]

    def __add__(self, other):
        v = Vector(data = self._data)
        v += other
        return v

    def __iadd__(self, other):
        if type(other) is float:
            self._data[0] += other
            self._data[1] += other
            self._data[2] += other
        elif type(other) is Vector:
            self._data[0] += other._data[0]
            self._data[1] += other._data[1]
            self._data[2] += other._data[2]
        else:
            raise NotImplementedError()

        return self

    def __sub__(self, other):
        v = Vector(data = self._data)
        v -= other
        return v

    def __isub__(self, other):
        if type(other) is float:
            self._data[0] -= other
            self._data[1] -= other
            self._data[2] -= other
        elif type(other) is Vector:
            self._data[0] -= other._data[0]
            self._data[1] -= other._data[1]
            self._data[2] -= other._data[2]
        else:
            raise NotImplementedError()

        return self

    def __mul__(self, other):
        v = Vector(data = self._data)
        v *= other
        return v

    def __imul__(self, other):
        t = type(other)
        if t is float or t is numpy.float32 or t is numpy.float64 or t is int:
            self._data *= other
            return self
        else:
            raise NotImplementedError()

    def __truediv__(self, other):
        v = Vector(data = self._data)
        v /= other
        return v

    def __itruediv__(self, other):
        if type(other) is float or type(other) is int:
            self._data /= other
            return self
        else:
            raise NotImplementedError()

    def __rtruediv__(self, other):
        if type(other) is float:
            v = numpy.float32(other) / self._data
            return Vector(v[0], v[1], v[2])
{'fraction_non_alphanumeric': 0.1155433287482806, 'fraction_numerical': 0.018156808803301238, 'mean_word_length': 1.9563567362428842, 'pattern_counts': {'":': 0, '<': 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': '6913148', 'n_tokens_mistral': 3517, 'n_tokens_neox': 3419, 'n_words': 997}