haojin2 commented on a change in pull request #17328: [numpy] add op pad
URL: https://github.com/apache/incubator-mxnet/pull/17328#discussion_r375087669
 
 

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -5866,4 +5866,83 @@ def bincount(x, weights=None, minlength=0):
     return _npi.bincount(x, weights=weights, minlength=minlength, 
has_weights=True)
 
 
+@set_module('mxnet.symbol.numpy')
+def pad(array, pad_width=None, mode="constant", reflect_type="even", 
constant_values=0):
+    """
+    Pad an array.
+
+    Parameters
+    ----------
+    array : array_like of rank N
+        The array to pad.
+    pad_width : {sequence, array_like, int}
+        Number of values padded to the edges of each axis.
+        ((before_1, after_1), ... (before_N, after_N)) unique pad widths
+        for each axis.
+        ((before, after),) yields same before and after pad for each axis.
+        (pad,) or int is a shortcut for before = after = pad width for all
+        axes.
+    mode : str or function, optional
+        One of the following string values or a user supplied function.
+        'constant' (default)
+            Pads with a constant value.
+        'edge'
+            Pads with the edge values of array.
+        'linear_ramp'
+            not supported yet
+        'maximum'
+            Pads with the maximum value of all of the
+            vector along each axis.
+        'mean'
+            not supported yet
+        'median'
+           not supported yet
+        'minimum'
+            Pads with the minimum value of all of the
+            vector along each axis.
+        'reflect'
+            Pads with the reflection of the vector mirrored on
+            the first and last values of the vector along each
+            axis.
+        'symmetric'
+            Pads with the reflection of the vector mirrored
+            along the edge of the array.
+        'wrap'
+            not supported yet
+        'empty'
+            Pads with undefined values.
+            .. versionadded:: 1.17
+        <function>
+            Padding function, see Notes.
+    stat_length : not supported yet
+    constant_values : scalar, optional
+        Used in 'constant'.  The values to set the padded values for each
+        axis.
+        Default is 0.
+
+    end_values : not supported yet
+    reflect_type : {'even', 'odd'}, optional
+        only support even now
+
+    Returns
+    -------
+    pad : ndarray
+        Padded array of rank equal to `array` with shape increased
+        according to `pad_width`.
+    """
+    if mode == "constant":
+        return _npi.pad(array, pad_width, 1, reflect_type, constant_values)
+    elif mode == "symmetric" and reflect_type == "even":
+        return _npi.pad(array, pad_width, 2, "even", constant_values)
+    elif mode == "edge":
+        return _npi.pad(array, pad_width, 3, reflect_type, constant_values)
+    elif mode == "reflect" and reflect_type == "even":
+        return _npi.pad(array, pad_width, 4, "even", constant_values)
+    elif mode == "maximum":
+        return _npi.pad(array, pad_width, 5, "even", constant_values)
+    elif mode == "minimum":
+        return _npi.pad(array, pad_width, 6, "even", constant_values)
+    else:
+        raise ValueError("didn't support these modes and reflect_types.")
 
 Review comment:
   give more specific error messages about the exact inputs which are not 
supported.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to