<commit_before>import math

import numpy
from OpenGL.GL import *

from vistas.core.graphics.vector import Vector


class ViewMatrix:
    def __init__(self):
        self.m = numpy.matrix('1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1', dtype=numpy.float32)  # Identity matrix
        self.stack = []

    def __getitem__(self, item):
        return self.m[item]

    def __setitem__(self, key, value):
        self.m[key] = value

    def __mul__(self, other):
        if isinstance(other, ViewMatrix):
            m = ViewMatrix()
            m.m = self.m * other.m

            return m

        elif isinstance(other, Vector):
            v = (self.m * other.v.reshape(4, 1)).reshape(1, 4).A[0]
            return Vector(*v)

        else:
            raise ValueError("Can't multiply matrix with {}".format(other.__class__.__name__))

    @classmethod
    def from_gl(cls, mode):
        matrix = glGetFloatv(mode)
        obj = cls()
        obj.m = numpy.matrix(matrix.reshape(4, 4), dtype=numpy.float32)

        return obj

    def push(self):
        self.stack.insert(0, self.m.copy())

    def pop(self):
        if self.stack:
            self.m = self.stack.pop()

    def transpose(self):
        t = ViewMatrix()
        t.m = self.m.T

        return t
<commit_msg>Add inplace multiplication operator for view matrix<commit_after>import math

import numpy
from OpenGL.GL import *

from vistas.core.graphics.vector import Vector


class ViewMatrix:
    def __init__(self):
        self.m = numpy.matrix('1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1', dtype=numpy.float32)  # Identity matrix
        self.stack = []

    def __getitem__(self, item):
        return self.m[item]

    def __setitem__(self, key, value):
        self.m[key] = value

    def __mul__(self, other):
        if isinstance(other, ViewMatrix):
            m = ViewMatrix()
            m.m = self.m * other.m

            return m

        elif isinstance(other, Vector):
            v = (self.m * other.v.reshape(4, 1)).reshape(1, 4).A[0]
            return Vector(*v)

        else:
            raise ValueError("Can't multiply matrix with {}".format(other.__class__.__name__))

    def __imul__(self, other):
        if isinstance(other, ViewMatrix):
            self.m *= other.m

            return self
        else:
            raise ValueError("Can't multiply matrix with {} in place".format(other.__class__.__name__))

    @classmethod
    def from_gl(cls, mode):
        matrix = glGetFloatv(mode)
        obj = cls()
        obj.m = numpy.matrix(matrix.reshape(4, 4), dtype=numpy.float32)

        return obj

    def push(self):
        self.stack.insert(0, self.m.copy())

    def pop(self):
        if self.stack:
            self.m = self.stack.pop()

    def transpose(self):
        t = ViewMatrix()
        t.m = self.m.T

        return t

{'fraction_non_alphanumeric': 0.11858407079646018, 'fraction_numerical': 0.01982300884955752, 'mean_word_length': 1.99364406779661, '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': '4995827', 'n_tokens_mistral': 949, 'n_tokens_neox': 878, 'n_words': 242}