AI: more functions 3

This commit is contained in:
mcDandy
2026-10-13 22:13:01 +02:00
parent 5f424f82df
commit 09a837d3cf
22 changed files with 12913 additions and 11030 deletions
+10
View File
@@ -148,7 +148,9 @@ You can also get the node from comfy manager under the name of More math.
#### 1.4 Activation / ML
- `relu(x)`: `max(0, x)`.
- `gelu(x)`: Gaussian Error Linear Unit.
- `leaky_relu(x, [negative_slope])`: Leaky ReLU; `negative_slope` defaults to `0.01`.
- `softplus(x)`: smooth ReLU-like function.
- `softsign(x)`: bounded activation `x / (1 + abs(x))`.
- `sigm(x)`: sigmoid.
- `softmax(x, [dim])`: softmax normalization.
- `softmin(x, [dim])`: softmin normalization.
@@ -221,6 +223,7 @@ You can also get the node from comfy manager under the name of More math.
- `scatter(tensor, dim, indices)`: scatter values along `dim` using `indices`
- `scatter_add(tensor, dim, indices)`: scatter-add values along `dim` using `indices`
- `nonzero(x)`: returns coordinate indices for non-zero elements.
- `one_hot(indices, classes)`: converts integer class indices into float32 one-hot vectors; indices must be in `0..classes-1`.
#### 2.4 Shape / Structure / Layout
- `shape(x)`: returns shape as a Python list.
@@ -240,6 +243,8 @@ You can also get the node from comfy manager under the name of More math.
- `stack(tensors, [dim])`: stack a non-empty list of tensors along a new dimension.
- `roll(tensor, shifts, [dim])`: circular shift.
- `tensor(shape, [value, [type]])`: create a filled tensor; `type` a tensor to copy its dtype to self when being created.
- `zeros(shape, [dtype_template])` / `ones(shape, [dtype_template])`: create zero- or one-filled tensors; an optional tensor supplies the output dtype.
- `eye(n, [dtype_template])`: create an `n`-by-`n` identity matrix; an optional tensor supplies the output dtype.
- `interpolate_linear(tensor, scale)`: linear interpolation-based resizing. Scale can be a single float or a list. When it is a list, it is interpreted as the target output size.
- `interpolate_area(tensor, scale)`: area interpolation-based resizing.
- `interpolate_nearest(tensor, scale)` / `interpolate_nearest_exact`: nearest neighbor interpolation-based resizing.
@@ -258,6 +263,11 @@ You can also get the node from comfy manager under the name of More math.
- intended for spatial remapping / resampling.
- `get_value(tensor, position)`: read value at an N-D position using flat offset math. Superseeded by tensor[position] indexing.
#### 2.7 Losses / Image Metrics
- `mse(a, b, [reduction])`: mean squared error; reduction is `mean` (default), `sum`, or `none` (`none` returns element-wise values).
- `mae(a, b, [reduction])`: mean absolute error; reduction is `mean` (default), `sum`, or `none` (`none` returns element-wise values).
- `psnr(a, b, [data_range])`: peak signal-to-noise ratio in decibels; `data_range` defaults to `1` and must be positive.
---
### 3) Imaging & Spatial Processing
+45
View File
@@ -269,6 +269,10 @@ func1:
relu(x) - applies rectified linear unit function: max(0, x)
*/
| RELU LPAREN expr RPAREN # ReluFunc
/**
softsign(x) - applies x / (1 + abs(x)) element-wise
*/
| SOFTSIGN LPAREN expr RPAREN # SoftsignFunc
/**
softplus(x) - applies the softplus function: ln(1 + exp(x))
*/
@@ -643,6 +647,38 @@ func2:
tensor(shape, [value], [dtype_template]) - creates a tensor with specified shape and optional value/type. Default value is 0 and default format FP32
*/
| TENSOR LPAREN indexExpr (COMMA expr (COMMA expr)? )? RPAREN # EmptyTensorFunc
/**
zeros(shape, [dtype_template]) - creates a zero-filled tensor on the current device
*/
| ZEROS LPAREN expr (COMMA expr)? RPAREN # ZerosFunc
/**
ones(shape, [dtype_template]) - creates a one-filled tensor on the current device
*/
| ONES LPAREN expr (COMMA expr)? RPAREN # OnesFunc
/**
eye(n, [dtype_template]) - creates an n-by-n identity matrix
*/
| EYE LPAREN expr (COMMA expr)? RPAREN # EyeFunc
/**
one_hot(indices, classes) - converts integer class indices to float32 one-hot vectors
*/
| ONE_HOT LPAREN expr COMMA expr RPAREN # OneHotFunc
/**
mse(a, b, [reduction]) - mean squared error; reduction is mean (default), sum, or none
*/
| MSE LPAREN expr COMMA expr (COMMA expr)? RPAREN # MseFunc
/**
mae(a, b, [reduction]) - mean absolute error; reduction is mean (default), sum, or none
*/
| MAE LPAREN expr COMMA expr (COMMA expr)? RPAREN # MaeFunc
/**
psnr(a, b, [data_range]) - peak signal-to-noise ratio in dB; data_range defaults to 1
*/
| PSNR LPAREN expr COMMA expr (COMMA expr)? RPAREN # PsnrFunc
/**
leaky_relu(x, [negative_slope]) - applies leaky ReLU element-wise; negative_slope defaults to 0.01
*/
| LEAKY_RELU LPAREN expr (COMMA expr)? RPAREN # LeakyReluFunc
/**
pad(x, padding) - pads tensor x with specified padding (dim 0 neg, dim 0 pos, dim 1 ...)
*/
@@ -1057,6 +1093,8 @@ STEP: 'step';
SMOOTHSTEP: 'smoothstep';
FRACT: 'fract';
RELU: 'relu';
SOFTSIGN: 'softsign';
LEAKY_RELU: 'leaky_relu';
SOFTPLUS: 'softplus';
GELU: 'gelu';
SIGN: 'sign';
@@ -1144,6 +1182,13 @@ BAND: 'band' | 'bitwise_and';
XOR: 'bxor' | 'bitwise_xor';
BOR: 'bor' | 'bitwise_or';
TENSOR: 'tensor';
ZEROS: 'zeros';
ONES: 'ones';
EYE: 'eye';
ONE_HOT: 'one_hot';
MSE: 'mse';
MAE: 'mae';
PSNR: 'psnr';
ADD_KEY: 'add_key';
REMOVE_KEY: 'remove_key' | 'rm_key';
PUSH: 'stack_push';
+107
View File
@@ -1097,6 +1097,26 @@ class UnifiedMathVisitor(MathExprVisitor):
def visitReluFunc(self, ctx):
return self._unary_op((yield ctx.expr()), torch.relu, lambda x: max(0.0, x))
def visitSoftsignFunc(self, ctx):
return self._unary_op((yield ctx.expr()), lambda x: x / (1 + torch.abs(x)), lambda x: x / (1 + abs(x)))
def visitLeakyReluFunc(self, ctx):
val = (yield ctx.expr(0))
negative_slope = 0.01
if len(ctx.expr()) > 1:
negative_slope = (yield ctx.expr(1))
if self._is_tensor(negative_slope):
if negative_slope.numel() != 1:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: leaky_relu negative_slope must be a scalar")
negative_slope = float(negative_slope.item())
elif self._is_list(negative_slope):
if len(negative_slope) != 1:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: leaky_relu negative_slope must be a scalar")
negative_slope = float(negative_slope[0])
else:
negative_slope = float(negative_slope)
return self._unary_op(val, lambda x: F.leaky_relu(x, negative_slope), lambda x: x if x >= 0 else negative_slope * x)
def visitSoftplusFunc(self, ctx):
return self._unary_op((yield ctx.expr()), F.softplus, lambda x: math.log(1.0 + math.exp(x)))
@@ -3846,6 +3866,93 @@ class UnifiedMathVisitor(MathExprVisitor):
return torch.full(shape, value, device=self.device,dtype=type)
def _filled_tensor(self, ctx, value):
shape = self._normalize_shape_arg((yield ctx.expr(0)), ctx, "tensor shape")
dtype = torch.float32
if len(ctx.expr()) > 1:
template = (yield ctx.expr(1))
if not self._is_tensor(template):
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: dtype_template must be a tensor")
dtype = template.dtype
return torch.full(shape, value, dtype=dtype, device=self.device)
def visitZerosFunc(self, ctx):
return (yield from self._filled_tensor(ctx, 0.0))
def visitOnesFunc(self, ctx):
return (yield from self._filled_tensor(ctx, 1.0))
def visitEyeFunc(self, ctx):
n = self._to_int((yield ctx.expr(0)), ctx, "eye size", strict=True)
if n < 0:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: eye size must be non-negative")
dtype = torch.float32
if len(ctx.expr()) > 1:
template = (yield ctx.expr(1))
if not self._is_tensor(template):
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: dtype_template must be a tensor")
dtype = template.dtype
return torch.eye(n, dtype=dtype, device=self.device)
def visitOneHotFunc(self, ctx):
indices = self._promote_to_tensor((yield ctx.expr(0)))
num_classes = self._to_int((yield ctx.expr(1)), ctx, "one_hot classes", strict=True)
if num_classes <= 0:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: one_hot classes must be positive")
if indices.is_floating_point():
numeric_indices = indices.float()
if not torch.equal(numeric_indices, numeric_indices.round()):
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: one_hot indices must be integers")
indices = indices.long()
if torch.any(indices < 0) or torch.any(indices >= num_classes):
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: one_hot index is outside the class range")
return F.one_hot(indices, num_classes=num_classes).to(dtype=torch.float32)
def _loss_metric(self, ctx, absolute):
left = self._promote_to_tensor((yield ctx.expr(0))).float()
right = self._promote_to_tensor((yield ctx.expr(1))).float()
left, right = torch.broadcast_tensors(left, right)
error = left - right
values = error.abs() if absolute else error.square()
reduction = "mean"
if len(ctx.expr()) > 2:
reduction = (yield ctx.expr(2))
if not isinstance(reduction, str):
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: reduction must be 'none', 'mean', or 'sum'")
reduction = reduction.strip().lower()
if reduction == "none":
return values
if reduction == "mean":
return values.mean()
if reduction == "sum":
return values.sum()
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: reduction must be 'none', 'mean', or 'sum'")
def visitMseFunc(self, ctx):
return (yield from self._loss_metric(ctx, absolute=False))
def visitMaeFunc(self, ctx):
return (yield from self._loss_metric(ctx, absolute=True))
def visitPsnrFunc(self, ctx):
left = self._promote_to_tensor((yield ctx.expr(0))).float()
right = self._promote_to_tensor((yield ctx.expr(1))).float()
left, right = torch.broadcast_tensors(left, right)
data_range = 1.0
if len(ctx.expr()) > 2:
data_range = (yield ctx.expr(2))
if self._is_tensor(data_range):
if data_range.numel() != 1:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: psnr data_range must be a scalar")
data_range = float(data_range.item())
data_range = float(data_range)
if not math.isfinite(data_range) or data_range <= 0:
raise ValueError(f"{ctx.start.line}:{ctx.start.column}: psnr data_range must be positive and finite")
mse = (left - right).square().mean()
if mse.item() == 0:
return torch.tensor(float("inf"), dtype=torch.float32, device=left.device)
return 20.0 * math.log10(data_range) - 10.0 * torch.log10(mse)
def visitSoftmaxFunc(self, ctx):
val = self._promote_to_tensor((yield ctx.expr(0))).float()
dim = -1
File diff suppressed because one or more lines are too long
+377 -359
View File
@@ -46,220 +46,229 @@ STEP=45
SMOOTHSTEP=46
FRACT=47
RELU=48
SOFTPLUS=49
GELU=50
SIGN=51
DEGREES=52
RADIANS=53
LOGICAL_NOT=54
LOGICAL_AND=55
LOGICAL_OR=56
HYPOT=57
MAP=58
EZCONV=59
CONV=60
SWAP=61
TRANSPOSE=62
PERM=63
RESHAPE=64
RANGE=65
LINSPACE=66
LOGSPACE=67
TOPK=68
BOTK=69
PINV=70
SUM=71
MEAN=72
STD=73
VAR=74
PROD=75
ISCLOSE=76
ALLCLOSE=77
QUARTILE=78
PERCENTILE=79
QUANTILE=80
DOT=81
MOMENT=82
ERF=83
ERFINV=84
ANY=85
ALL=86
EDGE=87
GAUSSIAN=88
MEDIAN=89
MODE=90
CUMSUM=91
CUMPROD=92
TOPK_IND=93
BOTK_IND=94
CUBIC_EASE=95
ELASTIC_EASE=96
SINE_EASE=97
SMOOTHERSTEP=98
DIST=99
REMAP=100
COSSIM=101
COUNT=102
KEYS=103
ENABLE_TRACKING=104
DISABLE_TRACKING=105
RESET_TRACKING=106
GET_CHANGED_KEYS=107
GET_ADDED_KEYS=108
GET_REMOVED_KEYS=109
GET_UNCHANGED_KEYS=110
REPEAT=111
FLATTEN=112
APPEND=113
GET_VALUE=114
FLOW_APPLY=115
BATCH_SHUFFLE=116
MOTION_MASK=117
FLOW_TO_IMAGE=118
FLOW_MAG=119
FLOW_ANG=120
WHERE=121
HISTOGRAM=122
OVERLAY=123
PAD=124
CROSS=125
MATMUL=126
RIFE=127
BNOT=128
BITCOUNT=129
SHAPE=130
BAND=131
XOR=132
BOR=133
TENSOR=134
ADD_KEY=135
REMOVE_KEY=136
PUSH=137
POP=138
CLEAR=139
HAS=140
GET=141
CONCAT=142
STACK=143
NONZERO=144
INT=145
FLOAT=146
UPPER=147
LOWER=148
TRIM=149
SPLIT=150
JOIN=151
SUBSTRING=152
FIND=153
REPLACE=154
DILATE=155
ERODE=156
MORPH_OPEN=157
MORPH_CLOSE=158
RGB_TO_OKLAB=159
RGB_TO_CIELAB=160
OKLAB_TO_RGB=161
CIELAB_TO_RGB=162
RGB_TO_HSV=163
HSV_TO_RGB=164
INT_TO_RGB=165
RGB_TO_INT=166
INTERPOLATE_LINEAR=167
INTERPOLATE_AREA=168
INTERPOLATE_NEAREST=169
TEXT_IMAGE=170
AS_NESTED=171
SVD=172
DIAG=173
IF=174
ELSE=175
WHILE=176
FOR=177
IN=178
BREAK=179
CONTINUE=180
RETURN=181
TIMESTAMP=182
SORT=183
ARGSORT=184
ARGMIN=185
ARGMAX=186
SOFTMAX=187
SOFTMIN=188
UNIQUE=189
FLIP=190
STARTSWITH=191
ENDSWITH=192
SQUEEZE=193
UNSQUEEZE=194
ROLL=195
COV=196
CORR=197
ENTROPY=198
CROP=199
NONE=200
COORDS=201
GATHER=202
SCATTER=203
SCATTER_ADD=204
NOISE=205
RAND=206
CAUCHY=207
EXPONENTIAL=208
LOGNORMAL=209
BERNOULLI=210
POISSON=211
GAMMADIST=212
BETADIST=213
LAPLACEDIST=214
GUMBELDIST=215
WEIBULLDIST=216
CHI2DIST=217
STUDENTTDIST=218
PERLIN=219
CELLULAR=220
PLASMA=221
RIDGED=222
DOMAIN_WARP=223
PLUS=224
MINUS=225
MULT=226
DIV=227
MOD=228
POW=229
LSHIFT=230
RSHIFT=231
GE=232
GT=233
LE=234
LT=235
EQ=236
EQUEALS=237
PLUS_EQ=238
MINUS_EQ=239
MULT_EQ=240
DIV_EQ=241
MOD_EQ=242
NE=243
PIPE=244
LPAREN=245
RPAREN=246
COMMA=247
SEMICOLON=248
ARROW=249
LBRACKET=250
RBRACKET=251
QUESTION=252
COLON=253
LBRACE=254
RBRACE=255
NUMBER=256
CONSTANT=257
STRING=258
VARIABLE=259
SL_COMMENT=260
ML_COMMENT=261
WS=262
SOFTSIGN=49
LEAKY_RELU=50
SOFTPLUS=51
GELU=52
SIGN=53
DEGREES=54
RADIANS=55
LOGICAL_NOT=56
LOGICAL_AND=57
LOGICAL_OR=58
HYPOT=59
MAP=60
EZCONV=61
CONV=62
SWAP=63
TRANSPOSE=64
PERM=65
RESHAPE=66
RANGE=67
LINSPACE=68
LOGSPACE=69
TOPK=70
BOTK=71
PINV=72
SUM=73
MEAN=74
STD=75
VAR=76
PROD=77
ISCLOSE=78
ALLCLOSE=79
QUARTILE=80
PERCENTILE=81
QUANTILE=82
DOT=83
MOMENT=84
ERF=85
ERFINV=86
ANY=87
ALL=88
EDGE=89
GAUSSIAN=90
MEDIAN=91
MODE=92
CUMSUM=93
CUMPROD=94
TOPK_IND=95
BOTK_IND=96
CUBIC_EASE=97
ELASTIC_EASE=98
SINE_EASE=99
SMOOTHERSTEP=100
DIST=101
REMAP=102
COSSIM=103
COUNT=104
KEYS=105
ENABLE_TRACKING=106
DISABLE_TRACKING=107
RESET_TRACKING=108
GET_CHANGED_KEYS=109
GET_ADDED_KEYS=110
GET_REMOVED_KEYS=111
GET_UNCHANGED_KEYS=112
REPEAT=113
FLATTEN=114
APPEND=115
GET_VALUE=116
FLOW_APPLY=117
BATCH_SHUFFLE=118
MOTION_MASK=119
FLOW_TO_IMAGE=120
FLOW_MAG=121
FLOW_ANG=122
WHERE=123
HISTOGRAM=124
OVERLAY=125
PAD=126
CROSS=127
MATMUL=128
RIFE=129
BNOT=130
BITCOUNT=131
SHAPE=132
BAND=133
XOR=134
BOR=135
TENSOR=136
ZEROS=137
ONES=138
EYE=139
ONE_HOT=140
MSE=141
MAE=142
PSNR=143
ADD_KEY=144
REMOVE_KEY=145
PUSH=146
POP=147
CLEAR=148
HAS=149
GET=150
CONCAT=151
STACK=152
NONZERO=153
INT=154
FLOAT=155
UPPER=156
LOWER=157
TRIM=158
SPLIT=159
JOIN=160
SUBSTRING=161
FIND=162
REPLACE=163
DILATE=164
ERODE=165
MORPH_OPEN=166
MORPH_CLOSE=167
RGB_TO_OKLAB=168
RGB_TO_CIELAB=169
OKLAB_TO_RGB=170
CIELAB_TO_RGB=171
RGB_TO_HSV=172
HSV_TO_RGB=173
INT_TO_RGB=174
RGB_TO_INT=175
INTERPOLATE_LINEAR=176
INTERPOLATE_AREA=177
INTERPOLATE_NEAREST=178
TEXT_IMAGE=179
AS_NESTED=180
SVD=181
DIAG=182
IF=183
ELSE=184
WHILE=185
FOR=186
IN=187
BREAK=188
CONTINUE=189
RETURN=190
TIMESTAMP=191
SORT=192
ARGSORT=193
ARGMIN=194
ARGMAX=195
SOFTMAX=196
SOFTMIN=197
UNIQUE=198
FLIP=199
STARTSWITH=200
ENDSWITH=201
SQUEEZE=202
UNSQUEEZE=203
ROLL=204
COV=205
CORR=206
ENTROPY=207
CROP=208
NONE=209
COORDS=210
GATHER=211
SCATTER=212
SCATTER_ADD=213
NOISE=214
RAND=215
CAUCHY=216
EXPONENTIAL=217
LOGNORMAL=218
BERNOULLI=219
POISSON=220
GAMMADIST=221
BETADIST=222
LAPLACEDIST=223
GUMBELDIST=224
WEIBULLDIST=225
CHI2DIST=226
STUDENTTDIST=227
PERLIN=228
CELLULAR=229
PLASMA=230
RIDGED=231
DOMAIN_WARP=232
PLUS=233
MINUS=234
MULT=235
DIV=236
MOD=237
POW=238
LSHIFT=239
RSHIFT=240
GE=241
GT=242
LE=243
LT=244
EQ=245
EQUEALS=246
PLUS_EQ=247
MINUS_EQ=248
MULT_EQ=249
DIV_EQ=250
MOD_EQ=251
NE=252
PIPE=253
LPAREN=254
RPAREN=255
COMMA=256
SEMICOLON=257
ARROW=258
LBRACKET=259
RBRACKET=260
QUESTION=261
COLON=262
LBRACE=263
RBRACE=264
NUMBER=265
CONSTANT=266
STRING=267
VARIABLE=268
SL_COMMENT=269
ML_COMMENT=270
WS=271
'sin'=1
'cos'=2
'tan'=3
@@ -306,148 +315,157 @@ WS=262
'smoothstep'=46
'fract'=47
'relu'=48
'softplus'=49
'gelu'=50
'sign'=51
'degrees'=52
'radians'=53
'logical_not'=54
'logical_and'=55
'logical_or'=56
'hypot'=57
'map'=58
'swap'=61
'range'=65
'linspace'=66
'logspace'=67
'topk'=68
'botk'=69
'pinv'=70
'sum'=71
'mean'=72
'std'=73
'var'=74
'prod'=75
'isclose'=76
'allclose'=77
'quantile'=80
'dot'=81
'moment'=82
'erf'=83
'erfinv'=84
'any'=85
'all'=86
'edge'=87
'median'=89
'mode'=90
'cumsum'=91
'cumprod'=92
'smootherstep'=98
'remap'=100
'keys'=103
'repeat'=111
'flatten'=112
'append'=113
'get_value'=114
'flow_apply'=115
'motion_mask'=117
'flow_to_image'=118
'where'=121
'overlay'=123
'pad'=124
'cross'=125
'matmul'=126
'rife'=127
'shape'=130
'tensor'=134
'add_key'=135
'stack_push'=137
'stack_pop'=138
'stack_clear'=139
'stack_has'=140
'stack_get'=141
'stack'=143
'nonzero'=144
'int'=145
'float'=146
'upper'=147
'lower'=148
'trim'=149
'split'=150
'join'=151
'find'=153
'replace'=154
'dilate'=155
'erode'=156
'morph_open'=157
'morph_close'=158
'rgb_to_oklab'=159
'rgb_to_cielab'=160
'oklab_to_rgb'=161
'cielab_to_rgb'=162
'rgb_to_hsv'=163
'hsv_to_rgb'=164
'int_to_rgb'=165
'rgb_to_int'=166
'interpolate_linear'=167
'interpolate_area'=168
'text_image'=170
'if'=174
'else'=175
'while'=176
'for'=177
'in'=178
'break'=179
'continue'=180
'return'=181
'sort'=183
'argsort'=184
'argmin'=185
'argmax'=186
'softmax'=187
'softmin'=188
'unique'=189
'flip'=190
'startswith'=191
'endswith'=192
'squeeze'=193
'unsqueeze'=194
'roll'=195
'cov'=196
'entropy'=198
'crop'=199
'gather'=202
'scatter'=203
'scatter_add'=204
'+'=224
'-'=225
'*'=226
'/'=227
'%'=228
'^'=229
'<<'=230
'>>'=231
'>='=232
'>'=233
'<='=234
'<'=235
'=='=236
'='=237
'+='=238
'-='=239
'*='=240
'/='=241
'%='=242
'!='=243
'|'=244
'('=245
')'=246
','=247
';'=248
'->'=249
'['=250
']'=251
'?'=252
':'=253
'{'=254
'}'=255
'softsign'=49
'leaky_relu'=50
'softplus'=51
'gelu'=52
'sign'=53
'degrees'=54
'radians'=55
'logical_not'=56
'logical_and'=57
'logical_or'=58
'hypot'=59
'map'=60
'swap'=63
'range'=67
'linspace'=68
'logspace'=69
'topk'=70
'botk'=71
'pinv'=72
'sum'=73
'mean'=74
'std'=75
'var'=76
'prod'=77
'isclose'=78
'allclose'=79
'quantile'=82
'dot'=83
'moment'=84
'erf'=85
'erfinv'=86
'any'=87
'all'=88
'edge'=89
'median'=91
'mode'=92
'cumsum'=93
'cumprod'=94
'smootherstep'=100
'remap'=102
'keys'=105
'repeat'=113
'flatten'=114
'append'=115
'get_value'=116
'flow_apply'=117
'motion_mask'=119
'flow_to_image'=120
'where'=123
'overlay'=125
'pad'=126
'cross'=127
'matmul'=128
'rife'=129
'shape'=132
'tensor'=136
'zeros'=137
'ones'=138
'eye'=139
'one_hot'=140
'mse'=141
'mae'=142
'psnr'=143
'add_key'=144
'stack_push'=146
'stack_pop'=147
'stack_clear'=148
'stack_has'=149
'stack_get'=150
'stack'=152
'nonzero'=153
'int'=154
'float'=155
'upper'=156
'lower'=157
'trim'=158
'split'=159
'join'=160
'find'=162
'replace'=163
'dilate'=164
'erode'=165
'morph_open'=166
'morph_close'=167
'rgb_to_oklab'=168
'rgb_to_cielab'=169
'oklab_to_rgb'=170
'cielab_to_rgb'=171
'rgb_to_hsv'=172
'hsv_to_rgb'=173
'int_to_rgb'=174
'rgb_to_int'=175
'interpolate_linear'=176
'interpolate_area'=177
'text_image'=179
'if'=183
'else'=184
'while'=185
'for'=186
'in'=187
'break'=188
'continue'=189
'return'=190
'sort'=192
'argsort'=193
'argmin'=194
'argmax'=195
'softmax'=196
'softmin'=197
'unique'=198
'flip'=199
'startswith'=200
'endswith'=201
'squeeze'=202
'unsqueeze'=203
'roll'=204
'cov'=205
'entropy'=207
'crop'=208
'gather'=211
'scatter'=212
'scatter_add'=213
'+'=233
'-'=234
'*'=235
'/'=236
'%'=237
'^'=238
'<<'=239
'>>'=240
'>='=241
'>'=242
'<='=243
'<'=244
'=='=245
'='=246
'+='=247
'-='=248
'*='=249
'/='=250
'%='=251
'!='=252
'|'=253
'('=254
')'=255
','=256
';'=257
'->'=258
'['=259
']'=260
'?'=261
':'=262
'{'=263
'}'=264
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+377 -359
View File
@@ -46,220 +46,229 @@ STEP=45
SMOOTHSTEP=46
FRACT=47
RELU=48
SOFTPLUS=49
GELU=50
SIGN=51
DEGREES=52
RADIANS=53
LOGICAL_NOT=54
LOGICAL_AND=55
LOGICAL_OR=56
HYPOT=57
MAP=58
EZCONV=59
CONV=60
SWAP=61
TRANSPOSE=62
PERM=63
RESHAPE=64
RANGE=65
LINSPACE=66
LOGSPACE=67
TOPK=68
BOTK=69
PINV=70
SUM=71
MEAN=72
STD=73
VAR=74
PROD=75
ISCLOSE=76
ALLCLOSE=77
QUARTILE=78
PERCENTILE=79
QUANTILE=80
DOT=81
MOMENT=82
ERF=83
ERFINV=84
ANY=85
ALL=86
EDGE=87
GAUSSIAN=88
MEDIAN=89
MODE=90
CUMSUM=91
CUMPROD=92
TOPK_IND=93
BOTK_IND=94
CUBIC_EASE=95
ELASTIC_EASE=96
SINE_EASE=97
SMOOTHERSTEP=98
DIST=99
REMAP=100
COSSIM=101
COUNT=102
KEYS=103
ENABLE_TRACKING=104
DISABLE_TRACKING=105
RESET_TRACKING=106
GET_CHANGED_KEYS=107
GET_ADDED_KEYS=108
GET_REMOVED_KEYS=109
GET_UNCHANGED_KEYS=110
REPEAT=111
FLATTEN=112
APPEND=113
GET_VALUE=114
FLOW_APPLY=115
BATCH_SHUFFLE=116
MOTION_MASK=117
FLOW_TO_IMAGE=118
FLOW_MAG=119
FLOW_ANG=120
WHERE=121
HISTOGRAM=122
OVERLAY=123
PAD=124
CROSS=125
MATMUL=126
RIFE=127
BNOT=128
BITCOUNT=129
SHAPE=130
BAND=131
XOR=132
BOR=133
TENSOR=134
ADD_KEY=135
REMOVE_KEY=136
PUSH=137
POP=138
CLEAR=139
HAS=140
GET=141
CONCAT=142
STACK=143
NONZERO=144
INT=145
FLOAT=146
UPPER=147
LOWER=148
TRIM=149
SPLIT=150
JOIN=151
SUBSTRING=152
FIND=153
REPLACE=154
DILATE=155
ERODE=156
MORPH_OPEN=157
MORPH_CLOSE=158
RGB_TO_OKLAB=159
RGB_TO_CIELAB=160
OKLAB_TO_RGB=161
CIELAB_TO_RGB=162
RGB_TO_HSV=163
HSV_TO_RGB=164
INT_TO_RGB=165
RGB_TO_INT=166
INTERPOLATE_LINEAR=167
INTERPOLATE_AREA=168
INTERPOLATE_NEAREST=169
TEXT_IMAGE=170
AS_NESTED=171
SVD=172
DIAG=173
IF=174
ELSE=175
WHILE=176
FOR=177
IN=178
BREAK=179
CONTINUE=180
RETURN=181
TIMESTAMP=182
SORT=183
ARGSORT=184
ARGMIN=185
ARGMAX=186
SOFTMAX=187
SOFTMIN=188
UNIQUE=189
FLIP=190
STARTSWITH=191
ENDSWITH=192
SQUEEZE=193
UNSQUEEZE=194
ROLL=195
COV=196
CORR=197
ENTROPY=198
CROP=199
NONE=200
COORDS=201
GATHER=202
SCATTER=203
SCATTER_ADD=204
NOISE=205
RAND=206
CAUCHY=207
EXPONENTIAL=208
LOGNORMAL=209
BERNOULLI=210
POISSON=211
GAMMADIST=212
BETADIST=213
LAPLACEDIST=214
GUMBELDIST=215
WEIBULLDIST=216
CHI2DIST=217
STUDENTTDIST=218
PERLIN=219
CELLULAR=220
PLASMA=221
RIDGED=222
DOMAIN_WARP=223
PLUS=224
MINUS=225
MULT=226
DIV=227
MOD=228
POW=229
LSHIFT=230
RSHIFT=231
GE=232
GT=233
LE=234
LT=235
EQ=236
EQUEALS=237
PLUS_EQ=238
MINUS_EQ=239
MULT_EQ=240
DIV_EQ=241
MOD_EQ=242
NE=243
PIPE=244
LPAREN=245
RPAREN=246
COMMA=247
SEMICOLON=248
ARROW=249
LBRACKET=250
RBRACKET=251
QUESTION=252
COLON=253
LBRACE=254
RBRACE=255
NUMBER=256
CONSTANT=257
STRING=258
VARIABLE=259
SL_COMMENT=260
ML_COMMENT=261
WS=262
SOFTSIGN=49
LEAKY_RELU=50
SOFTPLUS=51
GELU=52
SIGN=53
DEGREES=54
RADIANS=55
LOGICAL_NOT=56
LOGICAL_AND=57
LOGICAL_OR=58
HYPOT=59
MAP=60
EZCONV=61
CONV=62
SWAP=63
TRANSPOSE=64
PERM=65
RESHAPE=66
RANGE=67
LINSPACE=68
LOGSPACE=69
TOPK=70
BOTK=71
PINV=72
SUM=73
MEAN=74
STD=75
VAR=76
PROD=77
ISCLOSE=78
ALLCLOSE=79
QUARTILE=80
PERCENTILE=81
QUANTILE=82
DOT=83
MOMENT=84
ERF=85
ERFINV=86
ANY=87
ALL=88
EDGE=89
GAUSSIAN=90
MEDIAN=91
MODE=92
CUMSUM=93
CUMPROD=94
TOPK_IND=95
BOTK_IND=96
CUBIC_EASE=97
ELASTIC_EASE=98
SINE_EASE=99
SMOOTHERSTEP=100
DIST=101
REMAP=102
COSSIM=103
COUNT=104
KEYS=105
ENABLE_TRACKING=106
DISABLE_TRACKING=107
RESET_TRACKING=108
GET_CHANGED_KEYS=109
GET_ADDED_KEYS=110
GET_REMOVED_KEYS=111
GET_UNCHANGED_KEYS=112
REPEAT=113
FLATTEN=114
APPEND=115
GET_VALUE=116
FLOW_APPLY=117
BATCH_SHUFFLE=118
MOTION_MASK=119
FLOW_TO_IMAGE=120
FLOW_MAG=121
FLOW_ANG=122
WHERE=123
HISTOGRAM=124
OVERLAY=125
PAD=126
CROSS=127
MATMUL=128
RIFE=129
BNOT=130
BITCOUNT=131
SHAPE=132
BAND=133
XOR=134
BOR=135
TENSOR=136
ZEROS=137
ONES=138
EYE=139
ONE_HOT=140
MSE=141
MAE=142
PSNR=143
ADD_KEY=144
REMOVE_KEY=145
PUSH=146
POP=147
CLEAR=148
HAS=149
GET=150
CONCAT=151
STACK=152
NONZERO=153
INT=154
FLOAT=155
UPPER=156
LOWER=157
TRIM=158
SPLIT=159
JOIN=160
SUBSTRING=161
FIND=162
REPLACE=163
DILATE=164
ERODE=165
MORPH_OPEN=166
MORPH_CLOSE=167
RGB_TO_OKLAB=168
RGB_TO_CIELAB=169
OKLAB_TO_RGB=170
CIELAB_TO_RGB=171
RGB_TO_HSV=172
HSV_TO_RGB=173
INT_TO_RGB=174
RGB_TO_INT=175
INTERPOLATE_LINEAR=176
INTERPOLATE_AREA=177
INTERPOLATE_NEAREST=178
TEXT_IMAGE=179
AS_NESTED=180
SVD=181
DIAG=182
IF=183
ELSE=184
WHILE=185
FOR=186
IN=187
BREAK=188
CONTINUE=189
RETURN=190
TIMESTAMP=191
SORT=192
ARGSORT=193
ARGMIN=194
ARGMAX=195
SOFTMAX=196
SOFTMIN=197
UNIQUE=198
FLIP=199
STARTSWITH=200
ENDSWITH=201
SQUEEZE=202
UNSQUEEZE=203
ROLL=204
COV=205
CORR=206
ENTROPY=207
CROP=208
NONE=209
COORDS=210
GATHER=211
SCATTER=212
SCATTER_ADD=213
NOISE=214
RAND=215
CAUCHY=216
EXPONENTIAL=217
LOGNORMAL=218
BERNOULLI=219
POISSON=220
GAMMADIST=221
BETADIST=222
LAPLACEDIST=223
GUMBELDIST=224
WEIBULLDIST=225
CHI2DIST=226
STUDENTTDIST=227
PERLIN=228
CELLULAR=229
PLASMA=230
RIDGED=231
DOMAIN_WARP=232
PLUS=233
MINUS=234
MULT=235
DIV=236
MOD=237
POW=238
LSHIFT=239
RSHIFT=240
GE=241
GT=242
LE=243
LT=244
EQ=245
EQUEALS=246
PLUS_EQ=247
MINUS_EQ=248
MULT_EQ=249
DIV_EQ=250
MOD_EQ=251
NE=252
PIPE=253
LPAREN=254
RPAREN=255
COMMA=256
SEMICOLON=257
ARROW=258
LBRACKET=259
RBRACKET=260
QUESTION=261
COLON=262
LBRACE=263
RBRACE=264
NUMBER=265
CONSTANT=266
STRING=267
VARIABLE=268
SL_COMMENT=269
ML_COMMENT=270
WS=271
'sin'=1
'cos'=2
'tan'=3
@@ -306,148 +315,157 @@ WS=262
'smoothstep'=46
'fract'=47
'relu'=48
'softplus'=49
'gelu'=50
'sign'=51
'degrees'=52
'radians'=53
'logical_not'=54
'logical_and'=55
'logical_or'=56
'hypot'=57
'map'=58
'swap'=61
'range'=65
'linspace'=66
'logspace'=67
'topk'=68
'botk'=69
'pinv'=70
'sum'=71
'mean'=72
'std'=73
'var'=74
'prod'=75
'isclose'=76
'allclose'=77
'quantile'=80
'dot'=81
'moment'=82
'erf'=83
'erfinv'=84
'any'=85
'all'=86
'edge'=87
'median'=89
'mode'=90
'cumsum'=91
'cumprod'=92
'smootherstep'=98
'remap'=100
'keys'=103
'repeat'=111
'flatten'=112
'append'=113
'get_value'=114
'flow_apply'=115
'motion_mask'=117
'flow_to_image'=118
'where'=121
'overlay'=123
'pad'=124
'cross'=125
'matmul'=126
'rife'=127
'shape'=130
'tensor'=134
'add_key'=135
'stack_push'=137
'stack_pop'=138
'stack_clear'=139
'stack_has'=140
'stack_get'=141
'stack'=143
'nonzero'=144
'int'=145
'float'=146
'upper'=147
'lower'=148
'trim'=149
'split'=150
'join'=151
'find'=153
'replace'=154
'dilate'=155
'erode'=156
'morph_open'=157
'morph_close'=158
'rgb_to_oklab'=159
'rgb_to_cielab'=160
'oklab_to_rgb'=161
'cielab_to_rgb'=162
'rgb_to_hsv'=163
'hsv_to_rgb'=164
'int_to_rgb'=165
'rgb_to_int'=166
'interpolate_linear'=167
'interpolate_area'=168
'text_image'=170
'if'=174
'else'=175
'while'=176
'for'=177
'in'=178
'break'=179
'continue'=180
'return'=181
'sort'=183
'argsort'=184
'argmin'=185
'argmax'=186
'softmax'=187
'softmin'=188
'unique'=189
'flip'=190
'startswith'=191
'endswith'=192
'squeeze'=193
'unsqueeze'=194
'roll'=195
'cov'=196
'entropy'=198
'crop'=199
'gather'=202
'scatter'=203
'scatter_add'=204
'+'=224
'-'=225
'*'=226
'/'=227
'%'=228
'^'=229
'<<'=230
'>>'=231
'>='=232
'>'=233
'<='=234
'<'=235
'=='=236
'='=237
'+='=238
'-='=239
'*='=240
'/='=241
'%='=242
'!='=243
'|'=244
'('=245
')'=246
','=247
';'=248
'->'=249
'['=250
']'=251
'?'=252
':'=253
'{'=254
'}'=255
'softsign'=49
'leaky_relu'=50
'softplus'=51
'gelu'=52
'sign'=53
'degrees'=54
'radians'=55
'logical_not'=56
'logical_and'=57
'logical_or'=58
'hypot'=59
'map'=60
'swap'=63
'range'=67
'linspace'=68
'logspace'=69
'topk'=70
'botk'=71
'pinv'=72
'sum'=73
'mean'=74
'std'=75
'var'=76
'prod'=77
'isclose'=78
'allclose'=79
'quantile'=82
'dot'=83
'moment'=84
'erf'=85
'erfinv'=86
'any'=87
'all'=88
'edge'=89
'median'=91
'mode'=92
'cumsum'=93
'cumprod'=94
'smootherstep'=100
'remap'=102
'keys'=105
'repeat'=113
'flatten'=114
'append'=115
'get_value'=116
'flow_apply'=117
'motion_mask'=119
'flow_to_image'=120
'where'=123
'overlay'=125
'pad'=126
'cross'=127
'matmul'=128
'rife'=129
'shape'=132
'tensor'=136
'zeros'=137
'ones'=138
'eye'=139
'one_hot'=140
'mse'=141
'mae'=142
'psnr'=143
'add_key'=144
'stack_push'=146
'stack_pop'=147
'stack_clear'=148
'stack_has'=149
'stack_get'=150
'stack'=152
'nonzero'=153
'int'=154
'float'=155
'upper'=156
'lower'=157
'trim'=158
'split'=159
'join'=160
'find'=162
'replace'=163
'dilate'=164
'erode'=165
'morph_open'=166
'morph_close'=167
'rgb_to_oklab'=168
'rgb_to_cielab'=169
'oklab_to_rgb'=170
'cielab_to_rgb'=171
'rgb_to_hsv'=172
'hsv_to_rgb'=173
'int_to_rgb'=174
'rgb_to_int'=175
'interpolate_linear'=176
'interpolate_area'=177
'text_image'=179
'if'=183
'else'=184
'while'=185
'for'=186
'in'=187
'break'=188
'continue'=189
'return'=190
'sort'=192
'argsort'=193
'argmin'=194
'argmax'=195
'softmax'=196
'softmin'=197
'unique'=198
'flip'=199
'startswith'=200
'endswith'=201
'squeeze'=202
'unsqueeze'=203
'roll'=204
'cov'=205
'entropy'=207
'crop'=208
'gather'=211
'scatter'=212
'scatter_add'=213
'+'=233
'-'=234
'*'=235
'/'=236
'%'=237
'^'=238
'<<'=239
'>>'=240
'>='=241
'>'=242
'<='=243
'<'=244
'=='=245
'='=246
'+='=247
'-='=248
'*='=249
'/='=250
'%='=251
'!='=252
'|'=253
'('=254
')'=255
','=256
';'=257
'->'=258
'['=259
']'=260
'?'=261
':'=262
'{'=263
'}'=264
@@ -1034,6 +1034,15 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#SoftsignFunc.
def enterSoftsignFunc(self, ctx:MathExprParser.SoftsignFuncContext):
pass
# Exit a parse tree produced by MathExprParser#SoftsignFunc.
def exitSoftsignFunc(self, ctx:MathExprParser.SoftsignFuncContext):
pass
# Enter a parse tree produced by MathExprParser#SoftplusFunc.
def enterSoftplusFunc(self, ctx:MathExprParser.SoftplusFuncContext):
pass
@@ -1871,6 +1880,78 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#ZerosFunc.
def enterZerosFunc(self, ctx:MathExprParser.ZerosFuncContext):
pass
# Exit a parse tree produced by MathExprParser#ZerosFunc.
def exitZerosFunc(self, ctx:MathExprParser.ZerosFuncContext):
pass
# Enter a parse tree produced by MathExprParser#OnesFunc.
def enterOnesFunc(self, ctx:MathExprParser.OnesFuncContext):
pass
# Exit a parse tree produced by MathExprParser#OnesFunc.
def exitOnesFunc(self, ctx:MathExprParser.OnesFuncContext):
pass
# Enter a parse tree produced by MathExprParser#EyeFunc.
def enterEyeFunc(self, ctx:MathExprParser.EyeFuncContext):
pass
# Exit a parse tree produced by MathExprParser#EyeFunc.
def exitEyeFunc(self, ctx:MathExprParser.EyeFuncContext):
pass
# Enter a parse tree produced by MathExprParser#OneHotFunc.
def enterOneHotFunc(self, ctx:MathExprParser.OneHotFuncContext):
pass
# Exit a parse tree produced by MathExprParser#OneHotFunc.
def exitOneHotFunc(self, ctx:MathExprParser.OneHotFuncContext):
pass
# Enter a parse tree produced by MathExprParser#MseFunc.
def enterMseFunc(self, ctx:MathExprParser.MseFuncContext):
pass
# Exit a parse tree produced by MathExprParser#MseFunc.
def exitMseFunc(self, ctx:MathExprParser.MseFuncContext):
pass
# Enter a parse tree produced by MathExprParser#MaeFunc.
def enterMaeFunc(self, ctx:MathExprParser.MaeFuncContext):
pass
# Exit a parse tree produced by MathExprParser#MaeFunc.
def exitMaeFunc(self, ctx:MathExprParser.MaeFuncContext):
pass
# Enter a parse tree produced by MathExprParser#PsnrFunc.
def enterPsnrFunc(self, ctx:MathExprParser.PsnrFuncContext):
pass
# Exit a parse tree produced by MathExprParser#PsnrFunc.
def exitPsnrFunc(self, ctx:MathExprParser.PsnrFuncContext):
pass
# Enter a parse tree produced by MathExprParser#LeakyReluFunc.
def enterLeakyReluFunc(self, ctx:MathExprParser.LeakyReluFuncContext):
pass
# Exit a parse tree produced by MathExprParser#LeakyReluFunc.
def exitLeakyReluFunc(self, ctx:MathExprParser.LeakyReluFuncContext):
pass
# Enter a parse tree produced by MathExprParser#PadFunc.
def enterPadFunc(self, ctx:MathExprParser.PadFuncContext):
pass
File diff suppressed because it is too large Load Diff
@@ -579,6 +579,11 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#SoftsignFunc.
def visitSoftsignFunc(self, ctx:MathExprParser.SoftsignFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#SoftplusFunc.
def visitSoftplusFunc(self, ctx:MathExprParser.SoftplusFuncContext):
return self.visitChildren(ctx)
@@ -1044,6 +1049,46 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#ZerosFunc.
def visitZerosFunc(self, ctx:MathExprParser.ZerosFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#OnesFunc.
def visitOnesFunc(self, ctx:MathExprParser.OnesFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#EyeFunc.
def visitEyeFunc(self, ctx:MathExprParser.EyeFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#OneHotFunc.
def visitOneHotFunc(self, ctx:MathExprParser.OneHotFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#MseFunc.
def visitMseFunc(self, ctx:MathExprParser.MseFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#MaeFunc.
def visitMaeFunc(self, ctx:MathExprParser.MaeFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#PsnrFunc.
def visitPsnrFunc(self, ctx:MathExprParser.PsnrFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#LeakyReluFunc.
def visitLeakyReluFunc(self, ctx:MathExprParser.LeakyReluFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#PadFunc.
def visitPadFunc(self, ctx:MathExprParser.PadFuncContext):
return self.visitChildren(ctx)
+10 -1
View File
@@ -6,7 +6,7 @@ INBUILT_CONSTANTS = {
'e', 'pi'
}
INBUILT_FUNCTIONS = {
'abs', 'acos', 'acosh', 'add_key', 'added_keys', 'all', 'allclose', 'angle', 'any', 'append', 'argmax', 'argmin', 'argsort', 'as_nested', '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', 'degrees', 'diag', 'diagonal_matrix', 'dilate', 'disable_tracking', 'dist', 'distance', 'domain_warp', 'domain_warp_noise', 'dot', 'edge', 'elastic', 'elastic_ease', 'enable_tracking', 'endswith', 'entropy', 'erf', 'erfinv', 'erode', 'exp', 'expm1', 'ezconv', 'ezconvolution', 'fft', 'find', 'flatten', 'flip', 'float', 'floor', 'flow_ang', 'flow_angle', 'flow_apply', 'flow_mag', 'flow_magnitude', 'flow_to_image', 'fract', 'gamma', 'gather', 'gaussian', 'gelu', 'get_added_keys', 'get_changed_keys', 'get_removed_keys', 'get_unchanged_keys', 'get_value', 'hist', 'histogram', 'hsv_to_rgb', 'hypot', 'changed_keys', 'ifft', 'int', 'int_to_rgb', 'interpolate_area', 'interpolate_linear', 'interpolate_nearest', 'interpolate_nearest_exact', 'isclose', 'isfinite', 'isinf', 'isnan', 'join', 'keys', 'length', 'lerp', 'linspace', 'ln', 'log', 'log1p', 'log2', 'logical_and', 'logical_not', 'logical_or', 'logspace', 'lower', 'map', 'matmul', 'mean', 'median', 'mode', 'moment', 'morph_close', 'morph_open', 'motion_mask', 'nan_to_num', 'noise', 'nonzero', 'now', 'nvl', 'oklab_to_rgb', 'overlay', 'pad', 'percentile', 'perlin', 'perlin_noise', 'perm', 'permute', 'pinv', 'plasma', 'plasma_noise', 'popcnt', 'popcount', 'pow', 'prcnt', 'print', 'print_shape', 'prod', 'pshp', 'quantile', 'quartil', 'quartile', 'radians', '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_key', 'removed_keys', 'repeat', 'replace', 'reset_tracking', 'reshape', 'rgb_to_cielab', 'rgb_to_hsv', 'rgb_to_int', 'rgb_to_oklab', 'ridged', 'ridged_noise', 'rife', 'rm_key', 'roll', 'round', 'rshp', 'scatter', 'scatter_add', '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', 'stack_clear', 'stack_get', 'stack_has', 'stack_pop', 'stack_push', 'startswith', 'std', 'step', 'substr', 'substring', 'sum', 'svd', 'swap', 'swapaxes', 'tan', 'tanh', 'tensor', 'text_image', 'timestamp', 'tmax', 'tmin', 'tnorm', 'topk', 'topk_ind', 'topk_indices', 'track_off', 'track_on', 'track_reset', 'transpose', 'trim', 'turbulence', 'unchanged_keys', 'unique', 'unsqueeze', 'upper', 'var', 'voronoi', 'voronoi_noise', 'where', 'worley'
'abs', 'acos', 'acosh', 'add_key', 'added_keys', 'all', 'allclose', 'angle', 'any', 'append', 'argmax', 'argmin', 'argsort', 'as_nested', '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', 'degrees', 'diag', 'diagonal_matrix', 'dilate', 'disable_tracking', 'dist', 'distance', 'domain_warp', 'domain_warp_noise', 'dot', 'edge', 'elastic', 'elastic_ease', 'enable_tracking', 'endswith', 'entropy', 'erf', 'erfinv', 'erode', 'exp', 'expm1', 'eye', 'ezconv', 'ezconvolution', 'fft', 'find', 'flatten', 'flip', 'float', 'floor', 'flow_ang', 'flow_angle', 'flow_apply', 'flow_mag', 'flow_magnitude', 'flow_to_image', 'fract', 'gamma', 'gather', 'gaussian', 'gelu', 'get_added_keys', 'get_changed_keys', 'get_removed_keys', 'get_unchanged_keys', 'get_value', 'hist', 'histogram', 'hsv_to_rgb', 'hypot', 'changed_keys', 'ifft', 'int', 'int_to_rgb', 'interpolate_area', 'interpolate_linear', 'interpolate_nearest', 'interpolate_nearest_exact', 'isclose', 'isfinite', 'isinf', 'isnan', 'join', 'keys', 'leaky_relu', 'length', 'lerp', 'linspace', 'ln', 'log', 'log1p', 'log2', 'logical_and', 'logical_not', 'logical_or', 'logspace', 'lower', 'mae', 'map', 'matmul', 'mean', 'median', 'mode', 'moment', 'morph_close', 'morph_open', 'motion_mask', 'mse', 'nan_to_num', 'noise', 'nonzero', 'now', 'nvl', 'oklab_to_rgb', 'one_hot', 'ones', 'overlay', 'pad', 'percentile', 'perlin', 'perlin_noise', 'perm', 'permute', 'pinv', 'plasma', 'plasma_noise', 'popcnt', 'popcount', 'pow', 'prcnt', 'print', 'print_shape', 'prod', 'pshp', 'psnr', 'quantile', 'quartil', 'quartile', 'radians', '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_key', 'removed_keys', 'repeat', 'replace', 'reset_tracking', 'reshape', 'rgb_to_cielab', 'rgb_to_hsv', 'rgb_to_int', 'rgb_to_oklab', 'ridged', 'ridged_noise', 'rife', 'rm_key', 'roll', 'round', 'rshp', 'scatter', 'scatter_add', 'select', 'shape', 'shuffle', 'sigm', 'sign', 'sin', 'sine', 'sine_ease', 'singular_value_decomposition', 'sinh', 'smax', 'smin', 'smootherstep', 'smoothstep', 'snorm', 'softmax', 'softmin', 'softplus', 'softsign', 'sort', 'split', 'sqrt', 'squeeze', 'stack', 'stack_clear', 'stack_get', 'stack_has', 'stack_pop', 'stack_push', 'startswith', 'std', 'step', 'substr', 'substring', 'sum', 'svd', 'swap', 'swapaxes', 'tan', 'tanh', 'tensor', 'text_image', 'timestamp', 'tmax', 'tmin', 'tnorm', 'topk', 'topk_ind', 'topk_indices', 'track_off', 'track_on', 'track_reset', 'transpose', 'trim', 'turbulence', 'unchanged_keys', 'unique', 'unsqueeze', 'upper', 'var', 'voronoi', 'voronoi_noise', 'where', 'worley', 'zeros'
}
INBUILT_FUNCTION_META = {
@@ -60,6 +60,8 @@ INBUILT_FUNCTION_META = {
'smoothstep': {'min_args': 3, 'max_args': 3, 'snippet': 'smoothstep(x, edge0, edge1)', 'description': 'smooth interpolation between edge0 and edge1'},
'fract': {'min_args': 1, 'max_args': 1, 'snippet': 'fract(x)', 'description': 'returns the fractional part of x: x - floor(x)'},
'relu': {'min_args': 1, 'max_args': 1, 'snippet': 'relu(x)', 'description': 'applies rectified linear unit function: max(0, x)'},
'softsign': {'min_args': 1, 'max_args': 1, 'snippet': 'softsign(x)', 'description': 'applies x / (1 + abs(x)) element-wise'},
'leaky_relu': {'min_args': 1, 'max_args': 2, 'snippet': 'leaky_relu(x, negative_slope)', 'description': 'applies leaky ReLU element-wise; negative_slope defaults to 0.01'},
'softplus': {'min_args': 1, 'max_args': 1, 'snippet': 'softplus(x)', 'description': 'applies the softplus function: ln(1 + exp(x))'},
'gelu': {'min_args': 1, 'max_args': 1, 'snippet': 'gelu(x)', 'description': 'applies the Gaussian Error Linear Unit (GELU) activation function'},
'sign': {'min_args': 1, 'max_args': 1, 'snippet': 'sign(x)', 'description': 'returns the sign of x: -1, 0, or 1'},
@@ -181,6 +183,13 @@ INBUILT_FUNCTION_META = {
'bor': {'min_args': 2, 'max_args': 2, 'snippet': 'bor(x, y)', 'description': 'computes the element-wise bitwise OR of x and y'},
'bitwise_or': {'min_args': 2, 'max_args': 2, 'snippet': 'bitwise_or(x, y)', 'description': 'computes the element-wise bitwise OR of x and y'},
'tensor': {'min_args': 1, 'max_args': 3, 'snippet': 'tensor(shape, value, dtype_template)', 'description': 'creates a tensor with specified shape and optional value/type. Default value is 0 and default format FP32'},
'zeros': {'min_args': 1, 'max_args': 2, 'snippet': 'zeros(shape, dtype_template)', 'description': 'creates a zero-filled tensor on the current device'},
'ones': {'min_args': 1, 'max_args': 2, 'snippet': 'ones(shape, dtype_template)', 'description': 'creates a one-filled tensor on the current device'},
'eye': {'min_args': 1, 'max_args': 2, 'snippet': 'eye(n, dtype_template)', 'description': 'creates an n-by-n identity matrix'},
'one_hot': {'min_args': 2, 'max_args': 2, 'snippet': 'one_hot(indices, classes)', 'description': 'converts integer class indices to float32 one-hot vectors'},
'mse': {'min_args': 2, 'max_args': 3, 'snippet': 'mse(a, b, reduction)', 'description': 'mean squared error; reduction is mean (default), sum, or none'},
'mae': {'min_args': 2, 'max_args': 3, 'snippet': 'mae(a, b, reduction)', 'description': 'mean absolute error; reduction is mean (default), sum, or none'},
'psnr': {'min_args': 2, 'max_args': 3, 'snippet': 'psnr(a, b, data_range)', 'description': 'peak signal-to-noise ratio in dB; data_range defaults to 1'},
'add_key': {'min_args': 3, 'max_args': 3, 'snippet': 'add_key(dict, key, value)', 'description': 'adds or replaces a dictionary entry and returns the updated dictionary'},
'remove_key': {'min_args': 2, 'max_args': 2, 'snippet': 'remove_key(dict, key)', 'description': 'removes a dictionary entry and returns the updated dictionary'},
'rm_key': {'min_args': 2, 'max_args': 2, 'snippet': 'rm_key(dict, key)', 'description': 'removes a dictionary entry and returns the updated dictionary'},
File diff suppressed because one or more lines are too long
+377 -359
View File
@@ -46,220 +46,229 @@ STEP=45
SMOOTHSTEP=46
FRACT=47
RELU=48
SOFTPLUS=49
GELU=50
SIGN=51
DEGREES=52
RADIANS=53
LOGICAL_NOT=54
LOGICAL_AND=55
LOGICAL_OR=56
HYPOT=57
MAP=58
EZCONV=59
CONV=60
SWAP=61
TRANSPOSE=62
PERM=63
RESHAPE=64
RANGE=65
LINSPACE=66
LOGSPACE=67
TOPK=68
BOTK=69
PINV=70
SUM=71
MEAN=72
STD=73
VAR=74
PROD=75
ISCLOSE=76
ALLCLOSE=77
QUARTILE=78
PERCENTILE=79
QUANTILE=80
DOT=81
MOMENT=82
ERF=83
ERFINV=84
ANY=85
ALL=86
EDGE=87
GAUSSIAN=88
MEDIAN=89
MODE=90
CUMSUM=91
CUMPROD=92
TOPK_IND=93
BOTK_IND=94
CUBIC_EASE=95
ELASTIC_EASE=96
SINE_EASE=97
SMOOTHERSTEP=98
DIST=99
REMAP=100
COSSIM=101
COUNT=102
KEYS=103
ENABLE_TRACKING=104
DISABLE_TRACKING=105
RESET_TRACKING=106
GET_CHANGED_KEYS=107
GET_ADDED_KEYS=108
GET_REMOVED_KEYS=109
GET_UNCHANGED_KEYS=110
REPEAT=111
FLATTEN=112
APPEND=113
GET_VALUE=114
FLOW_APPLY=115
BATCH_SHUFFLE=116
MOTION_MASK=117
FLOW_TO_IMAGE=118
FLOW_MAG=119
FLOW_ANG=120
WHERE=121
HISTOGRAM=122
OVERLAY=123
PAD=124
CROSS=125
MATMUL=126
RIFE=127
BNOT=128
BITCOUNT=129
SHAPE=130
BAND=131
XOR=132
BOR=133
TENSOR=134
ADD_KEY=135
REMOVE_KEY=136
PUSH=137
POP=138
CLEAR=139
HAS=140
GET=141
CONCAT=142
STACK=143
NONZERO=144
INT=145
FLOAT=146
UPPER=147
LOWER=148
TRIM=149
SPLIT=150
JOIN=151
SUBSTRING=152
FIND=153
REPLACE=154
DILATE=155
ERODE=156
MORPH_OPEN=157
MORPH_CLOSE=158
RGB_TO_OKLAB=159
RGB_TO_CIELAB=160
OKLAB_TO_RGB=161
CIELAB_TO_RGB=162
RGB_TO_HSV=163
HSV_TO_RGB=164
INT_TO_RGB=165
RGB_TO_INT=166
INTERPOLATE_LINEAR=167
INTERPOLATE_AREA=168
INTERPOLATE_NEAREST=169
TEXT_IMAGE=170
AS_NESTED=171
SVD=172
DIAG=173
IF=174
ELSE=175
WHILE=176
FOR=177
IN=178
BREAK=179
CONTINUE=180
RETURN=181
TIMESTAMP=182
SORT=183
ARGSORT=184
ARGMIN=185
ARGMAX=186
SOFTMAX=187
SOFTMIN=188
UNIQUE=189
FLIP=190
STARTSWITH=191
ENDSWITH=192
SQUEEZE=193
UNSQUEEZE=194
ROLL=195
COV=196
CORR=197
ENTROPY=198
CROP=199
NONE=200
COORDS=201
GATHER=202
SCATTER=203
SCATTER_ADD=204
NOISE=205
RAND=206
CAUCHY=207
EXPONENTIAL=208
LOGNORMAL=209
BERNOULLI=210
POISSON=211
GAMMADIST=212
BETADIST=213
LAPLACEDIST=214
GUMBELDIST=215
WEIBULLDIST=216
CHI2DIST=217
STUDENTTDIST=218
PERLIN=219
CELLULAR=220
PLASMA=221
RIDGED=222
DOMAIN_WARP=223
PLUS=224
MINUS=225
MULT=226
DIV=227
MOD=228
POW=229
LSHIFT=230
RSHIFT=231
GE=232
GT=233
LE=234
LT=235
EQ=236
EQUEALS=237
PLUS_EQ=238
MINUS_EQ=239
MULT_EQ=240
DIV_EQ=241
MOD_EQ=242
NE=243
PIPE=244
LPAREN=245
RPAREN=246
COMMA=247
SEMICOLON=248
ARROW=249
LBRACKET=250
RBRACKET=251
QUESTION=252
COLON=253
LBRACE=254
RBRACE=255
NUMBER=256
CONSTANT=257
STRING=258
VARIABLE=259
SL_COMMENT=260
ML_COMMENT=261
WS=262
SOFTSIGN=49
LEAKY_RELU=50
SOFTPLUS=51
GELU=52
SIGN=53
DEGREES=54
RADIANS=55
LOGICAL_NOT=56
LOGICAL_AND=57
LOGICAL_OR=58
HYPOT=59
MAP=60
EZCONV=61
CONV=62
SWAP=63
TRANSPOSE=64
PERM=65
RESHAPE=66
RANGE=67
LINSPACE=68
LOGSPACE=69
TOPK=70
BOTK=71
PINV=72
SUM=73
MEAN=74
STD=75
VAR=76
PROD=77
ISCLOSE=78
ALLCLOSE=79
QUARTILE=80
PERCENTILE=81
QUANTILE=82
DOT=83
MOMENT=84
ERF=85
ERFINV=86
ANY=87
ALL=88
EDGE=89
GAUSSIAN=90
MEDIAN=91
MODE=92
CUMSUM=93
CUMPROD=94
TOPK_IND=95
BOTK_IND=96
CUBIC_EASE=97
ELASTIC_EASE=98
SINE_EASE=99
SMOOTHERSTEP=100
DIST=101
REMAP=102
COSSIM=103
COUNT=104
KEYS=105
ENABLE_TRACKING=106
DISABLE_TRACKING=107
RESET_TRACKING=108
GET_CHANGED_KEYS=109
GET_ADDED_KEYS=110
GET_REMOVED_KEYS=111
GET_UNCHANGED_KEYS=112
REPEAT=113
FLATTEN=114
APPEND=115
GET_VALUE=116
FLOW_APPLY=117
BATCH_SHUFFLE=118
MOTION_MASK=119
FLOW_TO_IMAGE=120
FLOW_MAG=121
FLOW_ANG=122
WHERE=123
HISTOGRAM=124
OVERLAY=125
PAD=126
CROSS=127
MATMUL=128
RIFE=129
BNOT=130
BITCOUNT=131
SHAPE=132
BAND=133
XOR=134
BOR=135
TENSOR=136
ZEROS=137
ONES=138
EYE=139
ONE_HOT=140
MSE=141
MAE=142
PSNR=143
ADD_KEY=144
REMOVE_KEY=145
PUSH=146
POP=147
CLEAR=148
HAS=149
GET=150
CONCAT=151
STACK=152
NONZERO=153
INT=154
FLOAT=155
UPPER=156
LOWER=157
TRIM=158
SPLIT=159
JOIN=160
SUBSTRING=161
FIND=162
REPLACE=163
DILATE=164
ERODE=165
MORPH_OPEN=166
MORPH_CLOSE=167
RGB_TO_OKLAB=168
RGB_TO_CIELAB=169
OKLAB_TO_RGB=170
CIELAB_TO_RGB=171
RGB_TO_HSV=172
HSV_TO_RGB=173
INT_TO_RGB=174
RGB_TO_INT=175
INTERPOLATE_LINEAR=176
INTERPOLATE_AREA=177
INTERPOLATE_NEAREST=178
TEXT_IMAGE=179
AS_NESTED=180
SVD=181
DIAG=182
IF=183
ELSE=184
WHILE=185
FOR=186
IN=187
BREAK=188
CONTINUE=189
RETURN=190
TIMESTAMP=191
SORT=192
ARGSORT=193
ARGMIN=194
ARGMAX=195
SOFTMAX=196
SOFTMIN=197
UNIQUE=198
FLIP=199
STARTSWITH=200
ENDSWITH=201
SQUEEZE=202
UNSQUEEZE=203
ROLL=204
COV=205
CORR=206
ENTROPY=207
CROP=208
NONE=209
COORDS=210
GATHER=211
SCATTER=212
SCATTER_ADD=213
NOISE=214
RAND=215
CAUCHY=216
EXPONENTIAL=217
LOGNORMAL=218
BERNOULLI=219
POISSON=220
GAMMADIST=221
BETADIST=222
LAPLACEDIST=223
GUMBELDIST=224
WEIBULLDIST=225
CHI2DIST=226
STUDENTTDIST=227
PERLIN=228
CELLULAR=229
PLASMA=230
RIDGED=231
DOMAIN_WARP=232
PLUS=233
MINUS=234
MULT=235
DIV=236
MOD=237
POW=238
LSHIFT=239
RSHIFT=240
GE=241
GT=242
LE=243
LT=244
EQ=245
EQUEALS=246
PLUS_EQ=247
MINUS_EQ=248
MULT_EQ=249
DIV_EQ=250
MOD_EQ=251
NE=252
PIPE=253
LPAREN=254
RPAREN=255
COMMA=256
SEMICOLON=257
ARROW=258
LBRACKET=259
RBRACKET=260
QUESTION=261
COLON=262
LBRACE=263
RBRACE=264
NUMBER=265
CONSTANT=266
STRING=267
VARIABLE=268
SL_COMMENT=269
ML_COMMENT=270
WS=271
'sin'=1
'cos'=2
'tan'=3
@@ -306,148 +315,157 @@ WS=262
'smoothstep'=46
'fract'=47
'relu'=48
'softplus'=49
'gelu'=50
'sign'=51
'degrees'=52
'radians'=53
'logical_not'=54
'logical_and'=55
'logical_or'=56
'hypot'=57
'map'=58
'swap'=61
'range'=65
'linspace'=66
'logspace'=67
'topk'=68
'botk'=69
'pinv'=70
'sum'=71
'mean'=72
'std'=73
'var'=74
'prod'=75
'isclose'=76
'allclose'=77
'quantile'=80
'dot'=81
'moment'=82
'erf'=83
'erfinv'=84
'any'=85
'all'=86
'edge'=87
'median'=89
'mode'=90
'cumsum'=91
'cumprod'=92
'smootherstep'=98
'remap'=100
'keys'=103
'repeat'=111
'flatten'=112
'append'=113
'get_value'=114
'flow_apply'=115
'motion_mask'=117
'flow_to_image'=118
'where'=121
'overlay'=123
'pad'=124
'cross'=125
'matmul'=126
'rife'=127
'shape'=130
'tensor'=134
'add_key'=135
'stack_push'=137
'stack_pop'=138
'stack_clear'=139
'stack_has'=140
'stack_get'=141
'stack'=143
'nonzero'=144
'int'=145
'float'=146
'upper'=147
'lower'=148
'trim'=149
'split'=150
'join'=151
'find'=153
'replace'=154
'dilate'=155
'erode'=156
'morph_open'=157
'morph_close'=158
'rgb_to_oklab'=159
'rgb_to_cielab'=160
'oklab_to_rgb'=161
'cielab_to_rgb'=162
'rgb_to_hsv'=163
'hsv_to_rgb'=164
'int_to_rgb'=165
'rgb_to_int'=166
'interpolate_linear'=167
'interpolate_area'=168
'text_image'=170
'if'=174
'else'=175
'while'=176
'for'=177
'in'=178
'break'=179
'continue'=180
'return'=181
'sort'=183
'argsort'=184
'argmin'=185
'argmax'=186
'softmax'=187
'softmin'=188
'unique'=189
'flip'=190
'startswith'=191
'endswith'=192
'squeeze'=193
'unsqueeze'=194
'roll'=195
'cov'=196
'entropy'=198
'crop'=199
'gather'=202
'scatter'=203
'scatter_add'=204
'+'=224
'-'=225
'*'=226
'/'=227
'%'=228
'^'=229
'<<'=230
'>>'=231
'>='=232
'>'=233
'<='=234
'<'=235
'=='=236
'='=237
'+='=238
'-='=239
'*='=240
'/='=241
'%='=242
'!='=243
'|'=244
'('=245
')'=246
','=247
';'=248
'->'=249
'['=250
']'=251
'?'=252
':'=253
'{'=254
'}'=255
'softsign'=49
'leaky_relu'=50
'softplus'=51
'gelu'=52
'sign'=53
'degrees'=54
'radians'=55
'logical_not'=56
'logical_and'=57
'logical_or'=58
'hypot'=59
'map'=60
'swap'=63
'range'=67
'linspace'=68
'logspace'=69
'topk'=70
'botk'=71
'pinv'=72
'sum'=73
'mean'=74
'std'=75
'var'=76
'prod'=77
'isclose'=78
'allclose'=79
'quantile'=82
'dot'=83
'moment'=84
'erf'=85
'erfinv'=86
'any'=87
'all'=88
'edge'=89
'median'=91
'mode'=92
'cumsum'=93
'cumprod'=94
'smootherstep'=100
'remap'=102
'keys'=105
'repeat'=113
'flatten'=114
'append'=115
'get_value'=116
'flow_apply'=117
'motion_mask'=119
'flow_to_image'=120
'where'=123
'overlay'=125
'pad'=126
'cross'=127
'matmul'=128
'rife'=129
'shape'=132
'tensor'=136
'zeros'=137
'ones'=138
'eye'=139
'one_hot'=140
'mse'=141
'mae'=142
'psnr'=143
'add_key'=144
'stack_push'=146
'stack_pop'=147
'stack_clear'=148
'stack_has'=149
'stack_get'=150
'stack'=152
'nonzero'=153
'int'=154
'float'=155
'upper'=156
'lower'=157
'trim'=158
'split'=159
'join'=160
'find'=162
'replace'=163
'dilate'=164
'erode'=165
'morph_open'=166
'morph_close'=167
'rgb_to_oklab'=168
'rgb_to_cielab'=169
'oklab_to_rgb'=170
'cielab_to_rgb'=171
'rgb_to_hsv'=172
'hsv_to_rgb'=173
'int_to_rgb'=174
'rgb_to_int'=175
'interpolate_linear'=176
'interpolate_area'=177
'text_image'=179
'if'=183
'else'=184
'while'=185
'for'=186
'in'=187
'break'=188
'continue'=189
'return'=190
'sort'=192
'argsort'=193
'argmin'=194
'argmax'=195
'softmax'=196
'softmin'=197
'unique'=198
'flip'=199
'startswith'=200
'endswith'=201
'squeeze'=202
'unsqueeze'=203
'roll'=204
'cov'=205
'entropy'=207
'crop'=208
'gather'=211
'scatter'=212
'scatter_add'=213
'+'=233
'-'=234
'*'=235
'/'=236
'%'=237
'^'=238
'<<'=239
'>>'=240
'>='=241
'>'=242
'<='=243
'<'=244
'=='=245
'='=246
'+='=247
'-='=248
'*='=249
'/='=250
'%='=251
'!='=252
'|'=253
'('=254
')'=255
','=256
';'=257
'->'=258
'['=259
']'=260
'?'=261
':'=262
'{'=263
'}'=264
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+377 -359
View File
@@ -46,220 +46,229 @@ STEP=45
SMOOTHSTEP=46
FRACT=47
RELU=48
SOFTPLUS=49
GELU=50
SIGN=51
DEGREES=52
RADIANS=53
LOGICAL_NOT=54
LOGICAL_AND=55
LOGICAL_OR=56
HYPOT=57
MAP=58
EZCONV=59
CONV=60
SWAP=61
TRANSPOSE=62
PERM=63
RESHAPE=64
RANGE=65
LINSPACE=66
LOGSPACE=67
TOPK=68
BOTK=69
PINV=70
SUM=71
MEAN=72
STD=73
VAR=74
PROD=75
ISCLOSE=76
ALLCLOSE=77
QUARTILE=78
PERCENTILE=79
QUANTILE=80
DOT=81
MOMENT=82
ERF=83
ERFINV=84
ANY=85
ALL=86
EDGE=87
GAUSSIAN=88
MEDIAN=89
MODE=90
CUMSUM=91
CUMPROD=92
TOPK_IND=93
BOTK_IND=94
CUBIC_EASE=95
ELASTIC_EASE=96
SINE_EASE=97
SMOOTHERSTEP=98
DIST=99
REMAP=100
COSSIM=101
COUNT=102
KEYS=103
ENABLE_TRACKING=104
DISABLE_TRACKING=105
RESET_TRACKING=106
GET_CHANGED_KEYS=107
GET_ADDED_KEYS=108
GET_REMOVED_KEYS=109
GET_UNCHANGED_KEYS=110
REPEAT=111
FLATTEN=112
APPEND=113
GET_VALUE=114
FLOW_APPLY=115
BATCH_SHUFFLE=116
MOTION_MASK=117
FLOW_TO_IMAGE=118
FLOW_MAG=119
FLOW_ANG=120
WHERE=121
HISTOGRAM=122
OVERLAY=123
PAD=124
CROSS=125
MATMUL=126
RIFE=127
BNOT=128
BITCOUNT=129
SHAPE=130
BAND=131
XOR=132
BOR=133
TENSOR=134
ADD_KEY=135
REMOVE_KEY=136
PUSH=137
POP=138
CLEAR=139
HAS=140
GET=141
CONCAT=142
STACK=143
NONZERO=144
INT=145
FLOAT=146
UPPER=147
LOWER=148
TRIM=149
SPLIT=150
JOIN=151
SUBSTRING=152
FIND=153
REPLACE=154
DILATE=155
ERODE=156
MORPH_OPEN=157
MORPH_CLOSE=158
RGB_TO_OKLAB=159
RGB_TO_CIELAB=160
OKLAB_TO_RGB=161
CIELAB_TO_RGB=162
RGB_TO_HSV=163
HSV_TO_RGB=164
INT_TO_RGB=165
RGB_TO_INT=166
INTERPOLATE_LINEAR=167
INTERPOLATE_AREA=168
INTERPOLATE_NEAREST=169
TEXT_IMAGE=170
AS_NESTED=171
SVD=172
DIAG=173
IF=174
ELSE=175
WHILE=176
FOR=177
IN=178
BREAK=179
CONTINUE=180
RETURN=181
TIMESTAMP=182
SORT=183
ARGSORT=184
ARGMIN=185
ARGMAX=186
SOFTMAX=187
SOFTMIN=188
UNIQUE=189
FLIP=190
STARTSWITH=191
ENDSWITH=192
SQUEEZE=193
UNSQUEEZE=194
ROLL=195
COV=196
CORR=197
ENTROPY=198
CROP=199
NONE=200
COORDS=201
GATHER=202
SCATTER=203
SCATTER_ADD=204
NOISE=205
RAND=206
CAUCHY=207
EXPONENTIAL=208
LOGNORMAL=209
BERNOULLI=210
POISSON=211
GAMMADIST=212
BETADIST=213
LAPLACEDIST=214
GUMBELDIST=215
WEIBULLDIST=216
CHI2DIST=217
STUDENTTDIST=218
PERLIN=219
CELLULAR=220
PLASMA=221
RIDGED=222
DOMAIN_WARP=223
PLUS=224
MINUS=225
MULT=226
DIV=227
MOD=228
POW=229
LSHIFT=230
RSHIFT=231
GE=232
GT=233
LE=234
LT=235
EQ=236
EQUEALS=237
PLUS_EQ=238
MINUS_EQ=239
MULT_EQ=240
DIV_EQ=241
MOD_EQ=242
NE=243
PIPE=244
LPAREN=245
RPAREN=246
COMMA=247
SEMICOLON=248
ARROW=249
LBRACKET=250
RBRACKET=251
QUESTION=252
COLON=253
LBRACE=254
RBRACE=255
NUMBER=256
CONSTANT=257
STRING=258
VARIABLE=259
SL_COMMENT=260
ML_COMMENT=261
WS=262
SOFTSIGN=49
LEAKY_RELU=50
SOFTPLUS=51
GELU=52
SIGN=53
DEGREES=54
RADIANS=55
LOGICAL_NOT=56
LOGICAL_AND=57
LOGICAL_OR=58
HYPOT=59
MAP=60
EZCONV=61
CONV=62
SWAP=63
TRANSPOSE=64
PERM=65
RESHAPE=66
RANGE=67
LINSPACE=68
LOGSPACE=69
TOPK=70
BOTK=71
PINV=72
SUM=73
MEAN=74
STD=75
VAR=76
PROD=77
ISCLOSE=78
ALLCLOSE=79
QUARTILE=80
PERCENTILE=81
QUANTILE=82
DOT=83
MOMENT=84
ERF=85
ERFINV=86
ANY=87
ALL=88
EDGE=89
GAUSSIAN=90
MEDIAN=91
MODE=92
CUMSUM=93
CUMPROD=94
TOPK_IND=95
BOTK_IND=96
CUBIC_EASE=97
ELASTIC_EASE=98
SINE_EASE=99
SMOOTHERSTEP=100
DIST=101
REMAP=102
COSSIM=103
COUNT=104
KEYS=105
ENABLE_TRACKING=106
DISABLE_TRACKING=107
RESET_TRACKING=108
GET_CHANGED_KEYS=109
GET_ADDED_KEYS=110
GET_REMOVED_KEYS=111
GET_UNCHANGED_KEYS=112
REPEAT=113
FLATTEN=114
APPEND=115
GET_VALUE=116
FLOW_APPLY=117
BATCH_SHUFFLE=118
MOTION_MASK=119
FLOW_TO_IMAGE=120
FLOW_MAG=121
FLOW_ANG=122
WHERE=123
HISTOGRAM=124
OVERLAY=125
PAD=126
CROSS=127
MATMUL=128
RIFE=129
BNOT=130
BITCOUNT=131
SHAPE=132
BAND=133
XOR=134
BOR=135
TENSOR=136
ZEROS=137
ONES=138
EYE=139
ONE_HOT=140
MSE=141
MAE=142
PSNR=143
ADD_KEY=144
REMOVE_KEY=145
PUSH=146
POP=147
CLEAR=148
HAS=149
GET=150
CONCAT=151
STACK=152
NONZERO=153
INT=154
FLOAT=155
UPPER=156
LOWER=157
TRIM=158
SPLIT=159
JOIN=160
SUBSTRING=161
FIND=162
REPLACE=163
DILATE=164
ERODE=165
MORPH_OPEN=166
MORPH_CLOSE=167
RGB_TO_OKLAB=168
RGB_TO_CIELAB=169
OKLAB_TO_RGB=170
CIELAB_TO_RGB=171
RGB_TO_HSV=172
HSV_TO_RGB=173
INT_TO_RGB=174
RGB_TO_INT=175
INTERPOLATE_LINEAR=176
INTERPOLATE_AREA=177
INTERPOLATE_NEAREST=178
TEXT_IMAGE=179
AS_NESTED=180
SVD=181
DIAG=182
IF=183
ELSE=184
WHILE=185
FOR=186
IN=187
BREAK=188
CONTINUE=189
RETURN=190
TIMESTAMP=191
SORT=192
ARGSORT=193
ARGMIN=194
ARGMAX=195
SOFTMAX=196
SOFTMIN=197
UNIQUE=198
FLIP=199
STARTSWITH=200
ENDSWITH=201
SQUEEZE=202
UNSQUEEZE=203
ROLL=204
COV=205
CORR=206
ENTROPY=207
CROP=208
NONE=209
COORDS=210
GATHER=211
SCATTER=212
SCATTER_ADD=213
NOISE=214
RAND=215
CAUCHY=216
EXPONENTIAL=217
LOGNORMAL=218
BERNOULLI=219
POISSON=220
GAMMADIST=221
BETADIST=222
LAPLACEDIST=223
GUMBELDIST=224
WEIBULLDIST=225
CHI2DIST=226
STUDENTTDIST=227
PERLIN=228
CELLULAR=229
PLASMA=230
RIDGED=231
DOMAIN_WARP=232
PLUS=233
MINUS=234
MULT=235
DIV=236
MOD=237
POW=238
LSHIFT=239
RSHIFT=240
GE=241
GT=242
LE=243
LT=244
EQ=245
EQUEALS=246
PLUS_EQ=247
MINUS_EQ=248
MULT_EQ=249
DIV_EQ=250
MOD_EQ=251
NE=252
PIPE=253
LPAREN=254
RPAREN=255
COMMA=256
SEMICOLON=257
ARROW=258
LBRACKET=259
RBRACKET=260
QUESTION=261
COLON=262
LBRACE=263
RBRACE=264
NUMBER=265
CONSTANT=266
STRING=267
VARIABLE=268
SL_COMMENT=269
ML_COMMENT=270
WS=271
'sin'=1
'cos'=2
'tan'=3
@@ -306,148 +315,157 @@ WS=262
'smoothstep'=46
'fract'=47
'relu'=48
'softplus'=49
'gelu'=50
'sign'=51
'degrees'=52
'radians'=53
'logical_not'=54
'logical_and'=55
'logical_or'=56
'hypot'=57
'map'=58
'swap'=61
'range'=65
'linspace'=66
'logspace'=67
'topk'=68
'botk'=69
'pinv'=70
'sum'=71
'mean'=72
'std'=73
'var'=74
'prod'=75
'isclose'=76
'allclose'=77
'quantile'=80
'dot'=81
'moment'=82
'erf'=83
'erfinv'=84
'any'=85
'all'=86
'edge'=87
'median'=89
'mode'=90
'cumsum'=91
'cumprod'=92
'smootherstep'=98
'remap'=100
'keys'=103
'repeat'=111
'flatten'=112
'append'=113
'get_value'=114
'flow_apply'=115
'motion_mask'=117
'flow_to_image'=118
'where'=121
'overlay'=123
'pad'=124
'cross'=125
'matmul'=126
'rife'=127
'shape'=130
'tensor'=134
'add_key'=135
'stack_push'=137
'stack_pop'=138
'stack_clear'=139
'stack_has'=140
'stack_get'=141
'stack'=143
'nonzero'=144
'int'=145
'float'=146
'upper'=147
'lower'=148
'trim'=149
'split'=150
'join'=151
'find'=153
'replace'=154
'dilate'=155
'erode'=156
'morph_open'=157
'morph_close'=158
'rgb_to_oklab'=159
'rgb_to_cielab'=160
'oklab_to_rgb'=161
'cielab_to_rgb'=162
'rgb_to_hsv'=163
'hsv_to_rgb'=164
'int_to_rgb'=165
'rgb_to_int'=166
'interpolate_linear'=167
'interpolate_area'=168
'text_image'=170
'if'=174
'else'=175
'while'=176
'for'=177
'in'=178
'break'=179
'continue'=180
'return'=181
'sort'=183
'argsort'=184
'argmin'=185
'argmax'=186
'softmax'=187
'softmin'=188
'unique'=189
'flip'=190
'startswith'=191
'endswith'=192
'squeeze'=193
'unsqueeze'=194
'roll'=195
'cov'=196
'entropy'=198
'crop'=199
'gather'=202
'scatter'=203
'scatter_add'=204
'+'=224
'-'=225
'*'=226
'/'=227
'%'=228
'^'=229
'<<'=230
'>>'=231
'>='=232
'>'=233
'<='=234
'<'=235
'=='=236
'='=237
'+='=238
'-='=239
'*='=240
'/='=241
'%='=242
'!='=243
'|'=244
'('=245
')'=246
','=247
';'=248
'->'=249
'['=250
']'=251
'?'=252
':'=253
'{'=254
'}'=255
'softsign'=49
'leaky_relu'=50
'softplus'=51
'gelu'=52
'sign'=53
'degrees'=54
'radians'=55
'logical_not'=56
'logical_and'=57
'logical_or'=58
'hypot'=59
'map'=60
'swap'=63
'range'=67
'linspace'=68
'logspace'=69
'topk'=70
'botk'=71
'pinv'=72
'sum'=73
'mean'=74
'std'=75
'var'=76
'prod'=77
'isclose'=78
'allclose'=79
'quantile'=82
'dot'=83
'moment'=84
'erf'=85
'erfinv'=86
'any'=87
'all'=88
'edge'=89
'median'=91
'mode'=92
'cumsum'=93
'cumprod'=94
'smootherstep'=100
'remap'=102
'keys'=105
'repeat'=113
'flatten'=114
'append'=115
'get_value'=116
'flow_apply'=117
'motion_mask'=119
'flow_to_image'=120
'where'=123
'overlay'=125
'pad'=126
'cross'=127
'matmul'=128
'rife'=129
'shape'=132
'tensor'=136
'zeros'=137
'ones'=138
'eye'=139
'one_hot'=140
'mse'=141
'mae'=142
'psnr'=143
'add_key'=144
'stack_push'=146
'stack_pop'=147
'stack_clear'=148
'stack_has'=149
'stack_get'=150
'stack'=152
'nonzero'=153
'int'=154
'float'=155
'upper'=156
'lower'=157
'trim'=158
'split'=159
'join'=160
'find'=162
'replace'=163
'dilate'=164
'erode'=165
'morph_open'=166
'morph_close'=167
'rgb_to_oklab'=168
'rgb_to_cielab'=169
'oklab_to_rgb'=170
'cielab_to_rgb'=171
'rgb_to_hsv'=172
'hsv_to_rgb'=173
'int_to_rgb'=174
'rgb_to_int'=175
'interpolate_linear'=176
'interpolate_area'=177
'text_image'=179
'if'=183
'else'=184
'while'=185
'for'=186
'in'=187
'break'=188
'continue'=189
'return'=190
'sort'=192
'argsort'=193
'argmin'=194
'argmax'=195
'softmax'=196
'softmin'=197
'unique'=198
'flip'=199
'startswith'=200
'endswith'=201
'squeeze'=202
'unsqueeze'=203
'roll'=204
'cov'=205
'entropy'=207
'crop'=208
'gather'=211
'scatter'=212
'scatter_add'=213
'+'=233
'-'=234
'*'=235
'/'=236
'%'=237
'^'=238
'<<'=239
'>>'=240
'>='=241
'>'=242
'<='=243
'<'=244
'=='=245
'='=246
'+='=247
'-='=248
'*='=249
'/='=250
'%='=251
'!='=252
'|'=253
'('=254
')'=255
','=256
';'=257
'->'=258
'['=259
']'=260
'?'=261
':'=262
'{'=263
'}'=264
@@ -1034,6 +1034,15 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#SoftsignFunc.
def enterSoftsignFunc(self, ctx:MathExprParser.SoftsignFuncContext):
pass
# Exit a parse tree produced by MathExprParser#SoftsignFunc.
def exitSoftsignFunc(self, ctx:MathExprParser.SoftsignFuncContext):
pass
# Enter a parse tree produced by MathExprParser#SoftplusFunc.
def enterSoftplusFunc(self, ctx:MathExprParser.SoftplusFuncContext):
pass
@@ -1871,6 +1880,78 @@ class MathExprListener(ParseTreeListener):
pass
# Enter a parse tree produced by MathExprParser#ZerosFunc.
def enterZerosFunc(self, ctx:MathExprParser.ZerosFuncContext):
pass
# Exit a parse tree produced by MathExprParser#ZerosFunc.
def exitZerosFunc(self, ctx:MathExprParser.ZerosFuncContext):
pass
# Enter a parse tree produced by MathExprParser#OnesFunc.
def enterOnesFunc(self, ctx:MathExprParser.OnesFuncContext):
pass
# Exit a parse tree produced by MathExprParser#OnesFunc.
def exitOnesFunc(self, ctx:MathExprParser.OnesFuncContext):
pass
# Enter a parse tree produced by MathExprParser#EyeFunc.
def enterEyeFunc(self, ctx:MathExprParser.EyeFuncContext):
pass
# Exit a parse tree produced by MathExprParser#EyeFunc.
def exitEyeFunc(self, ctx:MathExprParser.EyeFuncContext):
pass
# Enter a parse tree produced by MathExprParser#OneHotFunc.
def enterOneHotFunc(self, ctx:MathExprParser.OneHotFuncContext):
pass
# Exit a parse tree produced by MathExprParser#OneHotFunc.
def exitOneHotFunc(self, ctx:MathExprParser.OneHotFuncContext):
pass
# Enter a parse tree produced by MathExprParser#MseFunc.
def enterMseFunc(self, ctx:MathExprParser.MseFuncContext):
pass
# Exit a parse tree produced by MathExprParser#MseFunc.
def exitMseFunc(self, ctx:MathExprParser.MseFuncContext):
pass
# Enter a parse tree produced by MathExprParser#MaeFunc.
def enterMaeFunc(self, ctx:MathExprParser.MaeFuncContext):
pass
# Exit a parse tree produced by MathExprParser#MaeFunc.
def exitMaeFunc(self, ctx:MathExprParser.MaeFuncContext):
pass
# Enter a parse tree produced by MathExprParser#PsnrFunc.
def enterPsnrFunc(self, ctx:MathExprParser.PsnrFuncContext):
pass
# Exit a parse tree produced by MathExprParser#PsnrFunc.
def exitPsnrFunc(self, ctx:MathExprParser.PsnrFuncContext):
pass
# Enter a parse tree produced by MathExprParser#LeakyReluFunc.
def enterLeakyReluFunc(self, ctx:MathExprParser.LeakyReluFuncContext):
pass
# Exit a parse tree produced by MathExprParser#LeakyReluFunc.
def exitLeakyReluFunc(self, ctx:MathExprParser.LeakyReluFuncContext):
pass
# Enter a parse tree produced by MathExprParser#PadFunc.
def enterPadFunc(self, ctx:MathExprParser.PadFuncContext):
pass
File diff suppressed because one or more lines are too long
@@ -579,6 +579,11 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#SoftsignFunc.
def visitSoftsignFunc(self, ctx:MathExprParser.SoftsignFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#SoftplusFunc.
def visitSoftplusFunc(self, ctx:MathExprParser.SoftplusFuncContext):
return self.visitChildren(ctx)
@@ -1044,6 +1049,46 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#ZerosFunc.
def visitZerosFunc(self, ctx:MathExprParser.ZerosFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#OnesFunc.
def visitOnesFunc(self, ctx:MathExprParser.OnesFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#EyeFunc.
def visitEyeFunc(self, ctx:MathExprParser.EyeFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#OneHotFunc.
def visitOneHotFunc(self, ctx:MathExprParser.OneHotFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#MseFunc.
def visitMseFunc(self, ctx:MathExprParser.MseFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#MaeFunc.
def visitMaeFunc(self, ctx:MathExprParser.MaeFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#PsnrFunc.
def visitPsnrFunc(self, ctx:MathExprParser.PsnrFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#LeakyReluFunc.
def visitLeakyReluFunc(self, ctx:MathExprParser.LeakyReluFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#PadFunc.
def visitPadFunc(self, ctx:MathExprParser.PadFuncContext):
return self.visitChildren(ctx)
+43
View File
@@ -2,6 +2,7 @@ import torch
import sys
import os
import math
import pytest
# Ensure test runner usage (Visual Studio) can import the package regardless of working dir.
_here = os.path.abspath(os.path.dirname(__file__))
@@ -109,6 +110,48 @@ def test_added_math_and_logical_functions():
assert torch.allclose(eval_expr("logical_or(A, B)", {"A": torch.tensor([0.0, 1.0]), "B": torch.tensor([0.0, 0.0])}), torch.tensor([0.0, 1.0]))
assert torch.allclose(eval_expr("degrees(T)", {"T": torch.tensor([0.0, math.pi])}), torch.tensor([0.0, 180.0]))
def test_tensor_constructors_and_one_hot():
template = torch.empty((), dtype=torch.float64)
zeros = eval_expr("zeros([2, 3], T)", {"T": template})
assert zeros.shape == (2, 3)
assert zeros.dtype == torch.float64
assert torch.count_nonzero(zeros) == 0
assert torch.equal(eval_expr("ones([2])"), torch.ones(2))
assert torch.equal(eval_expr("eye(3)"), torch.eye(3))
assert torch.equal(eval_expr("eye(2, T)", {"T": template}), torch.eye(2, dtype=torch.float64))
assert torch.equal(
eval_expr("one_hot([0, 2], 3)"),
torch.tensor([[1.0, 0.0, 0.0], [0.0, 0.0, 1.0]]),
)
assert "one_hot" in INBUILT_FUNCTIONS
with pytest.raises(ValueError, match="outside the class range"):
eval_expr("one_hot([3], 3)")
with pytest.raises(ValueError, match="must be integers"):
eval_expr("one_hot([0.5], 3)")
def test_loss_metrics_and_psnr():
a = torch.tensor([1.0, 3.0])
b = torch.tensor([2.0, 1.0])
variables = {"a": a, "b": b}
assert math.isclose(eval_expr("mse(a, b)", variables).item(), 2.5)
assert math.isclose(eval_expr("mse(a, b, 'sum')", variables).item(), 5.0)
assert torch.equal(eval_expr("mse(a, b, 'none')", variables), torch.tensor([1.0, 4.0]))
assert math.isclose(eval_expr("mae(a, b)", variables).item(), 1.5)
assert math.isclose(eval_expr("mae(a, b, 'sum')", variables).item(), 3.0)
assert math.isclose(eval_expr("psnr(a, b)", variables).item(), 10.0 * math.log10(0.4), rel_tol=1e-6)
assert math.isinf(eval_expr("psnr(a, a)", variables).item())
assert "mse" in INBUILT_FUNCTIONS and "mae" in INBUILT_FUNCTIONS and "psnr" in INBUILT_FUNCTIONS
with pytest.raises(ValueError, match="reduction must be"):
eval_expr("mse(a, b, 'median')", variables)
with pytest.raises(ValueError, match="data_range must be positive"):
eval_expr("psnr(a, b, 0)", variables)
def test_leaky_relu_and_softsign():
assert eval_expr("leaky_relu([-2, 0, 2])") == [-0.02, 0.0, 2.0]
assert eval_expr("leaky_relu(-2, 0.2)") == -0.4
assert eval_expr("softsign([-2, 0, 2])") == [-2.0 / 3.0, 0.0, 2.0 / 3.0]
assert "leaky_relu" in INBUILT_FUNCTIONS and "softsign" in INBUILT_FUNCTIONS
if __name__ == "__main__":
test_logic_functions()
test_spatial_functions()
+10 -1
View File
@@ -9,7 +9,7 @@ export const CONSTANTS = new Set([
]);
export const FUNCTIONS = new Set([
"abs", "acos", "acosh", "add_key", "added_keys", "all", "allclose", "angle", "any", "append", "argmax", "argmin", "argsort", "as_nested", "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", "degrees", "diag", "diagonal_matrix", "dilate", "disable_tracking", "dist", "distance", "domain_warp", "domain_warp_noise", "dot", "edge", "elastic", "elastic_ease", "enable_tracking", "endswith", "entropy", "erf", "erfinv", "erode", "exp", "expm1", "ezconv", "ezconvolution", "fft", "find", "flatten", "flip", "float", "floor", "flow_ang", "flow_angle", "flow_apply", "flow_mag", "flow_magnitude", "flow_to_image", "fract", "gamma", "gather", "gaussian", "gelu", "get_added_keys", "get_changed_keys", "get_removed_keys", "get_unchanged_keys", "get_value", "hist", "histogram", "hsv_to_rgb", "hypot", "changed_keys", "ifft", "int", "int_to_rgb", "interpolate_area", "interpolate_linear", "interpolate_nearest", "interpolate_nearest_exact", "isclose", "isfinite", "isinf", "isnan", "join", "keys", "length", "lerp", "linspace", "ln", "log", "log1p", "log2", "logical_and", "logical_not", "logical_or", "logspace", "lower", "map", "matmul", "mean", "median", "mode", "moment", "morph_close", "morph_open", "motion_mask", "nan_to_num", "noise", "nonzero", "now", "nvl", "oklab_to_rgb", "overlay", "pad", "percentile", "perlin", "perlin_noise", "perm", "permute", "pinv", "plasma", "plasma_noise", "popcnt", "popcount", "pow", "prcnt", "print", "print_shape", "prod", "pshp", "quantile", "quartil", "quartile", "radians", "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_key", "removed_keys", "repeat", "replace", "reset_tracking", "reshape", "rgb_to_cielab", "rgb_to_hsv", "rgb_to_int", "rgb_to_oklab", "ridged", "ridged_noise", "rife", "rm_key", "roll", "round", "rshp", "scatter", "scatter_add", "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", "stack_clear", "stack_get", "stack_has", "stack_pop", "stack_push", "startswith", "std", "step", "substr", "substring", "sum", "svd", "swap", "swapaxes", "tan", "tanh", "tensor", "text_image", "timestamp", "tmax", "tmin", "tnorm", "topk", "topk_ind", "topk_indices", "track_off", "track_on", "track_reset", "transpose", "trim", "turbulence", "unchanged_keys", "unique", "unsqueeze", "upper", "var", "voronoi", "voronoi_noise", "where", "worley"
"abs", "acos", "acosh", "add_key", "added_keys", "all", "allclose", "angle", "any", "append", "argmax", "argmin", "argsort", "as_nested", "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", "degrees", "diag", "diagonal_matrix", "dilate", "disable_tracking", "dist", "distance", "domain_warp", "domain_warp_noise", "dot", "edge", "elastic", "elastic_ease", "enable_tracking", "endswith", "entropy", "erf", "erfinv", "erode", "exp", "expm1", "eye", "ezconv", "ezconvolution", "fft", "find", "flatten", "flip", "float", "floor", "flow_ang", "flow_angle", "flow_apply", "flow_mag", "flow_magnitude", "flow_to_image", "fract", "gamma", "gather", "gaussian", "gelu", "get_added_keys", "get_changed_keys", "get_removed_keys", "get_unchanged_keys", "get_value", "hist", "histogram", "hsv_to_rgb", "hypot", "changed_keys", "ifft", "int", "int_to_rgb", "interpolate_area", "interpolate_linear", "interpolate_nearest", "interpolate_nearest_exact", "isclose", "isfinite", "isinf", "isnan", "join", "keys", "leaky_relu", "length", "lerp", "linspace", "ln", "log", "log1p", "log2", "logical_and", "logical_not", "logical_or", "logspace", "lower", "mae", "map", "matmul", "mean", "median", "mode", "moment", "morph_close", "morph_open", "motion_mask", "mse", "nan_to_num", "noise", "nonzero", "now", "nvl", "oklab_to_rgb", "one_hot", "ones", "overlay", "pad", "percentile", "perlin", "perlin_noise", "perm", "permute", "pinv", "plasma", "plasma_noise", "popcnt", "popcount", "pow", "prcnt", "print", "print_shape", "prod", "pshp", "psnr", "quantile", "quartil", "quartile", "radians", "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_key", "removed_keys", "repeat", "replace", "reset_tracking", "reshape", "rgb_to_cielab", "rgb_to_hsv", "rgb_to_int", "rgb_to_oklab", "ridged", "ridged_noise", "rife", "rm_key", "roll", "round", "rshp", "scatter", "scatter_add", "select", "shape", "shuffle", "sigm", "sign", "sin", "sine", "sine_ease", "singular_value_decomposition", "sinh", "smax", "smin", "smootherstep", "smoothstep", "snorm", "softmax", "softmin", "softplus", "softsign", "sort", "split", "sqrt", "squeeze", "stack", "stack_clear", "stack_get", "stack_has", "stack_pop", "stack_push", "startswith", "std", "step", "substr", "substring", "sum", "svd", "swap", "swapaxes", "tan", "tanh", "tensor", "text_image", "timestamp", "tmax", "tmin", "tnorm", "topk", "topk_ind", "topk_indices", "track_off", "track_on", "track_reset", "transpose", "trim", "turbulence", "unchanged_keys", "unique", "unsqueeze", "upper", "var", "voronoi", "voronoi_noise", "where", "worley", "zeros"
]);
export const FUNCTION_META = {
@@ -63,6 +63,8 @@ export const FUNCTION_META = {
"smoothstep": { minArgs: 3, maxArgs: 3, snippet: "smoothstep(x, edge0, edge1)", description: "smooth interpolation between edge0 and edge1" },
"fract": { minArgs: 1, maxArgs: 1, snippet: "fract(x)", description: "returns the fractional part of x: x - floor(x)" },
"relu": { minArgs: 1, maxArgs: 1, snippet: "relu(x)", description: "applies rectified linear unit function: max(0, x)" },
"softsign": { minArgs: 1, maxArgs: 1, snippet: "softsign(x)", description: "applies x / (1 + abs(x)) element-wise" },
"leaky_relu": { minArgs: 1, maxArgs: 2, snippet: "leaky_relu(x, negative_slope)", description: "applies leaky ReLU element-wise; negative_slope defaults to 0.01" },
"softplus": { minArgs: 1, maxArgs: 1, snippet: "softplus(x)", description: "applies the softplus function: ln(1 + exp(x))" },
"gelu": { minArgs: 1, maxArgs: 1, snippet: "gelu(x)", description: "applies the Gaussian Error Linear Unit (GELU) activation function" },
"sign": { minArgs: 1, maxArgs: 1, snippet: "sign(x)", description: "returns the sign of x: -1, 0, or 1" },
@@ -184,6 +186,13 @@ export const FUNCTION_META = {
"bor": { minArgs: 2, maxArgs: 2, snippet: "bor(x, y)", description: "computes the element-wise bitwise OR of x and y" },
"bitwise_or": { minArgs: 2, maxArgs: 2, snippet: "bitwise_or(x, y)", description: "computes the element-wise bitwise OR of x and y" },
"tensor": { minArgs: 1, maxArgs: 3, snippet: "tensor(shape, value, dtype_template)", description: "creates a tensor with specified shape and optional value/type. Default value is 0 and default format FP32" },
"zeros": { minArgs: 1, maxArgs: 2, snippet: "zeros(shape, dtype_template)", description: "creates a zero-filled tensor on the current device" },
"ones": { minArgs: 1, maxArgs: 2, snippet: "ones(shape, dtype_template)", description: "creates a one-filled tensor on the current device" },
"eye": { minArgs: 1, maxArgs: 2, snippet: "eye(n, dtype_template)", description: "creates an n-by-n identity matrix" },
"one_hot": { minArgs: 2, maxArgs: 2, snippet: "one_hot(indices, classes)", description: "converts integer class indices to float32 one-hot vectors" },
"mse": { minArgs: 2, maxArgs: 3, snippet: "mse(a, b, reduction)", description: "mean squared error; reduction is mean (default), sum, or none" },
"mae": { minArgs: 2, maxArgs: 3, snippet: "mae(a, b, reduction)", description: "mean absolute error; reduction is mean (default), sum, or none" },
"psnr": { minArgs: 2, maxArgs: 3, snippet: "psnr(a, b, data_range)", description: "peak signal-to-noise ratio in dB; data_range defaults to 1" },
"add_key": { minArgs: 3, maxArgs: 3, snippet: "add_key(dict, key, value)", description: "adds or replaces a dictionary entry and returns the updated dictionary" },
"remove_key": { minArgs: 2, maxArgs: 2, snippet: "remove_key(dict, key)", description: "removes a dictionary entry and returns the updated dictionary" },
"rm_key": { minArgs: 2, maxArgs: 2, snippet: "rm_key(dict, key)", description: "removes a dictionary entry and returns the updated dictionary" },