Skip to content

Commit e7d913c

Browse files
committed
add time measurement and updated readme
1 parent 13e5b4e commit e7d913c

File tree

10 files changed

+1816
-1692
lines changed

10 files changed

+1816
-1692
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ You can also get the node from comfy manager under the name of More math.
2323
- Vector Math: Support for List literals `[v1, v2, ...]` and operations between lists/scalars/tensors
2424
- Custom functions `funcname(variable,variable,...)->expression;` they can be used in any later defined custom function or in expression. Shadowing inbuilt functions do not work. **Be careful with recursion. There is no stack limit. Got to 700 000 iterations before I got bored.**
2525
- Custom variables `varname=expression;` They can be used in any later assigment or final expression.
26-
- Support for control flow statements including `if/else`, `while` loops, blocks `{}`, and `return` statements. These do not work like ternary operator or other inbuilts. They colapse tensors and list to single value using any.
26+
- Support for control flow statements including `if/else`, `while` loops, blocks `{}`, and `return` statements. `if`/`else`/`while` do not work like ternary operator or other inbuilts. They colapse tensors and list to single value using any.
2727
- Support for stack. Stack survives between field evaluations but not between nodes or end of node execution.
2828
- Usefull in GuiderMath node to store variables between steps.
29+
- comments `#...` and `/*...*/`
2930

3031
### Control Flow Statements
3132

@@ -160,6 +161,7 @@ You can also get the node from comfy manager under the name of More math.
160161
- `range(start, end, step)`: Generates a list of values from start (inclusive) to end (exclusive) with given step.
161162
- `nan_to_num(x, nan_value, posinf_value, neginf_value)` or `nvl`: Replaces NaN and infinite values in tensor with specified values.
162163
- `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]`.
164+
- `timestamp()` or `now`: Returns current UNIX timestamp (precision to microseconds, can be different on other systems)
163165

164166
### Random Distributions
165167

more_math/Parser/MathExpr.g4

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ indexExpr:
6060

6161
// Atoms: function calls, variable, number, constant, or parenthesized expression
6262
atom:
63-
func1 # Func1Exp
63+
func0 # Func0Exp
64+
| func1 # Func1Exp
6465
| func2 # Func2Exp
6566
| func3 # Func3Exp
6667
| func4 # Func4Exp
@@ -76,6 +77,8 @@ atom:
7677

7778
exprList: expr (COMMA expr)*;
7879

80+
func0:
81+
TIMESTAMP LPAREN RPAREN #TimestampFunc;
7982
// Single-argument functions
8083
func1:
8184
SIN LPAREN expr RPAREN # SinFunc
@@ -295,6 +298,8 @@ COV: 'cov';
295298
SORT: 'sort';
296299
APPEND: 'append';
297300

301+
TIMESTAMP: 'timestamp' | 'now';
302+
298303
PLUS: '+';
299304
MINUS: '-';
300305
MULT: '*';

more_math/Parser/MathExpr.interp

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

more_math/Parser/MathExpr.tokens

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -99,37 +99,38 @@ FLIP=98
9999
COV=99
100100
SORT=100
101101
APPEND=101
102-
PLUS=102
103-
MINUS=103
104-
MULT=104
105-
DIV=105
106-
MOD=106
107-
POW=107
108-
GE=108
109-
GT=109
110-
LE=110
111-
LT=111
112-
EQ=112
113-
EQUEALS=113
114-
NE=114
115-
PIPE=115
116-
LPAREN=116
117-
RPAREN=117
118-
COMMA=118
119-
SEMICOLON=119
120-
ARROW=120
121-
LBRACKET=121
122-
RBRACKET=122
123-
QUESTION=123
124-
COLON=124
125-
LBRACE=125
126-
RBRACE=126
127-
CONSTANT=127
128-
NUMBER=128
129-
VARIABLE=129
130-
SL_COMMENT=130
131-
ML_COMMENT=131
132-
WS=132
102+
TIMESTAMP=102
103+
PLUS=103
104+
MINUS=104
105+
MULT=105
106+
DIV=106
107+
MOD=107
108+
POW=108
109+
GE=109
110+
GT=110
111+
LE=111
112+
LT=112
113+
EQ=113
114+
EQUEALS=114
115+
NE=115
116+
PIPE=116
117+
LPAREN=117
118+
RPAREN=118
119+
COMMA=119
120+
SEMICOLON=120
121+
ARROW=121
122+
LBRACKET=122
123+
RBRACKET=123
124+
QUESTION=124
125+
COLON=125
126+
LBRACE=126
127+
RBRACE=127
128+
CONSTANT=128
129+
NUMBER=129
130+
VARIABLE=130
131+
SL_COMMENT=131
132+
ML_COMMENT=132
133+
WS=133
133134
'sin'=1
134135
'cos'=2
135136
'tan'=3
@@ -209,28 +210,28 @@ WS=132
209210
'cov'=99
210211
'sort'=100
211212
'append'=101
212-
'+'=102
213-
'-'=103
214-
'*'=104
215-
'/'=105
216-
'%'=106
217-
'^'=107
218-
'>='=108
219-
'>'=109
220-
'<='=110
221-
'<'=111
222-
'=='=112
223-
'='=113
224-
'!='=114
225-
'|'=115
226-
'('=116
227-
')'=117
228-
','=118
229-
';'=119
230-
'->'=120
231-
'['=121
232-
']'=122
233-
'?'=123
234-
':'=124
235-
'{'=125
236-
'}'=126
213+
'+'=103
214+
'-'=104
215+
'*'=105
216+
'/'=106
217+
'%'=107
218+
'^'=108
219+
'>='=109
220+
'>'=110
221+
'<='=111
222+
'<'=112
223+
'=='=113
224+
'='=114
225+
'!='=115
226+
'|'=116
227+
'('=117
228+
')'=118
229+
','=119
230+
';'=120
231+
'->'=121
232+
'['=122
233+
']'=123
234+
'?'=124
235+
':'=125
236+
'{'=126
237+
'}'=127

