[Numpy-discussion] better error message possible?

2012-06-01 Thread Chris Withers
Hi All,

Any reason why this:

  import numpy
  numpy.zeros(10)[-123]
Traceback (most recent call last):
   File stdin, line 1, in module
IndexError: index out of bounds

...could say this:

  numpy.zeros(10)[-123]
Traceback (most recent call last):
   File stdin, line 1, in module
IndexError: -123 is out of bounds

cheers,

Chris

-- 
Simplistix - Content Management, Batch Processing  Python Consulting
 - http://www.simplistix.co.uk
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] better error message possible?

2012-06-01 Thread Nathaniel Smith
On Fri, Jun 1, 2012 at 10:46 AM, Chris Withers ch...@simplistix.co.uk wrote:
 Hi All,

 Any reason why this:

   import numpy
   numpy.zeros(10)[-123]
 Traceback (most recent call last):
   File stdin, line 1, in module
 IndexError: index out of bounds

 ...could say this:

   numpy.zeros(10)[-123]
 Traceback (most recent call last):
   File stdin, line 1, in module
 IndexError: -123 is out of bounds

Only that no-one has implemented it, I guess. If you want to then
that'd be cool :-).

To be generally useful for debugging, it would probably be good for
the error message to also mention which dimension is involved, and/or
the actual size of the array in that dimension. You can also get such
error messages from expressions like 'arr[i, j, k]', after all, where
it's even less obvious what went wrong.

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


Re: [Numpy-discussion] better error message possible?

2012-06-01 Thread Benjamin Root
On Fri, Jun 1, 2012 at 9:14 AM, Nathaniel Smith n...@pobox.com wrote:

 On Fri, Jun 1, 2012 at 10:46 AM, Chris Withers ch...@simplistix.co.uk
 wrote:
  Hi All,
 
  Any reason why this:
 
import numpy
numpy.zeros(10)[-123]
  Traceback (most recent call last):
File stdin, line 1, in module
  IndexError: index out of bounds
 
  ...could say this:
 
numpy.zeros(10)[-123]
  Traceback (most recent call last):
File stdin, line 1, in module
  IndexError: -123 is out of bounds

 Only that no-one has implemented it, I guess. If you want to then
 that'd be cool :-).

 To be generally useful for debugging, it would probably be good for
 the error message to also mention which dimension is involved, and/or
 the actual size of the array in that dimension. You can also get such
 error messages from expressions like 'arr[i, j, k]', after all, where
 it's even less obvious what went wrong.

 -- Nathaniel


+1, please!

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


Re: [Numpy-discussion] better error message possible?

2012-06-01 Thread Chris Barker
 On Fri, Jun 1, 2012 at 10:46 AM, Chris Withers ch...@simplistix.co.uk

  Any reason why this:
 
    import numpy
    numpy.zeros(10)[-123]
  Traceback (most recent call last):
    File stdin, line 1, in module
  IndexError: index out of bounds
 
  ...could say this:
 
    numpy.zeros(10)[-123]
  Traceback (most recent call last):
    File stdin, line 1, in module
  IndexError: -123 is out of bounds

 Only that no-one has implemented it, I guess. If you want to then
 that'd be cool :-).

That would be nice, but to be fair, python itself doesn't do it either:

 l = range(10)
 l[12]
Traceback (most recent call last):
  File stdin, line 1, in module
IndexError: list index out of range

Though Python's standard error messages are lacking in a lot of places...

-Chris


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

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


[Numpy-discussion] Error when multiplying large sparse matrices

2012-06-01 Thread Jeremy Lecoeur
Hi,

I have been using the sparse matrix tools for a while to do all sort of 
things and, using the same code that was working just fine, I now 
encounter a problem when trying . I do have very large sparse matrices 
and when i multiplying them the number of non zeros exceed the max value 
of an intc, which cause indptr to hold negative values. Hence in the 
multiplication function of csr, whenc reating the resulting matrix, i 
get an error as it is not possible to have a negative value for a matrix 
size.
Am I missing something that would allow me to do that computation ?

Here is the code I am using:

