Charles R Harris | 1 Dec 01:15
Picon

Re: trouble building from svn



On Mon, Nov 30, 2009 at 2:53 PM, Darren Dale <dsdale24 <at> gmail.com> wrote:
I am attempting to build scipy from svn sources on OS X 10.6. I get
the following error, could anyone please advise?

C compiler: gcc-4.2 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes
-arch x86_64 -pipe


What numpy version?

<snip>

Chuck

_______________________________________________
SciPy-Dev mailing list
SciPy-Dev <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-dev
David Cournapeau | 1 Dec 05:37
Picon
Picon

Re: trouble building from svn

Darren Dale wrote:
> I am attempting to build scipy from svn sources on OS X 10.6. I get
> the following error, could anyone please advise?
>
> C compiler: gcc-4.2 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes
> -arch x86_64 -pipe
>   

Most likely you have LDFLAGS defined in your environment, which screws
up the build. LDFLAGS (and other similar variables) do not work as
expected with distutils, they *override* the options instead of
completing them.

The actual error is that the link step is missing the -shared option,
hence the missing errors, as the linker tries to build an executable.

cheers,

David
Tim Victor | 1 Dec 07:53
Picon

Re: Possible fix for scipy.sparse.lil_matrix column-slicing problem

On Mon, Nov 30, 2009 at 5:32 AM, Robert Cimrman wrote:
> Hi Tim,
>
> Tim Victor wrote:
>> On Thu, Nov 26, 2009 at 10:58 PM, Nathan Bell wrote:
>>> On Thu, Nov 26, 2009 at 7:21 PM, Tim Victor wrote:
>>>> I didn't know that I could do that! I've just created an account and
>>>> added a comment there with a link to this email thread. Thanks for the
>>>> reply.
>>>>
>>> Nice work!
>>>
>>> Your patch has been merged into r6121 [1].  The previous
>>> implementation was a bit of a nightmare so I'm glad someone finally
>>> took the time to simplify it :)
>>>
>>> Thanks for your contribution.  I hope it is the first of many!
>>>
>>> [1] http://projects.scipy.org/scipy/changeset/6121
>>>
>>> --
>>> Nathan Bell wnbell <at> gmail.com
>>> http://www.wnbell.com/
>>
>> Thanks for the really quick turnaround and the kind words, Nathan. I
>> enjoyed working on it. It was kinda like helping someone else on their
>> class project when I was a student. That was always more fun than
>> doing my own work.
>>
>> I might see what other open tickets there are. It seems like a good
>> way to learn something about the different parts of the system.
>>
>> Best regards,
>>
>> Tim Victor
>
> Is there are reason why you removed the special case of x being a scalar, namely:
>
> -        elif issequence(i) and issequence(j):
> -            if np.isscalar(x):
> -                for ii, jj in zip(i, j):
> -                    self._insertat(ii, jj, x)
> -            else:
> -                for ii, jj, xx in zip(i, j, x):
> -                    self._insertat(ii, jj, xx)
>
> This removal broke a code of mine, which now takes forever, and behaves in a
> different way. Try this:
>
> In [1]: import scipy.sparse as spp
> In [2]: a = spp.lil_matrix((1000, 1000))
> In [3]: a
> Out[3]:
> <1000x1000 sparse matrix of type '<type 'numpy.float64'>'
>         with 0 stored elements in LInked List format>
> In [4]: import numpy as np
> In [5]: ir = ic = np.arange(1000)
> In [6]: a[ir, ic] = 1
>
> The result is a matrix with all the entries set to 1 (= full!), not just the
> diagonal, which was the previous (IMHO good) behaviour. In the real code I do
> not set the diagonal, but some other elements given by two lists ir, ic, but
> the code above shows the symptoms.
>
> I can fix easily my code by not using the LIL matrix:
>
> In [15]: a = spp.coo_matrix((np.ones((ir.shape[0],)), (ir, ic)))
> In [16]: a
> Out[16]:
> <1000x1000 sparse matrix of type '<type 'numpy.float64'>'
>         with 1000 stored elements in COOrdinate format>
>
> but I wonder, if the above change in behaviour was intended...
>
> cheers,
> r.
---------------------

Robert,

> Is there are reason why you removed the special case of x being a scalar, namely:

Actually I don't think it was the special case of x being a scalar,
but rather the special case of the row index and the column index both
being sequences.

Let me know if this looks wrong to you, but using NumPy dense arrays
and matrices as a reference for correct behavior, I get:

m = sp.zeros((10,10))

# set first column of m to ones:
m[range(10),0] = 1

# set diagonal of m to -1:
m[range(10),range(10)] = -1
m

(prints:)
array([[-1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 1., -1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 1.,  0., -1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 1.,  0.,  0., -1.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 1.,  0.,  0.,  0., -1.,  0.,  0.,  0.,  0.,  0.],
       [ 1.,  0.,  0.,  0.,  0., -1.,  0.,  0.,  0.,  0.],
       [ 1.,  0.,  0.,  0.,  0.,  0., -1.,  0.,  0.,  0.],
       [ 1.,  0.,  0.,  0.,  0.,  0.,  0., -1.,  0.,  0.],
       [ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0., -1.,  0.],
       [ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0., -1.]])

The first case, assigning a scalar with a range for the row index and
a scalar for the column index, lil_matrix still works the way it did.
It iterates the range of rows and sets column 0 for each. The second
case, iterating both of the ranges and using the row/column indexes in
pairs, was inadvertently changed.

A third case suggests that it isn't only about assigning a scalar,
since assigning from a sequence using pairwise-matched sequences of
row and column indices should work similarly:

# assign random values to the reverse diagonal:
m[range(10),range(9,-1,-1)] = sp.rand(10)
m

(prints:)
array([[-1.        ,  0.        ,  0.        ,  0.        ,  0.        ,
         0.        ,  0.        ,  0.        ,  0.        ,  0.90216781],
       [ 1.        , -1.        ,  0.        ,  0.        ,  0.        ,
         0.        ,  0.        ,  0.        ,  0.54728632,  0.        ],
       [ 1.        ,  0.        , -1.        ,  0.        ,  0.        ,
         0.        ,  0.        ,  0.97993962,  0.        ,  0.        ],
       [ 1.        ,  0.        ,  0.        , -1.        ,  0.        ,
         0.        ,  0.66932184,  0.        ,  0.        ,  0.        ],
       [ 1.        ,  0.        ,  0.        ,  0.        , -1.        ,
         0.64246538,  0.        ,  0.        ,  0.        ,  0.        ],
       [ 1.        ,  0.        ,  0.        ,  0.        ,  0.93092643,
        -1.        ,  0.        ,  0.        ,  0.        ,  0.        ],
       [ 1.        ,  0.        ,  0.        ,  0.25711642,  0.        ,
         0.        , -1.        ,  0.        ,  0.        ,  0.        ],
       [ 1.        ,  0.        ,  0.28826595,  0.        ,  0.        ,
         0.        ,  0.        , -1.        ,  0.        ,  0.        ],
       [ 1.        ,  0.01331807,  0.        ,  0.        ,  0.        ,
         0.        ,  0.        ,  0.        , -1.        ,  0.        ],
       [ 0.86963499,  0.        ,  0.        ,  0.        ,  0.        ,
         0.        ,  0.        ,  0.        ,  0.        , -1.        ]])

Yes, I broke that. :-) I haven't used this behavior or seen it
documented and it wasn't covered by a unit test, and I missed it. (In
my defense, lil_matrix is broken even worse for that third case in
both SciPy versions 0.7.0 and 0.7.1.)

Robert, can you (or anyone else out there) tell me if this covers it
all, or whether there is some more general array-indexing behavior
that should be implemented? I'll be happy to put in a case to handle
it.

I'm reminded of the Zen of Python "Explicit is better than implicit." guideline.

Best regards, and many apologies for the inconvenience,

Tim
Darren Dale | 1 Dec 14:08
Picon
Gravatar

