[Numpy-discussion] Linear algebra functions on empty arrays
njs at pobox.com
Tue Sep 16 16:04:08 EDT 2014
On 15 Sep 2014 05:49, "Sebastian Berg" <sebastian at sipsolutions.net> wrote:
> For example the QR and eigvals does not allow it, but on the other hand
> solve explicitly does (most probably never did, simply because lapack
> does not). So I am wondering if there is some convention for this, or
> what convention we should implement.
To me the obvious convention would be that whenever there's a unique
obvious answer that satisfies the operation's invariants, then we
should prefer to implement it (though possibly with low priority),
even if this means papering over lapack edge cases. This is consistent
with how e.g. we already define sum() and prod() and empty matrix
Of course this requires some thinking... e.g. the empty matrix is a
null matrix, b/c given
empty_vec = np.ones((0,))
empty_mat = np.ones((0, 0))
then we have
empty_vec @ empty_mat @ empty_vec = empty_vec @ empty_vec = sum() = 0
and therefore empty_mat is not positive definite. np.linalg.cholesky
raises an error on non-positive-definite matrices in general (e.g. try
np.linalg.cholesky(np.zeros((1, 1)))), so I guess cholesky shouldn't
handle empty matrices.
For eigvals, I guess empty_mat @ empty_vec = empty_vec, meaning that
empty_vec is a arguably an eigenvector with some indeterminate
eigenvalue? Or maybe the fact that scalar * empty_vec = empty_vec for
ever scalar means that empty_vec should be counted as a zero vector,
and thus be ineligible to be an eigenvector. Saying that the empty
matrix has zero eigenvectors or eigenvalues seems pretty intuitive.
I don't see any trouble with defining qr for empty matrices either.
More information about the NumPy-Discussion