Conversation
bf55550 to
c3aeda6
Compare
c3aeda6 to
5c346a1
Compare
|
Why not just use |
Or even |
lib/iris/cube.py
Outdated
| if result: | ||
| result = np.all(np.abs(self.data - other.data) < 1e-8) | ||
|
|
||
| result = da.array.allclose(self.data, other.data) |
There was a problem hiding this comment.
da is already dask.array and the function returns a dask array. So I think you need:
da.allclose(self.core_data(), other.core_data()).compute()(edited following @pp-mo's comment)
lib/iris/cube.py
Outdated
| @@ -3021,8 +3021,7 @@ def __eq__(self, other): | |||
| # having checked everything else, check approximate data | |||
| # equality - loading the data if has not already been loaded. | |||
There was a problem hiding this comment.
If we're happy with using da.allclose, I guess this comment about loading the data can be removed?
There was a problem hiding this comment.
If this is using 'self.data', 'other.data' then of course it is still realising the cubes.
In fact I don't think we can use dask here, as the result needs to be a concrete boolean, whereas da.allclose returns a lazy scalar value, even when the args are concrete ...
>>> da.allclose(np.array([1,2]), np.array([1,1]))
dask.array<all-aggregate, shape=(), dtype=bool, chunksize=()>
>>> _.compute()
False
>>>
There was a problem hiding this comment.
If this is using 'self.data', 'other.data' then of course it is still realising the cubes.
Ah yes of course, you'd want to use core_data() or lazy_data()
Definitely in learning mode here...
Is there no advantage to using da.allclose with the compute call? I was thinking it would access the files in chunks and therefore avoid busting memory.
Aside: that thing you did with the underscore, I did not know was a thing 😮 .
There was a problem hiding this comment.
Is there no advantage to using da.allclose with the compute call? I was thinking it would access the files in chunks and therefore avoid busting memory.
Actually that is a really good point 👍
It won't realise any more, which it used to, but I think we always view that as a good thing 😉
you'd want to use core_data()
I think it makes sense to use 'core_data' as it involves the minimum of extra work.
My key point was : the routine itself must still return a regular boolean, not a lazy value.
... but I see now you have just added the ".compute()" above ! 👍
the underscore
Yes, it's where the interpreter puts unassigned results (in addition to printing them).
Also very handy when you forgot to save the result of a calculation !
>>> long_and_complicated()
BigObject(...)
>>> keep_that = _
f8ab698 to
cccd653
Compare
891517c to
2135850
Compare
|
@cpelley Sorry about this! The travis tests are failing but I believe the fix for those tests went in already. If you rebase we should be able to get a green tick. Do you mind rebasing and then this can go in? |
|
Hi @cpelley ! |
b53f4ba to
9e6a840
Compare
|
#3431 replaced : closing. |
Issue introduced in numpy 1.14 I think where subtracting two boolean arrays was deprecated.
This may be better placed as a more general numpy comparison operator in iris but I don't see there is anywhere suitable for such a thing to live currently.