Re: trouble building from svn

On Mon, Nov 30, 2009 at 7:15 PM, Charles R Harris
<charlesr.harris <at> gmail.com> wrote:
>
>
> On Mon, Nov 30, 2009 at 2:53 PM, Darren Dale <dsdale24 <at> gmail.com> wrote:
>>
>> I am attempting to build scipy from svn sources on OS X 10.6. I get
>> the following error, could anyone please advise?
>>
>> C compiler: gcc-4.2 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes
>> -arch x86_64 -pipe
>>
>
> What numpy version?

svn trunk
Darren Dale | 1 Dec 14:10
Picon
Gravatar

Re: trouble building from svn

On Mon, Nov 30, 2009 at 11:37 PM, David Cournapeau
<david <at> ar.media.kyoto-u.ac.jp> wrote:
> Darren Dale wrote:
>> I am attempting to build scipy from svn sources on OS X 10.6. I get
>> the following error, could anyone please advise?
>>
>> C compiler: gcc-4.2 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes
>> -arch x86_64 -pipe
>>
>
> Most likely you have LDFLAGS defined in your environment, which screws
> up the build. LDFLAGS (and other similar variables) do not work as
> expected with distutils, they *override* the options instead of
> completing them.
>
> The actual error is that the link step is missing the -shared option,
> hence the missing errors, as the linker tries to build an executable.

Thanks David, I think you are probably right. I had set some
environment variables to build packages like hdf5, which defaults to
32 bit because "uname" returns i386 on snow leopard. I'll not at work
today, so I will try again on the mac tomorrow.
Robert Cimrman | 1 Dec 14:11
Picon

Re: Possible fix for scipy.sparse.lil_matrix column-slicing problem

Hi Tim,

Tim Victor wrote:
> On Mon, Nov 30, 2009 at 5:32 AM, Robert Cimrman wrote:
>> Is there are reason why you removed the special case of x being a scalar, namely:
>>
>> -        elif issequence(i) and issequence(j):
>> -            if np.isscalar(x):
>> -                for ii, jj in zip(i, j):
>> -                    self._insertat(ii, jj, x)
>> -            else:
>> -                for ii, jj, xx in zip(i, j, x):
>> -                    self._insertat(ii, jj, xx)
>>
>> This removal broke a code of mine, which now takes forever, and behaves in a
>> different way. Try this:
>>
>> In [1]: import scipy.sparse as spp
>> In [2]: a = spp.lil_matrix((1000, 1000))
>> In [3]: a
>> Out[3]:
>> <1000x1000 sparse matrix of type '<type 'numpy.float64'>'
>>         with 0 stored elements in LInked List format>
>> In [4]: import numpy as np
>> In [5]: ir = ic = np.arange(1000)
>> In [6]: a[ir, ic] = 1
>>
>> The result is a matrix with all the entries set to 1 (= full!), not just the
>> diagonal, which was the previous (IMHO good) behaviour. In the real code I do
>> not set the diagonal, but some other elements given by two lists ir, ic, but
>> the code above shows the symptoms.
>>
>> I can fix easily my code by not using the LIL matrix:
>>
>> In [15]: a = spp.coo_matrix((np.ones((ir.shape[0],)), (ir, ic)))
>> In [16]: a
>> Out[16]:
>> <1000x1000 sparse matrix of type '<type 'numpy.float64'>'
>>         with 1000 stored elements in COOrdinate format>
>>
>> but I wonder, if the above change in behaviour was intended...
>>
>> cheers,
>> r.
> ---------------------
> 
> Robert,
> 
>> Is there are reason why you removed the special case of x being a scalar, namely:
> 
> Actually I don't think it was the special case of x being a scalar,
> but rather the special case of the row index and the column index both
> being sequences.

Yes, x being scalar is in a sense a subset of the case when i, j, x are three 
sequences of the same length.

