[SciPy-User] scipy.linalg.solve()'s overwrite option does not work
braingateway
braingateway at gmail.com
Sat Nov 6 17:46:27 EDT 2010
josef.pktd at gmail.com :
> On Sat, Nov 6, 2010 at 1:13 PM, braingateway <braingateway at gmail.com> wrote:
>
>> David Warde-Farley:
>>
>>> On 2010-11-05, at 9:21 PM, braingateway wrote:
>>>
>>>
>>>
>>>> Hi everyone,
>>>> I believe the overwrite option is used for reduce memory usage. But I
>>>> did following test, and find out it does not work at all. Maybe I
>>>> misunderstood the purpose of overwrite option. If anybody could explain
>>>> this, I shall highly appreciate your help.
>>>>
>>>>
>>> First of all, this is a SciPy issue, so please don't crosspost to NumPy-discussion.
>>>
>>>
>>>
>>>>>>> a=npy.random.randn(20,20)
>>>>>>> x=npy.random.randn(20,4)
>>>>>>> a=npy.matrix(a)
>>>>>>> x=npy.matrix(x)
>>>>>>> b=a*x
>>>>>>> import scipy.linalg as sla
>>>>>>> a0=npy.matrix(a)
>>>>>>> a is a0
>>>>>>>
>>>>>>>
>>>> False
>>>>
>>>>
>>>>>>> b0=npy.matrix(b)
>>>>>>> b is b0
>>>>>>>
>>>>>>>
>>>> False
>>>>
>>>>
>>> You shouldn't use 'is' to compare arrays unless you mean to compare them by object identity. Use all(b == b0) to compare by value.
>>>
>>> David
>>>
>>>
>>>
>> Thanks for reply, but I have to say u did not understand my post at all.
>> I did this 'is' comparison on purpose, because I wanna know if the
>> overwrite flag is work or not.
>> See following example:
>> >>> a=numpy.matrix([0,0,1])
>> >>> a
>> matrix([[0, 0, 1]])
>> >>> a0=a
>> >>> a0 is a
>> True
>> This means a0 and a is actually point to a same object. Then a0 act
>> similar to the C pointer of a.
>> I compared a0/b0 and a/b by 'is' first to show I did create a new object
>> from the original matrix, so the following (a0==a).all() comparison can
>> actually prove the values inside the a and b were not overwritten.
>>
>
> even if "a0 is not a" they can still share the same memory:
>
>
>
Thanks a lot, but I checked again, there is no sharing on memory.
>>>> aa = np.ones(5)
>>>> bb = aa[:,None]
>>>> aa is bb
>>>>
> False
>
>>>> bb[0] = 10
>>>> aa
>>>>
> array([ 10., 1., 1., 1., 1.])
>
>>>> (aa == bb.ravel()).all()
>>>>
> True
>
> When I check a variation on your example, I have `a` overwritten but
> not `b`. But the docstring makes only a weak statement, allowing that
> it can be overwritten, doesn't necessarily mean it will be overwritten
> in every case.
>
>
> Josef
>
Thanks very much for trying it. Also good to know, the 'overwrite flag'
is actually refer to modify the input matrixs. Would you mind tell me
exactly how did u make it overwritten? I get a for-loop to try this
about 50 times (attached script), none of them got overwritten.
Probably, it depends on size? so I increased it to 200x200 or even
2000x2000, still no any effect. Would you please show me the variation
in which you could actually have (a==a0).all() return 'False'? I also
tried arrays instead of matrix (attached script), the result is the same.
Best Regards,
LittleBigBrain
>
>
>> Sincerely,
>> LittleBigBrain
>>
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>
>>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: tryScipyOverwrite.py
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20101106/55b095fa/attachment.ksh>
More information about the SciPy-User
mailing list