chore: black

This commit is contained in:
psychedelicious 2023-09-13 15:49:19 +10:00
parent 93c55ebcf2
commit ec0f6e7248

View File

@ -64,13 +64,21 @@ class RandomIntInvocation(BaseInvocation):
return IntegerOutput(value=np.random.randint(self.low, self.high)) return IntegerOutput(value=np.random.randint(self.low, self.high))
@invocation("float_to_int", title="Float To Integer", tags=["math", "round", "integer", "float", "convert"], category="math", version="1.0.0") @invocation(
"float_to_int",
title="Float To Integer",
tags=["math", "round", "integer", "float", "convert"],
category="math",
version="1.0.0",
)
class FloatToIntegerInvocation(BaseInvocation): class FloatToIntegerInvocation(BaseInvocation):
"""Rounds a float number to (a multiple of) an integer.""" """Rounds a float number to (a multiple of) an integer."""
value: float = InputField(default=0, description="The value to round") value: float = InputField(default=0, description="The value to round")
multiple: int = InputField(default=1, ge=1,title="Multiple of", description="The multiple to round to") multiple: int = InputField(default=1, ge=1, title="Multiple of", description="The multiple to round to")
method: Literal["Nearest", "Floor", "Ceiling", "Truncate"] = InputField(default="Nearest", description="The method to use for rounding") method: Literal["Nearest", "Floor", "Ceiling", "Truncate"] = InputField(
default="Nearest", description="The method to use for rounding"
)
def invoke(self, context: InvocationContext) -> IntegerOutput: def invoke(self, context: InvocationContext) -> IntegerOutput:
if self.method == "Nearest": if self.method == "Nearest":
@ -79,7 +87,7 @@ class FloatToIntegerInvocation(BaseInvocation):
return IntegerOutput(value=np.floor(self.value / self.multiple) * self.multiple) return IntegerOutput(value=np.floor(self.value / self.multiple) * self.multiple)
elif self.method == "Ceiling": elif self.method == "Ceiling":
return IntegerOutput(value=np.ceil(self.value / self.multiple) * self.multiple) return IntegerOutput(value=np.ceil(self.value / self.multiple) * self.multiple)
else: #self.method == "Truncate" else: # self.method == "Truncate"
return IntegerOutput(value=int(self.value / self.multiple) * self.multiple) return IntegerOutput(value=int(self.value / self.multiple) * self.multiple)
@ -103,7 +111,7 @@ INTEGER_OPERATIONS = Literal[
"Modulus A%B", "Modulus A%B",
"Absolute Value of A", "Absolute Value of A",
"Minimum(A,B)", "Minimum(A,B)",
"Maximum(A,B)" "Maximum(A,B)",
] ]
@ -121,10 +129,10 @@ INTEGER_OPERATIONS = Literal[
"power", "power",
"absolute value", "absolute value",
"min", "min",
"max" "max",
], ],
category="math", category="math",
version="1.0.0" version="1.0.0",
) )
class IntegerMathInvocation(BaseInvocation): class IntegerMathInvocation(BaseInvocation):
"""Performs integer math.""" """Performs integer math."""
@ -144,7 +152,7 @@ class IntegerMathInvocation(BaseInvocation):
return v return v
def invoke(self, context: InvocationContext) -> IntegerOutput: def invoke(self, context: InvocationContext) -> IntegerOutput:
#Python doesn't support switch statements until 3.10, but InvokeAI supports back to 3.9 # Python doesn't support switch statements until 3.10, but InvokeAI supports back to 3.9
if self.operation == "Add A+B": if self.operation == "Add A+B":
return IntegerOutput(value=self.a + self.b) return IntegerOutput(value=self.a + self.b)
elif self.operation == "Subtract A-B": elif self.operation == "Subtract A-B":
@ -154,14 +162,14 @@ class IntegerMathInvocation(BaseInvocation):
elif self.operation == "Divide A/B": elif self.operation == "Divide A/B":
return IntegerOutput(value=int(self.a / self.b)) return IntegerOutput(value=int(self.a / self.b))
elif self.operation == "Exponentiate A^B": elif self.operation == "Exponentiate A^B":
return IntegerOutput(value=self.a ** self.b) return IntegerOutput(value=self.a**self.b)
elif self.operation == "Modulus A%B": elif self.operation == "Modulus A%B":
return IntegerOutput(value=self.a % self.b) return IntegerOutput(value=self.a % self.b)
elif self.operation == "Absolute Value of A": elif self.operation == "Absolute Value of A":
return IntegerOutput(value=abs(self.a)) return IntegerOutput(value=abs(self.a))
elif self.operation == "Minimum(A,B)": elif self.operation == "Minimum(A,B)":
return IntegerOutput(value=min(self.a, self.b)) return IntegerOutput(value=min(self.a, self.b))
else: #self.operation == "Maximum(A,B)": else: # self.operation == "Maximum(A,B)":
return IntegerOutput(value=max(self.a, self.b)) return IntegerOutput(value=max(self.a, self.b))
@ -173,28 +181,16 @@ FLOAT_OPERATIONS = Literal[
"Exponentiate A^B", "Exponentiate A^B",
"Absolute Value of A", "Absolute Value of A",
"Minimum(A,B)", "Minimum(A,B)",
"Maximum(A,B)" "Maximum(A,B)",
] ]
@invocation( @invocation(
"float_math", "float_math",
title="Float Math", title="Float Math",
tags=[ tags=["math", "float", "add", "subtract", "multiply", "divide", "power", "root", "absolute value", "min", "max"],
"math",
"float",
"add",
"subtract",
"multiply",
"divide",
"power",
"root",
"absolute value",
"min",
"max"
],
category="math", category="math",
version="1.0.0" version="1.0.0",
) )
class FloatMathInvocation(BaseInvocation): class FloatMathInvocation(BaseInvocation):
"""Performs floating point math.""" """Performs floating point math."""
@ -209,12 +205,12 @@ class FloatMathInvocation(BaseInvocation):
raise ValueError("Cannot divide by zero") raise ValueError("Cannot divide by zero")
elif values["operation"] == "Exponentiate A^B" and values["a"] == 0 and v < 0: elif values["operation"] == "Exponentiate A^B" and values["a"] == 0 and v < 0:
raise ValueError("Cannot raise zero to a negative power") raise ValueError("Cannot raise zero to a negative power")
elif values["operation"] == "Exponentiate A^B" and type(values["a"]**v) == complex: elif values["operation"] == "Exponentiate A^B" and type(values["a"] ** v) == complex:
raise ValueError("Root operation resulted in a complex number") raise ValueError("Root operation resulted in a complex number")
return v return v
def invoke(self, context: InvocationContext) -> FloatOutput: def invoke(self, context: InvocationContext) -> FloatOutput:
#Python doesn't support switch statements until 3.10, but InvokeAI supports back to 3.9 # Python doesn't support switch statements until 3.10, but InvokeAI supports back to 3.9
if self.operation == "Add A+B": if self.operation == "Add A+B":
return FloatOutput(value=self.a + self.b) return FloatOutput(value=self.a + self.b)
elif self.operation == "Subtract A-B": elif self.operation == "Subtract A-B":
@ -224,12 +220,12 @@ class FloatMathInvocation(BaseInvocation):
elif self.operation == "Divide A/B": elif self.operation == "Divide A/B":
return FloatOutput(value=self.a / self.b) return FloatOutput(value=self.a / self.b)
elif self.operation == "Exponentiate A^B": elif self.operation == "Exponentiate A^B":
return FloatOutput(value=self.a ** self.b) return FloatOutput(value=self.a**self.b)
elif self.operation == "Square Root of A": elif self.operation == "Square Root of A":
return FloatOutput(value=np.sqrt(self.a)) return FloatOutput(value=np.sqrt(self.a))
elif self.operation == "Absolute Value of A": elif self.operation == "Absolute Value of A":
return FloatOutput(value=abs(self.a)) return FloatOutput(value=abs(self.a))
elif self.operation == "Minimum(A,B)": elif self.operation == "Minimum(A,B)":
return FloatOutput(value=min(self.a, self.b)) return FloatOutput(value=min(self.a, self.b))
else: #self.operation == "Maximum(A,B)": else: # self.operation == "Maximum(A,B)":
return FloatOutput(value=max(self.a, self.b)) return FloatOutput(value=max(self.a, self.b))