> Let me know if this looks wrong to you, but using NumPy dense arrays
> and matrices as a reference for correct behavior, I get:
> 
> m = sp.zeros((10,10))
> 
> # set first column of m to ones:
> m[range(10),0] = 1
> 
> # set diagonal of m to -1:
> m[range(10),range(10)] = -1
> m
> 
> (prints:)
> array([[-1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
>        [ 1., -1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
>        [ 1.,  0., -1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
>        [ 1.,  0.,  0., -1.,  0.,  0.,  0.,  0.,  0.,  0.],
>        [ 1.,  0.,  0.,  0., -1.,  0.,  0.,  0.,  0.,  0.],
>        [ 1.,  0.,  0.,  0.,  0., -1.,  0.,  0.,  0.,  0.],
>        [ 1.,  0.,  0.,  0.,  0.,  0., -1.,  0.,  0.,  0.],
>        [ 1.,  0.,  0.,  0.,  0.,  0.,  0., -1.,  0.,  0.],
>        [ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0., -1.,  0.],
>        [ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0., -1.]])
> 
> The first case, assigning a scalar with a range for the row index and
> a scalar for the column index, lil_matrix still works the way it did.
> It iterates the range of rows and sets column 0 for each. The second
> case, iterating both of the ranges and using the row/column indexes in
> pairs, was inadvertently changed.
> 
> A third case suggests that it isn't only about assigning a scalar,
> since assigning from a sequence using pairwise-matched sequences of
> row and column indices should work similarly:
> 
> # assign random values to the reverse diagonal:
> m[range(10),range(9,-1,-1)] = sp.rand(10)
> m
> 
> (prints:)
> array([[-1.        ,  0.        ,  0.        ,  0.        ,  0.        ,
>          0.        ,  0.        ,  0.        ,  0.        ,  0.90216781],
>        [ 1.        , -1.        ,  0.        ,  0.        ,  0.        ,
>          0.        ,  0.        ,  0.        ,  0.54728632,  0.        ],
>        [ 1.        ,  0.        , -1.        ,  0.        ,  0.        ,
>          0.        ,  0.        ,  0.97993962,  0.        ,  0.        ],
>        [ 1.        ,  0.        ,  0.        , -1.        ,  0.        ,
>          0.        ,  0.66932184,  0.        ,  0.        ,  0.        ],
>        [ 1.        ,  0.        ,  0.        ,  0.        , -1.        ,
>          0.64246538,  0.        ,  0.        ,  0.        ,  0.        ],
>        [ 1.        ,  0.        ,  0.        ,  0.        ,  0.93092643,
>         -1.        ,  0.        ,  0.        ,  0.        ,  0.        ],
>        [ 1.        ,  0.        ,  0.        ,  0.25711642,  0.        ,
>          0.        , -1.        ,  0.        ,  0.        ,  0.        ],
>        [ 1.        ,  0.        ,  0.28826595,  0.        ,  0.        ,
>          0.        ,  0.        , -1.        ,  0.        ,  0.        ],
>        [ 1.        ,  0.01331807,  0.        ,  0.        ,  0.        ,
>          0.        ,  0.        ,  0.        , -1.        ,  0.        ],
>        [ 0.86963499,  0.        ,  0.        ,  0.        ,  0.        ,
>          0.        ,  0.        ,  0.        ,  0.        , -1.        ]])
> 
> Yes, I broke that. :-) I haven't used this behavior or seen it
> documented and it wasn't covered by a unit test, and I missed it. (In
> my defense, lil_matrix is broken even worse for that third case in
> both SciPy versions 0.7.0 and 0.7.1.)
> 
> Robert, can you (or anyone else out there) tell me if this covers it
> all, or whether there is some more general array-indexing behavior
> that should be implemented? I'll be happy to put in a case to handle
> it.

I think scipy.sparse indexing should follow the behavior of numpy dense arrays. 
  This is what current SVN scipy does (0.8.0.dev6122):

In [1]: import scipy.sparse as spp
In [2]: a = spp.lil_matrix((10,10))
In [3]: a[range(10),0] = 1

This is ok.

In [5]: a[range(10),range(10)] = -1
In [8]: print a.todense()
------> print(a.todense())
[[-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]]

This is IMHO not ok (what other sparse matrix users think?)

In [9]: import scipy as sp
In [10]: a[range(10),range(9,-1,-1)] = sp.rand(10)
In [12]: print a.todense()
-------> print(a.todense())
[[ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
    0.34837324  0.48012982  0.87469439  0.98490982]
  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
    0.34837324  0.48012982  0.87469439  0.98490982]
  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
    0.34837324  0.48012982  0.87469439  0.98490982]
  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
    0.34837324  0.48012982  0.87469439  0.98490982]
  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
    0.34837324  0.48012982  0.87469439  0.98490982]
  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
    0.34837324  0.48012982  0.87469439  0.98490982]
  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
    0.34837324  0.48012982  0.87469439  0.98490982]
  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
    0.34837324  0.48012982  0.87469439  0.98490982]
  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
    0.34837324  0.48012982  0.87469439  0.98490982]
  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
    0.34837324  0.48012982  0.87469439  0.98490982]]

