added the permute which does not rearrange dims.

This commit is contained in:
mcDandy
2026-01-09 23:06:35 +01:00
parent d3ed28041a
commit 9e55ed1209
10 changed files with 759 additions and 1354 deletions
+5 -3
View File
@@ -92,11 +92,13 @@ You can also get the node from comfy manager under the name of More math.
- `map(tensor, c1, ...)`: Remaps `tensor` using source coordinates.
- Up to 3 coordinate mapping functions can be provided which map to the last (up to 3) dimensions of the tensor. Rest uses identity mapping.
- `conv(tensor, kw, [kh], [kd], k_expr)`: Applies a convolution to `tensor`.
- `ezconvolution(tensor, kw, [kh], [kd], k_expr)` or `ezconv`: Applies a convolution to `tensor`. Automatically permutes tensor to try to make it work with various inputs without the need to permute manually.
- `k_expr` can be a math expression (using `kX`, `kY`, `kZ`) or a list literal.
- `convolution(tensor, kw, [kh], [kd], k_expr)` or `conv`: Applies a convolution to `tensor`. Does not perform automatic permutations. Expects standard PyTorch layout `(Batch, Channel, Spatial...)`.
- `k_expr` can be a math expression (using `kX`, `kY`, `kZ`) or a list literal.
- `permute(tensor, dims)`: Rearranges the dimensions of the tensor. (e.g., `permute(a, [2, 3, 0, 1])`)
- `reshape(tensor, shape)`: Reshapes the tensor to a new shape. (e.g., `reshape(a, [S0*S1, S2, S3])`)
- `permute(tensor, dims)` or `perm`: Rearranges the dimensions of the tensor. (e.g., `perm(a, [2, 3, 0, 1])`)
- `reshape(tensor, shape)` or `rshp`: Reshapes the tensor to a new shape. (e.g., `rshp(a, [S0*S1, S2, S3])`)
### FFT (Tensor Only)
+6 -6
View File
@@ -89,7 +89,6 @@ func1
| SOFTPLUS '(' expr ')' # SoftplusFunc
| GELU '(' expr ')' # GeluFunc
| SIGN '(' expr ')' # SignFunc
| PRINT_SHAPE_L '(' expr ')' # PrintShapeFunc
| PRINT_SHAPE '(' expr ')' # PrintShapeFunc
| PINV '(' expr ')' # PinvFunc
;
@@ -121,6 +120,7 @@ funcN
: SMIN '(' expr (',' expr)* ')' # SMinFunc
| SMAX '(' expr (',' expr)* ')' # SMaxFunc
| MAP '(' expr (',' expr)+ ')' # MapFunc
| EZCONV '(' expr (',' expr)+ ')' # EzConvFunc
| CONV '(' expr (',' expr)+ ')' # ConvFunc
| PERM '(' expr ',' expr ')' # PermuteFunc
| RESHAPE '(' expr ',' expr ')' # ReshapeFunc
@@ -163,8 +163,7 @@ SFFT : 'fft';
SIFFT : 'ifft';
ANGL : 'angle';
PRNT : 'print';
PRINT_SHAPE_L : 'print_shape';
PRINT_SHAPE : 'pshp';
PRINT_SHAPE : 'print_shape' | 'pshp';
LERP : 'lerp';
STEP : 'step';
SMOOTHSTEP : 'smoothstep';
@@ -174,10 +173,11 @@ SOFTPLUS : 'softplus';
GELU : 'gelu';
SIGN : 'sign';
MAP : 'map';
CONV : 'conv';
EZCONV : 'ezconvolution' | 'ezconv';
CONV : 'convolution' | 'conv';
SWAP : 'swap';
PERM : 'permute';
RESHAPE : 'reshape';
PERM : 'permute' | 'perm';
RESHAPE : 'reshape' | 'rshp';
RANGE : 'range';
TOPK : 'topk';
BOTK : 'botk';
File diff suppressed because one or more lines are too long
+20 -25
View File
@@ -38,17 +38,17 @@ SFFT=37
SIFFT=38
ANGL=39
PRNT=40
PRINT_SHAPE_L=41
PRINT_SHAPE=42
LERP=43
STEP=44
SMOOTHSTEP=45
FRACT=46
RELU=47
SOFTPLUS=48
GELU=49
SIGN=50
MAP=51
PRINT_SHAPE=41
LERP=42
STEP=43
SMOOTHSTEP=44
FRACT=45
RELU=46
SOFTPLUS=47
GELU=48
SIGN=49
MAP=50
EZCONV=51
CONV=52
SWAP=53
PERM=54
@@ -114,21 +114,16 @@ WS=76
'ifft'=38
'angle'=39
'print'=40
'print_shape'=41
'pshp'=42
'lerp'=43
'step'=44
'smoothstep'=45
'fract'=46
'relu'=47
'softplus'=48
'gelu'=49
'sign'=50
'map'=51
'conv'=52
'lerp'=42
'step'=43
'smoothstep'=44
'fract'=45
'relu'=46
'softplus'=47
'gelu'=48
'sign'=49
'map'=50
'swap'=53
'permute'=54
'reshape'=55
'range'=56
'topk'=57
'botk'=58
File diff suppressed because one or more lines are too long
+200 -186
View File
@@ -1,4 +1,4 @@
# Generated from ./MathExpr.g4 by ANTLR 4.13.2
# Generated from MathExpr.g4 by ANTLR 4.13.2
from antlr4 import *
from io import StringIO
import sys
@@ -10,7 +10,7 @@ else:
def serializedATN():
return [
4,0,76,523,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
4,0,76,566,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,
2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,
13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,
19,2,20,7,20,2,21,7,21,2,22,7,22,2,23,7,23,2,24,7,24,2,25,7,25,2,
@@ -36,164 +36,180 @@ def serializedATN():
33,1,33,1,34,1,34,1,34,1,34,1,34,1,35,1,35,1,35,1,35,1,35,1,35,1,
36,1,36,1,36,1,36,1,37,1,37,1,37,1,37,1,37,1,38,1,38,1,38,1,38,1,
38,1,38,1,39,1,39,1,39,1,39,1,39,1,39,1,40,1,40,1,40,1,40,1,40,1,
40,1,40,1,40,1,40,1,40,1,40,1,40,1,41,1,41,1,41,1,41,1,41,1,42,1,
42,1,42,1,42,1,42,1,43,1,43,1,43,1,43,1,43,1,44,1,44,1,44,1,44,1,
44,1,44,1,44,1,44,1,44,1,44,1,44,1,45,1,45,1,45,1,45,1,45,1,45,1,
46,1,46,1,46,1,46,1,46,1,47,1,47,1,47,1,47,1,47,1,47,1,47,1,47,1,
47,1,48,1,48,1,48,1,48,1,48,1,49,1,49,1,49,1,49,1,49,1,50,1,50,1,
50,1,50,1,51,1,51,1,51,1,51,1,51,1,52,1,52,1,52,1,52,1,52,1,53,1,
53,1,53,1,53,1,53,1,53,1,53,1,53,1,54,1,54,1,54,1,54,1,54,1,54,1,
54,1,54,1,55,1,55,1,55,1,55,1,55,1,55,1,56,1,56,1,56,1,56,1,56,1,
57,1,57,1,57,1,57,1,57,1,58,1,58,1,58,1,58,1,58,1,59,1,59,1,60,1,
60,1,61,1,61,1,62,1,62,1,63,1,63,1,64,1,64,1,65,1,65,1,65,1,66,1,
66,1,67,1,67,1,67,1,68,1,68,1,69,1,69,1,69,1,70,1,70,1,70,1,71,1,
71,1,72,1,72,1,72,1,72,1,72,3,72,495,8,72,1,73,4,73,498,8,73,11,
73,12,73,499,1,73,1,73,4,73,504,8,73,11,73,12,73,505,3,73,508,8,
73,1,74,1,74,5,74,512,8,74,10,74,12,74,515,9,74,1,75,4,75,518,8,
75,11,75,12,75,519,1,75,1,75,0,0,76,1,1,3,2,5,3,7,4,9,5,11,6,13,
7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,29,15,31,16,33,17,35,18,
37,19,39,20,41,21,43,22,45,23,47,24,49,25,51,26,53,27,55,28,57,29,
59,30,61,31,63,32,65,33,67,34,69,35,71,36,73,37,75,38,77,39,79,40,
81,41,83,42,85,43,87,44,89,45,91,46,93,47,95,48,97,49,99,50,101,
51,103,52,105,53,107,54,109,55,111,56,113,57,115,58,117,59,119,60,
121,61,123,62,125,63,127,64,129,65,131,66,133,67,135,68,137,69,139,
70,141,71,143,72,145,73,147,74,149,75,151,76,1,0,5,2,0,69,69,101,
101,1,0,48,57,3,0,65,90,95,95,97,122,4,0,48,57,65,90,95,95,97,122,
3,0,9,10,13,13,32,32,529,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,
1,0,0,0,0,9,1,0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,
1,0,0,0,0,19,1,0,0,0,0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,
1,0,0,0,0,29,1,0,0,0,0,31,1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,
1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,
1,0,0,0,0,49,1,0,0,0,0,51,1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,57,
1,0,0,0,0,59,1,0,0,0,0,61,1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,67,
1,0,0,0,0,69,1,0,0,0,0,71,1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,77,
1,0,0,0,0,79,1,0,0,0,0,81,1,0,0,0,0,83,1,0,0,0,0,85,1,0,0,0,0,87,
1,0,0,0,0,89,1,0,0,0,0,91,1,0,0,0,0,93,1,0,0,0,0,95,1,0,0,0,0,97,
1,0,0,0,0,99,1,0,0,0,0,101,1,0,0,0,0,103,1,0,0,0,0,105,1,0,0,0,0,
107,1,0,0,0,0,109,1,0,0,0,0,111,1,0,0,0,0,113,1,0,0,0,0,115,1,0,
0,0,0,117,1,0,0,0,0,119,1,0,0,0,0,121,1,0,0,0,0,123,1,0,0,0,0,125,
1,0,0,0,0,127,1,0,0,0,0,129,1,0,0,0,0,131,1,0,0,0,0,133,1,0,0,0,
0,135,1,0,0,0,0,137,1,0,0,0,0,139,1,0,0,0,0,141,1,0,0,0,0,143,1,
0,0,0,0,145,1,0,0,0,0,147,1,0,0,0,0,149,1,0,0,0,0,151,1,0,0,0,1,
153,1,0,0,0,3,155,1,0,0,0,5,157,1,0,0,0,7,159,1,0,0,0,9,161,1,0,
0,0,11,163,1,0,0,0,13,167,1,0,0,0,15,171,1,0,0,0,17,175,1,0,0,0,
19,180,1,0,0,0,21,185,1,0,0,0,23,190,1,0,0,0,25,196,1,0,0,0,27,201,
1,0,0,0,29,206,1,0,0,0,31,211,1,0,0,0,33,217,1,0,0,0,35,223,1,0,
0,0,37,229,1,0,0,0,39,233,1,0,0,0,41,238,1,0,0,0,43,241,1,0,0,0,
45,245,1,0,0,0,47,249,1,0,0,0,49,254,1,0,0,0,51,259,1,0,0,0,53,264,
1,0,0,0,55,269,1,0,0,0,57,275,1,0,0,0,59,281,1,0,0,0,61,287,1,0,
0,0,63,292,1,0,0,0,65,298,1,0,0,0,67,304,1,0,0,0,69,308,1,0,0,0,
71,313,1,0,0,0,73,319,1,0,0,0,75,323,1,0,0,0,77,328,1,0,0,0,79,334,
1,0,0,0,81,340,1,0,0,0,83,352,1,0,0,0,85,357,1,0,0,0,87,362,1,0,
0,0,89,367,1,0,0,0,91,378,1,0,0,0,93,384,1,0,0,0,95,389,1,0,0,0,
97,398,1,0,0,0,99,403,1,0,0,0,101,408,1,0,0,0,103,412,1,0,0,0,105,
417,1,0,0,0,107,422,1,0,0,0,109,430,1,0,0,0,111,438,1,0,0,0,113,
444,1,0,0,0,115,449,1,0,0,0,117,454,1,0,0,0,119,459,1,0,0,0,121,
461,1,0,0,0,123,463,1,0,0,0,125,465,1,0,0,0,127,467,1,0,0,0,129,
469,1,0,0,0,131,471,1,0,0,0,133,474,1,0,0,0,135,476,1,0,0,0,137,
479,1,0,0,0,139,481,1,0,0,0,141,484,1,0,0,0,143,487,1,0,0,0,145,
494,1,0,0,0,147,497,1,0,0,0,149,509,1,0,0,0,151,517,1,0,0,0,153,
154,5,40,0,0,154,2,1,0,0,0,155,156,5,41,0,0,156,4,1,0,0,0,157,158,
5,91,0,0,158,6,1,0,0,0,159,160,5,44,0,0,160,8,1,0,0,0,161,162,5,
93,0,0,162,10,1,0,0,0,163,164,5,115,0,0,164,165,5,105,0,0,165,166,
5,110,0,0,166,12,1,0,0,0,167,168,5,99,0,0,168,169,5,111,0,0,169,
170,5,115,0,0,170,14,1,0,0,0,171,172,5,116,0,0,172,173,5,97,0,0,
173,174,5,110,0,0,174,16,1,0,0,0,175,176,5,97,0,0,176,177,5,115,
0,0,177,178,5,105,0,0,178,179,5,110,0,0,179,18,1,0,0,0,180,181,5,
97,0,0,181,182,5,99,0,0,182,183,5,111,0,0,183,184,5,115,0,0,184,
20,1,0,0,0,185,186,5,97,0,0,186,187,5,116,0,0,187,188,5,97,0,0,188,
189,5,110,0,0,189,22,1,0,0,0,190,191,5,97,0,0,191,192,5,116,0,0,
192,193,5,97,0,0,193,194,5,110,0,0,194,195,5,50,0,0,195,24,1,0,0,
0,196,197,5,115,0,0,197,198,5,105,0,0,198,199,5,110,0,0,199,200,
5,104,0,0,200,26,1,0,0,0,201,202,5,99,0,0,202,203,5,111,0,0,203,
204,5,115,0,0,204,205,5,104,0,0,205,28,1,0,0,0,206,207,5,116,0,0,
207,208,5,97,0,0,208,209,5,110,0,0,209,210,5,104,0,0,210,30,1,0,
0,0,211,212,5,97,0,0,212,213,5,115,0,0,213,214,5,105,0,0,214,215,
5,110,0,0,215,216,5,104,0,0,216,32,1,0,0,0,217,218,5,97,0,0,218,
219,5,99,0,0,219,220,5,111,0,0,220,221,5,115,0,0,221,222,5,104,0,
0,222,34,1,0,0,0,223,224,5,97,0,0,224,225,5,116,0,0,225,226,5,97,
0,0,226,227,5,110,0,0,227,228,5,104,0,0,228,36,1,0,0,0,229,230,5,
97,0,0,230,231,5,98,0,0,231,232,5,115,0,0,232,38,1,0,0,0,233,234,
5,115,0,0,234,235,5,113,0,0,235,236,5,114,0,0,236,237,5,116,0,0,
237,40,1,0,0,0,238,239,5,108,0,0,239,240,5,110,0,0,240,42,1,0,0,
0,241,242,5,108,0,0,242,243,5,111,0,0,243,244,5,103,0,0,244,44,1,
0,0,0,245,246,5,101,0,0,246,247,5,120,0,0,247,248,5,112,0,0,248,
46,1,0,0,0,249,250,5,115,0,0,250,251,5,109,0,0,251,252,5,105,0,0,
252,253,5,110,0,0,253,48,1,0,0,0,254,255,5,115,0,0,255,256,5,109,
0,0,256,257,5,97,0,0,257,258,5,120,0,0,258,50,1,0,0,0,259,260,5,
116,0,0,260,261,5,109,0,0,261,262,5,105,0,0,262,263,5,110,0,0,263,
52,1,0,0,0,264,265,5,116,0,0,265,266,5,109,0,0,266,267,5,97,0,0,
267,268,5,120,0,0,268,54,1,0,0,0,269,270,5,116,0,0,270,271,5,110,
0,0,271,272,5,111,0,0,272,273,5,114,0,0,273,274,5,109,0,0,274,56,
1,0,0,0,275,276,5,115,0,0,276,277,5,110,0,0,277,278,5,111,0,0,278,
279,5,114,0,0,279,280,5,109,0,0,280,58,1,0,0,0,281,282,5,102,0,0,
282,283,5,108,0,0,283,284,5,111,0,0,284,285,5,111,0,0,285,286,5,
114,0,0,286,60,1,0,0,0,287,288,5,99,0,0,288,289,5,101,0,0,289,290,
5,105,0,0,290,291,5,108,0,0,291,62,1,0,0,0,292,293,5,114,0,0,293,
294,5,111,0,0,294,295,5,117,0,0,295,296,5,110,0,0,296,297,5,100,
0,0,297,64,1,0,0,0,298,299,5,103,0,0,299,300,5,97,0,0,300,301,5,
109,0,0,301,302,5,109,0,0,302,303,5,97,0,0,303,66,1,0,0,0,304,305,
5,112,0,0,305,306,5,111,0,0,306,307,5,119,0,0,307,68,1,0,0,0,308,
309,5,115,0,0,309,310,5,105,0,0,310,311,5,103,0,0,311,312,5,109,
0,0,312,70,1,0,0,0,313,314,5,99,0,0,314,315,5,108,0,0,315,316,5,
97,0,0,316,317,5,109,0,0,317,318,5,112,0,0,318,72,1,0,0,0,319,320,
5,102,0,0,320,321,5,102,0,0,321,322,5,116,0,0,322,74,1,0,0,0,323,
324,5,105,0,0,324,325,5,102,0,0,325,326,5,102,0,0,326,327,5,116,
0,0,327,76,1,0,0,0,328,329,5,97,0,0,329,330,5,110,0,0,330,331,5,
103,0,0,331,332,5,108,0,0,332,333,5,101,0,0,333,78,1,0,0,0,334,335,
5,112,0,0,335,336,5,114,0,0,336,337,5,105,0,0,337,338,5,110,0,0,
338,339,5,116,0,0,339,80,1,0,0,0,340,341,5,112,0,0,341,342,5,114,
0,0,342,343,5,105,0,0,343,344,5,110,0,0,344,345,5,116,0,0,345,346,
5,95,0,0,346,347,5,115,0,0,347,348,5,104,0,0,348,349,5,97,0,0,349,
350,5,112,0,0,350,351,5,101,0,0,351,82,1,0,0,0,352,353,5,112,0,0,
353,354,5,115,0,0,354,355,5,104,0,0,355,356,5,112,0,0,356,84,1,0,
0,0,357,358,5,108,0,0,358,359,5,101,0,0,359,360,5,114,0,0,360,361,
5,112,0,0,361,86,1,0,0,0,362,363,5,115,0,0,363,364,5,116,0,0,364,
365,5,101,0,0,365,366,5,112,0,0,366,88,1,0,0,0,367,368,5,115,0,0,
368,369,5,109,0,0,369,370,5,111,0,0,370,371,5,111,0,0,371,372,5,
116,0,0,372,373,5,104,0,0,373,374,5,115,0,0,374,375,5,116,0,0,375,
376,5,101,0,0,376,377,5,112,0,0,377,90,1,0,0,0,378,379,5,102,0,0,
379,380,5,114,0,0,380,381,5,97,0,0,381,382,5,99,0,0,382,383,5,116,
0,0,383,92,1,0,0,0,384,385,5,114,0,0,385,386,5,101,0,0,386,387,5,
108,0,0,387,388,5,117,0,0,388,94,1,0,0,0,389,390,5,115,0,0,390,391,
5,111,0,0,391,392,5,102,0,0,392,393,5,116,0,0,393,394,5,112,0,0,
394,395,5,108,0,0,395,396,5,117,0,0,396,397,5,115,0,0,397,96,1,0,
0,0,398,399,5,103,0,0,399,400,5,101,0,0,400,401,5,108,0,0,401,402,
5,117,0,0,402,98,1,0,0,0,403,404,5,115,0,0,404,405,5,105,0,0,405,
406,5,103,0,0,406,407,5,110,0,0,407,100,1,0,0,0,408,409,5,109,0,
0,409,410,5,97,0,0,410,411,5,112,0,0,411,102,1,0,0,0,412,413,5,99,
0,0,413,414,5,111,0,0,414,415,5,110,0,0,415,416,5,118,0,0,416,104,
1,0,0,0,417,418,5,115,0,0,418,419,5,119,0,0,419,420,5,97,0,0,420,
421,5,112,0,0,421,106,1,0,0,0,422,423,5,112,0,0,423,424,5,101,0,
0,424,425,5,114,0,0,425,426,5,109,0,0,426,427,5,117,0,0,427,428,
5,116,0,0,428,429,5,101,0,0,429,108,1,0,0,0,430,431,5,114,0,0,431,
432,5,101,0,0,432,433,5,115,0,0,433,434,5,104,0,0,434,435,5,97,0,
0,435,436,5,112,0,0,436,437,5,101,0,0,437,110,1,0,0,0,438,439,5,
114,0,0,439,440,5,97,0,0,440,441,5,110,0,0,441,442,5,103,0,0,442,
443,5,101,0,0,443,112,1,0,0,0,444,445,5,116,0,0,445,446,5,111,0,
0,446,447,5,112,0,0,447,448,5,107,0,0,448,114,1,0,0,0,449,450,5,
98,0,0,450,451,5,111,0,0,451,452,5,116,0,0,452,453,5,107,0,0,453,
116,1,0,0,0,454,455,5,112,0,0,455,456,5,105,0,0,456,457,5,110,0,
0,457,458,5,118,0,0,458,118,1,0,0,0,459,460,5,43,0,0,460,120,1,0,
0,0,461,462,5,45,0,0,462,122,1,0,0,0,463,464,5,42,0,0,464,124,1,
0,0,0,465,466,5,47,0,0,466,126,1,0,0,0,467,468,5,37,0,0,468,128,
1,0,0,0,469,470,5,94,0,0,470,130,1,0,0,0,471,472,5,62,0,0,472,473,
5,61,0,0,473,132,1,0,0,0,474,475,5,62,0,0,475,134,1,0,0,0,476,477,
5,60,0,0,477,478,5,61,0,0,478,136,1,0,0,0,479,480,5,60,0,0,480,138,
1,0,0,0,481,482,5,61,0,0,482,483,5,61,0,0,483,140,1,0,0,0,484,485,
5,33,0,0,485,486,5,61,0,0,486,142,1,0,0,0,487,488,5,124,0,0,488,
144,1,0,0,0,489,490,5,112,0,0,490,495,5,105,0,0,491,492,5,80,0,0,
492,495,5,73,0,0,493,495,7,0,0,0,494,489,1,0,0,0,494,491,1,0,0,0,
494,493,1,0,0,0,495,146,1,0,0,0,496,498,7,1,0,0,497,496,1,0,0,0,
498,499,1,0,0,0,499,497,1,0,0,0,499,500,1,0,0,0,500,507,1,0,0,0,
501,503,5,46,0,0,502,504,7,1,0,0,503,502,1,0,0,0,504,505,1,0,0,0,
505,503,1,0,0,0,505,506,1,0,0,0,506,508,1,0,0,0,507,501,1,0,0,0,
507,508,1,0,0,0,508,148,1,0,0,0,509,513,7,2,0,0,510,512,7,3,0,0,
511,510,1,0,0,0,512,515,1,0,0,0,513,511,1,0,0,0,513,514,1,0,0,0,
514,150,1,0,0,0,515,513,1,0,0,0,516,518,7,4,0,0,517,516,1,0,0,0,
518,519,1,0,0,0,519,517,1,0,0,0,519,520,1,0,0,0,520,521,1,0,0,0,
521,522,6,75,0,0,522,152,1,0,0,0,7,0,494,499,505,507,513,519,1,6,
0,0
40,1,40,1,40,1,40,1,40,1,40,1,40,1,40,1,40,1,40,3,40,356,8,40,1,
41,1,41,1,41,1,41,1,41,1,42,1,42,1,42,1,42,1,42,1,43,1,43,1,43,1,
43,1,43,1,43,1,43,1,43,1,43,1,43,1,43,1,44,1,44,1,44,1,44,1,44,1,
44,1,45,1,45,1,45,1,45,1,45,1,46,1,46,1,46,1,46,1,46,1,46,1,46,1,
46,1,46,1,47,1,47,1,47,1,47,1,47,1,48,1,48,1,48,1,48,1,48,1,49,1,
49,1,49,1,49,1,50,1,50,1,50,1,50,1,50,1,50,1,50,1,50,1,50,1,50,1,
50,1,50,1,50,1,50,1,50,1,50,1,50,1,50,1,50,3,50,432,8,50,1,51,1,
51,1,51,1,51,1,51,1,51,1,51,1,51,1,51,1,51,1,51,1,51,1,51,1,51,1,
51,3,51,449,8,51,1,52,1,52,1,52,1,52,1,52,1,53,1,53,1,53,1,53,1,
53,1,53,1,53,1,53,1,53,1,53,1,53,3,53,467,8,53,1,54,1,54,1,54,1,
54,1,54,1,54,1,54,1,54,1,54,1,54,1,54,3,54,480,8,54,1,55,1,55,1,
55,1,55,1,55,1,55,1,56,1,56,1,56,1,56,1,56,1,57,1,57,1,57,1,57,1,
57,1,58,1,58,1,58,1,58,1,58,1,59,1,59,1,60,1,60,1,61,1,61,1,62,1,
62,1,63,1,63,1,64,1,64,1,65,1,65,1,65,1,66,1,66,1,67,1,67,1,67,1,
68,1,68,1,69,1,69,1,69,1,70,1,70,1,70,1,71,1,71,1,72,1,72,1,72,1,
72,1,72,3,72,538,8,72,1,73,4,73,541,8,73,11,73,12,73,542,1,73,1,
73,4,73,547,8,73,11,73,12,73,548,3,73,551,8,73,1,74,1,74,5,74,555,
8,74,10,74,12,74,558,9,74,1,75,4,75,561,8,75,11,75,12,75,562,1,75,
1,75,0,0,76,1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,
23,12,25,13,27,14,29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,
45,23,47,24,49,25,51,26,53,27,55,28,57,29,59,30,61,31,63,32,65,33,
67,34,69,35,71,36,73,37,75,38,77,39,79,40,81,41,83,42,85,43,87,44,
89,45,91,46,93,47,95,48,97,49,99,50,101,51,103,52,105,53,107,54,
109,55,111,56,113,57,115,58,117,59,119,60,121,61,123,62,125,63,127,
64,129,65,131,66,133,67,135,68,137,69,139,70,141,71,143,72,145,73,
147,74,149,75,151,76,1,0,5,2,0,69,69,101,101,1,0,48,57,3,0,65,90,
95,95,97,122,4,0,48,57,65,90,95,95,97,122,3,0,9,10,13,13,32,32,577,
0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,0,0,0,0,11,
1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,0,21,
1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,
1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,
1,0,0,0,0,43,1,0,0,0,0,45,1,0,0,0,0,47,1,0,0,0,0,49,1,0,0,0,0,51,
1,0,0,0,0,53,1,0,0,0,0,55,1,0,0,0,0,57,1,0,0,0,0,59,1,0,0,0,0,61,
1,0,0,0,0,63,1,0,0,0,0,65,1,0,0,0,0,67,1,0,0,0,0,69,1,0,0,0,0,71,
1,0,0,0,0,73,1,0,0,0,0,75,1,0,0,0,0,77,1,0,0,0,0,79,1,0,0,0,0,81,
1,0,0,0,0,83,1,0,0,0,0,85,1,0,0,0,0,87,1,0,0,0,0,89,1,0,0,0,0,91,
1,0,0,0,0,93,1,0,0,0,0,95,1,0,0,0,0,97,1,0,0,0,0,99,1,0,0,0,0,101,
1,0,0,0,0,103,1,0,0,0,0,105,1,0,0,0,0,107,1,0,0,0,0,109,1,0,0,0,
0,111,1,0,0,0,0,113,1,0,0,0,0,115,1,0,0,0,0,117,1,0,0,0,0,119,1,
0,0,0,0,121,1,0,0,0,0,123,1,0,0,0,0,125,1,0,0,0,0,127,1,0,0,0,0,
129,1,0,0,0,0,131,1,0,0,0,0,133,1,0,0,0,0,135,1,0,0,0,0,137,1,0,
0,0,0,139,1,0,0,0,0,141,1,0,0,0,0,143,1,0,0,0,0,145,1,0,0,0,0,147,
1,0,0,0,0,149,1,0,0,0,0,151,1,0,0,0,1,153,1,0,0,0,3,155,1,0,0,0,
5,157,1,0,0,0,7,159,1,0,0,0,9,161,1,0,0,0,11,163,1,0,0,0,13,167,
1,0,0,0,15,171,1,0,0,0,17,175,1,0,0,0,19,180,1,0,0,0,21,185,1,0,
0,0,23,190,1,0,0,0,25,196,1,0,0,0,27,201,1,0,0,0,29,206,1,0,0,0,
31,211,1,0,0,0,33,217,1,0,0,0,35,223,1,0,0,0,37,229,1,0,0,0,39,233,
1,0,0,0,41,238,1,0,0,0,43,241,1,0,0,0,45,245,1,0,0,0,47,249,1,0,
0,0,49,254,1,0,0,0,51,259,1,0,0,0,53,264,1,0,0,0,55,269,1,0,0,0,
57,275,1,0,0,0,59,281,1,0,0,0,61,287,1,0,0,0,63,292,1,0,0,0,65,298,
1,0,0,0,67,304,1,0,0,0,69,308,1,0,0,0,71,313,1,0,0,0,73,319,1,0,
0,0,75,323,1,0,0,0,77,328,1,0,0,0,79,334,1,0,0,0,81,355,1,0,0,0,
83,357,1,0,0,0,85,362,1,0,0,0,87,367,1,0,0,0,89,378,1,0,0,0,91,384,
1,0,0,0,93,389,1,0,0,0,95,398,1,0,0,0,97,403,1,0,0,0,99,408,1,0,
0,0,101,431,1,0,0,0,103,448,1,0,0,0,105,450,1,0,0,0,107,466,1,0,
0,0,109,479,1,0,0,0,111,481,1,0,0,0,113,487,1,0,0,0,115,492,1,0,
0,0,117,497,1,0,0,0,119,502,1,0,0,0,121,504,1,0,0,0,123,506,1,0,
0,0,125,508,1,0,0,0,127,510,1,0,0,0,129,512,1,0,0,0,131,514,1,0,
0,0,133,517,1,0,0,0,135,519,1,0,0,0,137,522,1,0,0,0,139,524,1,0,
0,0,141,527,1,0,0,0,143,530,1,0,0,0,145,537,1,0,0,0,147,540,1,0,
0,0,149,552,1,0,0,0,151,560,1,0,0,0,153,154,5,40,0,0,154,2,1,0,0,
0,155,156,5,41,0,0,156,4,1,0,0,0,157,158,5,91,0,0,158,6,1,0,0,0,
159,160,5,44,0,0,160,8,1,0,0,0,161,162,5,93,0,0,162,10,1,0,0,0,163,
164,5,115,0,0,164,165,5,105,0,0,165,166,5,110,0,0,166,12,1,0,0,0,
167,168,5,99,0,0,168,169,5,111,0,0,169,170,5,115,0,0,170,14,1,0,
0,0,171,172,5,116,0,0,172,173,5,97,0,0,173,174,5,110,0,0,174,16,
1,0,0,0,175,176,5,97,0,0,176,177,5,115,0,0,177,178,5,105,0,0,178,
179,5,110,0,0,179,18,1,0,0,0,180,181,5,97,0,0,181,182,5,99,0,0,182,
183,5,111,0,0,183,184,5,115,0,0,184,20,1,0,0,0,185,186,5,97,0,0,
186,187,5,116,0,0,187,188,5,97,0,0,188,189,5,110,0,0,189,22,1,0,
0,0,190,191,5,97,0,0,191,192,5,116,0,0,192,193,5,97,0,0,193,194,
5,110,0,0,194,195,5,50,0,0,195,24,1,0,0,0,196,197,5,115,0,0,197,
198,5,105,0,0,198,199,5,110,0,0,199,200,5,104,0,0,200,26,1,0,0,0,
201,202,5,99,0,0,202,203,5,111,0,0,203,204,5,115,0,0,204,205,5,104,
0,0,205,28,1,0,0,0,206,207,5,116,0,0,207,208,5,97,0,0,208,209,5,
110,0,0,209,210,5,104,0,0,210,30,1,0,0,0,211,212,5,97,0,0,212,213,
5,115,0,0,213,214,5,105,0,0,214,215,5,110,0,0,215,216,5,104,0,0,
216,32,1,0,0,0,217,218,5,97,0,0,218,219,5,99,0,0,219,220,5,111,0,
0,220,221,5,115,0,0,221,222,5,104,0,0,222,34,1,0,0,0,223,224,5,97,
0,0,224,225,5,116,0,0,225,226,5,97,0,0,226,227,5,110,0,0,227,228,
5,104,0,0,228,36,1,0,0,0,229,230,5,97,0,0,230,231,5,98,0,0,231,232,
5,115,0,0,232,38,1,0,0,0,233,234,5,115,0,0,234,235,5,113,0,0,235,
236,5,114,0,0,236,237,5,116,0,0,237,40,1,0,0,0,238,239,5,108,0,0,
239,240,5,110,0,0,240,42,1,0,0,0,241,242,5,108,0,0,242,243,5,111,
0,0,243,244,5,103,0,0,244,44,1,0,0,0,245,246,5,101,0,0,246,247,5,
120,0,0,247,248,5,112,0,0,248,46,1,0,0,0,249,250,5,115,0,0,250,251,
5,109,0,0,251,252,5,105,0,0,252,253,5,110,0,0,253,48,1,0,0,0,254,
255,5,115,0,0,255,256,5,109,0,0,256,257,5,97,0,0,257,258,5,120,0,
0,258,50,1,0,0,0,259,260,5,116,0,0,260,261,5,109,0,0,261,262,5,105,
0,0,262,263,5,110,0,0,263,52,1,0,0,0,264,265,5,116,0,0,265,266,5,
109,0,0,266,267,5,97,0,0,267,268,5,120,0,0,268,54,1,0,0,0,269,270,
5,116,0,0,270,271,5,110,0,0,271,272,5,111,0,0,272,273,5,114,0,0,
273,274,5,109,0,0,274,56,1,0,0,0,275,276,5,115,0,0,276,277,5,110,
0,0,277,278,5,111,0,0,278,279,5,114,0,0,279,280,5,109,0,0,280,58,
1,0,0,0,281,282,5,102,0,0,282,283,5,108,0,0,283,284,5,111,0,0,284,
285,5,111,0,0,285,286,5,114,0,0,286,60,1,0,0,0,287,288,5,99,0,0,
288,289,5,101,0,0,289,290,5,105,0,0,290,291,5,108,0,0,291,62,1,0,
0,0,292,293,5,114,0,0,293,294,5,111,0,0,294,295,5,117,0,0,295,296,
5,110,0,0,296,297,5,100,0,0,297,64,1,0,0,0,298,299,5,103,0,0,299,
300,5,97,0,0,300,301,5,109,0,0,301,302,5,109,0,0,302,303,5,97,0,
0,303,66,1,0,0,0,304,305,5,112,0,0,305,306,5,111,0,0,306,307,5,119,
0,0,307,68,1,0,0,0,308,309,5,115,0,0,309,310,5,105,0,0,310,311,5,
103,0,0,311,312,5,109,0,0,312,70,1,0,0,0,313,314,5,99,0,0,314,315,
5,108,0,0,315,316,5,97,0,0,316,317,5,109,0,0,317,318,5,112,0,0,318,
72,1,0,0,0,319,320,5,102,0,0,320,321,5,102,0,0,321,322,5,116,0,0,
322,74,1,0,0,0,323,324,5,105,0,0,324,325,5,102,0,0,325,326,5,102,
0,0,326,327,5,116,0,0,327,76,1,0,0,0,328,329,5,97,0,0,329,330,5,
110,0,0,330,331,5,103,0,0,331,332,5,108,0,0,332,333,5,101,0,0,333,
78,1,0,0,0,334,335,5,112,0,0,335,336,5,114,0,0,336,337,5,105,0,0,
337,338,5,110,0,0,338,339,5,116,0,0,339,80,1,0,0,0,340,341,5,112,
0,0,341,342,5,114,0,0,342,343,5,105,0,0,343,344,5,110,0,0,344,345,
5,116,0,0,345,346,5,95,0,0,346,347,5,115,0,0,347,348,5,104,0,0,348,
349,5,97,0,0,349,350,5,112,0,0,350,356,5,101,0,0,351,352,5,112,0,
0,352,353,5,115,0,0,353,354,5,104,0,0,354,356,5,112,0,0,355,340,
1,0,0,0,355,351,1,0,0,0,356,82,1,0,0,0,357,358,5,108,0,0,358,359,
5,101,0,0,359,360,5,114,0,0,360,361,5,112,0,0,361,84,1,0,0,0,362,
363,5,115,0,0,363,364,5,116,0,0,364,365,5,101,0,0,365,366,5,112,
0,0,366,86,1,0,0,0,367,368,5,115,0,0,368,369,5,109,0,0,369,370,5,
111,0,0,370,371,5,111,0,0,371,372,5,116,0,0,372,373,5,104,0,0,373,
374,5,115,0,0,374,375,5,116,0,0,375,376,5,101,0,0,376,377,5,112,
0,0,377,88,1,0,0,0,378,379,5,102,0,0,379,380,5,114,0,0,380,381,5,
97,0,0,381,382,5,99,0,0,382,383,5,116,0,0,383,90,1,0,0,0,384,385,
5,114,0,0,385,386,5,101,0,0,386,387,5,108,0,0,387,388,5,117,0,0,
388,92,1,0,0,0,389,390,5,115,0,0,390,391,5,111,0,0,391,392,5,102,
0,0,392,393,5,116,0,0,393,394,5,112,0,0,394,395,5,108,0,0,395,396,
5,117,0,0,396,397,5,115,0,0,397,94,1,0,0,0,398,399,5,103,0,0,399,
400,5,101,0,0,400,401,5,108,0,0,401,402,5,117,0,0,402,96,1,0,0,0,
403,404,5,115,0,0,404,405,5,105,0,0,405,406,5,103,0,0,406,407,5,
110,0,0,407,98,1,0,0,0,408,409,5,109,0,0,409,410,5,97,0,0,410,411,
5,112,0,0,411,100,1,0,0,0,412,413,5,101,0,0,413,414,5,122,0,0,414,
415,5,99,0,0,415,416,5,111,0,0,416,417,5,110,0,0,417,418,5,118,0,
0,418,419,5,111,0,0,419,420,5,108,0,0,420,421,5,117,0,0,421,422,
5,116,0,0,422,423,5,105,0,0,423,424,5,111,0,0,424,432,5,110,0,0,
425,426,5,101,0,0,426,427,5,122,0,0,427,428,5,99,0,0,428,429,5,111,
0,0,429,430,5,110,0,0,430,432,5,118,0,0,431,412,1,0,0,0,431,425,
1,0,0,0,432,102,1,0,0,0,433,434,5,99,0,0,434,435,5,111,0,0,435,436,
5,110,0,0,436,437,5,118,0,0,437,438,5,111,0,0,438,439,5,108,0,0,
439,440,5,117,0,0,440,441,5,116,0,0,441,442,5,105,0,0,442,443,5,
111,0,0,443,449,5,110,0,0,444,445,5,99,0,0,445,446,5,111,0,0,446,
447,5,110,0,0,447,449,5,118,0,0,448,433,1,0,0,0,448,444,1,0,0,0,
449,104,1,0,0,0,450,451,5,115,0,0,451,452,5,119,0,0,452,453,5,97,
0,0,453,454,5,112,0,0,454,106,1,0,0,0,455,456,5,112,0,0,456,457,
5,101,0,0,457,458,5,114,0,0,458,459,5,109,0,0,459,460,5,117,0,0,
460,461,5,116,0,0,461,467,5,101,0,0,462,463,5,112,0,0,463,464,5,
101,0,0,464,465,5,114,0,0,465,467,5,109,0,0,466,455,1,0,0,0,466,
462,1,0,0,0,467,108,1,0,0,0,468,469,5,114,0,0,469,470,5,101,0,0,
470,471,5,115,0,0,471,472,5,104,0,0,472,473,5,97,0,0,473,474,5,112,
0,0,474,480,5,101,0,0,475,476,5,114,0,0,476,477,5,115,0,0,477,478,
5,104,0,0,478,480,5,112,0,0,479,468,1,0,0,0,479,475,1,0,0,0,480,
110,1,0,0,0,481,482,5,114,0,0,482,483,5,97,0,0,483,484,5,110,0,0,
484,485,5,103,0,0,485,486,5,101,0,0,486,112,1,0,0,0,487,488,5,116,
0,0,488,489,5,111,0,0,489,490,5,112,0,0,490,491,5,107,0,0,491,114,
1,0,0,0,492,493,5,98,0,0,493,494,5,111,0,0,494,495,5,116,0,0,495,
496,5,107,0,0,496,116,1,0,0,0,497,498,5,112,0,0,498,499,5,105,0,
0,499,500,5,110,0,0,500,501,5,118,0,0,501,118,1,0,0,0,502,503,5,
43,0,0,503,120,1,0,0,0,504,505,5,45,0,0,505,122,1,0,0,0,506,507,
5,42,0,0,507,124,1,0,0,0,508,509,5,47,0,0,509,126,1,0,0,0,510,511,
5,37,0,0,511,128,1,0,0,0,512,513,5,94,0,0,513,130,1,0,0,0,514,515,
5,62,0,0,515,516,5,61,0,0,516,132,1,0,0,0,517,518,5,62,0,0,518,134,
1,0,0,0,519,520,5,60,0,0,520,521,5,61,0,0,521,136,1,0,0,0,522,523,
5,60,0,0,523,138,1,0,0,0,524,525,5,61,0,0,525,526,5,61,0,0,526,140,
1,0,0,0,527,528,5,33,0,0,528,529,5,61,0,0,529,142,1,0,0,0,530,531,
5,124,0,0,531,144,1,0,0,0,532,533,5,112,0,0,533,538,5,105,0,0,534,
535,5,80,0,0,535,538,5,73,0,0,536,538,7,0,0,0,537,532,1,0,0,0,537,
534,1,0,0,0,537,536,1,0,0,0,538,146,1,0,0,0,539,541,7,1,0,0,540,
539,1,0,0,0,541,542,1,0,0,0,542,540,1,0,0,0,542,543,1,0,0,0,543,
550,1,0,0,0,544,546,5,46,0,0,545,547,7,1,0,0,546,545,1,0,0,0,547,
548,1,0,0,0,548,546,1,0,0,0,548,549,1,0,0,0,549,551,1,0,0,0,550,
544,1,0,0,0,550,551,1,0,0,0,551,148,1,0,0,0,552,556,7,2,0,0,553,
555,7,3,0,0,554,553,1,0,0,0,555,558,1,0,0,0,556,554,1,0,0,0,556,
557,1,0,0,0,557,150,1,0,0,0,558,556,1,0,0,0,559,561,7,4,0,0,560,
559,1,0,0,0,561,562,1,0,0,0,562,560,1,0,0,0,562,563,1,0,0,0,563,
564,1,0,0,0,564,565,6,75,0,0,565,152,1,0,0,0,12,0,355,431,448,466,
479,537,542,548,550,556,562,1,6,0,0
]
class MathExprLexer(Lexer):
@@ -242,17 +258,17 @@ class MathExprLexer(Lexer):
SIFFT = 38
ANGL = 39
PRNT = 40
PRINT_SHAPE_L = 41
PRINT_SHAPE = 42
LERP = 43
STEP = 44
SMOOTHSTEP = 45
FRACT = 46
RELU = 47
SOFTPLUS = 48
GELU = 49
SIGN = 50
MAP = 51
PRINT_SHAPE = 41
LERP = 42
STEP = 43
SMOOTHSTEP = 44
FRACT = 45
RELU = 46
SOFTPLUS = 47
GELU = 48
SIGN = 49
MAP = 50
EZCONV = 51
CONV = 52
SWAP = 53
PERM = 54
@@ -290,20 +306,19 @@ class MathExprLexer(Lexer):
"'ln'", "'log'", "'exp'", "'smin'", "'smax'", "'tmin'", "'tmax'",
"'tnorm'", "'snorm'", "'floor'", "'ceil'", "'round'", "'gamma'",
"'pow'", "'sigm'", "'clamp'", "'fft'", "'ifft'", "'angle'",
"'print'", "'print_shape'", "'pshp'", "'lerp'", "'step'", "'smoothstep'",
"'fract'", "'relu'", "'softplus'", "'gelu'", "'sign'", "'map'",
"'conv'", "'swap'", "'permute'", "'reshape'", "'range'", "'topk'",
"'botk'", "'pinv'", "'+'", "'-'", "'*'", "'/'", "'%'", "'^'",
"'>='", "'>'", "'<='", "'<'", "'=='", "'!='", "'|'" ]
"'print'", "'lerp'", "'step'", "'smoothstep'", "'fract'", "'relu'",
"'softplus'", "'gelu'", "'sign'", "'map'", "'swap'", "'range'",
"'topk'", "'botk'", "'pinv'", "'+'", "'-'", "'*'", "'/'", "'%'",
"'^'", "'>='", "'>'", "'<='", "'<'", "'=='", "'!='", "'|'" ]
symbolicNames = [ "<INVALID>",
"SIN", "COS", "TAN", "ASIN", "ACOS", "ATAN", "ATAN2", "SINH",
"COSH", "TANH", "ASINH", "ACOSH", "ATANH", "ABS", "SQRT", "LN",
"LOG", "EXP", "SMIN", "SMAX", "TMIN", "TMAX", "TNORM", "SNORM",
"FLOOR", "CEIL", "ROUND", "GAMMA", "POWE", "SIGM", "CLAMP",
"SFFT", "SIFFT", "ANGL", "PRNT", "PRINT_SHAPE_L", "PRINT_SHAPE",
"LERP", "STEP", "SMOOTHSTEP", "FRACT", "RELU", "SOFTPLUS", "GELU",
"SIGN", "MAP", "CONV", "SWAP", "PERM", "RESHAPE", "RANGE", "TOPK",
"SFFT", "SIFFT", "ANGL", "PRNT", "PRINT_SHAPE", "LERP", "STEP",
"SMOOTHSTEP", "FRACT", "RELU", "SOFTPLUS", "GELU", "SIGN", "MAP",
"EZCONV", "CONV", "SWAP", "PERM", "RESHAPE", "RANGE", "TOPK",
"BOTK", "PINV", "PLUS", "MINUS", "MULT", "DIV", "MOD", "POW",
"GE", "GT", "LE", "LT", "EQ", "NE", "PIPE", "CONSTANT", "NUMBER",
"VARIABLE", "WS" ]
@@ -313,13 +328,12 @@ class MathExprLexer(Lexer):
"TANH", "ASINH", "ACOSH", "ATANH", "ABS", "SQRT", "LN",
"LOG", "EXP", "SMIN", "SMAX", "TMIN", "TMAX", "TNORM",
"SNORM", "FLOOR", "CEIL", "ROUND", "GAMMA", "POWE", "SIGM",
"CLAMP", "SFFT", "SIFFT", "ANGL", "PRNT", "PRINT_SHAPE_L",
"PRINT_SHAPE", "LERP", "STEP", "SMOOTHSTEP", "FRACT",
"RELU", "SOFTPLUS", "GELU", "SIGN", "MAP", "CONV", "SWAP",
"PERM", "RESHAPE", "RANGE", "TOPK", "BOTK", "PINV", "PLUS",
"MINUS", "MULT", "DIV", "MOD", "POW", "GE", "GT", "LE",
"LT", "EQ", "NE", "PIPE", "CONSTANT", "NUMBER", "VARIABLE",
"WS" ]
"CLAMP", "SFFT", "SIFFT", "ANGL", "PRNT", "PRINT_SHAPE",
"LERP", "STEP", "SMOOTHSTEP", "FRACT", "RELU", "SOFTPLUS",
"GELU", "SIGN", "MAP", "EZCONV", "CONV", "SWAP", "PERM",
"RESHAPE", "RANGE", "TOPK", "BOTK", "PINV", "PLUS", "MINUS",
"MULT", "DIV", "MOD", "POW", "GE", "GT", "LE", "LT", "EQ",
"NE", "PIPE", "CONSTANT", "NUMBER", "VARIABLE", "WS" ]
grammarFileName = "MathExpr.g4"
+20 -25
View File
@@ -38,17 +38,17 @@ SFFT=37
SIFFT=38
ANGL=39
PRNT=40
PRINT_SHAPE_L=41
PRINT_SHAPE=42
LERP=43
STEP=44
SMOOTHSTEP=45
FRACT=46
RELU=47
SOFTPLUS=48
GELU=49
SIGN=50
MAP=51
PRINT_SHAPE=41
LERP=42
STEP=43
SMOOTHSTEP=44
FRACT=45
RELU=46
SOFTPLUS=47
GELU=48
SIGN=49
MAP=50
EZCONV=51
CONV=52
SWAP=53
PERM=54
@@ -114,21 +114,16 @@ WS=76
'ifft'=38
'angle'=39
'print'=40
'print_shape'=41
'pshp'=42
'lerp'=43
'step'=44
'smoothstep'=45
'fract'=46
'relu'=47
'softplus'=48
'gelu'=49
'sign'=50
'map'=51
'conv'=52
'lerp'=42
'step'=43
'smoothstep'=44
'fract'=45
'relu'=46
'softplus'=47
'gelu'=48
'sign'=49
'map'=50
'swap'=53
'permute'=54
'reshape'=55
'range'=56
'topk'=57
'botk'=58
File diff suppressed because it is too large Load Diff
+6 -1
View File
@@ -1,4 +1,4 @@
# Generated from ./MathExpr.g4 by ANTLR 4.13.2
# Generated from MathExpr.g4 by ANTLR 4.13.2
from antlr4 import *
if "." in __name__:
from .MathExprParser import MathExprParser
@@ -414,6 +414,11 @@ class MathExprVisitor(ParseTreeVisitor):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#EzConvFunc.
def visitEzConvFunc(self, ctx:MathExprParser.EzConvFuncContext):
return self.visitChildren(ctx)
# Visit a parse tree produced by MathExprParser#ConvFunc.
def visitConvFunc(self, ctx:MathExprParser.ConvFuncContext):
return self.visitChildren(ctx)
+65 -36
View File
@@ -648,44 +648,9 @@ class UnifiedMathVisitor(MathExprVisitor):
final_shape = list(leading_shape) + list(actual_spatial)
return output.reshape(final_shape)
def _apply_conv_internal(self, conv_input, kernel_val, kernel_sizes, spatial_dims_count):
"""
Executes the convolution with asymmetric padding support for even kernels.
Input: [Batch, Channel, Spatial...]
Kernel: [Spatial...] (to be promoted/repeated)
kernel_sizes: [W, H, D]
"""
in_channels = conv_input.size(1)
pads = []
for k in kernel_sizes:
p_total = k - 1
p_low = k // 2
p_high = p_total - p_low
pads.extend([p_low, p_high])
padded_input = torch.nn.functional.pad(conv_input, tuple(pads), mode="constant", value=0)
actual_kernel_sizes = kernel_sizes[::-1]
if kernel_val.numel() == 1:
kernel_val = kernel_val.expand(tuple(actual_kernel_sizes))
elif kernel_val.ndim != spatial_dims_count:
kernel_val = kernel_val.reshape(tuple(actual_kernel_sizes))
final_kernel = kernel_val.unsqueeze(0).unsqueeze(0)
final_kernel = final_kernel.to(conv_input.dtype)
final_kernel = final_kernel.repeat(in_channels, 1, *([1] * spatial_dims_count))
conv_fn = F.conv1d if spatial_dims_count == 1 else (F.conv2d if spatial_dims_count == 2 else F.conv3d)
result = conv_fn(padded_input, final_kernel, padding=0, groups=in_channels)
return result
def visitConvFunc(self, ctx):
def _parse_conv_args(self, ctx):
input_raw = self.visit(ctx.expr(0))
tensor = self._promote_to_tensor(input_raw)
input_ndim = tensor.ndim
num_args = len(ctx.expr())
if num_args < 3:
raise ValueError("conv() requires at least 3 arguments")
@@ -730,6 +695,46 @@ class UnifiedMathVisitor(MathExprVisitor):
self.shape = original_shape
self.variables = old_vars
return tensor, kernel_val, kernel_sizes, spatial_dims_count
def _apply_conv_internal(self, conv_input, kernel_val, kernel_sizes, spatial_dims_count):
"""
Executes the convolution with asymmetric padding support for even kernels.
Input: [Batch, Channel, Spatial...]
Kernel: [Spatial...] (to be promoted/repeated)
kernel_sizes: [W, H, D]
"""
in_channels = conv_input.size(1)
pads = []
for k in kernel_sizes:
p_total = k - 1
p_low = k // 2
p_high = p_total - p_low
pads.extend([p_low, p_high])
padded_input = torch.nn.functional.pad(conv_input, tuple(pads), mode="constant", value=0)
actual_kernel_sizes = kernel_sizes[::-1]
if kernel_val.numel() == 1:
kernel_val = kernel_val.expand(tuple(actual_kernel_sizes))
elif kernel_val.ndim != spatial_dims_count:
kernel_val = kernel_val.reshape(tuple(actual_kernel_sizes))
final_kernel = kernel_val.unsqueeze(0).unsqueeze(0)
final_kernel = final_kernel.to(conv_input.dtype)
final_kernel = final_kernel.repeat(in_channels, 1, *([1] * spatial_dims_count))
conv_fn = F.conv1d if spatial_dims_count == 1 else (F.conv2d if spatial_dims_count == 2 else F.conv3d)
result = conv_fn(padded_input, final_kernel, padding=0, groups=in_channels)
return result
def visitEzConvFunc(self, ctx):
tensor, kernel_val, kernel_sizes, spatial_dims_count = self._parse_conv_args(ctx)
input_ndim = tensor.ndim
is_channels_first = False
if tensor.ndim == spatial_dims_count + 2:
c_front = tensor.shape[1]
@@ -791,3 +796,27 @@ class UnifiedMathVisitor(MathExprVisitor):
out = out.permute(0, 4, 1, 2, 3)
return out
def visitConvFunc(self, ctx):
tensor, kernel_val, kernel_sizes, spatial_dims_count = self._parse_conv_args(ctx)
# Expect (Batch..., Channel, Spatial...)
# spatial_dims_count = 1, 2, or 3
# Must have at least Channel + Spatial dims
min_dims = spatial_dims_count + 1
if tensor.ndim < min_dims:
raise ValueError(f"convolution() input requires at least Channels + Spatial dimensions. Got shape {tensor.shape} for {spatial_dims_count}D conv.")
spatial_shape = tensor.shape[-spatial_dims_count:]
in_channels = tensor.shape[-(spatial_dims_count + 1)]
batch_shape = tensor.shape[:-(spatial_dims_count + 1)]
total_batch = 1
for s in batch_shape:
total_batch *= s
conv_input = tensor.reshape(total_batch, in_channels, *spatial_shape)
result = self._apply_conv_internal(conv_input, kernel_val, kernel_sizes, spatial_dims_count)
return result.reshape(*batch_shape, in_channels, *spatial_shape)