reminisce commented on a change in pull request #14053: in-place reshape ops
URL: https://github.com/apache/incubator-mxnet/pull/14053#discussion_r259485740
##########
File path: python/mxnet/ndarray/ndarray.py
##########
@@ -1701,13 +1765,41 @@ def softmin(self, *args, **kwargs):
"""
return op.softmin(self, *args, **kwargs)
- def squeeze(self, *args, **kwargs):
- """Convenience fluent method for :py:func:`squeeze`.
+ def squeeze(self, axis=None, inplace=False):
+ """Returns a **view** of this array with squeezed shape without
altering any data.
- The arguments are the same as for :py:func:`squeeze`, with
- this array as data.
+ Parameters
+ ----------
+ axis : int, tuple of int, or None
+ Selects a subset of the single-dimensional entries in the shape.
+ If an axis is selected with shape entry greater than one, an error
is raised.
+ inplace : bool, default False
+ If True, this method returns a **view** of this array
+ that shares data with this array. Otherwise, a copy is returned.
"""
- return op.squeeze(self, *args, **kwargs)
+ if not inplace:
+ return op.squeeze(self, axis=axis)
+ else:
+ new_shape = list(self.shape)
+ if isinstance(axis, int):
+ axis = [axis]
+ if axis:
+ assert len(axis) == len(set(axis)), \
+ "axis {} contains duplicate which is not
allowed.".format(axis)
+ for i in axis:
+ assert 0 <= i < len(new_shape), "axis {} is out of
range.".format(i)
Review comment:
Negative axes should be supported.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services