MCPcopy Index your code
hub / github.com/apache/tvm / pad_tensor

Function pad_tensor

python/tvm/topi/testing/poolnd_python.py:102–123  ·  view source on GitHub ↗

Pad the spatial dimensions of the given array.

(
    np_arr: np.array,
    pad_value: float,
    padding_before: list[int],
    padding_after: list[int],
    dtype: str,
)

Source from the content-addressed store, hash-verified

100
101
102def pad_tensor(
103 np_arr: np.array,
104 pad_value: float,
105 padding_before: list[int],
106 padding_after: list[int],
107 dtype: str,
108) -> np.array:
109 """Pad the spatial dimensions of the given array."""
110 orig_shape = list(np_arr.shape)
111 padded_shape = list(np_arr.shape)
112 n = len(orig_shape)
113 for dim in range(2, n):
114 i = dim - 2
115 padded_shape[dim] += padding_after[i] + padding_before[i]
116
117 pad_np = (np.zeros(shape=padded_shape) + pad_value).astype(dtype)
118 ranges_it = [range(padded_shape[0]), range(padded_shape[1])]
119 for dim in range(2, n):
120 i = dim - 2
121 ranges_it.append(range(padding_before[i], padding_before[i] + orig_shape[dim]))
122 pad_np[np.ix_(*ranges_it)] = np_arr
123 return pad_np
124
125
126def poolnd_python(

Callers 1

poolnd_pythonFunction · 0.85

Calls 3

astypeMethod · 0.45
zerosMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…