same as above...

> I'm reminded of the Zen of Python "Explicit is better than implicit." guideline.

:)

Consider also this: the current behavior (broadcasting the index arrays to the 
whole rectangle) is not compatible with NumPy, and does not allow setting 
elements e.g. in a random sequence of positions. On the other hand, the 
broadcasting behaviour can be easily, explicitely, obtained by using 
numpy.mgrid and similar functions.

> Best regards, and many apologies for the inconvenience,

No problem, any help and code contribution is more than welcome!

I guess that fixing this issue should not be too difficult, so you could make 
another stab :-) If there is a consensus here, of course... (Nathan?)

cheers,
r.
Tim Victor | 1 Dec 17:00
Picon

Re: Possible fix for scipy.sparse.lil_matrix column-slicing problem

On Tue, Dec 1, 2009 at 8:11 AM, Robert Cimrman wrote:
> Hi Tim,
>
> Tim Victor wrote:
>> On Mon, Nov 30, 2009 at 5:32 AM, Robert Cimrman wrote:
>>> Is there are reason why you removed the special case of x being a scalar, namely:
>>>
>>> -        elif issequence(i) and issequence(j):
>>> -            if np.isscalar(x):
>>> -                for ii, jj in zip(i, j):
>>> -                    self._insertat(ii, jj, x)
>>> -            else:
>>> -                for ii, jj, xx in zip(i, j, x):
>>> -                    self._insertat(ii, jj, xx)
>>>
>>> This removal broke a code of mine, which now takes forever, and behaves in a
>>> different way. Try this:
>>>
>>> In [1]: import scipy.sparse as spp
>>> In [2]: a = spp.lil_matrix((1000, 1000))
>>> In [3]: a
>>> Out[3]:
>>> <1000x1000 sparse matrix of type '<type 'numpy.float64'>'
>>>         with 0 stored elements in LInked List format>
>>> In [4]: import numpy as np
>>> In [5]: ir = ic = np.arange(1000)
>>> In [6]: a[ir, ic] = 1
>>>
>>> The result is a matrix with all the entries set to 1 (= full!), not just the
>>> diagonal, which was the previous (IMHO good) behaviour. In the real code I do
>>> not set the diagonal, but some other elements given by two lists ir, ic, but
>>> the code above shows the symptoms.
>>>
>>> I can fix easily my code by not using the LIL matrix:
>>>
>>> In [15]: a = spp.coo_matrix((np.ones((ir.shape[0],)), (ir, ic)))
>>> In [16]: a
>>> Out[16]:
>>> <1000x1000 sparse matrix of type '<type 'numpy.float64'>'
>>>         with 1000 stored elements in COOrdinate format>
>>>
>>> but I wonder, if the above change in behaviour was intended...
>>>
>>> cheers,
>>> r.
>> ---------------------
>>
>> Robert,
>>
>>> Is there are reason why you removed the special case of x being a scalar, namely:
>>
>> Actually I don't think it was the special case of x being a scalar,
>> but rather the special case of the row index and the column index both
>> being sequences.
>
> Yes, x being scalar is in a sense a subset of the case when i, j, x are three
> sequences of the same length.
>
>> Let me know if this looks wrong to you, but using NumPy dense arrays
>> and matrices as a reference for correct behavior, I get:
>>
>> m = sp.zeros((10,10))
>>
>> # set first column of m to ones:
>> m[range(10),0] = 1
>>
>> # set diagonal of m to -1:
>> m[range(10),range(10)] = -1
>> m
>>
>> (prints:)
>> array([[-1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
>>        [ 1., -1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
>>        [ 1.,  0., -1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
>>        [ 1.,  0.,  0., -1.,  0.,  0.,  0.,  0.,  0.,  0.],
>>        [ 1.,  0.,  0.,  0., -1.,  0.,  0.,  0.,  0.,  0.],
>>        [ 1.,  0.,  0.,  0.,  0., -1.,  0.,  0.,  0.,  0.],
>>        [ 1.,  0.,  0.,  0.,  0.,  0., -1.,  0.,  0.,  0.],
>>        [ 1.,  0.,  0.,  0.,  0.,  0.,  0., -1.,  0.,  0.],
>>        [ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0., -1.,  0.],
>>        [ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0., -1.]])
>>
>> The first case, assigning a scalar with a range for the row index and
>> a scalar for the column index, lil_matrix still works the way it did.
>> It iterates the range of rows and sets column 0 for each. The second
>> case, iterating both of the ranges and using the row/column indexes in
>> pairs, was inadvertently changed.
>>
>> A third case suggests that it isn't only about assigning a scalar,
>> since assigning from a sequence using pairwise-matched sequences of
>> row and column indices should work similarly:
>>
>> # assign random values to the reverse diagonal:
>> m[range(10),range(9,-1,-1)] = sp.rand(10)
>> m
>>
>> (prints:)
>> array([[-1.        ,  0.        ,  0.        ,  0.        ,  0.        ,
>>          0.        ,  0.        ,  0.        ,  0.        ,  0.90216781],
>>        [ 1.        , -1.        ,  0.        ,  0.        ,  0.        ,
>>          0.        ,  0.        ,  0.        ,  0.54728632,  0.        ],
>>        [ 1.        ,  0.        , -1.        ,  0.        ,  0.        ,
>>          0.        ,  0.        ,  0.97993962,  0.        ,  0.        ],
>>        [ 1.        ,  0.        ,  0.        , -1.        ,  0.        ,
>>          0.        ,  0.66932184,  0.        ,  0.        ,  0.        ],
>>        [ 1.        ,  0.        ,  0.        ,  0.        , -1.        ,
>>          0.64246538,  0.        ,  0.        ,  0.        ,  0.        ],
>>        [ 1.        ,  0.        ,  0.        ,  0.        ,  0.93092643,
>>         -1.        ,  0.        ,  0.        ,  0.        ,  0.        ],
>>        [ 1.        ,  0.        ,  0.        ,  0.25711642,  0.        ,
>>          0.        , -1.        ,  0.        ,  0.        ,  0.        ],
>>        [ 1.        ,  0.        ,  0.28826595,  0.        ,  0.        ,
>>          0.        ,  0.        , -1.        ,  0.        ,  0.        ],
>>        [ 1.        ,  0.01331807,  0.        ,  0.        ,  0.        ,
>>          0.        ,  0.        ,  0.        , -1.        ,  0.        ],
>>        [ 0.86963499,  0.        ,  0.        ,  0.        ,  0.        ,
>>          0.        ,  0.        ,  0.        ,  0.        , -1.        ]])
>>
>> Yes, I broke that. :-) I haven't used this behavior or seen it
>> documented and it wasn't covered by a unit test, and I missed it. (In
>> my defense, lil_matrix is broken even worse for that third case in
>> both SciPy versions 0.7.0 and 0.7.1.)
>>
>> Robert, can you (or anyone else out there) tell me if this covers it
>> all, or whether there is some more general array-indexing behavior
>> that should be implemented? I'll be happy to put in a case to handle
>> it.
>
>
> I think scipy.sparse indexing should follow the behavior of numpy dense arrays.
>  This is what current SVN scipy does (0.8.0.dev6122):
>
> In [1]: import scipy.sparse as spp
> In [2]: a = spp.lil_matrix((10,10))
> In [3]: a[range(10),0] = 1
>
> This is ok.
>
> In [5]: a[range(10),range(10)] = -1
> In [8]: print a.todense()
> ------> print(a.todense())
> [[-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]]
>
> This is IMHO not ok (what other sparse matrix users think?)
>
> In [9]: import scipy as sp
> In [10]: a[range(10),range(9,-1,-1)] = sp.rand(10)
> In [12]: print a.todense()
> -------> print(a.todense())
> [[ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
>    0.34837324  0.48012982  0.87469439  0.98490982]
>  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
>    0.34837324  0.48012982  0.87469439  0.98490982]
>  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
>    0.34837324  0.48012982  0.87469439  0.98490982]
>  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
>    0.34837324  0.48012982  0.87469439  0.98490982]
>  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
>    0.34837324  0.48012982  0.87469439  0.98490982]
>  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
>    0.34837324  0.48012982  0.87469439  0.98490982]
>  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
>    0.34837324  0.48012982  0.87469439  0.98490982]
>  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
>    0.34837324  0.48012982  0.87469439  0.98490982]
>  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
>    0.34837324  0.48012982  0.87469439  0.98490982]
>  [ 0.71485802  0.95410746  0.07350778  0.77786453  0.28376647  0.35679679
>    0.34837324  0.48012982  0.87469439  0.98490982]]
>
> same as above...
>
>> I'm reminded of the Zen of Python "Explicit is better than implicit." guideline.
>
> :)
>
> Consider also this: the current behavior (broadcasting the index arrays to the
> whole rectangle) is not compatible with NumPy, and does not allow setting
> elements e.g. in a random sequence of positions. On the other hand, the
> broadcasting behaviour can be easily, explicitely, obtained by using
> numpy.mgrid and similar functions.
>
>> Best regards, and many apologies for the inconvenience,
>
> No problem, any help and code contribution is more than welcome!
>
> I guess that fixing this issue should not be too difficult, so you could make
> another stab :-) If there is a consensus here, of course... (Nathan?)
>
> cheers,
> r.

