add noise math node + split min and max to scalar and tensor version

This commit is contained in:
mcDandy
2025-07-31 23:49:50 +02:00
parent 58f959bc3c
commit 4d4dea28c6
13 changed files with 726 additions and 411 deletions
+146
View File
@@ -0,0 +1,146 @@
from inspect import cleandoc
from math import e
from antlr4 import CommonTokenStream, InputStream
import torch
from .Parser.MathExprParser import MathExprParser
from .Parser.MathExprLexer import MathExprLexer
from .Parser.TensorEvalVisitor import TensorEvalVisitor
class NoiseMathNode:
"""
This node enables the use of math expressions on Latents.
INPUTS:
a, b, c, d:
Noise generators, bound to variables with the same name. Defaults to zero latent if not provided.
w, x, y, z:
Floats, bound to variables of the expression. Defaults to 0.0 if not provided.
Latent expression:
String, describing expression to mix latents. Valid functions are sin, cos, tan, abs, sqrt, min, max, norm. Valid operators are +, -, *, /, ^, %. Usable constants are e and pi.
OUTPUTS:
LATENT:
Returns a LATENT object that contains the result of the math expression applied to the input conditionings.
"""
def __init__(self):
va= None
vb= None
vc= None
vd= None
vw= 0.0
vx= 0.0
vy= 0.0
vz= 0.0
expr="";
@classmethod
def INPUT_TYPES(s):
"""
"""
return {
"required": {
"a": ("NOISE", {
}),
"Noise": ("STRING", {
"multiline": False, #True if you want the field to look like the one on the ClipTextEncode node
"default": "a*(1-w)+b*w",
"description": "Describes inital noise. Valid functions are sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, atanh, abs, sqrt, ln, log, exp, pow, min, max, norm, floor, ceil, round, gamma. Valid operators are +, -, *, /, %, ^,!˛&,|. Usable constants are e and pi."
}),
},
"optional": {
"b": ("NOISE", {
"default": 0,
}),
"c": ("NOISE", {
"default": 0,
}),
"d": ("NOISE", {
"default": 0,
}),
"w": ("FLOAT", {
"default": 0,
"forceInput":True
}),
"x": ("FLOAT", {
"default": 0,
"forceInput":True
}),
"y": ("FLOAT", {
"default": 0,
"forceInput":True
}),
"z": ("FLOAT", {
"default": 0,
"forceInput":True
}),
# "int_field": ("INT", {"default": 0, "min": 0, "max": 100, "step": 1}),
# "float_field": ("FLOAT", {"default": 0.5, "min": -10.0, "max": 10.0, "step": 0.001}),
}
}
RETURN_TYPES = ("NOISE",)
#RETURN_NAMES = ("image_output_name",)
DESCRIPTION = cleandoc(__doc__)
FUNCTION = "noiMathNode"
seed = 0
#OUTPUT_NODE = False
#OUTPUT_TOOLTIPS = ("",) # Tooltips for the output node
CATEGORY = "More math"
def noiMathNode(self, Noise, a, b=None, c=None, d=None, w=0.0, x=0.0, y=0.0, z=0.0):
self.va = a
self.vb = b
self.vc = c
self.vd = d
self.vw = w
self.vx = x
self.vy = y
self.vz = z
self.expr = Noise
return (self,)
"""
The node will always be re executed if any of the inputs change but
this method can be used to force the node to execute again even when the inputs don't change.
You can make this node return a number or a string. This value will be compared to the one returned the last time the node was
executed, if it is different the node will be executed again.
This method is used in the core repo for the LoadImage node where they return the image hash as a string, if the image hash
changes between executions the LoadImage node is executed again.
"""
#@classmethod
#def IS_CHANGED(s, image, string_field, int_field, float_field, print_to_screen):
# return ""
def generate_noise(self, input_latent:torch.Tensor) -> torch.Tensor:
print(input_latent)
if self.vb is None:
self.vb = torch.zeros_like(input_latent["samples"])
else:
self.vb = self.vb.generate_noise(input_latent)
if self.vc is None:
self.vc = torch.zeros_like(input_latent["samples"])
else:
self.vc = self.vc.generate_noise(input_latent)
if self.vd is None:
self.vd = torch.zeros_like(input_latent["samples"])
else:
self.vd = self.vd.generate_noise(input_latent)
variables = {'a': self.va.generate_noise(input_latent), 'b': self.vb, 'c': self.vc, 'd': self.vd, 'w': self.vw, 'x': self.vx, 'y': self.vy, 'z': self.vz}
input_stream = InputStream(self.expr)
lexer = MathExprLexer(input_stream)
stream = CommonTokenStream(lexer)
parser = MathExprParser(stream)
tree = parser.expr()
print("Tensor\n"+tree.toStringTree(recog=parser))
visitor = TensorEvalVisitor(variables,variables['a'].shape)
result = visitor.visit(tree)
print("Result1:", result)
print("Result:", result)
return result
+2 -2
View File
@@ -114,10 +114,10 @@ class FloatEvalVisitor(MathExprVisitor):
return math.atan2(self.visit(ctx.expr(0)), self.visit(ctx.expr(1)))
# N-argument functions
def visitMinFunc(self, ctx):
def visitSMinFunc(self, ctx):
args = [self.visit(e) for e in ctx.expr()]
return math.min(args)
def visitMaxFunc(self, ctx):
def visitSMaxFunc(self, ctx):
args = [self.visit(e) for e in ctx.expr()]
return math.max(args)
+9 -4
View File
@@ -75,14 +75,17 @@ func1
func2
: POWE '(' expr ',' expr ')' # PowFunc
| ATAN2 '(' expr ',' expr ')' # Atan2Func
| TMIN '(' expr ',' expr ')' # TMinFunc
| TMAX '(' expr ',' expr ')' # TMaxFunc
;
func3
: CLAMP '(' expr ',' expr ',' expr ')' # ClampFunc
;
// N-argument functions (at least 2 arguments)
funcN
: MIN '(' expr (',' expr)+ ')' # MinFunc
| MAX '(' expr (',' expr)+ ')' # MaxFunc
: SMIN '(' expr (',' expr)+ ')' # SMinFunc
| SMAX '(' expr (',' expr)+ ')' # SMaxFunc
;
// LEXER RULES
@@ -105,8 +108,10 @@ SQRT : 'sqrt';
LN : 'ln';
LOG : 'log';
EXP : 'exp';
MIN : 'min';
MAX : 'max';
SMIN : 'smin';
SMAX : 'smax';
TMIN : 'tmin';
TMAX : 'tmax';
TNORM : 'tnorm';
SNORM : 'snorm';
FLOOR : 'floor';
File diff suppressed because one or more lines are too long
+42 -38
View File
@@ -19,27 +19,29 @@ SQRT=18
LN=19
LOG=20
EXP=21
MIN=22
MAX=23
TNORM=24
SNORM=25
FLOOR=26
CEIL=27
ROUND=28
GAMMA=29
POWE=30
SIGM=31
CLAMP=32
PLUS=33
MINUS=34
MULT=35
DIV=36
MOD=37
POW=38
CONSTANT=39
NUMBER=40
VARIABLE=41
WS=42
SMIN=22
SMAX=23
TMIN=24
TMAX=25
TNORM=26
SNORM=27
FLOOR=28
CEIL=29
ROUND=30
GAMMA=31
POWE=32
SIGM=33
CLAMP=34
PLUS=35
MINUS=36
MULT=37
DIV=38
MOD=39
POW=40
CONSTANT=41
NUMBER=42
VARIABLE=43
WS=44
'('=1
')'=2
','=3
@@ -61,20 +63,22 @@ WS=42
'ln'=19
'log'=20
'exp'=21
'min'=22
'max'=23
'tnorm'=24
'snorm'=25
'floor'=26
'ceil'=27
'round'=28
'gamma'=29
'pow'=30
'sigmoid'=31
'clamp'=32
'+'=33
'-'=34
'*'=35
'/'=36
'%'=37
'^'=38
'smin'=22
'smax'=23
'tmin'=24
'tmax'=25
'tnorm'=26
'snorm'=27
'floor'=28
'ceil'=29
'round'=30
'gamma'=31
'pow'=32
'sigmoid'=33
'clamp'=34
'+'=35
'-'=36
'*'=37
'/'=38
'%'=39
'^'=40
File diff suppressed because one or more lines are too long
+135 -127
View File
@@ -10,106 +10,111 @@ else:
def serializedATN():
return [
4,0,42,284,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
4,0,44,300,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,
13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,
19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,
26,7,26,2,27,7,27,2,28,7,28,2,29,7,29,2,30,7,30,2,31,7,31,2,32,7,
32,2,33,7,33,2,34,7,34,2,35,7,35,2,36,7,36,2,37,7,37,2,38,7,38,2,
39,7,39,2,40,7,40,2,41,7,41,1,0,1,0,1,1,1,1,1,2,1,2,1,3,1,3,1,3,
1,3,1,4,1,4,1,4,1,4,1,5,1,5,1,5,1,5,1,6,1,6,1,6,1,6,1,6,1,7,1,7,
1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,1,9,1,9,1,9,1,10,1,10,
1,10,1,10,1,10,1,11,1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,12,
1,13,1,13,1,13,1,13,1,13,1,13,1,14,1,14,1,14,1,14,1,14,1,14,1,15,
1,15,1,15,1,15,1,15,1,15,1,16,1,16,1,16,1,16,1,17,1,17,1,17,1,17,
1,17,1,18,1,18,1,18,1,19,1,19,1,19,1,19,1,20,1,20,1,20,1,20,1,21,
1,21,1,21,1,21,1,22,1,22,1,22,1,22,1,23,1,23,1,23,1,23,1,23,1,23,
1,24,1,24,1,24,1,24,1,24,1,24,1,25,1,25,1,25,1,25,1,25,1,25,1,26,
1,26,1,26,1,26,1,26,1,27,1,27,1,27,1,27,1,27,1,27,1,28,1,28,1,28,
1,28,1,28,1,28,1,29,1,29,1,29,1,29,1,30,1,30,1,30,1,30,1,30,1,30,
1,30,1,30,1,31,1,31,1,31,1,31,1,31,1,31,1,32,1,32,1,33,1,33,1,34,
1,34,1,35,1,35,1,36,1,36,1,37,1,37,1,38,1,38,1,38,1,38,1,38,3,38,
256,8,38,1,39,4,39,259,8,39,11,39,12,39,260,1,39,1,39,4,39,265,8,
39,11,39,12,39,266,3,39,269,8,39,1,40,1,40,5,40,273,8,40,10,40,12,
40,276,9,40,1,41,4,41,279,8,41,11,41,12,41,280,1,41,1,41,0,0,42,
1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,
27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,45,23,47,24,
49,25,51,26,53,27,55,28,57,29,59,30,61,31,63,32,65,33,67,34,69,35,
71,36,73,37,75,38,77,39,79,40,81,41,83,42,1,0,5,2,0,69,69,101,101,
1,0,48,57,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,3,
0,9,10,13,13,32,32,290,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,
0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,
0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,
0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,
0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,1,
0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,57,1,
0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,67,1,
0,0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,77,1,
0,0,0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,1,85,1,0,0,0,3,87,1,
0,0,0,5,89,1,0,0,0,7,91,1,0,0,0,9,95,1,0,0,0,11,99,1,0,0,0,13,103,
1,0,0,0,15,108,1,0,0,0,17,113,1,0,0,0,19,118,1,0,0,0,21,124,1,0,
0,0,23,129,1,0,0,0,25,134,1,0,0,0,27,139,1,0,0,0,29,145,1,0,0,0,
31,151,1,0,0,0,33,157,1,0,0,0,35,161,1,0,0,0,37,166,1,0,0,0,39,169,
1,0,0,0,41,173,1,0,0,0,43,177,1,0,0,0,45,181,1,0,0,0,47,185,1,0,
0,0,49,191,1,0,0,0,51,197,1,0,0,0,53,203,1,0,0,0,55,208,1,0,0,0,
57,214,1,0,0,0,59,220,1,0,0,0,61,224,1,0,0,0,63,232,1,0,0,0,65,238,
1,0,0,0,67,240,1,0,0,0,69,242,1,0,0,0,71,244,1,0,0,0,73,246,1,0,
0,0,75,248,1,0,0,0,77,255,1,0,0,0,79,258,1,0,0,0,81,270,1,0,0,0,
83,278,1,0,0,0,85,86,5,40,0,0,86,2,1,0,0,0,87,88,5,41,0,0,88,4,1,
0,0,0,89,90,5,44,0,0,90,6,1,0,0,0,91,92,5,115,0,0,92,93,5,105,0,
0,93,94,5,110,0,0,94,8,1,0,0,0,95,96,5,99,0,0,96,97,5,111,0,0,97,
98,5,115,0,0,98,10,1,0,0,0,99,100,5,116,0,0,100,101,5,97,0,0,101,
102,5,110,0,0,102,12,1,0,0,0,103,104,5,97,0,0,104,105,5,115,0,0,
105,106,5,105,0,0,106,107,5,110,0,0,107,14,1,0,0,0,108,109,5,97,
0,0,109,110,5,99,0,0,110,111,5,111,0,0,111,112,5,115,0,0,112,16,
1,0,0,0,113,114,5,97,0,0,114,115,5,116,0,0,115,116,5,97,0,0,116,
117,5,110,0,0,117,18,1,0,0,0,118,119,5,97,0,0,119,120,5,116,0,0,
120,121,5,97,0,0,121,122,5,110,0,0,122,123,5,50,0,0,123,20,1,0,0,
0,124,125,5,115,0,0,125,126,5,105,0,0,126,127,5,110,0,0,127,128,
5,104,0,0,128,22,1,0,0,0,129,130,5,99,0,0,130,131,5,111,0,0,131,
132,5,115,0,0,132,133,5,104,0,0,133,24,1,0,0,0,134,135,5,116,0,0,
135,136,5,97,0,0,136,137,5,110,0,0,137,138,5,104,0,0,138,26,1,0,
0,0,139,140,5,97,0,0,140,141,5,115,0,0,141,142,5,105,0,0,142,143,
5,110,0,0,143,144,5,104,0,0,144,28,1,0,0,0,145,146,5,97,0,0,146,
147,5,99,0,0,147,148,5,111,0,0,148,149,5,115,0,0,149,150,5,104,0,
0,150,30,1,0,0,0,151,152,5,97,0,0,152,153,5,116,0,0,153,154,5,97,
0,0,154,155,5,110,0,0,155,156,5,104,0,0,156,32,1,0,0,0,157,158,5,
97,0,0,158,159,5,98,0,0,159,160,5,115,0,0,160,34,1,0,0,0,161,162,
5,115,0,0,162,163,5,113,0,0,163,164,5,114,0,0,164,165,5,116,0,0,
165,36,1,0,0,0,166,167,5,108,0,0,167,168,5,110,0,0,168,38,1,0,0,
0,169,170,5,108,0,0,170,171,5,111,0,0,171,172,5,103,0,0,172,40,1,
0,0,0,173,174,5,101,0,0,174,175,5,120,0,0,175,176,5,112,0,0,176,
42,1,0,0,0,177,178,5,109,0,0,178,179,5,105,0,0,179,180,5,110,0,0,
180,44,1,0,0,0,181,182,5,109,0,0,182,183,5,97,0,0,183,184,5,120,
0,0,184,46,1,0,0,0,185,186,5,116,0,0,186,187,5,110,0,0,187,188,5,
111,0,0,188,189,5,114,0,0,189,190,5,109,0,0,190,48,1,0,0,0,191,192,
5,115,0,0,192,193,5,110,0,0,193,194,5,111,0,0,194,195,5,114,0,0,
195,196,5,109,0,0,196,50,1,0,0,0,197,198,5,102,0,0,198,199,5,108,
0,0,199,200,5,111,0,0,200,201,5,111,0,0,201,202,5,114,0,0,202,52,
1,0,0,0,203,204,5,99,0,0,204,205,5,101,0,0,205,206,5,105,0,0,206,
207,5,108,0,0,207,54,1,0,0,0,208,209,5,114,0,0,209,210,5,111,0,0,
210,211,5,117,0,0,211,212,5,110,0,0,212,213,5,100,0,0,213,56,1,0,
0,0,214,215,5,103,0,0,215,216,5,97,0,0,216,217,5,109,0,0,217,218,
5,109,0,0,218,219,5,97,0,0,219,58,1,0,0,0,220,221,5,112,0,0,221,
222,5,111,0,0,222,223,5,119,0,0,223,60,1,0,0,0,224,225,5,115,0,0,
225,226,5,105,0,0,226,227,5,103,0,0,227,228,5,109,0,0,228,229,5,
111,0,0,229,230,5,105,0,0,230,231,5,100,0,0,231,62,1,0,0,0,232,233,
5,99,0,0,233,234,5,108,0,0,234,235,5,97,0,0,235,236,5,109,0,0,236,
237,5,112,0,0,237,64,1,0,0,0,238,239,5,43,0,0,239,66,1,0,0,0,240,
241,5,45,0,0,241,68,1,0,0,0,242,243,5,42,0,0,243,70,1,0,0,0,244,
245,5,47,0,0,245,72,1,0,0,0,246,247,5,37,0,0,247,74,1,0,0,0,248,
249,5,94,0,0,249,76,1,0,0,0,250,251,5,112,0,0,251,256,5,105,0,0,
252,253,5,80,0,0,253,256,5,73,0,0,254,256,7,0,0,0,255,250,1,0,0,
0,255,252,1,0,0,0,255,254,1,0,0,0,256,78,1,0,0,0,257,259,7,1,0,0,
258,257,1,0,0,0,259,260,1,0,0,0,260,258,1,0,0,0,260,261,1,0,0,0,
261,268,1,0,0,0,262,264,5,46,0,0,263,265,7,1,0,0,264,263,1,0,0,0,
265,266,1,0,0,0,266,264,1,0,0,0,266,267,1,0,0,0,267,269,1,0,0,0,
268,262,1,0,0,0,268,269,1,0,0,0,269,80,1,0,0,0,270,274,7,2,0,0,271,
273,7,3,0,0,272,271,1,0,0,0,273,276,1,0,0,0,274,272,1,0,0,0,274,
275,1,0,0,0,275,82,1,0,0,0,276,274,1,0,0,0,277,279,7,4,0,0,278,277,
1,0,0,0,279,280,1,0,0,0,280,278,1,0,0,0,280,281,1,0,0,0,281,282,
1,0,0,0,282,283,6,41,0,0,283,84,1,0,0,0,7,0,255,260,266,268,274,
280,1,6,0,0
39,7,39,2,40,7,40,2,41,7,41,2,42,7,42,2,43,7,43,1,0,1,0,1,1,1,1,
1,2,1,2,1,3,1,3,1,3,1,3,1,4,1,4,1,4,1,4,1,5,1,5,1,5,1,5,1,6,1,6,
1,6,1,6,1,6,1,7,1,7,1,7,1,7,1,7,1,8,1,8,1,8,1,8,1,8,1,9,1,9,1,9,
1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,10,1,11,1,11,1,11,1,11,1,11,1,
12,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,13,1,13,1,13,1,14,1,14,1,
14,1,14,1,14,1,14,1,15,1,15,1,15,1,15,1,15,1,15,1,16,1,16,1,16,1,
16,1,17,1,17,1,17,1,17,1,17,1,18,1,18,1,18,1,19,1,19,1,19,1,19,1,
20,1,20,1,20,1,20,1,21,1,21,1,21,1,21,1,21,1,22,1,22,1,22,1,22,1,
22,1,23,1,23,1,23,1,23,1,23,1,24,1,24,1,24,1,24,1,24,1,25,1,25,1,
25,1,25,1,25,1,25,1,26,1,26,1,26,1,26,1,26,1,26,1,27,1,27,1,27,1,
27,1,27,1,27,1,28,1,28,1,28,1,28,1,28,1,29,1,29,1,29,1,29,1,29,1,
29,1,30,1,30,1,30,1,30,1,30,1,30,1,31,1,31,1,31,1,31,1,32,1,32,1,
32,1,32,1,32,1,32,1,32,1,32,1,33,1,33,1,33,1,33,1,33,1,33,1,34,1,
34,1,35,1,35,1,36,1,36,1,37,1,37,1,38,1,38,1,39,1,39,1,40,1,40,1,
40,1,40,1,40,3,40,272,8,40,1,41,4,41,275,8,41,11,41,12,41,276,1,
41,1,41,4,41,281,8,41,11,41,12,41,282,3,41,285,8,41,1,42,1,42,5,
42,289,8,42,10,42,12,42,292,9,42,1,43,4,43,295,8,43,11,43,12,43,
296,1,43,1,43,0,0,44,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,
10,21,11,23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,
21,43,22,45,23,47,24,49,25,51,26,53,27,55,28,57,29,59,30,61,31,63,
32,65,33,67,34,69,35,71,36,73,37,75,38,77,39,79,40,81,41,83,42,85,
43,87,44,1,0,5,2,0,69,69,101,101,1,0,48,57,3,0,65,90,95,95,97,122,
4,0,48,57,65,90,95,95,97,122,3,0,9,10,13,13,32,32,306,0,1,1,0,0,
0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,
13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,
23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,
33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,
43,1,0,0,0,0,45,1,0,0,0,0,47,1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,
53,1,0,0,0,0,55,1,0,0,0,0,57,1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,
63,1,0,0,0,0,65,1,0,0,0,0,67,1,0,0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,
73,1,0,0,0,0,75,1,0,0,0,0,77,1,0,0,0,0,79,1,0,0,0,0,81,1,0,0,0,0,
83,1,0,0,0,0,85,1,0,0,0,0,87,1,0,0,0,1,89,1,0,0,0,3,91,1,0,0,0,5,
93,1,0,0,0,7,95,1,0,0,0,9,99,1,0,0,0,11,103,1,0,0,0,13,107,1,0,0,
0,15,112,1,0,0,0,17,117,1,0,0,0,19,122,1,0,0,0,21,128,1,0,0,0,23,
133,1,0,0,0,25,138,1,0,0,0,27,143,1,0,0,0,29,149,1,0,0,0,31,155,
1,0,0,0,33,161,1,0,0,0,35,165,1,0,0,0,37,170,1,0,0,0,39,173,1,0,
0,0,41,177,1,0,0,0,43,181,1,0,0,0,45,186,1,0,0,0,47,191,1,0,0,0,
49,196,1,0,0,0,51,201,1,0,0,0,53,207,1,0,0,0,55,213,1,0,0,0,57,219,
1,0,0,0,59,224,1,0,0,0,61,230,1,0,0,0,63,236,1,0,0,0,65,240,1,0,
0,0,67,248,1,0,0,0,69,254,1,0,0,0,71,256,1,0,0,0,73,258,1,0,0,0,
75,260,1,0,0,0,77,262,1,0,0,0,79,264,1,0,0,0,81,271,1,0,0,0,83,274,
1,0,0,0,85,286,1,0,0,0,87,294,1,0,0,0,89,90,5,40,0,0,90,2,1,0,0,
0,91,92,5,41,0,0,92,4,1,0,0,0,93,94,5,44,0,0,94,6,1,0,0,0,95,96,
5,115,0,0,96,97,5,105,0,0,97,98,5,110,0,0,98,8,1,0,0,0,99,100,5,
99,0,0,100,101,5,111,0,0,101,102,5,115,0,0,102,10,1,0,0,0,103,104,
5,116,0,0,104,105,5,97,0,0,105,106,5,110,0,0,106,12,1,0,0,0,107,
108,5,97,0,0,108,109,5,115,0,0,109,110,5,105,0,0,110,111,5,110,0,
0,111,14,1,0,0,0,112,113,5,97,0,0,113,114,5,99,0,0,114,115,5,111,
0,0,115,116,5,115,0,0,116,16,1,0,0,0,117,118,5,97,0,0,118,119,5,
116,0,0,119,120,5,97,0,0,120,121,5,110,0,0,121,18,1,0,0,0,122,123,
5,97,0,0,123,124,5,116,0,0,124,125,5,97,0,0,125,126,5,110,0,0,126,
127,5,50,0,0,127,20,1,0,0,0,128,129,5,115,0,0,129,130,5,105,0,0,
130,131,5,110,0,0,131,132,5,104,0,0,132,22,1,0,0,0,133,134,5,99,
0,0,134,135,5,111,0,0,135,136,5,115,0,0,136,137,5,104,0,0,137,24,
1,0,0,0,138,139,5,116,0,0,139,140,5,97,0,0,140,141,5,110,0,0,141,
142,5,104,0,0,142,26,1,0,0,0,143,144,5,97,0,0,144,145,5,115,0,0,
145,146,5,105,0,0,146,147,5,110,0,0,147,148,5,104,0,0,148,28,1,0,
0,0,149,150,5,97,0,0,150,151,5,99,0,0,151,152,5,111,0,0,152,153,
5,115,0,0,153,154,5,104,0,0,154,30,1,0,0,0,155,156,5,97,0,0,156,
157,5,116,0,0,157,158,5,97,0,0,158,159,5,110,0,0,159,160,5,104,0,
0,160,32,1,0,0,0,161,162,5,97,0,0,162,163,5,98,0,0,163,164,5,115,
0,0,164,34,1,0,0,0,165,166,5,115,0,0,166,167,5,113,0,0,167,168,5,
114,0,0,168,169,5,116,0,0,169,36,1,0,0,0,170,171,5,108,0,0,171,172,
5,110,0,0,172,38,1,0,0,0,173,174,5,108,0,0,174,175,5,111,0,0,175,
176,5,103,0,0,176,40,1,0,0,0,177,178,5,101,0,0,178,179,5,120,0,0,
179,180,5,112,0,0,180,42,1,0,0,0,181,182,5,115,0,0,182,183,5,109,
0,0,183,184,5,105,0,0,184,185,5,110,0,0,185,44,1,0,0,0,186,187,5,
115,0,0,187,188,5,109,0,0,188,189,5,97,0,0,189,190,5,120,0,0,190,
46,1,0,0,0,191,192,5,116,0,0,192,193,5,109,0,0,193,194,5,105,0,0,
194,195,5,110,0,0,195,48,1,0,0,0,196,197,5,116,0,0,197,198,5,109,
0,0,198,199,5,97,0,0,199,200,5,120,0,0,200,50,1,0,0,0,201,202,5,
116,0,0,202,203,5,110,0,0,203,204,5,111,0,0,204,205,5,114,0,0,205,
206,5,109,0,0,206,52,1,0,0,0,207,208,5,115,0,0,208,209,5,110,0,0,
209,210,5,111,0,0,210,211,5,114,0,0,211,212,5,109,0,0,212,54,1,0,
0,0,213,214,5,102,0,0,214,215,5,108,0,0,215,216,5,111,0,0,216,217,
5,111,0,0,217,218,5,114,0,0,218,56,1,0,0,0,219,220,5,99,0,0,220,
221,5,101,0,0,221,222,5,105,0,0,222,223,5,108,0,0,223,58,1,0,0,0,
224,225,5,114,0,0,225,226,5,111,0,0,226,227,5,117,0,0,227,228,5,
110,0,0,228,229,5,100,0,0,229,60,1,0,0,0,230,231,5,103,0,0,231,232,
5,97,0,0,232,233,5,109,0,0,233,234,5,109,0,0,234,235,5,97,0,0,235,
62,1,0,0,0,236,237,5,112,0,0,237,238,5,111,0,0,238,239,5,119,0,0,
239,64,1,0,0,0,240,241,5,115,0,0,241,242,5,105,0,0,242,243,5,103,
0,0,243,244,5,109,0,0,244,245,5,111,0,0,245,246,5,105,0,0,246,247,
5,100,0,0,247,66,1,0,0,0,248,249,5,99,0,0,249,250,5,108,0,0,250,
251,5,97,0,0,251,252,5,109,0,0,252,253,5,112,0,0,253,68,1,0,0,0,
254,255,5,43,0,0,255,70,1,0,0,0,256,257,5,45,0,0,257,72,1,0,0,0,
258,259,5,42,0,0,259,74,1,0,0,0,260,261,5,47,0,0,261,76,1,0,0,0,
262,263,5,37,0,0,263,78,1,0,0,0,264,265,5,94,0,0,265,80,1,0,0,0,
266,267,5,112,0,0,267,272,5,105,0,0,268,269,5,80,0,0,269,272,5,73,
0,0,270,272,7,0,0,0,271,266,1,0,0,0,271,268,1,0,0,0,271,270,1,0,
0,0,272,82,1,0,0,0,273,275,7,1,0,0,274,273,1,0,0,0,275,276,1,0,0,
0,276,274,1,0,0,0,276,277,1,0,0,0,277,284,1,0,0,0,278,280,5,46,0,
0,279,281,7,1,0,0,280,279,1,0,0,0,281,282,1,0,0,0,282,280,1,0,0,
0,282,283,1,0,0,0,283,285,1,0,0,0,284,278,1,0,0,0,284,285,1,0,0,
0,285,84,1,0,0,0,286,290,7,2,0,0,287,289,7,3,0,0,288,287,1,0,0,0,
289,292,1,0,0,0,290,288,1,0,0,0,290,291,1,0,0,0,291,86,1,0,0,0,292,
290,1,0,0,0,293,295,7,4,0,0,294,293,1,0,0,0,295,296,1,0,0,0,296,
294,1,0,0,0,296,297,1,0,0,0,297,298,1,0,0,0,298,299,6,43,0,0,299,
88,1,0,0,0,7,0,271,276,282,284,290,296,1,6,0,0
]
class MathExprLexer(Lexer):
@@ -139,27 +144,29 @@ class MathExprLexer(Lexer):
LN = 19
LOG = 20
EXP = 21
MIN = 22
MAX = 23
TNORM = 24
SNORM = 25
FLOOR = 26
CEIL = 27
ROUND = 28
GAMMA = 29
POWE = 30
SIGM = 31
CLAMP = 32
PLUS = 33
MINUS = 34
MULT = 35
DIV = 36
MOD = 37
POW = 38
CONSTANT = 39
NUMBER = 40
VARIABLE = 41
WS = 42
SMIN = 22
SMAX = 23
TMIN = 24
TMAX = 25
TNORM = 26
SNORM = 27
FLOOR = 28
CEIL = 29
ROUND = 30
GAMMA = 31
POWE = 32
SIGM = 33
CLAMP = 34
PLUS = 35
MINUS = 36
MULT = 37
DIV = 38
MOD = 39
POW = 40
CONSTANT = 41
NUMBER = 42
VARIABLE = 43
WS = 44
channelNames = [ u"DEFAULT_TOKEN_CHANNEL", u"HIDDEN" ]
@@ -169,24 +176,25 @@ class MathExprLexer(Lexer):
"'('", "')'", "','", "'sin'", "'cos'", "'tan'", "'asin'", "'acos'",
"'atan'", "'atan2'", "'sinh'", "'cosh'", "'tanh'", "'asinh'",
"'acosh'", "'atanh'", "'abs'", "'sqrt'", "'ln'", "'log'", "'exp'",
"'min'", "'max'", "'tnorm'", "'snorm'", "'floor'", "'ceil'",
"'round'", "'gamma'", "'pow'", "'sigmoid'", "'clamp'", "'+'",
"'-'", "'*'", "'/'", "'%'", "'^'" ]
"'smin'", "'smax'", "'tmin'", "'tmax'", "'tnorm'", "'snorm'",
"'floor'", "'ceil'", "'round'", "'gamma'", "'pow'", "'sigmoid'",
"'clamp'", "'+'", "'-'", "'*'", "'/'", "'%'", "'^'" ]
symbolicNames = [ "<INVALID>",
"SIN", "COS", "TAN", "ASIN", "ACOS", "ATAN", "ATAN2", "SINH",
"COSH", "TANH", "ASINH", "ACOSH", "ATANH", "ABS", "SQRT", "LN",
"LOG", "EXP", "MIN", "MAX", "TNORM", "SNORM", "FLOOR", "CEIL",
"ROUND", "GAMMA", "POWE", "SIGM", "CLAMP", "PLUS", "MINUS",
"MULT", "DIV", "MOD", "POW", "CONSTANT", "NUMBER", "VARIABLE",
"WS" ]
"LOG", "EXP", "SMIN", "SMAX", "TMIN", "TMAX", "TNORM", "SNORM",
"FLOOR", "CEIL", "ROUND", "GAMMA", "POWE", "SIGM", "CLAMP",
"PLUS", "MINUS", "MULT", "DIV", "MOD", "POW", "CONSTANT", "NUMBER",
"VARIABLE", "WS" ]
ruleNames = [ "T__0", "T__1", "T__2", "SIN", "COS", "TAN", "ASIN", "ACOS",
"ATAN", "ATAN2", "SINH", "COSH", "TANH", "ASINH", "ACOSH",
"ATANH", "ABS", "SQRT", "LN", "LOG", "EXP", "MIN", "MAX",
"TNORM", "SNORM", "FLOOR", "CEIL", "ROUND", "GAMMA", "POWE",
"SIGM", "CLAMP", "PLUS", "MINUS", "MULT", "DIV", "MOD",
"POW", "CONSTANT", "NUMBER", "VARIABLE", "WS" ]
"ATANH", "ABS", "SQRT", "LN", "LOG", "EXP", "SMIN", "SMAX",
"TMIN", "TMAX", "TNORM", "SNORM", "FLOOR", "CEIL", "ROUND",
"GAMMA", "POWE", "SIGM", "CLAMP", "PLUS", "MINUS", "MULT",
"DIV", "MOD", "POW", "CONSTANT", "NUMBER", "VARIABLE",
"WS" ]
grammarFileName = "MathExpr.g4"
+42 -38
View File
@@ -19,27 +19,29 @@ SQRT=18
LN=19
LOG=20
EXP=21
MIN=22
MAX=23
TNORM=24
SNORM=25
FLOOR=26
CEIL=27
ROUND=28
GAMMA=29
POWE=30
SIGM=31
CLAMP=32
PLUS=33
MINUS=34
MULT=35
DIV=36
MOD=37
POW=38
CONSTANT=39
NUMBER=40
VARIABLE=41
WS=42
SMIN=22
SMAX=23
TMIN=24
TMAX=25
TNORM=26
SNORM=27
FLOOR=28
CEIL=29
ROUND=30
GAMMA=31
POWE=32
SIGM=33
CLAMP=34
PLUS=35
MINUS=36
MULT=37
DIV=38
MOD=39
POW=40
CONSTANT=41
NUMBER=42
VARIABLE=43
WS=44
'('=1
')'=2
','=3
@@ -61,20 +63,22 @@ WS=42
'ln'=19
'log'=20
'exp'=21
'min'=22
'max'=23
'tnorm'=24
'snorm'=25
'floor'=26
'ceil'=27
'round'=28
'gamma'=29
'pow'=30
'sigmoid'=31
'clamp'=32
'+'=33
'-'=34
'*'=35
'/'=36
'%'=37
'^'=38
'smin'=22
'smax'=23
'tmin'=24
'tmax'=25
'tnorm'=26
'snorm'=27
'floor'=28
'ceil'=29
'round'=30
'gamma'=31
'pow'=32
'sigmoid'=33
'clamp'=34
'+'=35
'-'=36
'*'=37
'/'=38
'%'=39
'^'=40
+26 -8
View File
@@ -431,6 +431,24 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#TMinFunc.
def enterTMinFunc(self, ctx:MathExprParser.TMinFuncContext):
pass
# Exit a parse tree produced by MathExprParser#TMinFunc.
def exitTMinFunc(self, ctx:MathExprParser.TMinFuncContext):
pass
# Enter a parse tree produced by MathExprParser#TMaxFunc.
def enterTMaxFunc(self, ctx:MathExprParser.TMaxFuncContext):
pass
# Exit a parse tree produced by MathExprParser#TMaxFunc.
def exitTMaxFunc(self, ctx:MathExprParser.TMaxFuncContext):
pass
# Enter a parse tree produced by MathExprParser#ClampFunc.
def enterClampFunc(self, ctx:MathExprParser.ClampFuncContext):
pass
@@ -440,21 +458,21 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#MinFunc.
def enterMinFunc(self, ctx:MathExprParser.MinFuncContext):
# Enter a parse tree produced by MathExprParser#SMinFunc.
def enterSMinFunc(self, ctx:MathExprParser.SMinFuncContext):
pass
# Exit a parse tree produced by MathExprParser#MinFunc.
def exitMinFunc(self, ctx:MathExprParser.MinFuncContext):
# Exit a parse tree produced by MathExprParser#SMinFunc.
def exitSMinFunc(self, ctx:MathExprParser.SMinFuncContext):
pass
# Enter a parse tree produced by MathExprParser#MaxFunc.
def enterMaxFunc(self, ctx:MathExprParser.MaxFuncContext):
# Enter a parse tree produced by MathExprParser#SMaxFunc.
def enterSMaxFunc(self, ctx:MathExprParser.SMaxFuncContext):
pass
# Exit a parse tree produced by MathExprParser#MaxFunc.
def exitMaxFunc(self, ctx:MathExprParser.MaxFuncContext):
# Exit a parse tree produced by MathExprParser#SMaxFunc.
def exitSMaxFunc(self, ctx:MathExprParser.SMaxFuncContext):
pass
+269 -168
View File
@@ -10,7 +10,7 @@ else:
def serializedATN():
return [
4,1,42,254,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,
4,1,44,268,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,
6,2,7,7,7,2,8,7,8,2,9,7,9,1,0,1,0,3,0,23,8,0,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,5,1,34,8,1,10,1,12,1,37,9,1,1,2,1,2,1,2,1,2,1,2,
1,2,1,2,1,2,1,2,1,2,1,2,1,2,5,2,51,8,2,10,2,12,2,54,9,2,1,3,1,3,
@@ -24,79 +24,84 @@ def serializedATN():
1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,
1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,1,6,
1,6,1,6,1,6,3,6,203,8,6,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,
1,7,1,7,1,7,1,7,3,7,219,8,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,
1,9,1,9,1,9,1,9,1,9,4,9,235,8,9,11,9,12,9,236,1,9,1,9,1,9,1,9,1,
9,1,9,1,9,4,9,246,8,9,11,9,12,9,247,1,9,1,9,3,9,252,8,9,1,9,0,2,
2,4,10,0,2,4,6,8,10,12,14,16,18,0,0,286,0,22,1,0,0,0,2,24,1,0,0,
0,4,38,1,0,0,0,6,60,1,0,0,0,8,67,1,0,0,0,10,80,1,0,0,0,12,202,1,
0,0,0,14,218,1,0,0,0,16,220,1,0,0,0,18,251,1,0,0,0,20,23,3,10,5,
0,21,23,3,2,1,0,22,20,1,0,0,0,22,21,1,0,0,0,23,1,1,0,0,0,24,25,6,
1,-1,0,25,26,3,4,2,0,26,35,1,0,0,0,27,28,10,3,0,0,28,29,5,33,0,0,
29,34,3,4,2,0,30,31,10,2,0,0,31,32,5,34,0,0,32,34,3,4,2,0,33,27,
1,0,0,0,33,30,1,0,0,0,34,37,1,0,0,0,35,33,1,0,0,0,35,36,1,0,0,0,
36,3,1,0,0,0,37,35,1,0,0,0,38,39,6,2,-1,0,39,40,3,6,3,0,40,52,1,
0,0,0,41,42,10,4,0,0,42,43,5,35,0,0,43,51,3,6,3,0,44,45,10,3,0,0,
45,46,5,36,0,0,46,51,3,6,3,0,47,48,10,2,0,0,48,49,5,37,0,0,49,51,
3,6,3,0,50,41,1,0,0,0,50,44,1,0,0,0,50,47,1,0,0,0,51,54,1,0,0,0,
52,50,1,0,0,0,52,53,1,0,0,0,53,5,1,0,0,0,54,52,1,0,0,0,55,56,3,8,
4,0,56,57,5,38,0,0,57,58,3,6,3,0,58,61,1,0,0,0,59,61,3,8,4,0,60,
55,1,0,0,0,60,59,1,0,0,0,61,7,1,0,0,0,62,63,5,33,0,0,63,68,3,8,4,
0,64,65,5,34,0,0,65,68,3,8,4,0,66,68,3,10,5,0,67,62,1,0,0,0,67,64,
1,0,0,0,67,66,1,0,0,0,68,9,1,0,0,0,69,81,3,12,6,0,70,81,3,14,7,0,
71,81,3,16,8,0,72,81,3,18,9,0,73,81,5,41,0,0,74,81,5,40,0,0,75,81,
5,39,0,0,76,77,5,1,0,0,77,78,3,0,0,0,78,79,5,2,0,0,79,81,1,0,0,0,
80,69,1,0,0,0,80,70,1,0,0,0,80,71,1,0,0,0,80,72,1,0,0,0,80,73,1,
0,0,0,80,74,1,0,0,0,80,75,1,0,0,0,80,76,1,0,0,0,81,11,1,0,0,0,82,
83,5,4,0,0,83,84,5,1,0,0,84,85,3,0,0,0,85,86,5,2,0,0,86,203,1,0,
0,0,87,88,5,5,0,0,88,89,5,1,0,0,89,90,3,0,0,0,90,91,5,2,0,0,91,203,
1,0,0,0,92,93,5,6,0,0,93,94,5,1,0,0,94,95,3,0,0,0,95,96,5,2,0,0,
96,203,1,0,0,0,97,98,5,7,0,0,98,99,5,1,0,0,99,100,3,0,0,0,100,101,
5,2,0,0,101,203,1,0,0,0,102,103,5,8,0,0,103,104,5,1,0,0,104,105,
3,0,0,0,105,106,5,2,0,0,106,203,1,0,0,0,107,108,5,9,0,0,108,109,
5,1,0,0,109,110,3,0,0,0,110,111,5,2,0,0,111,203,1,0,0,0,112,113,
5,11,0,0,113,114,5,1,0,0,114,115,3,0,0,0,115,116,5,2,0,0,116,203,
1,0,0,0,117,118,5,12,0,0,118,119,5,1,0,0,119,120,3,0,0,0,120,121,
5,2,0,0,121,203,1,0,0,0,122,123,5,13,0,0,123,124,5,1,0,0,124,125,
3,0,0,0,125,126,5,2,0,0,126,203,1,0,0,0,127,128,5,14,0,0,128,129,
5,1,0,0,129,130,3,0,0,0,130,131,5,2,0,0,131,203,1,0,0,0,132,133,
5,15,0,0,133,134,5,1,0,0,134,135,3,0,0,0,135,136,5,2,0,0,136,203,
1,0,0,0,137,138,5,16,0,0,138,139,5,1,0,0,139,140,3,0,0,0,140,141,
5,2,0,0,141,203,1,0,0,0,142,143,5,17,0,0,143,144,5,1,0,0,144,145,
3,0,0,0,145,146,5,2,0,0,146,203,1,0,0,0,147,148,5,18,0,0,148,149,
5,1,0,0,149,150,3,0,0,0,150,151,5,2,0,0,151,203,1,0,0,0,152,153,
5,19,0,0,153,154,5,1,0,0,154,155,3,0,0,0,155,156,5,2,0,0,156,203,
1,0,0,0,157,158,5,20,0,0,158,159,5,1,0,0,159,160,3,0,0,0,160,161,
5,2,0,0,161,203,1,0,0,0,162,163,5,21,0,0,163,164,5,1,0,0,164,165,
3,0,0,0,165,166,5,2,0,0,166,203,1,0,0,0,167,168,5,24,0,0,168,169,
5,1,0,0,169,170,3,0,0,0,170,171,5,2,0,0,171,203,1,0,0,0,172,173,
5,25,0,0,173,174,5,1,0,0,174,175,3,0,0,0,175,176,5,2,0,0,176,203,
1,0,0,0,177,178,5,26,0,0,178,179,5,1,0,0,179,180,3,0,0,0,180,181,
5,2,0,0,181,203,1,0,0,0,182,183,5,27,0,0,183,184,5,1,0,0,184,185,
3,0,0,0,185,186,5,2,0,0,186,203,1,0,0,0,187,188,5,28,0,0,188,189,
5,1,0,0,189,190,3,0,0,0,190,191,5,2,0,0,191,203,1,0,0,0,192,193,
5,29,0,0,193,194,5,1,0,0,194,195,3,0,0,0,195,196,5,2,0,0,196,203,
1,0,0,0,197,198,5,31,0,0,198,199,5,1,0,0,199,200,3,0,0,0,200,201,
5,2,0,0,201,203,1,0,0,0,202,82,1,0,0,0,202,87,1,0,0,0,202,92,1,0,
0,0,202,97,1,0,0,0,202,102,1,0,0,0,202,107,1,0,0,0,202,112,1,0,0,
0,202,117,1,0,0,0,202,122,1,0,0,0,202,127,1,0,0,0,202,132,1,0,0,
0,202,137,1,0,0,0,202,142,1,0,0,0,202,147,1,0,0,0,202,152,1,0,0,
0,202,157,1,0,0,0,202,162,1,0,0,0,202,167,1,0,0,0,202,172,1,0,0,
0,202,177,1,0,0,0,202,182,1,0,0,0,202,187,1,0,0,0,202,192,1,0,0,
0,202,197,1,0,0,0,203,13,1,0,0,0,204,205,5,30,0,0,205,206,5,1,0,
0,206,207,3,0,0,0,207,208,5,3,0,0,208,209,3,0,0,0,209,210,5,2,0,
0,210,219,1,0,0,0,211,212,5,10,0,0,212,213,5,1,0,0,213,214,3,0,0,
0,214,215,5,3,0,0,215,216,3,0,0,0,216,217,5,2,0,0,217,219,1,0,0,
0,218,204,1,0,0,0,218,211,1,0,0,0,219,15,1,0,0,0,220,221,5,32,0,
0,221,222,5,1,0,0,222,223,3,0,0,0,223,224,5,3,0,0,224,225,3,0,0,
0,225,226,5,3,0,0,226,227,3,0,0,0,227,228,5,2,0,0,228,17,1,0,0,0,
229,230,5,22,0,0,230,231,5,1,0,0,231,234,3,0,0,0,232,233,5,3,0,0,
233,235,3,0,0,0,234,232,1,0,0,0,235,236,1,0,0,0,236,234,1,0,0,0,
236,237,1,0,0,0,237,238,1,0,0,0,238,239,5,2,0,0,239,252,1,0,0,0,
240,241,5,23,0,0,241,242,5,1,0,0,242,245,3,0,0,0,243,244,5,3,0,0,
244,246,3,0,0,0,245,243,1,0,0,0,246,247,1,0,0,0,247,245,1,0,0,0,
247,248,1,0,0,0,248,249,1,0,0,0,249,250,5,2,0,0,250,252,1,0,0,0,
251,229,1,0,0,0,251,240,1,0,0,0,252,19,1,0,0,0,13,22,33,35,50,52,
60,67,80,202,218,236,247,251
1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,1,7,
1,7,1,7,3,7,233,8,7,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,8,1,9,1,9,
1,9,1,9,1,9,4,9,249,8,9,11,9,12,9,250,1,9,1,9,1,9,1,9,1,9,1,9,1,
9,4,9,260,8,9,11,9,12,9,261,1,9,1,9,3,9,266,8,9,1,9,0,2,2,4,10,0,
2,4,6,8,10,12,14,16,18,0,0,302,0,22,1,0,0,0,2,24,1,0,0,0,4,38,1,
0,0,0,6,60,1,0,0,0,8,67,1,0,0,0,10,80,1,0,0,0,12,202,1,0,0,0,14,
232,1,0,0,0,16,234,1,0,0,0,18,265,1,0,0,0,20,23,3,10,5,0,21,23,3,
2,1,0,22,20,1,0,0,0,22,21,1,0,0,0,23,1,1,0,0,0,24,25,6,1,-1,0,25,
26,3,4,2,0,26,35,1,0,0,0,27,28,10,3,0,0,28,29,5,35,0,0,29,34,3,4,
2,0,30,31,10,2,0,0,31,32,5,36,0,0,32,34,3,4,2,0,33,27,1,0,0,0,33,
30,1,0,0,0,34,37,1,0,0,0,35,33,1,0,0,0,35,36,1,0,0,0,36,3,1,0,0,
0,37,35,1,0,0,0,38,39,6,2,-1,0,39,40,3,6,3,0,40,52,1,0,0,0,41,42,
10,4,0,0,42,43,5,37,0,0,43,51,3,6,3,0,44,45,10,3,0,0,45,46,5,38,
0,0,46,51,3,6,3,0,47,48,10,2,0,0,48,49,5,39,0,0,49,51,3,6,3,0,50,
41,1,0,0,0,50,44,1,0,0,0,50,47,1,0,0,0,51,54,1,0,0,0,52,50,1,0,0,
0,52,53,1,0,0,0,53,5,1,0,0,0,54,52,1,0,0,0,55,56,3,8,4,0,56,57,5,
40,0,0,57,58,3,6,3,0,58,61,1,0,0,0,59,61,3,8,4,0,60,55,1,0,0,0,60,
59,1,0,0,0,61,7,1,0,0,0,62,63,5,35,0,0,63,68,3,8,4,0,64,65,5,36,
0,0,65,68,3,8,4,0,66,68,3,10,5,0,67,62,1,0,0,0,67,64,1,0,0,0,67,
66,1,0,0,0,68,9,1,0,0,0,69,81,3,12,6,0,70,81,3,14,7,0,71,81,3,16,
8,0,72,81,3,18,9,0,73,81,5,43,0,0,74,81,5,42,0,0,75,81,5,41,0,0,
76,77,5,1,0,0,77,78,3,0,0,0,78,79,5,2,0,0,79,81,1,0,0,0,80,69,1,
0,0,0,80,70,1,0,0,0,80,71,1,0,0,0,80,72,1,0,0,0,80,73,1,0,0,0,80,
74,1,0,0,0,80,75,1,0,0,0,80,76,1,0,0,0,81,11,1,0,0,0,82,83,5,4,0,
0,83,84,5,1,0,0,84,85,3,0,0,0,85,86,5,2,0,0,86,203,1,0,0,0,87,88,
5,5,0,0,88,89,5,1,0,0,89,90,3,0,0,0,90,91,5,2,0,0,91,203,1,0,0,0,
92,93,5,6,0,0,93,94,5,1,0,0,94,95,3,0,0,0,95,96,5,2,0,0,96,203,1,
0,0,0,97,98,5,7,0,0,98,99,5,1,0,0,99,100,3,0,0,0,100,101,5,2,0,0,
101,203,1,0,0,0,102,103,5,8,0,0,103,104,5,1,0,0,104,105,3,0,0,0,
105,106,5,2,0,0,106,203,1,0,0,0,107,108,5,9,0,0,108,109,5,1,0,0,
109,110,3,0,0,0,110,111,5,2,0,0,111,203,1,0,0,0,112,113,5,11,0,0,
113,114,5,1,0,0,114,115,3,0,0,0,115,116,5,2,0,0,116,203,1,0,0,0,
117,118,5,12,0,0,118,119,5,1,0,0,119,120,3,0,0,0,120,121,5,2,0,0,
121,203,1,0,0,0,122,123,5,13,0,0,123,124,5,1,0,0,124,125,3,0,0,0,
125,126,5,2,0,0,126,203,1,0,0,0,127,128,5,14,0,0,128,129,5,1,0,0,
129,130,3,0,0,0,130,131,5,2,0,0,131,203,1,0,0,0,132,133,5,15,0,0,
133,134,5,1,0,0,134,135,3,0,0,0,135,136,5,2,0,0,136,203,1,0,0,0,
137,138,5,16,0,0,138,139,5,1,0,0,139,140,3,0,0,0,140,141,5,2,0,0,
141,203,1,0,0,0,142,143,5,17,0,0,143,144,5,1,0,0,144,145,3,0,0,0,
145,146,5,2,0,0,146,203,1,0,0,0,147,148,5,18,0,0,148,149,5,1,0,0,
149,150,3,0,0,0,150,151,5,2,0,0,151,203,1,0,0,0,152,153,5,19,0,0,
153,154,5,1,0,0,154,155,3,0,0,0,155,156,5,2,0,0,156,203,1,0,0,0,
157,158,5,20,0,0,158,159,5,1,0,0,159,160,3,0,0,0,160,161,5,2,0,0,
161,203,1,0,0,0,162,163,5,21,0,0,163,164,5,1,0,0,164,165,3,0,0,0,
165,166,5,2,0,0,166,203,1,0,0,0,167,168,5,26,0,0,168,169,5,1,0,0,
169,170,3,0,0,0,170,171,5,2,0,0,171,203,1,0,0,0,172,173,5,27,0,0,
173,174,5,1,0,0,174,175,3,0,0,0,175,176,5,2,0,0,176,203,1,0,0,0,
177,178,5,28,0,0,178,179,5,1,0,0,179,180,3,0,0,0,180,181,5,2,0,0,
181,203,1,0,0,0,182,183,5,29,0,0,183,184,5,1,0,0,184,185,3,0,0,0,
185,186,5,2,0,0,186,203,1,0,0,0,187,188,5,30,0,0,188,189,5,1,0,0,
189,190,3,0,0,0,190,191,5,2,0,0,191,203,1,0,0,0,192,193,5,31,0,0,
193,194,5,1,0,0,194,195,3,0,0,0,195,196,5,2,0,0,196,203,1,0,0,0,
197,198,5,33,0,0,198,199,5,1,0,0,199,200,3,0,0,0,200,201,5,2,0,0,
201,203,1,0,0,0,202,82,1,0,0,0,202,87,1,0,0,0,202,92,1,0,0,0,202,
97,1,0,0,0,202,102,1,0,0,0,202,107,1,0,0,0,202,112,1,0,0,0,202,117,
1,0,0,0,202,122,1,0,0,0,202,127,1,0,0,0,202,132,1,0,0,0,202,137,
1,0,0,0,202,142,1,0,0,0,202,147,1,0,0,0,202,152,1,0,0,0,202,157,
1,0,0,0,202,162,1,0,0,0,202,167,1,0,0,0,202,172,1,0,0,0,202,177,
1,0,0,0,202,182,1,0,0,0,202,187,1,0,0,0,202,192,1,0,0,0,202,197,
1,0,0,0,203,13,1,0,0,0,204,205,5,32,0,0,205,206,5,1,0,0,206,207,
3,0,0,0,207,208,5,3,0,0,208,209,3,0,0,0,209,210,5,2,0,0,210,233,
1,0,0,0,211,212,5,10,0,0,212,213,5,1,0,0,213,214,3,0,0,0,214,215,
5,3,0,0,215,216,3,0,0,0,216,217,5,2,0,0,217,233,1,0,0,0,218,219,
5,24,0,0,219,220,5,1,0,0,220,221,3,0,0,0,221,222,5,3,0,0,222,223,
3,0,0,0,223,224,5,2,0,0,224,233,1,0,0,0,225,226,5,25,0,0,226,227,
5,1,0,0,227,228,3,0,0,0,228,229,5,3,0,0,229,230,3,0,0,0,230,231,
5,2,0,0,231,233,1,0,0,0,232,204,1,0,0,0,232,211,1,0,0,0,232,218,
1,0,0,0,232,225,1,0,0,0,233,15,1,0,0,0,234,235,5,34,0,0,235,236,
5,1,0,0,236,237,3,0,0,0,237,238,5,3,0,0,238,239,3,0,0,0,239,240,
5,3,0,0,240,241,3,0,0,0,241,242,5,2,0,0,242,17,1,0,0,0,243,244,5,
22,0,0,244,245,5,1,0,0,245,248,3,0,0,0,246,247,5,3,0,0,247,249,3,
0,0,0,248,246,1,0,0,0,249,250,1,0,0,0,250,248,1,0,0,0,250,251,1,
0,0,0,251,252,1,0,0,0,252,253,5,2,0,0,253,266,1,0,0,0,254,255,5,
23,0,0,255,256,5,1,0,0,256,259,3,0,0,0,257,258,5,3,0,0,258,260,3,
0,0,0,259,257,1,0,0,0,260,261,1,0,0,0,261,259,1,0,0,0,261,262,1,
0,0,0,262,263,1,0,0,0,263,264,5,2,0,0,264,266,1,0,0,0,265,243,1,
0,0,0,265,254,1,0,0,0,266,19,1,0,0,0,13,22,33,35,50,52,60,67,80,
202,232,250,261,265
]
class MathExprParser ( Parser ):
@@ -112,18 +117,20 @@ class MathExprParser ( Parser ):
literalNames = [ "<INVALID>", "'('", "')'", "','", "'sin'", "'cos'",
"'tan'", "'asin'", "'acos'", "'atan'", "'atan2'", "'sinh'",
"'cosh'", "'tanh'", "'asinh'", "'acosh'", "'atanh'",
"'abs'", "'sqrt'", "'ln'", "'log'", "'exp'", "'min'",
"'max'", "'tnorm'", "'snorm'", "'floor'", "'ceil'",
"'round'", "'gamma'", "'pow'", "'sigmoid'", "'clamp'",
"'+'", "'-'", "'*'", "'/'", "'%'", "'^'" ]
"'abs'", "'sqrt'", "'ln'", "'log'", "'exp'", "'smin'",
"'smax'", "'tmin'", "'tmax'", "'tnorm'", "'snorm'",
"'floor'", "'ceil'", "'round'", "'gamma'", "'pow'",
"'sigmoid'", "'clamp'", "'+'", "'-'", "'*'", "'/'",
"'%'", "'^'" ]
symbolicNames = [ "<INVALID>", "<INVALID>", "<INVALID>", "<INVALID>",
"SIN", "COS", "TAN", "ASIN", "ACOS", "ATAN", "ATAN2",
"SINH", "COSH", "TANH", "ASINH", "ACOSH", "ATANH",
"ABS", "SQRT", "LN", "LOG", "EXP", "MIN", "MAX", "TNORM",
"SNORM", "FLOOR", "CEIL", "ROUND", "GAMMA", "POWE",
"SIGM", "CLAMP", "PLUS", "MINUS", "MULT", "DIV", "MOD",
"POW", "CONSTANT", "NUMBER", "VARIABLE", "WS" ]
"ABS", "SQRT", "LN", "LOG", "EXP", "SMIN", "SMAX",
"TMIN", "TMAX", "TNORM", "SNORM", "FLOOR", "CEIL",
"ROUND", "GAMMA", "POWE", "SIGM", "CLAMP", "PLUS",
"MINUS", "MULT", "DIV", "MOD", "POW", "CONSTANT",
"NUMBER", "VARIABLE", "WS" ]
RULE_expr = 0
RULE_addExpr = 1
@@ -161,27 +168,29 @@ class MathExprParser ( Parser ):
LN=19
LOG=20
EXP=21
MIN=22
MAX=23
TNORM=24
SNORM=25
FLOOR=26
CEIL=27
ROUND=28
GAMMA=29
POWE=30
SIGM=31
CLAMP=32
PLUS=33
MINUS=34
MULT=35
DIV=36
MOD=37
POW=38
CONSTANT=39
NUMBER=40
VARIABLE=41
WS=42
SMIN=22
SMAX=23
TMIN=24
TMAX=25
TNORM=26
SNORM=27
FLOOR=28
CEIL=29
ROUND=30
GAMMA=31
POWE=32
SIGM=33
CLAMP=34
PLUS=35
MINUS=36
MULT=37
DIV=38
MOD=39
POW=40
CONSTANT=41
NUMBER=42
VARIABLE=43
WS=44
def __init__(self, input:TokenStream, output:TextIO = sys.stdout):
super().__init__(input, output)
@@ -852,7 +861,7 @@ class MathExprParser ( Parser ):
self.state = 67
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [33]:
if token in [35]:
localctx = MathExprParser.UnaryPlusContext(self, localctx)
self.enterOuterAlt(localctx, 1)
self.state = 62
@@ -860,7 +869,7 @@ class MathExprParser ( Parser ):
self.state = 63
self.unaryExpr()
pass
elif token in [34]:
elif token in [36]:
localctx = MathExprParser.UnaryMinusContext(self, localctx)
self.enterOuterAlt(localctx, 2)
self.state = 64
@@ -868,7 +877,7 @@ class MathExprParser ( Parser ):
self.state = 65
self.unaryExpr()
pass
elif token in [1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 39, 40, 41]:
elif token in [1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 41, 42, 43]:
localctx = MathExprParser.ToAtomContext(self, localctx)
self.enterOuterAlt(localctx, 3)
self.state = 66
@@ -1109,19 +1118,19 @@ class MathExprParser ( Parser ):
self.state = 80
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 29, 31]:
if token in [4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 26, 27, 28, 29, 30, 31, 33]:
localctx = MathExprParser.Func1ExpContext(self, localctx)
self.enterOuterAlt(localctx, 1)
self.state = 69
self.func1()
pass
elif token in [10, 30]:
elif token in [10, 24, 25, 32]:
localctx = MathExprParser.Func2ExpContext(self, localctx)
self.enterOuterAlt(localctx, 2)
self.state = 70
self.func2()
pass
elif token in [32]:
elif token in [34]:
localctx = MathExprParser.Func3ExpContext(self, localctx)
self.enterOuterAlt(localctx, 3)
self.state = 71
@@ -1133,19 +1142,19 @@ class MathExprParser ( Parser ):
self.state = 72
self.funcN()
pass
elif token in [41]:
elif token in [43]:
localctx = MathExprParser.VariableExpContext(self, localctx)
self.enterOuterAlt(localctx, 5)
self.state = 73
self.match(MathExprParser.VARIABLE)
pass
elif token in [40]:
elif token in [42]:
localctx = MathExprParser.NumberExpContext(self, localctx)
self.enterOuterAlt(localctx, 6)
self.state = 74
self.match(MathExprParser.NUMBER)
pass
elif token in [39]:
elif token in [41]:
localctx = MathExprParser.ConstantExpContext(self, localctx)
self.enterOuterAlt(localctx, 7)
self.state = 75
@@ -2051,7 +2060,7 @@ class MathExprParser ( Parser ):
self.state = 165
self.match(MathExprParser.T__1)
pass
elif token in [24]:
elif token in [26]:
localctx = MathExprParser.TNormFuncContext(self, localctx)
self.enterOuterAlt(localctx, 18)
self.state = 167
@@ -2063,7 +2072,7 @@ class MathExprParser ( Parser ):
self.state = 170
self.match(MathExprParser.T__1)
pass
elif token in [25]:
elif token in [27]:
localctx = MathExprParser.SNormFuncContext(self, localctx)
self.enterOuterAlt(localctx, 19)
self.state = 172
@@ -2075,7 +2084,7 @@ class MathExprParser ( Parser ):
self.state = 175
self.match(MathExprParser.T__1)
pass
elif token in [26]:
elif token in [28]:
localctx = MathExprParser.FloorFuncContext(self, localctx)
self.enterOuterAlt(localctx, 20)
self.state = 177
@@ -2087,7 +2096,7 @@ class MathExprParser ( Parser ):
self.state = 180
self.match(MathExprParser.T__1)
pass
elif token in [27]:
elif token in [29]:
localctx = MathExprParser.CeilFuncContext(self, localctx)
self.enterOuterAlt(localctx, 21)
self.state = 182
@@ -2099,7 +2108,7 @@ class MathExprParser ( Parser ):
self.state = 185
self.match(MathExprParser.T__1)
pass
elif token in [28]:
elif token in [30]:
localctx = MathExprParser.RoundFuncContext(self, localctx)
self.enterOuterAlt(localctx, 22)
self.state = 187
@@ -2111,7 +2120,7 @@ class MathExprParser ( Parser ):
self.state = 190
self.match(MathExprParser.T__1)
pass
elif token in [29]:
elif token in [31]:
localctx = MathExprParser.GammaFuncContext(self, localctx)
self.enterOuterAlt(localctx, 23)
self.state = 192
@@ -2123,7 +2132,7 @@ class MathExprParser ( Parser ):
self.state = 195
self.match(MathExprParser.T__1)
pass
elif token in [31]:
elif token in [33]:
localctx = MathExprParser.SigmoidFuncContext(self, localctx)
self.enterOuterAlt(localctx, 24)
self.state = 197
@@ -2164,6 +2173,36 @@ class MathExprParser ( Parser ):
class TMaxFuncContext(Func2Context):
def __init__(self, parser, ctx:ParserRuleContext): # actually a MathExprParser.Func2Context
super().__init__(parser)
self.copyFrom(ctx)
def TMAX(self):
return self.getToken(MathExprParser.TMAX, 0)
def expr(self, i:int=None):
if i is None:
return self.getTypedRuleContexts(MathExprParser.ExprContext)
else:
return self.getTypedRuleContext(MathExprParser.ExprContext,i)
def enterRule(self, listener:ParseTreeListener):
if hasattr( listener, "enterTMaxFunc" ):
listener.enterTMaxFunc(self)
def exitRule(self, listener:ParseTreeListener):
if hasattr( listener, "exitTMaxFunc" ):
listener.exitTMaxFunc(self)
def accept(self, visitor:ParseTreeVisitor):
if hasattr( visitor, "visitTMaxFunc" ):
return visitor.visitTMaxFunc(self)
else:
return visitor.visitChildren(self)
class PowFuncContext(Func2Context):
def __init__(self, parser, ctx:ParserRuleContext): # actually a MathExprParser.Func2Context
@@ -2224,16 +2263,46 @@ class MathExprParser ( Parser ):
return visitor.visitChildren(self)
class TMinFuncContext(Func2Context):
def __init__(self, parser, ctx:ParserRuleContext): # actually a MathExprParser.Func2Context
super().__init__(parser)
self.copyFrom(ctx)
def TMIN(self):
return self.getToken(MathExprParser.TMIN, 0)
def expr(self, i:int=None):
if i is None:
return self.getTypedRuleContexts(MathExprParser.ExprContext)
else:
return self.getTypedRuleContext(MathExprParser.ExprContext,i)
def enterRule(self, listener:ParseTreeListener):
if hasattr( listener, "enterTMinFunc" ):
listener.enterTMinFunc(self)
def exitRule(self, listener:ParseTreeListener):
if hasattr( listener, "exitTMinFunc" ):
listener.exitTMinFunc(self)
def accept(self, visitor:ParseTreeVisitor):
if hasattr( visitor, "visitTMinFunc" ):
return visitor.visitTMinFunc(self)
else:
return visitor.visitChildren(self)
def func2(self):
localctx = MathExprParser.Func2Context(self, self._ctx, self.state)
self.enterRule(localctx, 14, self.RULE_func2)
try:
self.state = 218
self.state = 232
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [30]:
if token in [32]:
localctx = MathExprParser.PowFuncContext(self, localctx)
self.enterOuterAlt(localctx, 1)
self.state = 204
@@ -2265,6 +2334,38 @@ class MathExprParser ( Parser ):
self.state = 216
self.match(MathExprParser.T__1)
pass
elif token in [24]:
localctx = MathExprParser.TMinFuncContext(self, localctx)
self.enterOuterAlt(localctx, 3)
self.state = 218
self.match(MathExprParser.TMIN)
self.state = 219
self.match(MathExprParser.T__0)
self.state = 220
self.expr()
self.state = 221
self.match(MathExprParser.T__2)
self.state = 222
self.expr()
self.state = 223
self.match(MathExprParser.T__1)
pass
elif token in [25]:
localctx = MathExprParser.TMaxFuncContext(self, localctx)
self.enterOuterAlt(localctx, 4)
self.state = 225
self.match(MathExprParser.TMAX)
self.state = 226
self.match(MathExprParser.T__0)
self.state = 227
self.expr()
self.state = 228
self.match(MathExprParser.T__2)
self.state = 229
self.expr()
self.state = 230
self.match(MathExprParser.T__1)
pass
else:
raise NoViableAltException(self)
@@ -2332,21 +2433,21 @@ class MathExprParser ( Parser ):
try:
localctx = MathExprParser.ClampFuncContext(self, localctx)
self.enterOuterAlt(localctx, 1)
self.state = 220
self.state = 234
self.match(MathExprParser.CLAMP)
self.state = 221
self.state = 235
self.match(MathExprParser.T__0)
self.state = 222
self.state = 236
self.expr()
self.state = 223
self.state = 237
self.match(MathExprParser.T__2)
self.state = 224
self.state = 238
self.expr()
self.state = 225
self.state = 239
self.match(MathExprParser.T__2)
self.state = 226
self.state = 240
self.expr()
self.state = 227
self.state = 241
self.match(MathExprParser.T__1)
except RecognitionException as re:
localctx.exception = re
@@ -2374,14 +2475,14 @@ class MathExprParser ( Parser ):
class MinFuncContext(FuncNContext):
class SMaxFuncContext(FuncNContext):
def __init__(self, parser, ctx:ParserRuleContext): # actually a MathExprParser.FuncNContext
super().__init__(parser)
self.copyFrom(ctx)
def MIN(self):
return self.getToken(MathExprParser.MIN, 0)
def SMAX(self):
return self.getToken(MathExprParser.SMAX, 0)
def expr(self, i:int=None):
if i is None:
return self.getTypedRuleContexts(MathExprParser.ExprContext)
@@ -2390,28 +2491,28 @@ class MathExprParser ( Parser ):
def enterRule(self, listener:ParseTreeListener):
if hasattr( listener, "enterMinFunc" ):
listener.enterMinFunc(self)
if hasattr( listener, "enterSMaxFunc" ):
listener.enterSMaxFunc(self)
def exitRule(self, listener:ParseTreeListener):
if hasattr( listener, "exitMinFunc" ):
listener.exitMinFunc(self)
if hasattr( listener, "exitSMaxFunc" ):
listener.exitSMaxFunc(self)
def accept(self, visitor:ParseTreeVisitor):
if hasattr( visitor, "visitMinFunc" ):
return visitor.visitMinFunc(self)
if hasattr( visitor, "visitSMaxFunc" ):
return visitor.visitSMaxFunc(self)
else:
return visitor.visitChildren(self)
class MaxFuncContext(FuncNContext):
class SMinFuncContext(FuncNContext):
def __init__(self, parser, ctx:ParserRuleContext): # actually a MathExprParser.FuncNContext
super().__init__(parser)
self.copyFrom(ctx)
def MAX(self):
return self.getToken(MathExprParser.MAX, 0)
def SMIN(self):
return self.getToken(MathExprParser.SMIN, 0)
def expr(self, i:int=None):
if i is None:
return self.getTypedRuleContexts(MathExprParser.ExprContext)
@@ -2420,16 +2521,16 @@ class MathExprParser ( Parser ):
def enterRule(self, listener:ParseTreeListener):
if hasattr( listener, "enterMaxFunc" ):
listener.enterMaxFunc(self)
if hasattr( listener, "enterSMinFunc" ):
listener.enterSMinFunc(self)
def exitRule(self, listener:ParseTreeListener):
if hasattr( listener, "exitMaxFunc" ):
listener.exitMaxFunc(self)
if hasattr( listener, "exitSMinFunc" ):
listener.exitSMinFunc(self)
def accept(self, visitor:ParseTreeVisitor):
if hasattr( visitor, "visitMaxFunc" ):
return visitor.visitMaxFunc(self)
if hasattr( visitor, "visitSMinFunc" ):
return visitor.visitSMinFunc(self)
else:
return visitor.visitChildren(self)
@@ -2441,59 +2542,59 @@ class MathExprParser ( Parser ):
self.enterRule(localctx, 18, self.RULE_funcN)
self._la = 0 # Token type
try:
self.state = 251
self.state = 265
self._errHandler.sync(self)
token = self._input.LA(1)
if token in [22]:
localctx = MathExprParser.MinFuncContext(self, localctx)
localctx = MathExprParser.SMinFuncContext(self, localctx)
self.enterOuterAlt(localctx, 1)
self.state = 229
self.match(MathExprParser.MIN)
self.state = 230
self.state = 243
self.match(MathExprParser.SMIN)
self.state = 244
self.match(MathExprParser.T__0)
self.state = 231
self.state = 245
self.expr()
self.state = 234
self.state = 248
self._errHandler.sync(self)
_la = self._input.LA(1)
while True:
self.state = 232
self.state = 246
self.match(MathExprParser.T__2)
self.state = 233
self.state = 247
self.expr()
self.state = 236
self.state = 250
self._errHandler.sync(self)
_la = self._input.LA(1)
if not (_la==3):
break
self.state = 238
self.state = 252
self.match(MathExprParser.T__1)
pass
elif token in [23]:
localctx = MathExprParser.MaxFuncContext(self, localctx)
localctx = MathExprParser.SMaxFuncContext(self, localctx)
self.enterOuterAlt(localctx, 2)
self.state = 240
self.match(MathExprParser.MAX)
self.state = 241
self.state = 254
self.match(MathExprParser.SMAX)
self.state = 255
self.match(MathExprParser.T__0)
self.state = 242
self.state = 256
self.expr()
self.state = 245
self.state = 259
self._errHandler.sync(self)
_la = self._input.LA(1)
while True:
self.state = 243
self.state = 257
self.match(MathExprParser.T__2)
self.state = 244
self.state = 258
self.expr()
self.state = 247
self.state = 261
self._errHandler.sync(self)
_la = self._input.LA(1)
if not (_la==3):
break
self.state = 249
self.state = 263
self.match(MathExprParser.T__1)
pass
else:
+14 -4
View File
@@ -244,18 +244,28 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#TMinFunc.
def visitTMinFunc(self, ctx:MathExprParser.TMinFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#TMaxFunc.
def visitTMaxFunc(self, ctx:MathExprParser.TMaxFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#ClampFunc.
def visitClampFunc(self, ctx:MathExprParser.ClampFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#MinFunc.
def visitMinFunc(self, ctx:MathExprParser.MinFuncContext):
# Visit a parse tree produced by MathExprParser#SMinFunc.
def visitSMinFunc(self, ctx:MathExprParser.SMinFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#MaxFunc.
def visitMaxFunc(self, ctx:MathExprParser.MaxFuncContext):
# Visit a parse tree produced by MathExprParser#SMaxFunc.
def visitSMaxFunc(self, ctx:MathExprParser.SMaxFuncContext):
return self.visitChildren(ctx)
+11 -5
View File
@@ -122,12 +122,18 @@ class TensorEvalVisitor(MathExprVisitor):
return torch.atan2(self.visit(ctx.expr(0)), self.visit(ctx.expr(1)))
# N-argument functions
def visitMinFunc(self, ctx):
def visitSMinFunc(self, ctx):
args = [self.visit(e) for e in ctx.expr()]
return torch.min(torch.stack(args))
def visitMaxFunc(self, ctx):
args = [self.visit(e) for e in ctx.expr()]
return torch.max(torch.stack(args))
return torch.full(self.shape,torch.min(torch.stack(args)))
def visitSMaxFunc(self, ctx):
args = [torch.reshape(self.visit(e),self.shape) for e in ctx.expr()]
return torch.full(self.shape,torch.max(torch.stack(args)))
def visitTMinFunc(self, ctx):
print("Visiting TMin function with args:", [a.getText() for a in ctx.expr()])
return torch.minimum(self.visit(ctx.expr(0)),self.visit(ctx.expr(1)))
def visitTMaxFunc(self, ctx):
return torch.maximum(self.visit(ctx.expr(0)),self.visit(ctx.expr(1)))
def visitFunc1Exp(self, ctx):
return self.visitChildren(ctx)
+8 -5
View File
@@ -1,3 +1,4 @@
from .NoiseMathNode import NoiseMathNode
from .FloatMathNode import FloatMathNode
from .ConditioningMathNode import ConditioningMathNode
from .LatentMathNode import LatentMathNode
@@ -45,16 +46,18 @@ NODE_CLASS_MAPPINGS = {
"mrmth_ConditioningMathNode": ConditioningMathNode,
"mrmth_LatentMathNode": LatentMathNode,
"mrmth_ImageMathNode": ImageMathNode,
"mrmth_FloatMathNode": FloatMathNode,
"mrmth_NoiseMathNode": NoiseMathNode,
"mrmth_IntToFloat": IntToFloatNode,
"mrmth_FloatToInt": FloatToIntNode,
"mrmth_FloatMathNode": FloatMathNode,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"mrmth_ConditioningMathNode": "Conditioning math node",
"mrmth_LatentMathNode": "Latent math node",
"mrmth_ImageMathNode": "Image math node",
"mrmth_FloatMathNode": "Float math node",
"mrmth_ConditioningMathNode": "Conditioning math",
"mrmth_LatentMathNode": "Latent math",
"mrmth_ImageMathNode": "Image math",
"mrmth_FloatMathNode": "Float math",
"mrmth_NoiseMathNode": "Noise math",
"mrmth_IntToFloat": "Int → Float",
"mrmth_FloatToInt": "Float → Int",
"Tensor": "Tensor expression",