def main():

   inCondMatFile  = sys.argv[1]

   inNodeSize = sys.argv[2]

   outProfileFile = sys.argv[3]

   outNodeDistFile= sys.argv[4]

   outNodeDensityFile = sys.argv[5]

   Acsr = scipy.io.mmread(inCondMatFile).tocsr().sorted_indices()

   A = Acsr.tocoo()

   n = A.shape[0]

   nnz = A.nnz

   rows=numpy.zeros(3*nnz+n, dtype=numpy.int32)

   cols=numpy.zeros(3*nnz+n, dtype=numpy.int32)

   data=numpy.zeros(3*nnz+n, dtype=numpy.float64)

   #first n rows of constraint mat is A - I

   rows[0:nnz] = A.row

   cols[0:nnz] = A.col

   data[0:nnz] = A.data

   rows[nnz:nnz+n] =  numpy.arange(n)

   cols[nnz:nnz+n] =  numpy.arange(n)

   data[nnz:nnz+n] = -numpy.ones(n)

   #rows n to n+nnz are

   #A_{i,j} d_{j} - A_{j,i} d_{i} == 0

   rows[nnz+n:] = numpy.append(numpy.arange(n,n+nnz),numpy.arange(n,n+nnz))

   cols[nnz+n:] = numpy.append(A.col,A.row)

   data[nnz+n:] = numpy.append(A.data,-Acsr[A.col,A.row])

   tmpC = scipy.sparse.coo_matrix( (data, (rows,cols) ) )

   Ptmp = (tmpC.transpose().tocsr() * tmpC.tocsr()).tocoo()


And it fails for that last multiplication (i did not include the rest of 
the code) because of an nnz way too big for an intc.

Jeremy



The information contained in this e-mail message is intended only for the 
personal and confidential use of the recipient(s) named above. If the reader of 
this message is not the intended recipient or an agent responsible for 
delivering it to the intended recipient, you are hereby notified that you have 
received this document in error and that any review, dissemination, 
distribution, or copying of this message is strictly prohibited. If you have 
received this communication in error, please notify us immediately by e-mail, 
and delete the original message.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Error when multiplying large sparse matrices

2012-06-01 Thread Pauli Virtanen
01.06.2012 20:45, Jeremy Lecoeur kirjoitti:
 I have been using the sparse matrix tools for a while to do all sort of 
 things and, using the same code that was working just fine, I now 
 encounter a problem when trying . I do have very large sparse matrices 
 and when i multiplying them the number of non zeros exceed the max value 
 of an intc, which cause indptr to hold negative values. Hence in the 
 multiplication function of csr, whenc reating the resulting matrix, i 
 get an error as it is not possible to have a negative value for a matrix 
 size.
 Am I missing something that would allow me to do that computation ?

Using a larger integer type for the indices is not supported in Scipy at
the moment. It's possible to implement, but needs someone to still do a
bit of work:

http://projects.scipy.org/scipy/ticket/1307

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


Re: [Numpy-discussion] better error message possible?

2012-06-01 Thread Chris Withers
On 01/06/2012 16:39, Benjamin Root wrote:


import numpy
numpy.zeros(10)[-123]
   Traceback (most recent call last):
 File stdin, line 1, in module
   IndexError: index out of bounds
  
   ...could say this:
  
numpy.zeros(10)[-123]
   Traceback (most recent call last):
 File stdin, line 1, in module
   IndexError: -123 is out of bounds

 Only that no-one has implemented it, I guess. If you want to then
 that'd be cool :-).

 To be generally useful for debugging, it would probably be good for
 the error message to also mention which dimension is involved, and/or
 the actual size of the array in that dimension. You can also get such
 error messages from expressions like 'arr[i, j, k]', after all, where
 it's even less obvious what went wrong.

 -- Nathaniel


 +1, please!

Indeed, sadly I'm not a C developer. It's a pet bugbear of mine that 
Python's built-in exceptions often tell you what went wrong but not what 
data caused the error, even when it's easily to hand when raising the 
exception.

Where's the right place to raise an issue that a numpy developer can 
hopefully make the (I suspect) simple change to get this behaviour?

cheers,

Chris

-- 
Simplistix - Content Management, Batch Processing  Python Consulting
 - http://www.simplistix.co.uk
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion