Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/825 setitem slice dndarrays #826

Merged
merged 23 commits into from
Jul 20, 2021
Merged

Conversation

coquelin77
Copy link
Member

@coquelin77 coquelin77 commented Jun 29, 2021

Description

Fix for setting DNDarray values with a DNDarray which has a different size in the split dimension, could use cleaning.

Issue/s resolved: #825

Changes proposed:

  • Fix for setting DNDarray values with a DNDarray which has a different size in the split dimension
  • added OOP redistribute function
  • add lshape_map property (not used everywhere yet)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Due Diligence

  • All split configurations tested
  • Multiple dtypes tested in relevant functions
  • Documentation updated (if needed)
  • Updated changelog.md under the title "Pending Additions"

Does this change modify the behaviour of other functions? If so, which?

no

@codecov
Copy link

codecov bot commented Jun 29, 2021

Codecov Report

Merging #826 (89fb977) into master (b2939e5) will increase coverage by 0.02%.
The diff coverage is 98.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #826      +/-   ##
==========================================
+ Coverage   95.30%   95.32%   +0.02%     
==========================================
  Files          64       64              
  Lines        9004     9056      +52     
==========================================
+ Hits         8581     8633      +52     
  Misses        423      423              
Flag Coverage Δ
gpu 94.46% <98.44%> (+0.03%) ⬆️
unit 90.94% <98.44%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
heat/core/dndarray.py 97.30% <98.37%> (+0.18%) ⬆️
heat/core/manipulations.py 99.08% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2939e5...89fb977. Read the comment docs.

Copy link
Collaborator

@mtar mtar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it up! @coquelin77

I played around a little bit. It doesn't work when the split axes are different. Do you want to handle them too?

Some notes I took when reviewing the code. You wanted to clean it up anyway.

heat/core/dndarray.py Outdated Show resolved Hide resolved
heat/core/manipulations.py Show resolved Hide resolved
heat/core/dndarray.py Outdated Show resolved Hide resolved
heat/core/dndarray.py Outdated Show resolved Hide resolved
heat/core/dndarray.py Outdated Show resolved Hide resolved
heat/core/dndarray.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ClaudiaComito ClaudiaComito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the new lshape_map property. Brilliant.

A problem I'm having with setitem is this:

>>> import heat as ht
>>> a = ht.arange(10).reshape(2,5)
>>> a[1,ht.array([1])]
DNDarray([6], dtype=ht.int32, device=cpu:0, split=None)
>>> a[1,ht.array(1)]
DNDarray(6, dtype=ht.int32, device=cpu:0, split=None)
a[1,ht.array([1])] = 7
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/c.comito/HAF/heat/heat/core/dndarray.py", line 1404, in __setitem__
    return self.__setter(key, value)  # returns None
  File "/Users/c.comito/HAF/heat/heat/core/dndarray.py", line 1570, in __setter
    self.__array.__setitem__(key, value)
  File "/Users/c.comito/HAF/heat/heat/core/dndarray.py", line 976, in __len__
    return self.shape[0] 

This is not specific to this branch but maybe can be addressed here.

Thanks a lot!

heat/core/dndarray.py Outdated Show resolved Hide resolved
@coquelin77
Copy link
Member Author

Keep it up! @coquelin77

I played around a little bit. It doesn't work when the split axes are different. Do you want to handle them too?

Some notes I took when reviewing the code. You wanted to clean it up anyway.

do you mean to the value or the key for the different split axes?

if you mean the value is the one with a different split, then that is complicated, if the shapes are the right size, i dont have a problem with it. but that is easier said than done

@mtar
Copy link
Collaborator

mtar commented Jul 8, 2021

From the example in #825:

x = ht.ones((10, 10), split=0)
setting = ht.zeros((8, 8), split=1)
x[1:-1, 1:-1] = setting
print(x)

This doesn't work.

This works however

x = ht.ones((10, 10), split=0)
setting = ht.zeros((4, 8), split=1)
x[0:4, 1:-1] = setting
print(x)
[1,0]<stdout>:DNDarray([[1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
[1,0]<stdout>:          [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
[1,0]<stdout>:          [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
[1,0]<stdout>:          [1., 0., 0., 0., 0., 0., 0., 0., 0., 1.],
[1,0]<stdout>:          [1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1,0]<stdout>:          [1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1,0]<stdout>:          [1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1,0]<stdout>:          [1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1,0]<stdout>:          [1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[1,0]<stdout>:          [1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]], dtype=ht.float32, device=cpu:0, split=0)
[1,1]<stdout>:

@coquelin77
Copy link
Member Author

with some digging. the example that works in this case, only works because of an accident where all of the values are gathered onto rank 0.

I think that setting a split DNDarray with another differently split DNDarray should be handled in another issue

@coquelin77
Copy link
Member Author

rerun tests

Copy link
Collaborator

@mtar mtar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you increase the coverage?


array indexing is not available a[ht.array([0,1])] = ht.ones(2), but this is another issue.

CHANGELOG.md Outdated
@@ -50,6 +50,7 @@ Example on 2 processes:
- [#820](https://github.com/helmholtz-analytics/heat/pull/820) `randn` values are pushed away from 0 by the minimum value the given dtype before being transformed into the Gaussian shape
- [#821](https://github.com/helmholtz-analytics/heat/pull/821) Fixed `__getitem__` handling of distributed `DNDarray` key element
- [#826](https://github.com/helmholtz-analytics/heat/pull/826) Fixed `__setitem__` handling of distributed `DNDarray` values which have a different shape in the split dimension
- [#831](https://github.com/helmholtz-analytics/heat/pull/831) `__getitem__` handling of `array-like` 1-element key
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending Additions

heat/core/dndarray.py Outdated Show resolved Hide resolved
Comment on lines +1375 to +1377
f"\nvalue.split {val_split} not equal to this DNDarray's split:"
f" {sp}. this may cause errors or unwanted behavior",
category=RuntimeWarning,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😘

Copy link
Collaborator

@mtar mtar Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a test for the warning? No test according to codecov

step2 = key_step if key_step is not None else 1
key_start = (chunk_starts[rank] - og_key_start).item()
if key_start < 0:
key_start = 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no test according to codecov

@mtar mtar merged commit 3b31102 into master Jul 20, 2021
@mtar mtar deleted the bug/825-setitem-slice-dndarrays branch July 20, 2021 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

setitem not working with slices and values are DNDarrays
3 participants