← Back to team overview

larry-discuss team mailing list archive

Re: stream lining signature of assert_larry_equal

 

On Wed, Feb 10, 2010 at 6:22 PM, Keith Goodman <kwgoodman@xxxxxxxxx> wrote:
> On Wed, Feb 10, 2010 at 6:00 PM,  <josef.pktd@xxxxxxxxx> wrote:
>> On Wed, Feb 10, 2010 at 8:41 PM, Keith Goodman <kwgoodman@xxxxxxxxx> wrote:
>>> On Fri, Feb 5, 2010 at 8:52 AM, Keith Goodman <kwgoodman@xxxxxxxxx> wrote:
>>>> On Fri, Feb 5, 2010 at 7:28 AM, Keith Goodman <kwgoodman@xxxxxxxxx> wrote:
>>>>> On Fri, Feb 5, 2010 at 7:24 AM,  <josef.pktd@xxxxxxxxx> wrote:
>>>>>> The current signature
>>>>>>
>>>>>> assert_larry_equal(actual, desired, msg='', dtype=True, original=None,
>>>>>>                       noreference=True, nocopy=False)
>>>>>>
>>>>>> has 3 keywords, original, noreference, nocopy for the option to check
>>>>>> whether a larry is a view or a copy.
>>>>>>
>>>>>> This makes 8 binary options, only 3 are relevant cases, the other 5
>>>>>> combinations raise errors or are redundant. This was quite confusing
>>>>>> when I used the tests, since I often forgot to use, reset a keyword,
>>>>>> e.g. nocopy=True also requires setting noreference = False
>>>>>>
>>>>>> I think a more compact signature would be
>>>>>> assert_larry_equal(actual, desired, msg='', dtype=True, original=None,
>>>>>> noref=True)
>>>>>>
>>>>>> if not original is None:
>>>>>>    if noref:
>>>>>>       check noreference
>>>>>>    else:
>>>>>>       check nocopy
>>>>>>
>>>>>> otherwise don't do any reference/copy check
>>>>>>
>>>>>> the presence of original would indicate that we want the view check,
>>>>>> `noref` would tell which one.
>>>>>
>>>>> This is how larry gets improved---with cleaning like that.
>>>>>
>>>>> I'll make the change in the trunk.
>>>>
>>>> I changed the function signature as you suggested. I also changed
>>>> noref to iscopy. The change in the kw name will mess up your unit
>>>> tests :(
>>>>
>>>> And I change the name of assert_noreference to assert_iscopy and
>>>> assert_nocopy to assert_isview.
>>>
>>> I changed la.util.testing.iscopy and isview to accept larrys with
>>> different number of dimensions. I needed it to unit test the new
>>> insertaxis method.
>>>
>>> http://bazaar.launchpad.net/%7Ekwgoodman/larry/trunk/revision/200/la/util/testing.py
>>>
>>
>>
>> if larry1.x is not larry2.x
>>
>>
>>>>> a = np.ones((3,4))
>>>>> b = a[0]
>>>>> a is b
>> False
>>>>> a.base is b
>> False
>>>>> b.base is a
>> True
>>
>>>>> c = a[0].copy()
>>>>> c is b
>> False
>>>>> c.base is a
>> False
>>>>> a.base is c
>> False
>>
>> message will follow
>>
>> Josef
>
> Wow! Neat.

Robert Kern on the numpy mailing list suggested np.may_share_memory.
So in testing.iscopy (and similarly in isview) I'm now using:

    if np.may_share_memory(larry1.x, larry2.x):
        msg.append('The data arrays share a reference.')



References