From b1102e2732062ff444a7921479fa3df56c16843d Mon Sep 17 00:00:00 2001 From: akatzfey1 <katzfeyalex@gmail.com> Date: Mon, 2 Sep 2024 01:31:38 -0700 Subject: [PATCH] Updated with shrink num sequence node --- __init__.py | 6 ++-- pyproject.toml | 2 +- src/ak_shrink_num_sequence.py | 53 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/ak_shrink_num_sequence.py diff --git a/__init__.py b/__init__.py index 24aa81e..6282aa8 100644 --- a/__init__.py +++ b/__init__.py @@ -20,6 +20,7 @@ from .src.ak_adjust_list_size import AK_AdjustListSize from .src.ak_video_speed_adjust import AK_VideoSpeedAdjust from .src.ak_convert_list_to_float_list import AK_ConvertListToFloatList +from .src.ak_shrink_num_sequence import AK_ShrinkNumSequence NODE_CONFIG = { "AK_AnimatedDilationMaskLinear": {"class": AK_AnimatedDilationMaskLinear, "name": "AK Dilate Mask Linear"}, @@ -35,7 +36,8 @@ "AK_BinaryAmplitudeGate": {"class": AK_BinaryAmplitudeGate, "name": "AK Binary Amplitude Gate"}, "AK_AdjustListSize": {"class": AK_AdjustListSize, "name": "AK Adjust List Size"}, "AK_VideoSpeedAdjust": {"class": AK_VideoSpeedAdjust, "name": "AK Video Speed Adjust"}, - "AK_ConvertListToFloatList": {"class": AK_ConvertListToFloatList, "name": "AK Convert List To Float List"} + "AK_ConvertListToFloatList": {"class": AK_ConvertListToFloatList, "name": "AK Convert List To Float List"}, + "AK_ShrinkNumSequence": {"class": AK_ShrinkNumSequence, "name": "AK Shrink Num Sequence"}, } def generate_node_mappings(node_config): @@ -55,6 +57,6 @@ def generate_node_mappings(node_config): __all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS', "WEB_DIRECTORY"] ascii_art = """ -AKATZ NODES +π AKATZ NODES π """ print(ascii_art) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 869ed33..634f7bf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "comfyui-akatz-nodes" description = "Simple custom node pack for nodes I use in my workflows. Includes Dilate Mask Linear for animating masks." -version = "1.5.5" +version = "1.5.6" license = {file = "LICENSE"} [project.urls] diff --git a/src/ak_shrink_num_sequence.py b/src/ak_shrink_num_sequence.py new file mode 100644 index 0000000..63a2719 --- /dev/null +++ b/src/ak_shrink_num_sequence.py @@ -0,0 +1,53 @@ +class AK_ShrinkNumSequence: + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "float_list": ("FLOAT", {"forceInput": True}), # Expecting a list of floats + "target_number": ("FLOAT", {"default": 1.0, "step": 0.01, "round": False, "display": "number"}), # The float number to shrink + "max_occurrences": ("INT", {"default": 2, "min": 1}), # Maximum occurrences to keep + "use_epsilon": ("BOOLEAN", {"default": True}), # Boolean to use epsilon comparison + }, + } + + RETURN_TYPES = ("FLOAT",) # Output will be a list of floats + FUNCTION = "shrink_num_sequence" + CATEGORY = "πAkatz Nodes/Utils" + + def shrink_num_sequence(self, float_list, target_number=1.0, max_occurrences=2, use_epsilon=False) -> tuple: + """ + Shrink contiguous sequences of a specified float value in a list so that each sequence + contains only the first max_occurrences values. + + Args: + - float_list (list of float): The input list of float values. + - target_number (float): The float number to shrink. + - max_occurrences (int): Maximum number of target_number values to keep in each contiguous sequence. + - use_epsilon (bool): Whether to use epsilon comparison for float equality. + + Returns: + - tuple: A tuple containing the modified list with shrunk sequences of the specified float value. + """ + # Define epsilon for comparison + epsilon = 1e-7 + + # Initialize variables to store the output and a counter for the target number values + output_list = [] + count = 0 + + # Iterate through the list + for val in float_list: + # Check if the current value matches the target number + if (use_epsilon and abs(val - target_number) < epsilon) or (not use_epsilon and val == target_number): + # If the current value matches the target number, check the count + if count < max_occurrences: + output_list.append(val) + else: + output_list.append(0.0) + count += 1 + else: + # Reset count when a non-target value is found + output_list.append(val) + count = 0 + + return (output_list,) \ No newline at end of file