Skip to content

bug: matrix.adjuadge return a error value when row and col are greater than 2; #47

Description

@mmooyyii

A matrix dot by it's inverse matrix will be a cell matrix.
There are two example of numpy and trueskill.mathematics

>> from trueskill.trueskill.mathematics import Matrix
>> import numpy as np
>> d = [[1, 2, 3], [6, 5, 10], [7, 8, 9]]
>> m = Matrix(d[:])
>> m.inverse() * m
Matrix([[4.2222222222222205, 3.1666666666666656, 4.777777777777777], [-0.6666666666666659, 4.440892098500626e-16, -1.3333333333333321], [0.11111111111111138, -0.16666666666666652, 0.8888888888888893]])
>> m = np.array(d[:])
>> np.linalg.inv(m) @ m
array([[ 1.00000000e+00,  1.11022302e-15,  1.85962357e-15],
       [-5.27355937e-16,  1.00000000e+00, -3.60822483e-16],
       [-2.22044605e-16, -2.22044605e-16,  1.00000000e+00]])

This reason for this bug is that adjugate matrix is not transposed.

### trueskill\trueskill\mathematics.py

def adjugate(self):
        height, width = self.height, self.width
        if height != width:
            raise ValueError('Only square matrix can be adjugated')
        if height == 2:
            a, b = self[0][0], self[0][1]
            c, d = self[1][0], self[1][1]
            return type(self)([[d, -b], [-c, a]])
        src = {}
        for r in range(height):
            for c in range(width):
                sign = -1 if (r + c) % 2 else 1
                src[r, c] = self.minor(r, c).determinant() * sign
---     return type(self)(src, height, width)
+++     return type(self)(src, height, width).transpose()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions