mindspore_gl.graph.PadArray2d

View Source On Gitee
class mindspore_gl.graph.PadArray2d(dtype, direction, fill_value=None, reset_with_fill_value=True, mode=PadMode.AUTO, size=None, use_shared_numpy=False)[source]

PadArray2d, specific pad operator for 2D array.

Warning

PadArray2d will reuse memory buffer to speedup pad operation.

Parameters
  • dtype (numpy.dtype) – To determine result’s data type.

  • direction (PadDirection) – Pad direction for array, PadDirection. ROW means we will pad along axis=1, PadDirection.COl means we will pad along axis=0.

  • fill_value (Union[float, int, optional]) – Fill value for padded region. Default: None.

  • reset_with_fill_value (bool, optional) – PadArray2d will reuse memory buffer, you can set this value to False if you dont care about the padded value. Default: True.

  • mode (PadMode, optional) – Pad mode for array, if PadMode.CONST, this op will pad array to user-specific size. If PadMode.AUTO, this will choose padded result length according to input’s length. The expected length can be calculated as \(length=2^{\text{ceil}\left ( \log_{2}{input\_length} \right ) }\) Default: mindspore_gl.graph.PadMode.AUTO.

  • size (Union[List, Tuple, optional]) – User specific size for padding result. Default: None.

  • use_shared_numpy (bool, optional) – If we use SharedNDArray for speeding up inter process communication. This is recommended if you do feature collection and feature padding in child process and need inter process communication for graph feature. Default: False.

Inputs:
  • input_array (numpy.array) - input numpy array for pad.

Raises

ValueError – pad size should be provided when padding mode is PadMode.CONST.

Supported Platforms:

Ascend GPU

Examples

>>> from mindspore_gl.graph.ops import PadArray2d, PadMode, PadDirection
>>> pad_op = PadArray2d(dtype=np.float32, mode=PadMode.CONST, direction=PadDirection.COL,
...                               size=(3, 1), fill_value=0)
>>> node_list = np.array([[1]])
>>> res = pad_op(node_list)
>>> print(res)
[[1.]
 [0.]
 [0.]]
lazy(shape: Union[List, Tuple], **kwargs)[source]

Lazy Array Pad, this will just determine padded result shape and return an empty array with target shape.

Parameters
  • shape (Union[List, Tuple]) – input array’s shape for pad.

  • kwargs (dict) –

    config dict

    • fill_value (Union[int, float]): fill the padding array with value.

Returns

memory_buffer(numpy.ndarray), an empty numpy array with target padded shape.