more_math/Parser/MathExprLexer.interp

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

more_math/Parser/MathExprLexer.py

Lines changed: 476 additions & 468 deletions
Large diffs are not rendered by default.

more_math/Parser/MathExprLexer.tokens

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -99,37 +99,38 @@ FLIP=98
9999
COV=99
100100
SORT=100
101101
APPEND=101
102-
PLUS=102
103-
MINUS=103
104-
MULT=104
105-
DIV=105
106-
MOD=106
107-
POW=107
108-
GE=108
109-
GT=109
110-
LE=110
111-
LT=111
112-
EQ=112
113-
EQUEALS=113
114-
NE=114
115-
PIPE=115
116-
LPAREN=116
117-
RPAREN=117
118-
COMMA=118
119-
SEMICOLON=119
120-
ARROW=120
121-
LBRACKET=121
122-
RBRACKET=122
123-
QUESTION=123
124-
COLON=124
125-
LBRACE=125
126-
RBRACE=126
127-
CONSTANT=127
128-
NUMBER=128
129-
VARIABLE=129
130-
SL_COMMENT=130
131-
ML_COMMENT=131
132-
WS=132
102+
TIMESTAMP=102
103+
PLUS=103
104+
MINUS=104
105+
MULT=105
106+
DIV=106
107+
MOD=107
108+
POW=108
109+
GE=109
110+
GT=110
111+
LE=111
112+
LT=112
113+
EQ=113
114+
EQUEALS=114
115+
NE=115
116+
PIPE=116
117+
LPAREN=117
118+
RPAREN=118
119+
COMMA=119
120+
SEMICOLON=120
121+
ARROW=121
122+
LBRACKET=122
123+
RBRACKET=123
124+
QUESTION=124
125+
COLON=125
126+
LBRACE=126
127+
RBRACE=127
128+
CONSTANT=128
129+
NUMBER=129
130+
VARIABLE=130
131+
SL_COMMENT=131
132+
ML_COMMENT=132
133+
WS=133
133134
'sin'=1
134135
'cos'=2
135136
'tan'=3
@@ -209,28 +210,28 @@ WS=132
209210
'cov'=99
210211
'sort'=100
211212
'append'=101
212-
'+'=102
213-
'-'=103
214-
'*'=104
215-
'/'=105
216-
'%'=106
217-
'^'=107
218-
'>='=108
219-
'>'=109
220-
'<='=110
221-
'<'=111
222-
'=='=112
223-
'='=113
224-
'!='=114
225-
'|'=115
226-
'('=116
227-
')'=117
228-
','=118
229-
';'=119
230-
'->'=120
231-
'['=121
232-
']'=122
233-
'?'=123
234-
':'=124
235-
'{'=125
236-
'}'=126
213+
'+'=103
214+
'-'=104
215+
'*'=105
216+
'/'=106
217+
'%'=107
218+
'^'=108
219+
'>='=109
220+
'>'=110
221+
'<='=111
222+
'<'=112
223+
'=='=113
224+
'='=114
225+
'!='=115
226+
'|'=116
227+
'('=117
228+
')'=118
229+
','=119
230+
';'=120
231+
'->'=121
232+
'['=122
233+
']'=123
234+
'?'=124
235+
':'=125
236+
'{'=126
237+
'}'=127

0 commit comments

Comments
 (0)