Skip to content

Commit 49fd6d8

Browse files
committed
add docstring
1 parent 3fc6fd4 commit 49fd6d8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

hls4ml/backends/vivado/passes/reshaping_templates.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,25 @@ def format(self, node):
128128

129129

130130
def permute_config_gen(name: str, shape: tuple[int, ...], perm: tuple[int, ...]):
131+
"""
132+
Generate a configuration string for a permute operation. Operates by mapping the output index to input input index by:
133+
- unravel the output index
134+
- map each dimension to the corresponding stride in the input tensor, sum
135+
The operation can be expressed as:
136+
137+
new_shape = tuple(shape[i] for i in perm)
138+
strides = np.cumprod((shapes[1:] + (1,))[::-1])[::-1]
139+
perm_strides = [strides[i] for i in perm]
140+
out[index] = inp[np.dot(np.unravel_index(index, new_shape), perm_strides)]
141+
142+
Args:
143+
name (str): The name of the configuration.
144+
shape (tuple[int, ...]): The shape of the input tensor.
145+
perm (tuple[int, ...]): The permutation of the dimensions.
146+
147+
Returns:
148+
str: The formatted configuration string for the permute operation.
149+
"""
131150
new_shape = tuple(shape[i] for i in perm)
132151
strides = np.cumprod((shape[1:] + (1,))[::-1])[::-1]
133152
perm_strides = tuple(int(strides[i]) for i in perm)

0 commit comments

Comments
 (0)