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

Features/227 lshape #231

Merged
merged 45 commits into from
May 27, 2019
Merged

Features/227 lshape #231

merged 45 commits into from
May 27, 2019

Conversation

ClaudiaComito
Copy link
Contributor

@ClaudiaComito ClaudiaComito commented Apr 11, 2019

@Markus-Goetz there's still a quirk here with argmin and argmax. Even if axis = 0 (or contains 0), we can't lose the first dimension of partial, because partial_op in this case yields both the values and the indices, so dimension 0 of partial is by default at least 2 when it gets returned to the function. The fix has to happen in the argmin()/ argmax() functions. Not sure how to do that (yet).

Example:

>>> a = ht.random.randn(3,4,5)
>>> a
tensor([[[-0.3470, -0.3984,  0.0270,  0.3000,  1.0776],
         [-1.2756, -0.8707,  0.8296, -0.7750, -1.5317],
         [-0.2380, -0.3360, -1.4865,  0.5521, -0.2564],
         [-0.6830, -0.3591, -1.3159,  0.5883,  1.9217]],

        [[ 0.4855, -1.9448,  0.6220,  1.9253, -0.8722],
         [ 0.3382, -0.5159,  0.5053,  1.6421, -1.1279],
         [-0.5231, -0.1203,  1.3909,  0.4133,  0.6540],
         [-1.3037, -1.0900, -0.3871, -0.7963,  0.9564]],

        [[-1.0519,  0.0965, -0.9878, -0.0702, -0.2331],
         [ 0.0111, -1.1165, -1.6232, -0.1156, -0.3195],
         [-0.1528,  0.5501,  0.2335,  0.1948,  0.7384],
         [-1.8235,  1.4258,  0.2019,  1.0923,  1.0515]]])
>>> a.argmin(0)
tensor([[[2, 1, 2, 2, 1],
         [0, 2, 2, 0, 0],
         [1, 0, 0, 2, 0],
         [2, 1, 0, 1, 1]]])
>>> a.argmin(0).shape
(4, 5)
>>> a.argmin(0).lshape
(1, 4, 5)

With axis = 1:

>>> a.argmin(1)
tensor([[1, 1, 2, 1, 1],
        [3, 0, 3, 3, 1],
        [3, 1, 1, 1, 1]])
>>> a.argmin(1).shape
(3, 5)
>>> a.argmin(1).lshape
(3, 5)

@Markus-Goetz
Copy link
Member

Could the fix be a squeeze() after the partial call?

@ClaudiaComito
Copy link
Contributor Author

ClaudiaComito commented Apr 24, 2019

Could the fix be a squeeze() after the partial call?

Thanks, indeed, that's probably what I need. I'll work on it now.

@codecov-io
Copy link

codecov-io commented Apr 24, 2019

Codecov Report

Merging #231 into master will increase coverage by 0.01%.
The diff coverage is 96.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #231      +/-   ##
==========================================
+ Coverage   96.17%   96.18%   +0.01%     
==========================================
  Files          47       47              
  Lines        6514     6639     +125     
==========================================
+ Hits         6265     6386     +121     
- Misses        249      253       +4
Impacted Files Coverage Δ
heat/core/tests/test_arithmetics.py 100% <ø> (ø) ⬆️
heat/core/tests/test_factories.py 100% <100%> (ø) ⬆️
heat/core/operations.py 91.36% <100%> (+0.59%) ⬆️
heat/core/__init__.py 100% <100%> (ø) ⬆️
heat/core/tests/test_rounding.py 100% <100%> (ø) ⬆️
heat/core/tests/test_exponential.py 100% <100%> (ø) ⬆️
heat/core/tests/test_statistics.py 100% <100%> (ø) ⬆️
heat/core/logical.py 95% <100%> (ø) ⬆️
heat/core/tests/test_manipulations.py 100% <100%> (ø)
heat/core/tests/test_logical.py 100% <100%> (ø) ⬆️
... and 4 more

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 2ecac2d...59f2cc2. Read the comment docs.

@@ -208,8 +209,7 @@ def allclose(x, y, rtol=1e-05, atol=1e-08, equal_nan=False):
return bool(_local_allclose.item())



def any(x, axis=None, out=None):
def any(x, axis=None, out=None, keepdim=None):
Copy link
Member

Choose a reason for hiding this comment

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

should this be keepdim=False instead of None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (now in logical.py).

x : ht.tensor
Input data.

axis : None or int or tuple of ints, optional
Copy link
Member

Choose a reason for hiding this comment

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

can you add a bit of context to what this axis parameter does? i can see it in the examples but some text would be nice too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done (now in manipulations.py)

if 0 in axis:
lshape_losedim = (2,) + lshape_losedim
else:
lshape_losedim = (2 * lshape_losedim[0],) + lshape_losedim[1:]
Copy link
Member

Choose a reason for hiding this comment

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

the 2 seems fishy to me. can you justify it for me? I am just not seeing it

Copy link
Contributor Author

@ClaudiaComito ClaudiaComito May 8, 2019

Choose a reason for hiding this comment

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

Hi Daniel @coquelin77, EDITED
thanks, I'm really unhappy with this if statement. The problem is that, if axis is not None, the result of local_argmin/max and MPI_ARGMIN/MAX is made up of two sets of results really: the min/max values along a dimension, and the respective indices. So at this stage the dimension along the FIRST axis is the reduced dimension * 2. The min/max values are removed from the result at a later stage in the argmin/max() functions.

EDITED: never mind the par. below, I'm trying something else now.

(So having to re-add dimension of size 2 for the reduction axis is justified, it's cumbersome though and this "special behaviour" of argmin/max is giving me a lot of trouble pretty much whatever I'm working on. So @Markus-Goetz, @coquelin77 I'm thinking of adding __argreduce_op to operations.py and funnel argmin and argmax out to that function, leaving __reduce_op for "regular" reduction operations. )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK here's what it looks like now (operations.py lines 217-221)

# Take care of special cases argmin and argmax: keep partial.shape[0]
            if (0 in axis and partial.shape[0] != 1):
                lshape_losedim = (partial.shape[0],) + lshape_losedim
            if (not 0 in axis and partial.shape[0] != x.lshape[0]):
                lshape_losedim = (partial.shape[0],) + lshape_losedim[1:]

Basically, the assumption is that whenever the first dimension of partial is different from what it should be (1 if reduction along axis 0, or x.lshape[0] if reduction along any other axis), there will be a good reason for it so just keep that partial[0] as first dimension.

This way we don't need to add ifs for every quirky reduction operation that comes our way.

Please let me know if I'm overseeing something.

@@ -278,7 +280,7 @@ def allclose(self, other, rtol=1e-05, atol=1e-08, equal_nan=False):
"""
return operations.allclose(self, other, rtol, atol, equal_nan)

def any(self, axis=None, out=None):
def any(self, axis=None, out=None, keepdim=None):
Copy link
Member

Choose a reason for hiding this comment

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

keepdim=False vs =None again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done (dndarray.py)

x : ht.tensor
Input data.

axis : None or int or tuple of ints, optional
Copy link
Member

Choose a reason for hiding this comment

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

more explanation for axis as mentioned before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done (dndarray.py)

@Markus-Goetz
Copy link
Member

Bump, has a minor conflict with the master

@ClaudiaComito
Copy link
Contributor Author

Alright @Markus-Goetz , @coquelin77 , I've commented out the test that fails for now, fixing that (Issue #273) needs fixing Allgatherv (#233, @Cdebus ). It would still be good to have squeeze() and the lshape fixes merged into master.

Thanks,

Claudia

@ClaudiaComito ClaudiaComito merged commit 5955563 into master May 27, 2019
@ClaudiaComito ClaudiaComito deleted the features/227-lshape branch May 27, 2019 09:17
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.

4 participants