Yes, I agree with you 100%, Robert. The behavior of NumPy for dense
arrays should be the guide, and I tried to follow it but didn't know
to check that case.

I don't defend how my version handles your case where the i and j
indexes are both sequences. The behavior that you expect is correct
and I plan to fix it to make your code work. I would however like to
make sure that I understand it well and get it all correct this
time--including correctly handling the case where the right-hand side
is also a sequence.

Best regards,

Tim Victor
Robert Cimrman | 1 Dec 17:13
Picon

Re: Possible fix for scipy.sparse.lil_matrix column-slicing problem

Tim Victor wrote:
> On Tue, Dec 1, 2009 at 8:11 AM, Robert Cimrman wrote:
>> I think scipy.sparse indexing should follow the behavior of numpy dense arrays.
>>  This is what current SVN scipy does (0.8.0.dev6122):
>>
>> In [1]: import scipy.sparse as spp
>> In [2]: a = spp.lil_matrix((10,10))
>> In [3]: a[range(10),0] = 1
>>
>> This is ok.
>>
>> In [5]: a[range(10),range(10)] = -1
>> In [8]: print a.todense()
>> ------> print(a.todense())
>> [[-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]
>>  [-1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]]
>>
>> This is IMHO not ok (what other sparse matrix users think?)
>>
>> In [9]: import scipy as sp
>> In [10]: a[range(10),range(9,-1,-1)] = sp.rand(10)
>> In [12]: print a.todense()
 >> <snip>
