Skip to content

Unexpected determinant for 4X4 matrix #1618

@ja-b

Description

@ja-b

When upgrading to 0.10.0 we run into an expected 0 determinant for the following matrix

tensor = Nx.tensor([
  [-1.0, 1.0, -1.0, 0.0],
  [1.0, 0.0, 0.0, 0.0],
  [0.0, 0.0, 0.0, 1.0],
  [0.0, 1.0, 0.0, 0.0]
], type: :f64)

result = Nx.LinAlg.determinant(tensor)

IO.inspect(result)

With result

#Nx.Tensor<
  f64
  0.0
>

We had this trigger in our unit tests when upgrading to 0.10.0, but I'm having trouble at the moment reverting to a prior version to get a different value. Trying to figure this out at the moment.

But in the meantime -- numpy arrives at a 1.0 determinant for this matrix.

import numpy as np

if __name__ == "__main__":

    arr = np.array([
        [-1.0, 1.0, -1.0, 0.0],
        [1.0, 0.0, 0.0, 0.0],
        [0.0, 0.0, 0.0, 1.0],
        [0.0, 1.0, 0.0, 0.0]
    ])

    det = np.linalg.det(arr)

    print("Array:")
    print(arr)
    print("\nDeterminant:", det)

Determinant: 1.0

And I think 1.0 is correct, the matrix certainly doesn't seem ill-formed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions