Skip to content

Null matrices don't properly convert to repr string and attempting to compute the determinant of 0×0 matrix raised an exception. #745

Description

@haydenwong7bm
>>> from mpmath import mp, matrix
>>> mp.pretty = False
>>> null_matrix = matrix(0)
>>> null_matrix
matrix(
])
>>> mp.pretty = True
>>> null_matrix

>>> null_matrix = matrix(0, 2)
>>> null_matrix

>>> mp.pretty = False
>>> null_matrix
matrix(
])
>>> null_matrix = matrix(2, 0)
>>> null_matrix
matrix(
],
]])
>>> mp.pretty = True
>>> null_matrix
[]
[]
>>> mp.det(matrix(0, 0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python\Python310\lib\site-packages\mpmath\matrices\linalg.py", line 545, in det
    R, p = ctx.LU_decomp(A)
  File "C:\Python\Python310\lib\site-packages\mpmath\matrices\linalg.py", line 125, in LU_decomp
    tol = ctx.absmin(ctx.mnorm(A,1) * ctx.eps) # each pivot element has to be bigger
  File "C:\Python\Python310\lib\site-packages\mpmath\matrices\matrices.py", line 997, in mnorm
    return max(ctx.fsum((A[i,j] for i in xrange(m)), absolute=1) for j in xrange(n))
ValueError: max() arg is an empty sequence

The 0 × n matrix should be converted to repr string as matrix(0, n).
The n × 0 matrix should be converted to repr string as matrix(n, 0).
The determinant of the 0×0 matrix should be 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions