MCPcopy Create free account
hub / github.com/apache/singa / handle_odd_pad_fwd

Function handle_odd_pad_fwd

python/singa/utils.py:56–85  ·  view source on GitHub ↗

handle odd padding mode forward Args: x, the input tensor odd_padding, the odd_padding Returns: tensor, the output

(x, odd_padding, is_pool=False)

Source from the content-addressed store, hash-verified

54
55
56def handle_odd_pad_fwd(x, odd_padding, is_pool=False):
57 """
58 handle odd padding mode forward
59 Args:
60 x, the input tensor
61 odd_padding, the odd_padding
62 Returns:
63 tensor, the output
64 """
65 # (axis, left padding if True else right padding)
66 flags = [(2, True), (2, False), (3, True), (3, False)]
67 for (axis, left), pad in zip(flags, odd_padding):
68 if pad == 0:
69 continue
70 if is_pool:
71 if left:
72 padding = singa.SliceOn(x, 0, pad, axis)
73 else:
74 axis_shape = list(x.shape())[axis]
75 padding = singa.SliceOn(x, axis_shape - pad, axis_shape, axis)
76 else:
77 pad_shape = list(x.shape())
78 pad_shape[axis] = pad
79 padding = singa.Tensor(list(pad_shape), x.device())
80 padding.SetFloatValue(0.)
81 if left:
82 x = singa.ConcatOn(singa.VecTensor([padding, x]), axis)
83 else:
84 x = singa.ConcatOn(singa.VecTensor([x, padding]), axis)
85 return x
86
87
88def handle_odd_pad_bwd(dx, odd_padding):

Callers

nothing calls this directly

Calls 3

shapeMethod · 0.80
TensorMethod · 0.80
deviceMethod · 0.80

Tested by

no test coverage detected