MCPcopy Create free account
hub / github.com/Kosinkadink/ComfyUI-Advanced-ControlNet / SparseIndexMethod

Class SparseIndexMethod

adv_control/control_sparsectrl.py:270–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

268
269
270class SparseIndexMethod(SparseMethod):
271 def __init__(self, idxs: list[int]):
272 super().__init__(self.INDEX)
273 self.idxs = idxs
274
275 def _get_indexes(self, hint_length: int, full_length: int) -> list[int]:
276 orig_hint_length = hint_length
277 if hint_length > full_length:
278 hint_length = full_length
279 # if idxs is less than hint_length, throw error
280 if len(self.idxs) < hint_length:
281 err_msg = f"There are not enough indexes ({len(self.idxs)}) provided to fit the usable {hint_length} input images."
282 if orig_hint_length != hint_length:
283 err_msg = f"{err_msg} (original input images: {orig_hint_length})"
284 raise ValueError(err_msg)
285 # cap idxs to hint_length
286 idxs = self.idxs[:hint_length]
287 new_idxs = []
288 real_idxs = set()
289 for idx in idxs:
290 if idx < 0:
291 real_idx = full_length+idx
292 if real_idx in real_idxs:
293 raise ValueError(f"Index '{idx}' maps to '{real_idx}' and is duplicate - indexes in Sparse Index Method must be unique.")
294 else:
295 real_idx = idx
296 if real_idx in real_idxs:
297 raise ValueError(f"Index '{idx}' is duplicate (or a negative index is equivalent) - indexes in Sparse Index Method must be unique.")
298 real_idxs.add(real_idx)
299 new_idxs.append(real_idx)
300 return new_idxs
301
302
303def get_idx_list_from_str(indexes: str) -> list[int]:

Callers 2

get_methodMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected