MCPcopy Create free account
hub / github.com/CompVis/zigma / zigzag_path

Function zigzag_path

utils/utils_zigzag.py:144–175  ·  view source on GitHub ↗
(N)

Source from the content-addressed store, hash-verified

142
143
144def zigzag_path(N):
145 def zigzag_path_lr(N, start_row=0, start_col=0, dir_row=1, dir_col=1):
146 path = []
147 for i in range(N):
148 for j in range(N):
149 # If the row number is even, move right; otherwise, move left
150 col = j if i % 2 == 0 else N - 1 - j
151 path.append((start_row + dir_row * i) * N + start_col + dir_col * col)
152 return path
153
154 def zigzag_path_tb(N, start_row=0, start_col=0, dir_row=1, dir_col=1):
155 path = []
156 for j in range(N):
157 for i in range(N):
158 # If the column number is even, move down; otherwise, move up
159 row = i if j % 2 == 0 else N - 1 - i
160 path.append((start_row + dir_row * row) * N + start_col + dir_col * j)
161 return path
162
163 paths = []
164 for start_row, start_col, dir_row, dir_col in [
165 (0, 0, 1, 1),
166 (0, N - 1, 1, -1),
167 (N - 1, 0, -1, 1),
168 (N - 1, N - 1, -1, -1),
169 ]:
170 paths.append(zigzag_path_lr(N, start_row, start_col, dir_row, dir_col))
171 paths.append(zigzag_path_tb(N, start_row, start_col, dir_row, dir_col))
172
173 for _index, _p in enumerate(paths):
174 paths[_index] = np.array(_p)
175 return paths
176
177
178def rand_perm(N, num):

Callers 2

__init__Method · 0.90
utils_zigzag.pyFile · 0.85

Calls 2

zigzag_path_lrFunction · 0.85
zigzag_path_tbFunction · 0.85

Tested by

no test coverage detected