Skip to content

Commit d53d725

Browse files
committed
AI fix stack and large refactor + add count
1 parent a1d1ce8 commit d53d725

14 files changed

+2114
-1905
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ You can also get the node from comfy manager under the name of More math.
178178
- `nan_to_num(x, nan_value, posinf_value, neginf_value)` or `nvl`: Replaces NaN and infinite values in tensor with specified values.
179179
- `remap(v, i_min, i_max, o_min, o_max)`: Remaps value `v` from input range `[i_min, i_max]` to output range `[o_min, o_max]`.
180180
- `timestamp()` or `now`: Returns current UNIX timestamp (precision to microseconds, can be different on other systems)
181+
- `count(x)` or `length(x)` or `cnt(x)`: Returns the length of a list or the size of the first dimension of a tensor.
181182

182183
### Random Distributions
183184

more_math/LatentMathNode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def check_lazy_status(cls, Expression, V, F,batching, length_mismatch="tile",sta
8989
return needed1
9090

9191
@classmethod
92-
def execute(cls, V, F, Expression,batching, length_mismatch="tile",stack=[]) -> io.NodeOutput:
92+
def execute(cls, V, F, Expression,batching, length_mismatch="tile",stack=dict()) -> io.NodeOutput:
9393
# Determine reference latent
9494
ref_latent = None
9595
for lat in V.values():

more_math/ModelMathNode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def check_lazy_status(cls, Expression, V, F, length_mismatch="tile",stack=dict()
7272
return needed1
7373

7474
@classmethod
75-
def execute(cls, V, F, Expression, length_mismatch="tile",stack=[]) -> io.NodeOutput:
75+
def execute(cls, V, F, Expression, length_mismatch="tile",stack=dict()) -> io.NodeOutput:
7676
# Determine reference model for cloning
7777
a = V.get("V0")
7878
if a is None:

more_math/Parser/MathExpr.g4

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
grammar MathExpr;
22

33
// Top-level entry point
4-
start: (funcDef | varDef | stmt)* expr SEMICOLON? EOF;
4+
start: (funcDef | varDef | stmt)* expr? SEMICOLON? EOF;
55

66
funcDef:
77
VARIABLE LPAREN paramList? RPAREN ARROW (block | expr) SEMICOLON # FunctionDef;
@@ -81,7 +81,9 @@ atom:
8181
| PIPE expr PIPE # AbsExp
8282
| LBRACKET expr (COMMA expr)* RBRACKET # ListExp
8383
| VARIABLE LPAREN exprList? RPAREN # CallExp
84-
| NONE # NoneExp;
84+
| NONE # NoneExp
85+
| BREAK # BreakExp
86+
| CONTINUE # ContinueExp;
8587

8688
exprList: expr (COMMA expr)*;
8789

@@ -136,6 +138,7 @@ func1:
136138
| MEDIAN LPAREN expr RPAREN # MedianFunc
137139
| MODE LPAREN expr RPAREN # ModeFunc
138140
| CUMSUM LPAREN expr RPAREN # CumsumFunc
141+
| COUNT LPAREN expr RPAREN # CountFunc
139142
| CUMPROD LPAREN expr RPAREN # CumprodFunc
140143
| POP LPAREN expr RPAREN # PopFunc
141144
| CLEAR LPAREN expr RPAREN # ClearFunc
@@ -307,6 +310,7 @@ COSSIM: 'cossim';
307310
FLIP: 'flip';
308311
COV: 'cov';
309312
SORT: 'sort';
313+
COUNT: 'count' | 'length' | 'cnt';
310314
APPEND: 'append';
311315
GET_VALUE: 'get_value';
312316
CROP: 'crop';

more_math/Parser/MathExpr.interp

Lines changed: 3 additions & 1 deletion
Large diffs are not rendered by default.

more_math/Parser/MathExpr.tokens

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -98,46 +98,47 @@ COSSIM=97
9898
FLIP=98
9999
COV=99
100100
SORT=100
101-
APPEND=101
102-
GET_VALUE=102
103-
CROP=103
104-
FOR=104
105-
IN=105
106-
TIMESTAMP=106
107-
NONE=107
108-
BREAK=108
109-
CONTINUE=109
110-
PLUS=110
111-
MINUS=111
112-
MULT=112
113-
DIV=113
114-
MOD=114
115-
POW=115
116-
GE=116
117-
GT=117
118-
LE=118
119-
LT=119
120-
EQ=120
121-
EQUEALS=121
122-
NE=122
123-
PIPE=123
124-
LPAREN=124
125-
RPAREN=125
126-
COMMA=126
127-
SEMICOLON=127
128-
ARROW=128
129-
LBRACKET=129
130-
RBRACKET=130
131-
QUESTION=131
132-
COLON=132
133-
LBRACE=133
134-
RBRACE=134
135-
NUMBER=135
136-
CONSTANT=136
137-
VARIABLE=137
138-
SL_COMMENT=138
139-
ML_COMMENT=139
140-
WS=140
101+
COUNT=101
102+
APPEND=102
103+
GET_VALUE=103
104+
CROP=104
105+
FOR=105
106+
IN=106
107+
TIMESTAMP=107
108+
NONE=108
109+
BREAK=109
110+
CONTINUE=110
111+
PLUS=111
112+
MINUS=112
113+
MULT=113
114+
DIV=114
115+
MOD=115
116+
POW=116
117+
GE=117
118+
GT=118
119+
LE=119
120+
LT=120
121+
EQ=121
122+
EQUEALS=122
123+
NE=123
124+
PIPE=124
125+
LPAREN=125
126+
RPAREN=126
127+
COMMA=127
128+
SEMICOLON=128
129+
ARROW=129
130+
LBRACKET=130
131+
RBRACKET=131
132+
QUESTION=132
133+
COLON=133
134+
LBRACE=134
135+
RBRACE=135
136+
NUMBER=136
137+
CONSTANT=137
138+
VARIABLE=138
139+
SL_COMMENT=139
140+
ML_COMMENT=140
141+
WS=141
141142
'sin'=1
142143
'cos'=2
143144
'tan'=3
@@ -216,35 +217,35 @@ WS=140
216217
'flip'=98
217218
'cov'=99
218219
'sort'=100
219-
'append'=101
220-
'get_value'=102
221-
'crop'=103
222-
'for'=104
223-
'in'=105
224-
'break'=108
225-
'continue'=109
226-
'+'=110
227-
'-'=111
228-
'*'=112
229-
'/'=113
230-
'%'=114
231-
'^'=115
232-
'>='=116
233-
'>'=117
234-
'<='=118
235-
'<'=119
236-
'=='=120
237-
'='=121
238-
'!='=122
239-
'|'=123
240-
'('=124
241-
')'=125
242-
','=126
243-
';'=127
244-
'->'=128
245-
'['=129
246-
']'=130
247-
'?'=131
248-
':'=132
249-
'{'=133
250-
'}'=134
220+
'append'=102
221+
'get_value'=103
222+
'crop'=104
223+
'for'=105
224+
'in'=106
225+
'break'=109
226+
'continue'=110
227+
'+'=111
228+
'-'=112
229+
'*'=113
230+
'/'=114
231+
'%'=115
232+
'^'=116
233+
'>='=117
234+
'>'=118
235+
'<='=119
236+
'<'=120
237+
'=='=121
238+
'='=122
239+
'!='=123
240+
'|'=124
241+
'('=125
242+
')'=126
243+
','=127
244+
';'=128
245+
'->'=129
246+
'['=130
247+
']'=131
248+
'?'=132
249+
':'=133
250+
'{'=134
251+
'}'=135

more_math/Parser/MathExprLexer.interp

Lines changed: 4 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)