add ListRandomSeeds (#11)
* create node ListRandomSeeds * adjust XY Plot: Queue and GenericQueue to store input lists at first round
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import hashlib
|
||||
import math
|
||||
import random
|
||||
|
||||
from ..collection.register_nodes import register_node
|
||||
|
||||
@@ -383,3 +385,40 @@ class ListLimit:
|
||||
output = list[-nb_elements:]
|
||||
|
||||
return (output, len(output))
|
||||
|
||||
|
||||
@register_node('List: Random Seeds', 'list')
|
||||
class ListRandomSeeds:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
'required': {
|
||||
'count': (
|
||||
'INT',
|
||||
{'default': 1, 'min': 1, 'tooltip': 'number of random seeds'},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
FUNCTION = 'run'
|
||||
RETURN_TYPES = ('LIST', 'INT')
|
||||
RETURN_NAMES = ('list', 'count')
|
||||
OUTPUT_TOOLTIPS = (
|
||||
'list of random seeds',
|
||||
TOOLTIP_OUTPUT_COUNT,
|
||||
)
|
||||
DESCRIPTION = 'Return a list of random seeds.'
|
||||
|
||||
# ensure the list is regenerated
|
||||
@classmethod
|
||||
def IS_CHANGED(cls, **kwargs):
|
||||
return float('NaN')
|
||||
|
||||
def run(self, count):
|
||||
values = []
|
||||
for i in range(0, count):
|
||||
values.append(math.floor(random.randrange(0, 0xFFFFFFFFFFFFFFFF)))
|
||||
return (values, len(values))
|
||||
|
||||
@@ -82,6 +82,9 @@ class XYPlotQueue:
|
||||
)
|
||||
DESCRIPTION = 'Loop through all values of dim1, optionally combined with dim2 values, and send them to outputs.\nIMPORTANT: for a given dim1 value, all dim2 values are first iterated, before going to the next dim1 value.\nSo it is advised to associate slow operations (e.g. loading checkpoints) to dim1, to ensure better performance.'
|
||||
|
||||
dim1 = []
|
||||
dim2 = []
|
||||
|
||||
def run(
|
||||
self,
|
||||
dim1: list[str],
|
||||
@@ -90,8 +93,15 @@ class XYPlotQueue:
|
||||
index: int,
|
||||
dim2: list[str] = [''],
|
||||
):
|
||||
if len(dim2) == 0:
|
||||
dim2 = ['']
|
||||
# store the input lists, to allow using input nodes that change at each prompt (ex. ListRandomSeeds)
|
||||
if index == 0:
|
||||
if len(dim2) == 0:
|
||||
dim2 = ['']
|
||||
self.dim1 = dim1
|
||||
self.dim2 = dim2
|
||||
else:
|
||||
dim1 = self.dim1
|
||||
dim2 = self.dim2
|
||||
|
||||
# to simplify code below
|
||||
size = (len(dim1), len(dim2))
|
||||
|
||||
@@ -33,7 +33,15 @@ class GenericQueue:
|
||||
OUTPUT_TOOLTIPS = ('current value (not typed)', 'current index', 'total elements')
|
||||
DESCRIPTION = 'Loop through all values of input list, and send them to output.'
|
||||
|
||||
input_list = []
|
||||
|
||||
def run(self, input_list: list[Any], index: int):
|
||||
# store the input list, to allow using input nodes that change at each prompt (ex. ListRandomSeeds)
|
||||
if index == 0:
|
||||
self.input_list = input_list
|
||||
else:
|
||||
input_list = self.input_list
|
||||
|
||||
total = len(input_list)
|
||||
if total == 0:
|
||||
raise Exception('Empty input list')
|
||||
|
||||
Reference in New Issue
Block a user