>>
>> same as above...
>>
>>> I'm reminded of the Zen of Python "Explicit is better than implicit." guideline.
>> :)
>>
>> Consider also this: the current behavior (broadcasting the index arrays to the
>> whole rectangle) is not compatible with NumPy, and does not allow setting
>> elements e.g. in a random sequence of positions. On the other hand, the
>> broadcasting behaviour can be easily, explicitely, obtained by using
>> numpy.mgrid and similar functions.
>>
>>> Best regards, and many apologies for the inconvenience,
>> No problem, any help and code contribution is more than welcome!
>>
>> I guess that fixing this issue should not be too difficult, so you could make
>> another stab :-) If there is a consensus here, of course... (Nathan?)
>>
>> cheers,
>> r.
> 
> Yes, I agree with you 100%, Robert. The behavior of NumPy for dense
> arrays should be the guide, and I tried to follow it but didn't know
> to check that case.

No problem at all. It was a coincidence that I stumbled on a case that was not 
covered by the tests. I do not even uses lil_matrix much :)

> I don't defend how my version handles your case where the i and j
> indexes are both sequences. The behavior that you expect is correct
> and I plan to fix it to make your code work. I would however like to
> make sure that I understand it well and get it all correct this
> time--including correctly handling the case where the right-hand side
> is also a sequence.

Sure! I am not an expert in this either, so let's wait a bit if somebody chimes 
in... Could you summarize this discussion in a new ticket, if you have a little 
spare time?

Note that I do not push this to be fixed soon by any means, my code already 
runs ok with the current version. So take my "bugreport" easy ;)

Best,
r.
Nathan Bell | 1 Dec 20:32
Picon
Gravatar

Re: slow setitem

2009/11/30 Benny Malengier <benny.malengier <at> gmail.com>:
> A question about the sparse matrix and suggestion for speed improvement.
>
> I have a code of 1000*1000 sparse matrix of 11 full diagonals. Using csr.
> Assigning the matrix via setdiags takes 14 seconds, of which 13
> seconds is in the check_format function of sparse/base.py.
>
> This is due to setdiag doing:
>
>     self[i, i + k] = v
>
> while setitem in compressed.py always does a
>
>     self.check_format(full_check=True)
>
> Removing the check_format reduces assignment of the matrix to 1 second.
> Is it really needed that the assignmentof setdiag is again checked via
> check_format?
> Allowing for a setitem that does not call check_format would be usefull.
>
> One could set a dirty flag on a setitem call, and do a check_format
> only when a computation is performed and the flag is dirty. On the
> other hand, I'm not making errors, and to have a flag like
> NOCHECKS=TRUE would be handy as it would speed up the code a lot.
> I could create a solution that is acceptable for scipy, but then I'd
> need to know how such a solution should look like.
>
> Note that there are quite some zeroes in my diagonals now too, that
> are now set to 0., if setitem would be fast, I could drop setdiag
> call, and do a fast setitem call. Or are sparse matrixes supposed to
> be used differently?

Hi Pavol,

Try creating your matrix with the spdiags() function or the related
dia_matrix class.  Constructing a matrix from diagonals with one of
these methods will be at least 100x faster than inserting into a
csr_matrix.

We don't optimize the csr_matrix element insertion code because it's
inherently slow, checks or no checks.  Every time you introduce a new
nonzero the csr_matrix must perform an O(N) update to the underlying
data structure (hence, inserting N elements is O(N^2)).

--

-- 
Nathan Bell wnbell <at> gmail.com
http://www.wnbell.com/
Simon Clift | 2 Dec 02:34
Picon

Tri-diagonal LAPACK Routines - Shall I interface them?

Hi folks,

The tri-diagonal linear system routines (sdcz/gt*) in LAPACK don't seem to be 
interfaced to the scipy.linalg.flapack module.  These are (relatively) 
straightforward algorithms but it's always annoying when you need them and 
have to create your own implementation.

Is there a broader reason for not completing the interface?  Would anyone 
object if I went ahead and patched scipy/linalg/generic_flapack.pyf to allow 
the call?

Thanks
-- Simon

--

-- 
1129 Ibbetson Lane
Mississauga, Ontario
L5C 1K9       Canada

Gmane