AI: add dictionaries

This commit is contained in:
mcDandy
2026-09-09 21:57:22 +02:00
parent 59e40f8c6f
commit 0e4e2c06af
21 changed files with 11081 additions and 10032 deletions
+25 -8
View File
@@ -17,7 +17,7 @@ grammar MathExpr;
start: (funcDef | varDef | stmt)* expr SEMICOLON? EOF;
funcDef:
VARIABLE LPAREN paramList? RPAREN ARROW (block | expr) SEMICOLON # FunctionDef;
VARIABLE LPAREN paramList? RPAREN ARROW (expr | block) SEMICOLON # FunctionDef;
varDef:
VARIABLE (LBRACKET expr (COMMA expr)* RBRACKET)* (EQUEALS | PLUS_EQ | MINUS_EQ | MULT_EQ | DIV_EQ | MOD_EQ) expr SEMICOLON;
@@ -39,6 +39,12 @@ ifStmt: IF LPAREN expr RPAREN stmt (ELSE stmt)?;
whileStmt: WHILE LPAREN expr RPAREN stmt;
forStmt: FOR LPAREN VARIABLE IN expr RPAREN stmt;
block: LBRACE stmt* RBRACE;
dictEntryList: dictEntry (COMMA dictEntry)*;
dictEntry: VARIABLE COLON expr
| STRING COLON expr
| NUMBER COLON expr;
breakStmt: BREAK SEMICOLON;
continueStmt: CONTINUE SEMICOLON;
returnStmt: RETURN expr? SEMICOLON;
@@ -108,11 +114,12 @@ atom:
| NUMBER # NumberExp
| CONSTANT # ConstantExp
| STRING # StringExp
| LPAREN paramList RPAREN ARROW (block | expr) # LambdaExp
| LPAREN paramList RPAREN ARROW (expr | block) # LambdaExp
| LPAREN expr RPAREN # ParenExp
| LPAREN expr RPAREN # ParenExp
| PIPE expr PIPE # AbsExp
| LBRACKET expr (COMMA expr)* RBRACKET # ListExp
| LBRACE dictEntryList? RBRACE # DictExp
| VARIABLE LPAREN exprList? RPAREN # CallExp
| NONE # NoneExp
| BREAK # BreakExp
@@ -520,11 +527,15 @@ func2:
/**
append(x, y) - appends y to the end of x. If inputs are tensors use concatenate(x,...,dim)
*/
| APPEND LPAREN expr COMMA expr RPAREN # AppendFunc
/**
permute(x, dims) - permutes the dimensions of tensor x according to dims
*/
| PERM LPAREN expr COMMA expr RPAREN # PermuteFunc
| APPEND LPAREN expr COMMA expr RPAREN # AppendFunc
/**
add_key(dict, key, value) - adds or replaces a dictionary entry and returns the updated dictionary
*/
| ADD_KEY LPAREN expr COMMA expr COMMA expr RPAREN # AddKeyFunc
/**
permute(x, dims) - permutes the dimensions of tensor x according to dims
*/
| PERM LPAREN expr COMMA expr RPAREN # PermuteFunc
/**
gaussian(x, sigma, [reshape]) - applies a Gaussian blur to x with specified sigma. if reshape has value of 1.0, then it tries orienting the input such that channel is in the direction of filter. Otherwise it expect color dimension to be the last.
*/
@@ -627,7 +638,11 @@ func2:
/**
interpolate_nearest_exact(x, y) - performs nearest neighbor interpolation X. Assumes that dim 0 is batch and dim 1 = channel
*/
| INTERPOLATE_NEAREST LPAREN expr COMMA expr RPAREN # InterpolateNearestExactFunc;
| INTERPOLATE_NEAREST LPAREN expr COMMA expr RPAREN # InterpolateNearestExactFunc
/**
remove_key(dict, key) - removes a dictionary entry and returns the updated dictionary
*/
| REMOVE_KEY LPAREN expr COMMA expr RPAREN # RemoveKeyFunc;
func3:
@@ -986,6 +1001,8 @@ BAND: 'band' | 'bitwise_and';
XOR: 'bxor' | 'bitwise_xor';
BOR: 'bor' | 'bitwise_or';
TENSOR: 'tensor';
ADD_KEY: 'add_key';
REMOVE_KEY: 'remove_key' | 'remove_kay';
PUSH: 'stack_push';
POP: 'stack_pop';
CLEAR: 'stack_clear';
+112 -25
View File
@@ -32,6 +32,12 @@ class BreakSignal:
class ContinueSignal:
pass
class MathDict(dict):
def __str__(self):
return "{" + ", ".join(f"{k}:{v}" for k, v in self.items()) + "}"
__repr__ = __str__
class UnifiedMathVisitor(MathExprVisitor):
def __init__(self, variables, shape=None, device=None, functions=None, depth=0, state_storage=None):
@@ -108,6 +114,9 @@ class UnifiedMathVisitor(MathExprVisitor):
def _is_list(self, val):
return isinstance(val, (list, tuple))
def _decode_string_literal(self, text):
return text[1:-1].replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r').replace('\\\\', '\\').replace('\\"', '"').replace("\\'", "'")
def _promote_to_tensor(self, val,brodcast=False):
if self._is_tensor(val):
return val.contiguous()
@@ -435,10 +444,24 @@ class UnifiedMathVisitor(MathExprVisitor):
res.append((yield e))
return res
def visitDictExp(self, ctx):
res = MathDict()
entries = ctx.dictEntryList().dictEntry() if ctx.dictEntryList() else []
for entry in entries:
if entry.VARIABLE():
key = entry.VARIABLE().getText()
elif entry.STRING():
key = self._decode_string_literal(entry.STRING().getText())
else:
key_text = entry.NUMBER().getText()
key = float(key_text) if any(ch in key_text for ch in ".eE") else int(key_text)
value = yield entry.expr()
res[key] = value
return res
def visitStringExp(self, ctx):
val = yield ctx.STRING().getText()
val = val[1:-1].replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r').replace('\\\\', '\\').replace('\\"', '"').replace("\\'", "'")
return val
return self._decode_string_literal(val)
def visitParenExp(self, ctx):
return (yield ctx.expr())
@@ -456,22 +479,13 @@ class UnifiedMathVisitor(MathExprVisitor):
return (yield ctx.indexExpr())
def _process_slice_element(self, slice_elem_ctx):
"""Process a sliceElement context and return either an index (int) or a slice object."""
"""Process a sliceElement context and return either an index value or a slice object."""
# Get the context class name to determine which type of element this is
ctx_type = type(slice_elem_ctx).__name__
if ctx_type == "IndexOnlyContext":
# Regular index: expr
idx_val = yield slice_elem_ctx.expr(0)
if self._is_tensor(idx_val):
if idx_val.numel() == 1:
return int(idx_val.flatten()[0].item())
else:
return idx_val.long()
elif self._is_list(idx_val):
return torch.tensor(idx_val, dtype=torch.long, device=self.device)
else:
return int(idx_val)
return (yield slice_elem_ctx.expr())
# Handle slice expressions - all cases with colons
exprs = slice_elem_ctx.expr() if hasattr(slice_elem_ctx, 'expr') else []
@@ -523,22 +537,29 @@ class UnifiedMathVisitor(MathExprVisitor):
indices = []
for node in slice_elem_nodes:
elem = yield self._process_slice_element(node)
elem = yield from self._process_slice_element(node)
indices.append(elem)
# Use standard PyTorch/list indexing and slicing
# Use standard PyTorch/list/string/dictionary indexing and slicing
if self._is_tensor(val):
if len(indices) > val.ndim:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: Expected up to {val.ndim} dimensions but got {len(indices)}.")
# Build index tuple, handling both regular indices and slices
idx_tuple = []
for dim, idx in enumerate(indices):
if isinstance(idx, slice):
idx_tuple.append(idx)
continue
if self._is_tensor(idx):
if idx.numel() == 1:
idx = int(idx.flatten()[0].item())
else:
idx = idx.long()
elif self._is_list(idx):
idx = torch.tensor(idx, dtype=torch.long, device=self.device)
else:
# Normalize scalar index
idx_tuple.append(self._normalize_index_value(idx, val.shape[dim], ctx, f"dimension {dim}"))
idx = int(idx)
idx_tuple.append(self._normalize_index_value(idx, val.shape[dim], ctx, f"dimension {dim}"))
result = val[tuple(idx_tuple)]
if self._is_tensor(result):
@@ -553,38 +574,48 @@ class UnifiedMathVisitor(MathExprVisitor):
for idx in indices:
if isinstance(idx, slice):
current = current[idx]
elif isinstance(idx, torch.Tensor):
elif self._is_tensor(idx):
if idx.numel() != 1:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: Too many indices for string with 1 dimension. Got {idx.numel()}")
idx = int(idx.flatten()[0].item())
idx = self._normalize_index_value(idx, len(current), ctx, "string")
current = current[idx]
else:
idx = self._normalize_index_value(idx, len(current), ctx, "string")
idx = self._normalize_index_value(int(idx), len(current), ctx, "string")
current = current[idx]
return current
elif self._is_list(val):
# Navigate through nested lists, supporting both indexing and slicing
current = val
for idx in indices:
if isinstance(idx, slice):
current = current[idx]
elif isinstance(idx, torch.Tensor):
elif self._is_tensor(idx):
if idx.numel() != 1:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: List index must be a scalar. Got tensor with length of {idx.numel()}")
idx = int(idx.item())
idx = self._normalize_index_value(idx, len(current), ctx, "list")
current = current[idx]
else:
idx = self._normalize_index_value(idx, len(current), ctx, "list")
idx = self._normalize_index_value(int(idx), len(current), ctx, "list")
current = current[idx]
return current
elif isinstance(val, dict):
current = val
for idx in indices:
if isinstance(idx, slice):
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: Dictionary indexing does not support slices")
if self._is_tensor(idx):
if idx.numel() != 1:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: Dictionary keys must be scalar values")
idx = idx.item()
current = current[idx]
return current
error_prefix = f"{ctx.start.line}:{ctx.start.column}:"
raise ValueError(f"{error_prefix} Indexing only supported on tensors, lists, and strings (found {type(val).__name__})")
raise ValueError(f"{error_prefix} Indexing only supported on tensors, lists, strings, and dictionaries (found {type(val).__name__})")
def visitIndexOnly(self, ctx):
"""Visit slice element that is just an index expression."""
return (yield ctx.expr(0))
return (yield ctx.expr())
def visitSlice(self, ctx):
"""Visit slice element with start and stop: expr COLON expr"""
@@ -2093,6 +2124,29 @@ class UnifiedMathVisitor(MathExprVisitor):
b = [b]
return a + b
def visitAddKeyFunc(self, ctx):
target = yield ctx.expr(0)
key = yield ctx.expr(1)
value = yield ctx.expr(2)
if not isinstance(target, dict):
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: add_key() requires a dictionary")
target[key] = value
return target
def visitRemoveKeyFunc(self, ctx):
target = yield ctx.expr(0)
key = yield ctx.expr(1)
if not isinstance(target, dict):
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: remove_key() requires a dictionary")
if key in target:
del target[key]
return target
def visitStart(self, ctx):
count = ctx.getChildCount()
last_res = None
@@ -2325,6 +2379,39 @@ class UnifiedMathVisitor(MathExprVisitor):
else:
curr[real_idx] = assigned_val
return assigned_val
elif isinstance(target, dict):
curr = target
for idx in indices[:-1]:
if self._is_tensor(idx):
if idx.numel() != 1:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: Dictionary keys must be scalar values")
idx = idx.item()
curr = curr[idx]
if not isinstance(curr, dict):
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: Dictionary indexing can only traverse through dictionaries")
key = indices[-1]
if self._is_tensor(key):
if key.numel() != 1:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: Dictionary keys must be scalar values")
key = key.item()
if assign_op != "=":
existing_val = curr[key]
if assign_op == "+=":
new_val = self._bin_op(existing_val, assigned_val, torch.add, lambda a, b: a + b, ctx)
elif assign_op == "-=":
new_val = self._bin_op(existing_val, assigned_val, torch.sub, lambda a, b: a - b, ctx)
elif assign_op == "*=":
new_val = self._bin_op(existing_val, assigned_val, torch.mul, lambda a, b: a * b, ctx)
elif assign_op == "/=":
new_val = self._bin_op(existing_val, assigned_val, torch.div, lambda a, b: a / b, ctx)
elif assign_op == "%=":
new_val = self._bin_op(existing_val, assigned_val, torch.remainder, lambda a, b: a % b, ctx)
curr[key] = new_val
return new_val
else:
curr[key] = assigned_val
return assigned_val
else:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: Indexed assignment not supported for {type(target)}")
File diff suppressed because one or more lines are too long
+210 -207
View File
@@ -108,127 +108,129 @@ BAND=107
XOR=108
BOR=109
TENSOR=110
PUSH=111
POP=112
CLEAR=113
HAS=114
GET=115
CONCAT=116
INT=117
FLOAT=118
UPPER=119
LOWER=120
TRIM=121
SPLIT=122
JOIN=123
SUBSTRING=124
FIND=125
REPLACE=126
DILATE=127
ERODE=128
MORPH_OPEN=129
MORPH_CLOSE=130
RGB_TO_OKLAB=131
RGB_TO_CIELAB=132
OKLAB_TO_RGB=133
CIELAB_TO_RGB=134
RGB_TO_HSV=135
HSV_TO_RGB=136
INT_TO_RGB=137
RGB_TO_INT=138
INTERPOLATE_LINEAR=139
INTERPOLATE_AREA=140
INTERPOLATE_NEAREST=141
TEXT_IMAGE=142
AS_NESTED=143
SVD=144
DIAG=145
IF=146
ELSE=147
WHILE=148
FOR=149
IN=150
BREAK=151
CONTINUE=152
RETURN=153
TIMESTAMP=154
SORT=155
ARGSORT=156
ARGMIN=157
ARGMAX=158
SOFTMAX=159
SOFTMIN=160
UNIQUE=161
FLIP=162
STARTSWITH=163
ENDSWITH=164
SQUEEZE=165
UNSQUEEZE=166
ROLL=167
COV=168
CORR=169
ENTROPY=170
CROP=171
NONE=172
COORDS=173
NOISE=174
RAND=175
CAUCHY=176
EXPONENTIAL=177
LOGNORMAL=178
BERNOULLI=179
POISSON=180
GAMMADIST=181
BETADIST=182
LAPLACEDIST=183
GUMBELDIST=184
WEIBULLDIST=185
CHI2DIST=186
STUDENTTDIST=187
PERLIN=188
CELLULAR=189
PLASMA=190
RIDGED=191
DOMAIN_WARP=192
PLUS=193
MINUS=194
MULT=195
DIV=196
MOD=197
POW=198
LSHIFT=199
RSHIFT=200
GE=201
GT=202
LE=203
LT=204
EQ=205
EQUEALS=206
PLUS_EQ=207
MINUS_EQ=208
MULT_EQ=209
DIV_EQ=210
MOD_EQ=211
NE=212
PIPE=213
LPAREN=214
RPAREN=215
COMMA=216
SEMICOLON=217
ARROW=218
LBRACKET=219
RBRACKET=220
QUESTION=221
COLON=222
LBRACE=223
RBRACE=224
NUMBER=225
CONSTANT=226
STRING=227
VARIABLE=228
SL_COMMENT=229
ML_COMMENT=230
WS=231
ADD_KEY=111
REMOVE_KEY=112
PUSH=113
POP=114
CLEAR=115
HAS=116
GET=117
CONCAT=118
INT=119
FLOAT=120
UPPER=121
LOWER=122
TRIM=123
SPLIT=124
JOIN=125
SUBSTRING=126
FIND=127
REPLACE=128
DILATE=129
ERODE=130
MORPH_OPEN=131
MORPH_CLOSE=132
RGB_TO_OKLAB=133
RGB_TO_CIELAB=134
OKLAB_TO_RGB=135
CIELAB_TO_RGB=136
RGB_TO_HSV=137
HSV_TO_RGB=138
INT_TO_RGB=139
RGB_TO_INT=140
INTERPOLATE_LINEAR=141
INTERPOLATE_AREA=142
INTERPOLATE_NEAREST=143
TEXT_IMAGE=144
AS_NESTED=145
SVD=146
DIAG=147
IF=148
ELSE=149
WHILE=150
FOR=151
IN=152
BREAK=153
CONTINUE=154
RETURN=155
TIMESTAMP=156
SORT=157
ARGSORT=158
ARGMIN=159
ARGMAX=160
SOFTMAX=161
SOFTMIN=162
UNIQUE=163
FLIP=164
STARTSWITH=165
ENDSWITH=166
SQUEEZE=167
UNSQUEEZE=168
ROLL=169
COV=170
CORR=171
ENTROPY=172
CROP=173
NONE=174
COORDS=175
NOISE=176
RAND=177
CAUCHY=178
EXPONENTIAL=179
LOGNORMAL=180
BERNOULLI=181
POISSON=182
GAMMADIST=183
BETADIST=184
LAPLACEDIST=185
GUMBELDIST=186
WEIBULLDIST=187
CHI2DIST=188
STUDENTTDIST=189
PERLIN=190
CELLULAR=191
PLASMA=192
RIDGED=193
DOMAIN_WARP=194
PLUS=195
MINUS=196
MULT=197
DIV=198
MOD=199
POW=200
LSHIFT=201
RSHIFT=202
GE=203
GT=204
LE=205
LT=206
EQ=207
EQUEALS=208
PLUS_EQ=209
MINUS_EQ=210
MULT_EQ=211
DIV_EQ=212
MOD_EQ=213
NE=214
PIPE=215
LPAREN=216
RPAREN=217
COMMA=218
SEMICOLON=219
ARROW=220
LBRACKET=221
RBRACKET=222
QUESTION=223
COLON=224
LBRACE=225
RBRACE=226
NUMBER=227
CONSTANT=228
STRING=229
VARIABLE=230
SL_COMMENT=231
ML_COMMENT=232
WS=233
'sin'=1
'cos'=2
'tan'=3
@@ -313,89 +315,90 @@ WS=231
'rife'=103
'shape'=106
'tensor'=110
'stack_push'=111
'stack_pop'=112
'stack_clear'=113
'stack_has'=114
'stack_get'=115
'int'=117
'float'=118
'upper'=119
'lower'=120
'trim'=121
'split'=122
'join'=123
'find'=125
'replace'=126
'dilate'=127
'erode'=128
'morph_open'=129
'morph_close'=130
'rgb_to_oklab'=131
'rgb_to_cielab'=132
'oklab_to_rgb'=133
'cielab_to_rgb'=134
'rgb_to_hsv'=135
'hsv_to_rgb'=136
'int_to_rgb'=137
'rgb_to_int'=138
'interpolate_linear'=139
'interpolate_area'=140
'text_image'=142
'as_nested_tensor'=143
'if'=146
'else'=147
'while'=148
'for'=149
'in'=150
'break'=151
'continue'=152
'return'=153
'sort'=155
'argsort'=156
'argmin'=157
'argmax'=158
'softmax'=159
'softmin'=160
'unique'=161
'flip'=162
'startswith'=163
'endswith'=164
'squeeze'=165
'unsqueeze'=166
'roll'=167
'cov'=168
'entropy'=170
'crop'=171
'+'=193
'-'=194
'*'=195
'/'=196
'%'=197
'^'=198
'<<'=199
'>>'=200
'>='=201
'>'=202
'<='=203
'<'=204
'=='=205
'='=206
'+='=207
'-='=208
'*='=209
'/='=210
'%='=211
'!='=212
'|'=213
'('=214
')'=215
','=216
';'=217
'->'=218
'['=219
']'=220
'?'=221
':'=222
'{'=223
'}'=224
'add_key'=111
'stack_push'=113
'stack_pop'=114
'stack_clear'=115
'stack_has'=116
'stack_get'=117
'int'=119
'float'=120
'upper'=121
'lower'=122
'trim'=123
'split'=124
'join'=125
'find'=127
'replace'=128
'dilate'=129
'erode'=130
'morph_open'=131
'morph_close'=132
'rgb_to_oklab'=133
'rgb_to_cielab'=134
'oklab_to_rgb'=135
'cielab_to_rgb'=136
'rgb_to_hsv'=137
'hsv_to_rgb'=138
'int_to_rgb'=139
'rgb_to_int'=140
'interpolate_linear'=141
'interpolate_area'=142
'text_image'=144
'as_nested_tensor'=145
'if'=148
'else'=149
'while'=150
'for'=151
'in'=152
'break'=153
'continue'=154
'return'=155
'sort'=157
'argsort'=158
'argmin'=159
'argmax'=160
'softmax'=161
'softmin'=162
'unique'=163
'flip'=164
'startswith'=165
'endswith'=166
'squeeze'=167
'unsqueeze'=168
'roll'=169
'cov'=170
'entropy'=172
'crop'=173
'+'=195
'-'=196
'*'=197
'/'=198
'%'=199
'^'=200
'<<'=201
'>>'=202
'>='=203
'>'=204
'<='=205
'<'=206
'=='=207
'='=208
'+='=209
'-='=210
'*='=211
'/='=212
'%='=213
'!='=214
'|'=215
'('=216
')'=217
','=218
';'=219
'->'=220
'['=221
']'=222
'?'=223
':'=224
'{'=225
'}'=226
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+210 -207
View File
@@ -108,127 +108,129 @@ BAND=107
XOR=108
BOR=109
TENSOR=110
PUSH=111
POP=112
CLEAR=113
HAS=114
GET=115
CONCAT=116
INT=117
FLOAT=118
UPPER=119
LOWER=120
TRIM=121
SPLIT=122
JOIN=123
SUBSTRING=124
FIND=125
REPLACE=126
DILATE=127
ERODE=128
MORPH_OPEN=129
MORPH_CLOSE=130
RGB_TO_OKLAB=131
RGB_TO_CIELAB=132
OKLAB_TO_RGB=133
CIELAB_TO_RGB=134
RGB_TO_HSV=135
HSV_TO_RGB=136
INT_TO_RGB=137
RGB_TO_INT=138
INTERPOLATE_LINEAR=139
INTERPOLATE_AREA=140
INTERPOLATE_NEAREST=141
TEXT_IMAGE=142
AS_NESTED=143
SVD=144
DIAG=145
IF=146
ELSE=147
WHILE=148
FOR=149
IN=150
BREAK=151
CONTINUE=152
RETURN=153
TIMESTAMP=154
SORT=155
ARGSORT=156
ARGMIN=157
ARGMAX=158
SOFTMAX=159
SOFTMIN=160
UNIQUE=161
FLIP=162
STARTSWITH=163
ENDSWITH=164
SQUEEZE=165
UNSQUEEZE=166
ROLL=167
COV=168
CORR=169
ENTROPY=170
CROP=171
NONE=172
COORDS=173
NOISE=174
RAND=175
CAUCHY=176
EXPONENTIAL=177
LOGNORMAL=178
BERNOULLI=179
POISSON=180
GAMMADIST=181
BETADIST=182
LAPLACEDIST=183
GUMBELDIST=184
WEIBULLDIST=185
CHI2DIST=186
STUDENTTDIST=187
PERLIN=188
CELLULAR=189
PLASMA=190
RIDGED=191
DOMAIN_WARP=192
PLUS=193
MINUS=194
MULT=195
DIV=196
MOD=197
POW=198
LSHIFT=199
RSHIFT=200
GE=201
GT=202
LE=203
LT=204
EQ=205
EQUEALS=206
PLUS_EQ=207
MINUS_EQ=208
MULT_EQ=209
DIV_EQ=210
MOD_EQ=211
NE=212
PIPE=213
LPAREN=214
RPAREN=215
COMMA=216
SEMICOLON=217
ARROW=218
LBRACKET=219
RBRACKET=220
QUESTION=221
COLON=222
LBRACE=223
RBRACE=224
NUMBER=225
CONSTANT=226
STRING=227
VARIABLE=228
SL_COMMENT=229
ML_COMMENT=230
WS=231
ADD_KEY=111
REMOVE_KEY=112
PUSH=113
POP=114
CLEAR=115
HAS=116
GET=117
CONCAT=118
INT=119
FLOAT=120
UPPER=121
LOWER=122
TRIM=123
SPLIT=124
JOIN=125
SUBSTRING=126
FIND=127
REPLACE=128
DILATE=129
ERODE=130
MORPH_OPEN=131
MORPH_CLOSE=132
RGB_TO_OKLAB=133
RGB_TO_CIELAB=134
OKLAB_TO_RGB=135
CIELAB_TO_RGB=136
RGB_TO_HSV=137
HSV_TO_RGB=138
INT_TO_RGB=139
RGB_TO_INT=140
INTERPOLATE_LINEAR=141
INTERPOLATE_AREA=142
INTERPOLATE_NEAREST=143
TEXT_IMAGE=144
AS_NESTED=145
SVD=146
DIAG=147
IF=148
ELSE=149
WHILE=150
FOR=151
IN=152
BREAK=153
CONTINUE=154
RETURN=155
TIMESTAMP=156
SORT=157
ARGSORT=158
ARGMIN=159
ARGMAX=160
SOFTMAX=161
SOFTMIN=162
UNIQUE=163
FLIP=164
STARTSWITH=165
ENDSWITH=166
SQUEEZE=167
UNSQUEEZE=168
ROLL=169
COV=170
CORR=171
ENTROPY=172
CROP=173
NONE=174
COORDS=175
NOISE=176
RAND=177
CAUCHY=178
EXPONENTIAL=179
LOGNORMAL=180
BERNOULLI=181
POISSON=182
GAMMADIST=183
BETADIST=184
LAPLACEDIST=185
GUMBELDIST=186
WEIBULLDIST=187
CHI2DIST=188
STUDENTTDIST=189
PERLIN=190
CELLULAR=191
PLASMA=192
RIDGED=193
DOMAIN_WARP=194
PLUS=195
MINUS=196
MULT=197
DIV=198
MOD=199
POW=200
LSHIFT=201
RSHIFT=202
GE=203
GT=204
LE=205
LT=206
EQ=207
EQUEALS=208
PLUS_EQ=209
MINUS_EQ=210
MULT_EQ=211
DIV_EQ=212
MOD_EQ=213
NE=214
PIPE=215
LPAREN=216
RPAREN=217
COMMA=218
SEMICOLON=219
ARROW=220
LBRACKET=221
RBRACKET=222
QUESTION=223
COLON=224
LBRACE=225
RBRACE=226
NUMBER=227
CONSTANT=228
STRING=229
VARIABLE=230
SL_COMMENT=231
ML_COMMENT=232
WS=233
'sin'=1
'cos'=2
'tan'=3
@@ -313,89 +315,90 @@ WS=231
'rife'=103
'shape'=106
'tensor'=110
'stack_push'=111
'stack_pop'=112
'stack_clear'=113
'stack_has'=114
'stack_get'=115
'int'=117
'float'=118
'upper'=119
'lower'=120
'trim'=121
'split'=122
'join'=123
'find'=125
'replace'=126
'dilate'=127
'erode'=128
'morph_open'=129
'morph_close'=130
'rgb_to_oklab'=131
'rgb_to_cielab'=132
'oklab_to_rgb'=133
'cielab_to_rgb'=134
'rgb_to_hsv'=135
'hsv_to_rgb'=136
'int_to_rgb'=137
'rgb_to_int'=138
'interpolate_linear'=139
'interpolate_area'=140
'text_image'=142
'as_nested_tensor'=143
'if'=146
'else'=147
'while'=148
'for'=149
'in'=150
'break'=151
'continue'=152
'return'=153
'sort'=155
'argsort'=156
'argmin'=157
'argmax'=158
'softmax'=159
'softmin'=160
'unique'=161
'flip'=162
'startswith'=163
'endswith'=164
'squeeze'=165
'unsqueeze'=166
'roll'=167
'cov'=168
'entropy'=170
'crop'=171
'+'=193
'-'=194
'*'=195
'/'=196
'%'=197
'^'=198
'<<'=199
'>>'=200
'>='=201
'>'=202
'<='=203
'<'=204
'=='=205
'='=206
'+='=207
'-='=208
'*='=209
'/='=210
'%='=211
'!='=212
'|'=213
'('=214
')'=215
','=216
';'=217
'->'=218
'['=219
']'=220
'?'=221
':'=222
'{'=223
'}'=224
'add_key'=111
'stack_push'=113
'stack_pop'=114
'stack_clear'=115
'stack_has'=116
'stack_get'=117
'int'=119
'float'=120
'upper'=121
'lower'=122
'trim'=123
'split'=124
'join'=125
'find'=127
'replace'=128
'dilate'=129
'erode'=130
'morph_open'=131
'morph_close'=132
'rgb_to_oklab'=133
'rgb_to_cielab'=134
'oklab_to_rgb'=135
'cielab_to_rgb'=136
'rgb_to_hsv'=137
'hsv_to_rgb'=138
'int_to_rgb'=139
'rgb_to_int'=140
'interpolate_linear'=141
'interpolate_area'=142
'text_image'=144
'as_nested_tensor'=145
'if'=148
'else'=149
'while'=150
'for'=151
'in'=152
'break'=153
'continue'=154
'return'=155
'sort'=157
'argsort'=158
'argmin'=159
'argmax'=160
'softmax'=161
'softmin'=162
'unique'=163
'flip'=164
'startswith'=165
'endswith'=166
'squeeze'=167
'unsqueeze'=168
'roll'=169
'cov'=170
'entropy'=172
'crop'=173
'+'=195
'-'=196
'*'=197
'/'=198
'%'=199
'^'=200
'<<'=201
'>>'=202
'>='=203
'>'=204
'<='=205
'<'=206
'=='=207
'='=208
'+='=209
'-='=210
'*='=211
'/='=212
'%='=213
'!='=214
'|'=215
'('=216
')'=217
','=218
';'=219
'->'=220
'['=221
']'=222
'?'=223
':'=224
'{'=225
'}'=226
@@ -161,6 +161,24 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#dictEntryList.
def enterDictEntryList(self, ctx:MathExprParser.DictEntryListContext):
pass
# Exit a parse tree produced by MathExprParser#dictEntryList.
def exitDictEntryList(self, ctx:MathExprParser.DictEntryListContext):
pass
# Enter a parse tree produced by MathExprParser#dictEntry.
def enterDictEntry(self, ctx:MathExprParser.DictEntryContext):
pass
# Exit a parse tree produced by MathExprParser#dictEntry.
def exitDictEntry(self, ctx:MathExprParser.DictEntryContext):
pass
# Enter a parse tree produced by MathExprParser#breakStmt.
def enterBreakStmt(self, ctx:MathExprParser.BreakStmtContext):
pass
@@ -647,6 +665,15 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#DictExp.
def enterDictExp(self, ctx:MathExprParser.DictExpContext):
pass
# Exit a parse tree produced by MathExprParser#DictExp.
def exitDictExp(self, ctx:MathExprParser.DictExpContext):
pass
# Enter a parse tree produced by MathExprParser#CallExp.
def enterCallExp(self, ctx:MathExprParser.CallExpContext):
pass
@@ -1583,6 +1610,15 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#AddKeyFunc.
def enterAddKeyFunc(self, ctx:MathExprParser.AddKeyFuncContext):
pass
# Exit a parse tree produced by MathExprParser#AddKeyFunc.
def exitAddKeyFunc(self, ctx:MathExprParser.AddKeyFuncContext):
pass
# Enter a parse tree produced by MathExprParser#PermuteFunc.
def enterPermuteFunc(self, ctx:MathExprParser.PermuteFuncContext):
pass
@@ -1817,6 +1853,15 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#RemoveKeyFunc.
def enterRemoveKeyFunc(self, ctx:MathExprParser.RemoveKeyFuncContext):
pass
# Exit a parse tree produced by MathExprParser#RemoveKeyFunc.
def exitRemoveKeyFunc(self, ctx:MathExprParser.RemoveKeyFuncContext):
pass
# Enter a parse tree produced by MathExprParser#ClampFunc.
def enterClampFunc(self, ctx:MathExprParser.ClampFuncContext):
pass
File diff suppressed because it is too large Load Diff
@@ -94,6 +94,16 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#dictEntryList.
def visitDictEntryList(self, ctx:MathExprParser.DictEntryListContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#dictEntry.
def visitDictEntry(self, ctx:MathExprParser.DictEntryContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#breakStmt.
def visitBreakStmt(self, ctx:MathExprParser.BreakStmtContext):
return self.visitChildren(ctx)
@@ -364,6 +374,11 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#DictExp.
def visitDictExp(self, ctx:MathExprParser.DictExpContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#CallExp.
def visitCallExp(self, ctx:MathExprParser.CallExpContext):
return self.visitChildren(ctx)
@@ -884,6 +899,11 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#AddKeyFunc.
def visitAddKeyFunc(self, ctx:MathExprParser.AddKeyFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#PermuteFunc.
def visitPermuteFunc(self, ctx:MathExprParser.PermuteFuncContext):
return self.visitChildren(ctx)
@@ -1014,6 +1034,11 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#RemoveKeyFunc.
def visitRemoveKeyFunc(self, ctx:MathExprParser.RemoveKeyFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#ClampFunc.
def visitClampFunc(self, ctx:MathExprParser.ClampFuncContext):
return self.visitChildren(ctx)
+4 -1
View File
@@ -6,13 +6,14 @@ INBUILT_CONSTANTS = {
'e', 'pi'
}
INBUILT_FUNCTIONS = {
'abs', 'acos', 'acosh', 'all', 'angle', 'any', 'append', 'argmax', 'argmin', 'argsort', 'as_nested_tensor', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'band', 'batch_shuffle', 'bitcount', 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'blur', 'bnot', 'bor', 'botk', 'botk_ind', 'botk_indices', 'bxor', 'cat', 'ceil', 'cellular', 'cellular_noise', 'cielab_to_rgb', 'clamp', 'cnt', 'concat', 'concatenate', 'conv', 'convolution', 'coordinates', 'coords', 'corr', 'correlation', 'cos', 'cosh', 'cosine_similarity', 'cossim', 'count', 'cov', 'crop', 'cross', 'cubic', 'cubic_ease', 'cumprod', 'cumsum', 'diag', 'diagonal_matrix', 'dilate', 'dist', 'distance', 'domain_warp', 'domain_warp_noise', 'dot', 'edge', 'elastic', 'elastic_ease', 'endswith', 'entropy', 'erf', 'erfinv', 'erode', 'exp', 'ezconv', 'ezconvolution', 'fft', 'find', 'flatten', 'flip', 'float', 'floor', 'flow_ang', 'flow_angle', 'flow_apply', 'flow_mag', 'flow_magnitude', 'flow_to_image', 'fract', 'gamma', 'gaussian', 'gelu', 'get_value', 'hist', 'histogram', 'hsv_to_rgb', 'ifft', 'int', 'int_to_rgb', 'interpolate_area', 'interpolate_linear', 'interpolate_nearest', 'interpolate_nearest_exact', 'join', 'length', 'lerp', 'linspace', 'ln', 'log', 'logspace', 'lower', 'map', 'matmul', 'mean', 'median', 'mode', 'moment', 'morph_close', 'morph_open', 'motion_mask', 'nan_to_num', 'noise', 'now', 'nvl', 'oklab_to_rgb', 'overlay', 'pad', 'percentile', 'perlin', 'perlin_noise', 'perm', 'permute', 'pinv', 'plasma', 'plasma_noise', 'popcnt', 'popcount', 'pow', 'prcnt', 'print', 'print_shape', 'pshp', 'quantile', 'quartil', 'quartile', 'rand', 'randb', 'randbeta', 'randc', 'rande', 'randg', 'randgumbel', 'randchi2', 'randl', 'randln', 'randn', 'random_bernoulli', 'random_beta', 'random_cauchy', 'random_exponential', 'random_gamma', 'random_gumbel', 'random_chi2', 'random_laplace', 'random_log_normal', 'random_normal', 'random_poisson', 'random_studentt', 'random_uniform', 'random_weibull', 'randp', 'randt', 'randu', 'randw', 'range', 'relu', 'remap', 'repeat', 'replace', 'reshape', 'rgb_to_cielab', 'rgb_to_hsv', 'rgb_to_int', 'rgb_to_oklab', 'ridged', 'ridged_noise', 'rife', 'roll', 'round', 'rshp', 'select', 'shape', 'shuffle', 'sigm', 'sign', 'sin', 'sine', 'sine_ease', 'singular_value_decomposition', 'sinh', 'smax', 'smin', 'smootherstep', 'smoothstep', 'snorm', 'softmax', 'softmin', 'softplus', 'sort', 'split', 'sqrt', 'squeeze', 'stack_clear', 'stack_get', 'stack_has', 'stack_pop', 'stack_push', 'startswith', 'std', 'step', 'substr', 'substring', 'sum', 'svd', 'swap', 'tan', 'tanh', 'tensor', 'text_image', 'timestamp', 'tmax', 'tmin', 'tnorm', 'topk', 'topk_ind', 'topk_indices', 'trim', 'turbulence', 'unique', 'unsqueeze', 'upper', 'var', 'voronoi', 'voronoi_noise', 'where', 'worley'
'abs', 'acos', 'acosh', 'add_key', 'all', 'angle', 'any', 'append', 'argmax', 'argmin', 'argsort', 'as_nested_tensor', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'band', 'batch_shuffle', 'bitcount', 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'blur', 'bnot', 'bor', 'botk', 'botk_ind', 'botk_indices', 'bxor', 'cat', 'ceil', 'cellular', 'cellular_noise', 'cielab_to_rgb', 'clamp', 'cnt', 'concat', 'concatenate', 'conv', 'convolution', 'coordinates', 'coords', 'corr', 'correlation', 'cos', 'cosh', 'cosine_similarity', 'cossim', 'count', 'cov', 'crop', 'cross', 'cubic', 'cubic_ease', 'cumprod', 'cumsum', 'diag', 'diagonal_matrix', 'dilate', 'dist', 'distance', 'domain_warp', 'domain_warp_noise', 'dot', 'edge', 'elastic', 'elastic_ease', 'endswith', 'entropy', 'erf', 'erfinv', 'erode', 'exp', 'ezconv', 'ezconvolution', 'fft', 'find', 'flatten', 'flip', 'float', 'floor', 'flow_ang', 'flow_angle', 'flow_apply', 'flow_mag', 'flow_magnitude', 'flow_to_image', 'fract', 'gamma', 'gaussian', 'gelu', 'get_value', 'hist', 'histogram', 'hsv_to_rgb', 'ifft', 'int', 'int_to_rgb', 'interpolate_area', 'interpolate_linear', 'interpolate_nearest', 'interpolate_nearest_exact', 'join', 'length', 'lerp', 'linspace', 'ln', 'log', 'logspace', 'lower', 'map', 'matmul', 'mean', 'median', 'mode', 'moment', 'morph_close', 'morph_open', 'motion_mask', 'nan_to_num', 'noise', 'now', 'nvl', 'oklab_to_rgb', 'overlay', 'pad', 'percentile', 'perlin', 'perlin_noise', 'perm', 'permute', 'pinv', 'plasma', 'plasma_noise', 'popcnt', 'popcount', 'pow', 'prcnt', 'print', 'print_shape', 'pshp', 'quantile', 'quartil', 'quartile', 'rand', 'randb', 'randbeta', 'randc', 'rande', 'randg', 'randgumbel', 'randchi2', 'randl', 'randln', 'randn', 'random_bernoulli', 'random_beta', 'random_cauchy', 'random_exponential', 'random_gamma', 'random_gumbel', 'random_chi2', 'random_laplace', 'random_log_normal', 'random_normal', 'random_poisson', 'random_studentt', 'random_uniform', 'random_weibull', 'randp', 'randt', 'randu', 'randw', 'range', 'relu', 'remap', 'remove_kay', 'remove_key', 'repeat', 'replace', 'reshape', 'rgb_to_cielab', 'rgb_to_hsv', 'rgb_to_int', 'rgb_to_oklab', 'ridged', 'ridged_noise', 'rife', 'roll', 'round', 'rshp', 'select', 'shape', 'shuffle', 'sigm', 'sign', 'sin', 'sine', 'sine_ease', 'singular_value_decomposition', 'sinh', 'smax', 'smin', 'smootherstep', 'smoothstep', 'snorm', 'softmax', 'softmin', 'softplus', 'sort', 'split', 'sqrt', 'squeeze', 'stack_clear', 'stack_get', 'stack_has', 'stack_pop', 'stack_push', 'startswith', 'std', 'step', 'substr', 'substring', 'sum', 'svd', 'swap', 'tan', 'tanh', 'tensor', 'text_image', 'timestamp', 'tmax', 'tmin', 'tnorm', 'topk', 'topk_ind', 'topk_indices', 'trim', 'turbulence', 'unique', 'unsqueeze', 'upper', 'var', 'voronoi', 'voronoi_noise', 'where', 'worley'
}
INBUILT_FUNCTION_META = {
'abs': {'min_args': 1, 'max_args': 1, 'snippet': 'abs()', 'description': 'abs(x) - applies per element absolute value function. Same as |x| for numbers.'},
'acos': {'min_args': 1, 'max_args': 1, 'snippet': 'acos()', 'description': 'acos(x) - applies arcus cosinus function to value or each element of value'},
'acosh': {'min_args': 1, 'max_args': 1, 'snippet': 'acosh()', 'description': 'acosh(x) - applies hyperbolic arcus cosinus function to value or each element of value'},
'add_key': {'min_args': 3, 'max_args': 3, 'snippet': 'add_key()', 'description': 'add_key(dict, key, value) - adds or replaces a dictionary entry and returns the updated dictionary'},
'all': {'min_args': 1, 'max_args': 1, 'snippet': 'all()', 'description': 'all(x) - returns 1 if all elements of x are non-zero otherwise 0'},
'angle': {'min_args': 1, 'max_args': 1, 'snippet': 'angle()', 'description': 'angle(x) - returns the angle of a complex number or vector'},
'any': {'min_args': 1, 'max_args': 1, 'snippet': 'any()', 'description': 'any(x) - returns 1 if any element of x is non-zero otherwise 0'},
@@ -187,6 +188,8 @@ INBUILT_FUNCTION_META = {
'range': {'min_args': 3, 'max_args': 3, 'snippet': 'range()', 'description': 'range(start, stop, step) - creates a range of values between start (inclusive) and stop (exclusive) using step. Use linspace if you want value count.'},
'relu': {'min_args': 1, 'max_args': 1, 'snippet': 'relu()', 'description': 'relu(x) - applies rectified linear unit function: max(0, x)'},
'remap': {'min_args': 5, 'max_args': 5, 'snippet': 'remap()', 'description': 'remap(v, i_min, i_max, o_min, o_max) - remaps values from input range to output range'},
'remove_kay': {'min_args': 2, 'max_args': 2, 'snippet': 'remove_kay()', 'description': 'remove_key(dict, key) - removes a dictionary entry and returns the updated dictionary'},
'remove_key': {'min_args': 2, 'max_args': 2, 'snippet': 'remove_key()', 'description': 'remove_key(dict, key) - removes a dictionary entry and returns the updated dictionary'},
'repeat': {'min_args': 2, 'max_args': 3, 'snippet': 'repeat()', 'description': 'repeat(x, count, [dims]) - repeats tensor elements; count may be scalar or per-dim list'},
'replace': {'min_args': 3, 'max_args': 3, 'snippet': 'replace()', 'description': 'replace(s, old, new) - replaces occurrences of old with new in s. Mostly for strings but can work with lists and tensors.'},
'reshape': {'min_args': 2, 'max_args': 2, 'snippet': 'reshape()', 'description': 'reshape(x, shape) - reshapes tensor x to the specified shape'},
File diff suppressed because one or more lines are too long
+210 -207
View File
@@ -108,127 +108,129 @@ BAND=107
XOR=108
BOR=109
TENSOR=110
PUSH=111
POP=112
CLEAR=113
HAS=114
GET=115
CONCAT=116
INT=117
FLOAT=118
UPPER=119
LOWER=120
TRIM=121
SPLIT=122
JOIN=123
SUBSTRING=124
FIND=125
REPLACE=126
DILATE=127
ERODE=128
MORPH_OPEN=129
MORPH_CLOSE=130
RGB_TO_OKLAB=131
RGB_TO_CIELAB=132
OKLAB_TO_RGB=133
CIELAB_TO_RGB=134
RGB_TO_HSV=135
HSV_TO_RGB=136
INT_TO_RGB=137
RGB_TO_INT=138
INTERPOLATE_LINEAR=139
INTERPOLATE_AREA=140
INTERPOLATE_NEAREST=141
TEXT_IMAGE=142
AS_NESTED=143
SVD=144
DIAG=145
IF=146
ELSE=147
WHILE=148
FOR=149
IN=150
BREAK=151
CONTINUE=152
RETURN=153
TIMESTAMP=154
SORT=155
ARGSORT=156
ARGMIN=157
ARGMAX=158
SOFTMAX=159
SOFTMIN=160
UNIQUE=161
FLIP=162
STARTSWITH=163
ENDSWITH=164
SQUEEZE=165
UNSQUEEZE=166
ROLL=167
COV=168
CORR=169
ENTROPY=170
CROP=171
NONE=172
COORDS=173
NOISE=174
RAND=175
CAUCHY=176
EXPONENTIAL=177
LOGNORMAL=178
BERNOULLI=179
POISSON=180
GAMMADIST=181
BETADIST=182
LAPLACEDIST=183
GUMBELDIST=184
WEIBULLDIST=185
CHI2DIST=186
STUDENTTDIST=187
PERLIN=188
CELLULAR=189
PLASMA=190
RIDGED=191
DOMAIN_WARP=192
PLUS=193
MINUS=194
MULT=195
DIV=196
MOD=197
POW=198
LSHIFT=199
RSHIFT=200
GE=201
GT=202
LE=203
LT=204
EQ=205
EQUEALS=206
PLUS_EQ=207
MINUS_EQ=208
MULT_EQ=209
DIV_EQ=210
MOD_EQ=211
NE=212
PIPE=213
LPAREN=214
RPAREN=215
COMMA=216
SEMICOLON=217
ARROW=218
LBRACKET=219
RBRACKET=220
QUESTION=221
COLON=222
LBRACE=223
RBRACE=224
NUMBER=225
CONSTANT=226
STRING=227
VARIABLE=228
SL_COMMENT=229
ML_COMMENT=230
WS=231
ADD_KEY=111
REMOVE_KEY=112
PUSH=113
POP=114
CLEAR=115
HAS=116
GET=117
CONCAT=118
INT=119
FLOAT=120
UPPER=121
LOWER=122
TRIM=123
SPLIT=124
JOIN=125
SUBSTRING=126
FIND=127
REPLACE=128
DILATE=129
ERODE=130
MORPH_OPEN=131
MORPH_CLOSE=132
RGB_TO_OKLAB=133
RGB_TO_CIELAB=134
OKLAB_TO_RGB=135
CIELAB_TO_RGB=136
RGB_TO_HSV=137
HSV_TO_RGB=138
INT_TO_RGB=139
RGB_TO_INT=140
INTERPOLATE_LINEAR=141
INTERPOLATE_AREA=142
INTERPOLATE_NEAREST=143
TEXT_IMAGE=144
AS_NESTED=145
SVD=146
DIAG=147
IF=148
ELSE=149
WHILE=150
FOR=151
IN=152
BREAK=153
CONTINUE=154
RETURN=155
TIMESTAMP=156
SORT=157
ARGSORT=158
ARGMIN=159
ARGMAX=160
SOFTMAX=161
SOFTMIN=162
UNIQUE=163
FLIP=164
STARTSWITH=165
ENDSWITH=166
SQUEEZE=167
UNSQUEEZE=168
ROLL=169
COV=170
CORR=171
ENTROPY=172
CROP=173
NONE=174
COORDS=175
NOISE=176
RAND=177
CAUCHY=178
EXPONENTIAL=179
LOGNORMAL=180
BERNOULLI=181
POISSON=182
GAMMADIST=183
BETADIST=184
LAPLACEDIST=185
GUMBELDIST=186
WEIBULLDIST=187
CHI2DIST=188
STUDENTTDIST=189
PERLIN=190
CELLULAR=191
PLASMA=192
RIDGED=193
DOMAIN_WARP=194
PLUS=195
MINUS=196
MULT=197
DIV=198
MOD=199
POW=200
LSHIFT=201
RSHIFT=202
GE=203
GT=204
LE=205
LT=206
EQ=207
EQUEALS=208
PLUS_EQ=209
MINUS_EQ=210
MULT_EQ=211
DIV_EQ=212
MOD_EQ=213
NE=214
PIPE=215
LPAREN=216
RPAREN=217
COMMA=218
SEMICOLON=219
ARROW=220
LBRACKET=221
RBRACKET=222
QUESTION=223
COLON=224
LBRACE=225
RBRACE=226
NUMBER=227
CONSTANT=228
STRING=229
VARIABLE=230
SL_COMMENT=231
ML_COMMENT=232
WS=233
'sin'=1
'cos'=2
'tan'=3
@@ -313,89 +315,90 @@ WS=231
'rife'=103
'shape'=106
'tensor'=110
'stack_push'=111
'stack_pop'=112
'stack_clear'=113
'stack_has'=114
'stack_get'=115
'int'=117
'float'=118
'upper'=119
'lower'=120
'trim'=121
'split'=122
'join'=123
'find'=125
'replace'=126
'dilate'=127
'erode'=128
'morph_open'=129
'morph_close'=130
'rgb_to_oklab'=131
'rgb_to_cielab'=132
'oklab_to_rgb'=133
'cielab_to_rgb'=134
'rgb_to_hsv'=135
'hsv_to_rgb'=136
'int_to_rgb'=137
'rgb_to_int'=138
'interpolate_linear'=139
'interpolate_area'=140
'text_image'=142
'as_nested_tensor'=143
'if'=146
'else'=147
'while'=148
'for'=149
'in'=150
'break'=151
'continue'=152
'return'=153
'sort'=155
'argsort'=156
'argmin'=157
'argmax'=158
'softmax'=159
'softmin'=160
'unique'=161
'flip'=162
'startswith'=163
'endswith'=164
'squeeze'=165
'unsqueeze'=166
'roll'=167
'cov'=168
'entropy'=170
'crop'=171
'+'=193
'-'=194
'*'=195
'/'=196
'%'=197
'^'=198
'<<'=199
'>>'=200
'>='=201
'>'=202
'<='=203
'<'=204
'=='=205
'='=206
'+='=207
'-='=208
'*='=209
'/='=210
'%='=211
'!='=212
'|'=213
'('=214
')'=215
','=216
';'=217
'->'=218
'['=219
']'=220
'?'=221
':'=222
'{'=223
'}'=224
'add_key'=111
'stack_push'=113
'stack_pop'=114
'stack_clear'=115
'stack_has'=116
'stack_get'=117
'int'=119
'float'=120
'upper'=121
'lower'=122
'trim'=123
'split'=124
'join'=125
'find'=127
'replace'=128
'dilate'=129
'erode'=130
'morph_open'=131
'morph_close'=132
'rgb_to_oklab'=133
'rgb_to_cielab'=134
'oklab_to_rgb'=135
'cielab_to_rgb'=136
'rgb_to_hsv'=137
'hsv_to_rgb'=138
'int_to_rgb'=139
'rgb_to_int'=140
'interpolate_linear'=141
'interpolate_area'=142
'text_image'=144
'as_nested_tensor'=145
'if'=148
'else'=149
'while'=150
'for'=151
'in'=152
'break'=153
'continue'=154
'return'=155
'sort'=157
'argsort'=158
'argmin'=159
'argmax'=160
'softmax'=161
'softmin'=162
'unique'=163
'flip'=164
'startswith'=165
'endswith'=166
'squeeze'=167
'unsqueeze'=168
'roll'=169
'cov'=170
'entropy'=172
'crop'=173
'+'=195
'-'=196
'*'=197
'/'=198
'%'=199
'^'=200
'<<'=201
'>>'=202
'>='=203
'>'=204
'<='=205
'<'=206
'=='=207
'='=208
'+='=209
'-='=210
'*='=211
'/='=212
'%='=213
'!='=214
'|'=215
'('=216
')'=217
','=218
';'=219
'->'=220
'['=221
']'=222
'?'=223
':'=224
'{'=225
'}'=226
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+210 -207
View File
@@ -108,127 +108,129 @@ BAND=107
XOR=108
BOR=109
TENSOR=110
PUSH=111
POP=112
CLEAR=113
HAS=114
GET=115
CONCAT=116
INT=117
FLOAT=118
UPPER=119
LOWER=120
TRIM=121
SPLIT=122
JOIN=123
SUBSTRING=124
FIND=125
REPLACE=126
DILATE=127
ERODE=128
MORPH_OPEN=129
MORPH_CLOSE=130
RGB_TO_OKLAB=131
RGB_TO_CIELAB=132
OKLAB_TO_RGB=133
CIELAB_TO_RGB=134
RGB_TO_HSV=135
HSV_TO_RGB=136
INT_TO_RGB=137
RGB_TO_INT=138
INTERPOLATE_LINEAR=139
INTERPOLATE_AREA=140
INTERPOLATE_NEAREST=141
TEXT_IMAGE=142
AS_NESTED=143
SVD=144
DIAG=145
IF=146
ELSE=147
WHILE=148
FOR=149
IN=150
BREAK=151
CONTINUE=152
RETURN=153
TIMESTAMP=154
SORT=155
ARGSORT=156
ARGMIN=157
ARGMAX=158
SOFTMAX=159
SOFTMIN=160
UNIQUE=161
FLIP=162
STARTSWITH=163
ENDSWITH=164
SQUEEZE=165
UNSQUEEZE=166
ROLL=167
COV=168
CORR=169
ENTROPY=170
CROP=171
NONE=172
COORDS=173
NOISE=174
RAND=175
CAUCHY=176
EXPONENTIAL=177
LOGNORMAL=178
BERNOULLI=179
POISSON=180
GAMMADIST=181
BETADIST=182
LAPLACEDIST=183
GUMBELDIST=184
WEIBULLDIST=185
CHI2DIST=186
STUDENTTDIST=187
PERLIN=188
CELLULAR=189
PLASMA=190
RIDGED=191
DOMAIN_WARP=192
PLUS=193
MINUS=194
MULT=195
DIV=196
MOD=197
POW=198
LSHIFT=199
RSHIFT=200
GE=201
GT=202
LE=203
LT=204
EQ=205
EQUEALS=206
PLUS_EQ=207
MINUS_EQ=208
MULT_EQ=209
DIV_EQ=210
MOD_EQ=211
NE=212
PIPE=213
LPAREN=214
RPAREN=215
COMMA=216
SEMICOLON=217
ARROW=218
LBRACKET=219
RBRACKET=220
QUESTION=221
COLON=222
LBRACE=223
RBRACE=224
NUMBER=225
CONSTANT=226
STRING=227
VARIABLE=228
SL_COMMENT=229
ML_COMMENT=230
WS=231
ADD_KEY=111
REMOVE_KEY=112
PUSH=113
POP=114
CLEAR=115
HAS=116
GET=117
CONCAT=118
INT=119
FLOAT=120
UPPER=121
LOWER=122
TRIM=123
SPLIT=124
JOIN=125
SUBSTRING=126
FIND=127
REPLACE=128
DILATE=129
ERODE=130
MORPH_OPEN=131
MORPH_CLOSE=132
RGB_TO_OKLAB=133
RGB_TO_CIELAB=134
OKLAB_TO_RGB=135
CIELAB_TO_RGB=136
RGB_TO_HSV=137
HSV_TO_RGB=138
INT_TO_RGB=139
RGB_TO_INT=140
INTERPOLATE_LINEAR=141
INTERPOLATE_AREA=142
INTERPOLATE_NEAREST=143
TEXT_IMAGE=144
AS_NESTED=145
SVD=146
DIAG=147
IF=148
ELSE=149
WHILE=150
FOR=151
IN=152
BREAK=153
CONTINUE=154
RETURN=155
TIMESTAMP=156
SORT=157
ARGSORT=158
ARGMIN=159
ARGMAX=160
SOFTMAX=161
SOFTMIN=162
UNIQUE=163
FLIP=164
STARTSWITH=165
ENDSWITH=166
SQUEEZE=167
UNSQUEEZE=168
ROLL=169
COV=170
CORR=171
ENTROPY=172
CROP=173
NONE=174
COORDS=175
NOISE=176
RAND=177
CAUCHY=178
EXPONENTIAL=179
LOGNORMAL=180
BERNOULLI=181
POISSON=182
GAMMADIST=183
BETADIST=184
LAPLACEDIST=185
GUMBELDIST=186
WEIBULLDIST=187
CHI2DIST=188
STUDENTTDIST=189
PERLIN=190
CELLULAR=191
PLASMA=192
RIDGED=193
DOMAIN_WARP=194
PLUS=195
MINUS=196
MULT=197
DIV=198
MOD=199
POW=200
LSHIFT=201
RSHIFT=202
GE=203
GT=204
LE=205
LT=206
EQ=207
EQUEALS=208
PLUS_EQ=209
MINUS_EQ=210
MULT_EQ=211
DIV_EQ=212
MOD_EQ=213
NE=214
PIPE=215
LPAREN=216
RPAREN=217
COMMA=218
SEMICOLON=219
ARROW=220
LBRACKET=221
RBRACKET=222
QUESTION=223
COLON=224
LBRACE=225
RBRACE=226
NUMBER=227
CONSTANT=228
STRING=229
VARIABLE=230
SL_COMMENT=231
ML_COMMENT=232
WS=233
'sin'=1
'cos'=2
'tan'=3
@@ -313,89 +315,90 @@ WS=231
'rife'=103
'shape'=106
'tensor'=110
'stack_push'=111
'stack_pop'=112
'stack_clear'=113
'stack_has'=114
'stack_get'=115
'int'=117
'float'=118
'upper'=119
'lower'=120
'trim'=121
'split'=122
'join'=123
'find'=125
'replace'=126
'dilate'=127
'erode'=128
'morph_open'=129
'morph_close'=130
'rgb_to_oklab'=131
'rgb_to_cielab'=132
'oklab_to_rgb'=133
'cielab_to_rgb'=134
'rgb_to_hsv'=135
'hsv_to_rgb'=136
'int_to_rgb'=137
'rgb_to_int'=138
'interpolate_linear'=139
'interpolate_area'=140
'text_image'=142
'as_nested_tensor'=143
'if'=146
'else'=147
'while'=148
'for'=149
'in'=150
'break'=151
'continue'=152
'return'=153
'sort'=155
'argsort'=156
'argmin'=157
'argmax'=158
'softmax'=159
'softmin'=160
'unique'=161
'flip'=162
'startswith'=163
'endswith'=164
'squeeze'=165
'unsqueeze'=166
'roll'=167
'cov'=168
'entropy'=170
'crop'=171
'+'=193
'-'=194
'*'=195
'/'=196
'%'=197
'^'=198
'<<'=199
'>>'=200
'>='=201
'>'=202
'<='=203
'<'=204
'=='=205
'='=206
'+='=207
'-='=208
'*='=209
'/='=210
'%='=211
'!='=212
'|'=213
'('=214
')'=215
','=216
';'=217
'->'=218
'['=219
']'=220
'?'=221
':'=222
'{'=223
'}'=224
'add_key'=111
'stack_push'=113
'stack_pop'=114
'stack_clear'=115
'stack_has'=116
'stack_get'=117
'int'=119
'float'=120
'upper'=121
'lower'=122
'trim'=123
'split'=124
'join'=125
'find'=127
'replace'=128
'dilate'=129
'erode'=130
'morph_open'=131
'morph_close'=132
'rgb_to_oklab'=133
'rgb_to_cielab'=134
'oklab_to_rgb'=135
'cielab_to_rgb'=136
'rgb_to_hsv'=137
'hsv_to_rgb'=138
'int_to_rgb'=139
'rgb_to_int'=140
'interpolate_linear'=141
'interpolate_area'=142
'text_image'=144
'as_nested_tensor'=145
'if'=148
'else'=149
'while'=150
'for'=151
'in'=152
'break'=153
'continue'=154
'return'=155
'sort'=157
'argsort'=158
'argmin'=159
'argmax'=160
'softmax'=161
'softmin'=162
'unique'=163
'flip'=164
'startswith'=165
'endswith'=166
'squeeze'=167
'unsqueeze'=168
'roll'=169
'cov'=170
'entropy'=172
'crop'=173
'+'=195
'-'=196
'*'=197
'/'=198
'%'=199
'^'=200
'<<'=201
'>>'=202
'>='=203
'>'=204
'<='=205
'<'=206
'=='=207
'='=208
'+='=209
'-='=210
'*='=211
'/='=212
'%='=213
'!='=214
'|'=215
'('=216
')'=217
','=218
';'=219
'->'=220
'['=221
']'=222
'?'=223
':'=224
'{'=225
'}'=226
@@ -161,6 +161,24 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#dictEntryList.
def enterDictEntryList(self, ctx:MathExprParser.DictEntryListContext):
pass
# Exit a parse tree produced by MathExprParser#dictEntryList.
def exitDictEntryList(self, ctx:MathExprParser.DictEntryListContext):
pass
# Enter a parse tree produced by MathExprParser#dictEntry.
def enterDictEntry(self, ctx:MathExprParser.DictEntryContext):
pass
# Exit a parse tree produced by MathExprParser#dictEntry.
def exitDictEntry(self, ctx:MathExprParser.DictEntryContext):
pass
# Enter a parse tree produced by MathExprParser#breakStmt.
def enterBreakStmt(self, ctx:MathExprParser.BreakStmtContext):
pass
@@ -647,6 +665,15 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#DictExp.
def enterDictExp(self, ctx:MathExprParser.DictExpContext):
pass
# Exit a parse tree produced by MathExprParser#DictExp.
def exitDictExp(self, ctx:MathExprParser.DictExpContext):
pass
# Enter a parse tree produced by MathExprParser#CallExp.
def enterCallExp(self, ctx:MathExprParser.CallExpContext):
pass
@@ -1583,6 +1610,15 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#AddKeyFunc.
def enterAddKeyFunc(self, ctx:MathExprParser.AddKeyFuncContext):
pass
# Exit a parse tree produced by MathExprParser#AddKeyFunc.
def exitAddKeyFunc(self, ctx:MathExprParser.AddKeyFuncContext):
pass
# Enter a parse tree produced by MathExprParser#PermuteFunc.
def enterPermuteFunc(self, ctx:MathExprParser.PermuteFuncContext):
pass
@@ -1817,6 +1853,15 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#RemoveKeyFunc.
def enterRemoveKeyFunc(self, ctx:MathExprParser.RemoveKeyFuncContext):
pass
# Exit a parse tree produced by MathExprParser#RemoveKeyFunc.
def exitRemoveKeyFunc(self, ctx:MathExprParser.RemoveKeyFuncContext):
pass
# Enter a parse tree produced by MathExprParser#ClampFunc.
def enterClampFunc(self, ctx:MathExprParser.ClampFuncContext):
pass
File diff suppressed because one or more lines are too long
@@ -94,6 +94,16 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#dictEntryList.
def visitDictEntryList(self, ctx:MathExprParser.DictEntryListContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#dictEntry.
def visitDictEntry(self, ctx:MathExprParser.DictEntryContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#breakStmt.
def visitBreakStmt(self, ctx:MathExprParser.BreakStmtContext):
return self.visitChildren(ctx)
@@ -364,6 +374,11 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#DictExp.
def visitDictExp(self, ctx:MathExprParser.DictExpContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#CallExp.
def visitCallExp(self, ctx:MathExprParser.CallExpContext):
return self.visitChildren(ctx)
@@ -884,6 +899,11 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#AddKeyFunc.
def visitAddKeyFunc(self, ctx:MathExprParser.AddKeyFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#PermuteFunc.
def visitPermuteFunc(self, ctx:MathExprParser.PermuteFuncContext):
return self.visitChildren(ctx)
@@ -1014,6 +1034,11 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#RemoveKeyFunc.
def visitRemoveKeyFunc(self, ctx:MathExprParser.RemoveKeyFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#ClampFunc.
def visitClampFunc(self, ctx:MathExprParser.ClampFuncContext):
return self.visitChildren(ctx)
+40
View File
@@ -667,6 +667,46 @@ def test_text_replace():
assert result == "hello python"
def test_dict_literal_and_stringification():
from more_math.Parser.UnifiedMathVisitor import UnifiedMathVisitor
from more_math.helper_functions import parse_expr
expr = '{a:1, b:"two", nested:{c:3}}'
tree = parse_expr(expr)
visitor = UnifiedMathVisitor({}, (1,))
result = visitor.visit(tree)
assert result["a"] == 1.0
assert result["b"] == "two"
assert result["nested"]["c"] == 3.0
assert str(result) == "{a:1.0, b:two, nested:{c:3.0}}"
def test_dict_index_assignment_and_get():
from more_math.Parser.UnifiedMathVisitor import UnifiedMathVisitor, MathDict
from more_math.helper_functions import parse_expr
expr = 'd["b"] = 2; d["b"]'
tree = parse_expr(expr)
visitor = UnifiedMathVisitor({"d": MathDict({"a": 1.0})}, (1,))
result = visitor.visit(tree)
assert result == 2.0
assert visitor.variables["d"]["b"] == 2.0
def test_dict_add_remove_key_helpers():
from more_math.Parser.UnifiedMathVisitor import UnifiedMathVisitor, MathDict
from more_math.helper_functions import parse_expr
expr = 'add_key(d, "b", 2); remove_kay(d, "a"); d'
tree = parse_expr(expr)
visitor = UnifiedMathVisitor({"d": MathDict({"a": 1.0})}, (1,))
result = visitor.visit(tree)
assert result == {"b": 2.0} or str(result) == "{b:2.0}"
# ==========================================
# Crop Function Tests
# ==========================================
+4 -1
View File
@@ -9,13 +9,14 @@ export const CONSTANTS = new Set([
]);
export const FUNCTIONS = new Set([
"abs", "acos", "acosh", "all", "angle", "any", "append", "argmax", "argmin", "argsort", "as_nested_tensor", "asin", "asinh", "atan", "atan2", "atanh", "band", "batch_shuffle", "bitcount", "bitwise_and", "bitwise_not", "bitwise_or", "bitwise_xor", "blur", "bnot", "bor", "botk", "botk_ind", "botk_indices", "bxor", "cat", "ceil", "cellular", "cellular_noise", "cielab_to_rgb", "clamp", "cnt", "concat", "concatenate", "conv", "convolution", "coordinates", "coords", "corr", "correlation", "cos", "cosh", "cosine_similarity", "cossim", "count", "cov", "crop", "cross", "cubic", "cubic_ease", "cumprod", "cumsum", "diag", "diagonal_matrix", "dilate", "dist", "distance", "domain_warp", "domain_warp_noise", "dot", "edge", "elastic", "elastic_ease", "endswith", "entropy", "erf", "erfinv", "erode", "exp", "ezconv", "ezconvolution", "fft", "find", "flatten", "flip", "float", "floor", "flow_ang", "flow_angle", "flow_apply", "flow_mag", "flow_magnitude", "flow_to_image", "fract", "gamma", "gaussian", "gelu", "get_value", "hist", "histogram", "hsv_to_rgb", "ifft", "int", "int_to_rgb", "interpolate_area", "interpolate_linear", "interpolate_nearest", "interpolate_nearest_exact", "join", "length", "lerp", "linspace", "ln", "log", "logspace", "lower", "map", "matmul", "mean", "median", "mode", "moment", "morph_close", "morph_open", "motion_mask", "nan_to_num", "noise", "now", "nvl", "oklab_to_rgb", "overlay", "pad", "percentile", "perlin", "perlin_noise", "perm", "permute", "pinv", "plasma", "plasma_noise", "popcnt", "popcount", "pow", "prcnt", "print", "print_shape", "pshp", "quantile", "quartil", "quartile", "rand", "randb", "randbeta", "randc", "rande", "randg", "randgumbel", "randchi2", "randl", "randln", "randn", "random_bernoulli", "random_beta", "random_cauchy", "random_exponential", "random_gamma", "random_gumbel", "random_chi2", "random_laplace", "random_log_normal", "random_normal", "random_poisson", "random_studentt", "random_uniform", "random_weibull", "randp", "randt", "randu", "randw", "range", "relu", "remap", "repeat", "replace", "reshape", "rgb_to_cielab", "rgb_to_hsv", "rgb_to_int", "rgb_to_oklab", "ridged", "ridged_noise", "rife", "roll", "round", "rshp", "select", "shape", "shuffle", "sigm", "sign", "sin", "sine", "sine_ease", "singular_value_decomposition", "sinh", "smax", "smin", "smootherstep", "smoothstep", "snorm", "softmax", "softmin", "softplus", "sort", "split", "sqrt", "squeeze", "stack_clear", "stack_get", "stack_has", "stack_pop", "stack_push", "startswith", "std", "step", "substr", "substring", "sum", "svd", "swap", "tan", "tanh", "tensor", "text_image", "timestamp", "tmax", "tmin", "tnorm", "topk", "topk_ind", "topk_indices", "trim", "turbulence", "unique", "unsqueeze", "upper", "var", "voronoi", "voronoi_noise", "where", "worley"
"abs", "acos", "acosh", "add_key", "all", "angle", "any", "append", "argmax", "argmin", "argsort", "as_nested_tensor", "asin", "asinh", "atan", "atan2", "atanh", "band", "batch_shuffle", "bitcount", "bitwise_and", "bitwise_not", "bitwise_or", "bitwise_xor", "blur", "bnot", "bor", "botk", "botk_ind", "botk_indices", "bxor", "cat", "ceil", "cellular", "cellular_noise", "cielab_to_rgb", "clamp", "cnt", "concat", "concatenate", "conv", "convolution", "coordinates", "coords", "corr", "correlation", "cos", "cosh", "cosine_similarity", "cossim", "count", "cov", "crop", "cross", "cubic", "cubic_ease", "cumprod", "cumsum", "diag", "diagonal_matrix", "dilate", "dist", "distance", "domain_warp", "domain_warp_noise", "dot", "edge", "elastic", "elastic_ease", "endswith", "entropy", "erf", "erfinv", "erode", "exp", "ezconv", "ezconvolution", "fft", "find", "flatten", "flip", "float", "floor", "flow_ang", "flow_angle", "flow_apply", "flow_mag", "flow_magnitude", "flow_to_image", "fract", "gamma", "gaussian", "gelu", "get_value", "hist", "histogram", "hsv_to_rgb", "ifft", "int", "int_to_rgb", "interpolate_area", "interpolate_linear", "interpolate_nearest", "interpolate_nearest_exact", "join", "length", "lerp", "linspace", "ln", "log", "logspace", "lower", "map", "matmul", "mean", "median", "mode", "moment", "morph_close", "morph_open", "motion_mask", "nan_to_num", "noise", "now", "nvl", "oklab_to_rgb", "overlay", "pad", "percentile", "perlin", "perlin_noise", "perm", "permute", "pinv", "plasma", "plasma_noise", "popcnt", "popcount", "pow", "prcnt", "print", "print_shape", "pshp", "quantile", "quartil", "quartile", "rand", "randb", "randbeta", "randc", "rande", "randg", "randgumbel", "randchi2", "randl", "randln", "randn", "random_bernoulli", "random_beta", "random_cauchy", "random_exponential", "random_gamma", "random_gumbel", "random_chi2", "random_laplace", "random_log_normal", "random_normal", "random_poisson", "random_studentt", "random_uniform", "random_weibull", "randp", "randt", "randu", "randw", "range", "relu", "remap", "remove_kay", "remove_key", "repeat", "replace", "reshape", "rgb_to_cielab", "rgb_to_hsv", "rgb_to_int", "rgb_to_oklab", "ridged", "ridged_noise", "rife", "roll", "round", "rshp", "select", "shape", "shuffle", "sigm", "sign", "sin", "sine", "sine_ease", "singular_value_decomposition", "sinh", "smax", "smin", "smootherstep", "smoothstep", "snorm", "softmax", "softmin", "softplus", "sort", "split", "sqrt", "squeeze", "stack_clear", "stack_get", "stack_has", "stack_pop", "stack_push", "startswith", "std", "step", "substr", "substring", "sum", "svd", "swap", "tan", "tanh", "tensor", "text_image", "timestamp", "tmax", "tmin", "tnorm", "topk", "topk_ind", "topk_indices", "trim", "turbulence", "unique", "unsqueeze", "upper", "var", "voronoi", "voronoi_noise", "where", "worley"
]);
export const FUNCTION_META = {
abs: { minArgs: 1, maxArgs: 1, snippet: "abs()", description: "abs(x) - applies per element absolute value function. Same as |x| for numbers." },
acos: { minArgs: 1, maxArgs: 1, snippet: "acos()", description: "acos(x) - applies arcus cosinus function to value or each element of value" },
acosh: { minArgs: 1, maxArgs: 1, snippet: "acosh()", description: "acosh(x) - applies hyperbolic arcus cosinus function to value or each element of value" },
add_key: { minArgs: 3, maxArgs: 3, snippet: "add_key()", description: "add_key(dict, key, value) - adds or replaces a dictionary entry and returns the updated dictionary" },
all: { minArgs: 1, maxArgs: 1, snippet: "all()", description: "all(x) - returns 1 if all elements of x are non-zero otherwise 0" },
angle: { minArgs: 1, maxArgs: 1, snippet: "angle()", description: "angle(x) - returns the angle of a complex number or vector" },
any: { minArgs: 1, maxArgs: 1, snippet: "any()", description: "any(x) - returns 1 if any element of x is non-zero otherwise 0" },
@@ -190,6 +191,8 @@ export const FUNCTION_META = {
range: { minArgs: 3, maxArgs: 3, snippet: "range()", description: "range(start, stop, step) - creates a range of values between start (inclusive) and stop (exclusive) using step. Use linspace if you want value count." },
relu: { minArgs: 1, maxArgs: 1, snippet: "relu()", description: "relu(x) - applies rectified linear unit function: max(0, x)" },
remap: { minArgs: 5, maxArgs: 5, snippet: "remap()", description: "remap(v, i_min, i_max, o_min, o_max) - remaps values from input range to output range" },
remove_kay: { minArgs: 2, maxArgs: 2, snippet: "remove_kay()", description: "remove_key(dict, key) - removes a dictionary entry and returns the updated dictionary" },
remove_key: { minArgs: 2, maxArgs: 2, snippet: "remove_key()", description: "remove_key(dict, key) - removes a dictionary entry and returns the updated dictionary" },
repeat: { minArgs: 2, maxArgs: 3, snippet: "repeat()", description: "repeat(x, count, [dims]) - repeats tensor elements; count may be scalar or per-dim list" },
replace: { minArgs: 3, maxArgs: 3, snippet: "replace()", description: "replace(s, old, new) - replaces occurrences of old with new in s. Mostly for strings but can work with lists and tensors." },
reshape: { minArgs: 2, maxArgs: 2, snippet: "reshape()", description: "reshape(x, shape) - reshapes tensor x to the specified shape" },