Skip to content

Commit

Permalink
Merge pull request #15 from akatz-ai/alex-dev
Browse files Browse the repository at this point in the history
Updated with shrink num sequence node
  • Loading branch information
akatz-ai authored Sep 2, 2024
2 parents 5bf92c7 + b1102e2 commit b4a872c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
6 changes: 4 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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):
Expand All @@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
53 changes: 53 additions & 0 deletions src/ak_shrink_num_sequence.py
Original file line number Diff line number Diff line change
@@ -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,)

0 comments on commit b4a872c

Please sign in to comment.