Re: [Numpy-discussion] Linear algebra functions on empty arrays

2014-09-16 Thread Nathaniel Smith
On 15 Sep 2014 05:49, Sebastian Berg sebast...@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
products, etc.

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.

-n
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Linear algebra functions on empty arrays

2014-09-15 Thread Sebastian Berg
Hey all,

for https://github.com/numpy/numpy/pull/3861/files I would like to allow
0-sized dimensions for generalized ufuncs, meaning that the gufunc has
to be able to handle this, but also that it *can* handle it at all.
However lapack does not support this, so it needs some explicit fixing.
Also some of the linalg functions currently explicitly allow and others
explicitly disallow empty arrays.

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.

Regards,

Sebastian


signature.asc
Description: This is a digitally signed message part
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear algebra functions on empty arrays

2014-09-15 Thread josef.pktd
On Mon, Sep 15, 2014 at 5:48 AM, Sebastian Berg
sebast...@sipsolutions.net wrote:
 Hey all,

 for https://github.com/numpy/numpy/pull/3861/files I would like to allow
 0-sized dimensions for generalized ufuncs, meaning that the gufunc has
 to be able to handle this, but also that it *can* handle it at all.
 However lapack does not support this, so it needs some explicit fixing.
 Also some of the linalg functions currently explicitly allow and others
 explicitly disallow empty arrays.

 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.

What does an empty square matrix/array look like?

np.linalg.solve   can have empty rhs, but shape of empty lhs, `a`, is ?

If I do a QR(arr)  with arr.shape=(0, 5), what is R supposed to be ?


I just wrote some loops over linalg.qr, but I always initialized explicitly.

I didn't manage to figure out how empty arrays would be useful.

If an empty square matrix can only only be of shape (0, 0), then it's
no use (in my applications).


Josef



 Regards,

 Sebastian

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear algebra functions on empty arrays

2014-09-15 Thread Sebastian Berg
On Mo, 2014-09-15 at 07:07 -0400, josef.p...@gmail.com wrote:
 On Mon, Sep 15, 2014 at 5:48 AM, Sebastian Berg
 sebast...@sipsolutions.net wrote:
  Hey all,
 
  for https://github.com/numpy/numpy/pull/3861/files I would like to allow
  0-sized dimensions for generalized ufuncs, meaning that the gufunc has
  to be able to handle this, but also that it *can* handle it at all.
  However lapack does not support this, so it needs some explicit fixing.
  Also some of the linalg functions currently explicitly allow and others
  explicitly disallow empty arrays.
 
  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.
 
 What does an empty square matrix/array look like?
 
 np.linalg.solve   can have empty rhs, but shape of empty lhs, `a`, is ?
 
 If I do a QR(arr)  with arr.shape=(0, 5), what is R supposed to be ?
 

QR may be more difficult since R may itself could not be empty, begging
the question if you want to error out or fill it sensibly.
Cholesky would require (0, 0) for example and for eigenvalues it would
somewhat make sense too, the (0, 0) matrix has 0 eigenvalues.
I did not go through them all, but I would like to figure out whether we
should aim to generally allow it, or maybe just allow it for some
special ones.

- Sebastian

 
 I just wrote some loops over linalg.qr, but I always initialized explicitly.
 
 I didn't manage to figure out how empty arrays would be useful.
 
 If an empty square matrix can only only be of shape (0, 0), then it's
 no use (in my applications).
 
 
 Josef
 
 
 
  Regards,
 
  Sebastian
 
  ___
  NumPy-Discussion mailing list
  NumPy-Discussion@scipy.org
  http://mail.scipy.org/mailman/listinfo/numpy-discussion
 
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
 



signature.asc
Description: This is a digitally signed message part
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Linear algebra functions on empty arrays

2014-09-15 Thread josef.pktd
On Mon, Sep 15, 2014 at 7:26 AM, Sebastian Berg
sebast...@sipsolutions.net wrote:
 On Mo, 2014-09-15 at 07:07 -0400, josef.p...@gmail.com wrote:
 On Mon, Sep 15, 2014 at 5:48 AM, Sebastian Berg
 sebast...@sipsolutions.net wrote:
  Hey all,
 
  for https://github.com/numpy/numpy/pull/3861/files I would like to allow
  0-sized dimensions for generalized ufuncs, meaning that the gufunc has
  to be able to handle this, but also that it *can* handle it at all.
  However lapack does not support this, so it needs some explicit fixing.
  Also some of the linalg functions currently explicitly allow and others
  explicitly disallow empty arrays.
 
  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.

 What does an empty square matrix/array look like?

 np.linalg.solve   can have empty rhs, but shape of empty lhs, `a`, is ?

 If I do a QR(arr)  with arr.shape=(0, 5), what is R supposed to be ?


 QR may be more difficult since R may itself could not be empty, begging
 the question if you want to error out or fill it sensibly.

I shouldn't have tried it again (I got this a few times last week):

 ze = np.ones((z.shape[1], 0))
 np.linalg.qr(ze)
 ** On entry to DGEQRF parameter number  7 had an illegal value

crash

z.shape[1]  is 3
 np.__version__
'1.6.1'

I think, I would prefer an exception if the output would require a
empty square matrix with shape  (0, 0)
I don't see any useful fill value.


 Cholesky would require (0, 0) for example and for eigenvalues it would
 somewhat make sense too, the (0, 0) matrix has 0 eigenvalues.
 I did not go through them all, but I would like to figure out whether we
 should aim to generally allow it, or maybe just allow it for some
 special ones.

If the return square array has shape (0, 0), then it would make sense,
but I haven't run into a case for it yet.

np.cholesky(np.ones((0, 0)))  ?
(I didn't try since my interpreter is crashed. :)

Josef


 - Sebastian


 I just wrote some loops over linalg.qr, but I always initialized explicitly.

 I didn't manage to figure out how empty arrays would be useful.

 If an empty square matrix can only only be of shape (0, 0), then it's
 no use (in my applications).


 Josef


 
  Regards,
 
  Sebastian
 
  ___
  NumPy-Discussion mailing list
  NumPy-Discussion@scipy.org
  http://mail.scipy.org/mailman/listinfo/numpy-discussion
 
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion



 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion