Revert "snorm with dimension is tnorm 😅 moving it to tnorm"
This reverts commit ccff96aad4.
This commit is contained in:
@@ -168,9 +168,9 @@ func1:
|
||||
*/
|
||||
| EXP LPAREN expr RPAREN # ExpFunc
|
||||
/**
|
||||
snorm(x) - returns a frobenius norm of the tensor as a float number
|
||||
tnorm(x) - normalises tensor or list by multiplication such that sum(x^2)==1.0 for each slice. The slice is last dimension of the tensor.
|
||||
*/
|
||||
| SNORM LPAREN expr RPAREN # TNormFunc
|
||||
| TNORM LPAREN expr RPAREN # TNormFunc
|
||||
| FLOOR LPAREN expr RPAREN # FloorFunc
|
||||
| CEIL LPAREN expr RPAREN # CeilFunc
|
||||
| ROUND LPAREN expr RPAREN # RoundFunc
|
||||
@@ -238,9 +238,9 @@ func2:
|
||||
*/
|
||||
| TMAX LPAREN expr COMMA expr RPAREN # TMaxFunc
|
||||
/**
|
||||
tnorm(x,[dim]) - normalises tensor or list by multiplication such that sum(x^2)==1.0 for each slice. The slice is last dimension of the tensor when not provided. If dim = None, it behaves the same as snorm.
|
||||
snorm(x,[dim]) - frobenius norm of tensor. Along dimension if dimension specified. Dimension can be a list
|
||||
*/
|
||||
| TNORM LPAREN expr (COMMA expr)? RPAREN # SNormFunc
|
||||
| SNORM LPAREN expr (COMMA expr)? RPAREN # SNormFunc
|
||||
| STEP LPAREN expr COMMA expr RPAREN # StepFunc
|
||||
| TOPK LPAREN expr COMMA expr RPAREN # TopkFunc
|
||||
| BOTK LPAREN expr COMMA expr RPAREN # BotkFunc
|
||||
|
||||
@@ -614,14 +614,13 @@ class UnifiedMathVisitor(MathExprVisitor):
|
||||
print(f"{val}")
|
||||
return val
|
||||
|
||||
def visitSNormFunc(self, ctx):
|
||||
def visitTNormFunc(self, ctx):
|
||||
val = (yield ctx.expr())
|
||||
if self._is_tensor(val):
|
||||
return F.normalize(val, p=2)
|
||||
return F.normalize(val, p=2, dim=-1)
|
||||
return 1.0 if val != 0 else 0.0
|
||||
|
||||
def visitTNormFunc(self, ctx):
|
||||
dim = -1
|
||||
def visitSNormFunc(self, ctx):
|
||||
val = (yield ctx.expr(0))
|
||||
if len(ctx.expr()) > 1:
|
||||
dim = self._to_int((yield ctx.expr(1)), ctx, "s_norm dimension")
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -279,7 +279,7 @@ def serializedATN():
|
||||
207,0,0,431,765,1,0,0,0,432,433,5,17,0,0,433,434,5,206,0,0,434,435,
|
||||
3,24,12,0,435,436,5,207,0,0,436,765,1,0,0,0,437,438,5,18,0,0,438,
|
||||
439,5,206,0,0,439,440,3,24,12,0,440,441,5,207,0,0,441,765,1,0,0,
|
||||
0,442,443,5,24,0,0,443,444,5,206,0,0,444,445,3,24,12,0,445,446,5,
|
||||
0,442,443,5,23,0,0,443,444,5,206,0,0,444,445,3,24,12,0,445,446,5,
|
||||
207,0,0,446,765,1,0,0,0,447,448,5,25,0,0,448,449,5,206,0,0,449,450,
|
||||
3,24,12,0,450,451,5,207,0,0,451,765,1,0,0,0,452,453,5,26,0,0,453,
|
||||
454,5,206,0,0,454,455,3,24,12,0,455,456,5,207,0,0,456,765,1,0,0,
|
||||
@@ -394,7 +394,7 @@ def serializedATN():
|
||||
784,5,208,0,0,784,785,3,24,12,0,785,786,5,207,0,0,786,1116,1,0,0,
|
||||
0,787,788,5,22,0,0,788,789,5,206,0,0,789,790,3,24,12,0,790,791,5,
|
||||
208,0,0,791,792,3,24,12,0,792,793,5,207,0,0,793,1116,1,0,0,0,794,
|
||||
795,5,23,0,0,795,796,5,206,0,0,796,799,3,24,12,0,797,798,5,208,0,
|
||||
795,5,24,0,0,795,796,5,206,0,0,796,799,3,24,12,0,797,798,5,208,0,
|
||||
0,798,800,3,24,12,0,799,797,1,0,0,0,799,800,1,0,0,0,800,801,1,0,
|
||||
0,0,801,802,5,207,0,0,802,1116,1,0,0,0,803,804,5,39,0,0,804,805,
|
||||
5,206,0,0,805,806,3,24,12,0,806,807,5,208,0,0,807,808,3,24,12,0,
|
||||
@@ -5206,8 +5206,8 @@ class MathExprParser ( Parser ):
|
||||
super().__init__(parser)
|
||||
self.copyFrom(ctx)
|
||||
|
||||
def SNORM(self):
|
||||
return self.getToken(MathExprParser.SNORM, 0)
|
||||
def TNORM(self):
|
||||
return self.getToken(MathExprParser.TNORM, 0)
|
||||
def LPAREN(self):
|
||||
return self.getToken(MathExprParser.LPAREN, 0)
|
||||
def expr(self):
|
||||
@@ -7278,11 +7278,11 @@ class MathExprParser ( Parser ):
|
||||
self.state = 440
|
||||
self.match(MathExprParser.RPAREN)
|
||||
pass
|
||||
elif token in [24]:
|
||||
elif token in [23]:
|
||||
localctx = MathExprParser.TNormFuncContext(self, localctx)
|
||||
self.enterOuterAlt(localctx, 18)
|
||||
self.state = 442
|
||||
self.match(MathExprParser.SNORM)
|
||||
self.match(MathExprParser.TNORM)
|
||||
self.state = 443
|
||||
self.match(MathExprParser.LPAREN)
|
||||
self.state = 444
|
||||
@@ -8413,8 +8413,8 @@ class MathExprParser ( Parser ):
|
||||
super().__init__(parser)
|
||||
self.copyFrom(ctx)
|
||||
|
||||
def TNORM(self):
|
||||
return self.getToken(MathExprParser.TNORM, 0)
|
||||
def SNORM(self):
|
||||
return self.getToken(MathExprParser.SNORM, 0)
|
||||
def LPAREN(self):
|
||||
return self.getToken(MathExprParser.LPAREN, 0)
|
||||
def expr(self, i:int=None):
|
||||
@@ -9723,11 +9723,11 @@ class MathExprParser ( Parser ):
|
||||
self.state = 792
|
||||
self.match(MathExprParser.RPAREN)
|
||||
pass
|
||||
elif token in [23]:
|
||||
elif token in [24]:
|
||||
localctx = MathExprParser.SNormFuncContext(self, localctx)
|
||||
self.enterOuterAlt(localctx, 5)
|
||||
self.state = 794
|
||||
self.match(MathExprParser.TNORM)
|
||||
self.match(MathExprParser.SNORM)
|
||||
self.state = 795
|
||||
self.match(MathExprParser.LPAREN)
|
||||
self.state = 796
|
||||
|
||||
@@ -206,7 +206,7 @@ INBUILT_FUNCTION_META = {
|
||||
'smin': {'min_args': 1, 'max_args': None, 'snippet': 'smin()', 'description': ''},
|
||||
'smootherstep': {'min_args': 3, 'max_args': 3, 'snippet': 'smootherstep()', 'description': ''},
|
||||
'smoothstep': {'min_args': 3, 'max_args': 3, 'snippet': 'smoothstep()', 'description': ''},
|
||||
'snorm': {'min_args': 1, 'max_args': 1, 'snippet': 'snorm()', 'description': 'snorm(x) - returns a frobenius norm of the tensor as a float number'},
|
||||
'snorm': {'min_args': 1, 'max_args': 2, 'snippet': 'snorm()', 'description': 'snorm(x,[dim]) - frobenius norm of tensor. Along dimension if dimension specified. Dimension can be a list'},
|
||||
'softmax': {'min_args': 1, 'max_args': 2, 'snippet': 'softmax()', 'description': ''},
|
||||
'softmin': {'min_args': 1, 'max_args': 2, 'snippet': 'softmin()', 'description': ''},
|
||||
'softplus': {'min_args': 1, 'max_args': 1, 'snippet': 'softplus()', 'description': ''},
|
||||
@@ -231,7 +231,7 @@ INBUILT_FUNCTION_META = {
|
||||
'timestamp': {'min_args': 0, 'max_args': 0, 'snippet': 'timestamp()', 'description': ''},
|
||||
'tmax': {'min_args': 2, 'max_args': 2, 'snippet': 'tmax()', 'description': 'tmax(x,y) - elementwise maximum of tensor or list. max(x,y) when inputs are floats'},
|
||||
'tmin': {'min_args': 2, 'max_args': 2, 'snippet': 'tmin()', 'description': ''},
|
||||
'tnorm': {'min_args': 1, 'max_args': 2, 'snippet': 'tnorm()', 'description': 'tnorm(x,[dim]) - normalises tensor or list by multiplication such that sum(x^2)==1.0 for each slice. The slice is last dimension of the tensor when not provided. If dim = None, it behaves the same as snorm.'},
|
||||
'tnorm': {'min_args': 1, 'max_args': 1, 'snippet': 'tnorm()', 'description': 'tnorm(x) - normalises tensor or list by multiplication such that sum(x^2)==1.0 for each slice. The slice is last dimension of the tensor.'},
|
||||
'topk': {'min_args': 2, 'max_args': 2, 'snippet': 'topk()', 'description': ''},
|
||||
'topk_ind': {'min_args': 2, 'max_args': 2, 'snippet': 'topk_ind()', 'description': ''},
|
||||
'topk_indices': {'min_args': 2, 'max_args': 2, 'snippet': 'topk_indices()', 'description': ''},
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -347,7 +347,7 @@ def serializedATN():
|
||||
buf.write("\2\u01b5\u01b6\7\u00d1\2\2\u01b6\u02ff\3\2\2\2\u01b7\u01b8")
|
||||
buf.write("\7\24\2\2\u01b8\u01b9\7\u00d0\2\2\u01b9\u01ba\5\32\16")
|
||||
buf.write("\2\u01ba\u01bb\7\u00d1\2\2\u01bb\u02ff\3\2\2\2\u01bc\u01bd")
|
||||
buf.write("\7\32\2\2\u01bd\u01be\7\u00d0\2\2\u01be\u01bf\5\32\16")
|
||||
buf.write("\7\31\2\2\u01bd\u01be\7\u00d0\2\2\u01be\u01bf\5\32\16")
|
||||
buf.write("\2\u01bf\u01c0\7\u00d1\2\2\u01c0\u02ff\3\2\2\2\u01c1\u01c2")
|
||||
buf.write("\7\33\2\2\u01c2\u01c3\7\u00d0\2\2\u01c3\u01c4\5\32\16")
|
||||
buf.write("\2\u01c4\u01c5\7\u00d1\2\2\u01c5\u02ff\3\2\2\2\u01c6\u01c7")
|
||||
@@ -518,7 +518,7 @@ def serializedATN():
|
||||
buf.write("\u045e\3\2\2\2\u0315\u0316\7\30\2\2\u0316\u0317\7\u00d0")
|
||||
buf.write("\2\2\u0317\u0318\5\32\16\2\u0318\u0319\7\u00d2\2\2\u0319")
|
||||
buf.write("\u031a\5\32\16\2\u031a\u031b\7\u00d1\2\2\u031b\u045e\3")
|
||||
buf.write("\2\2\2\u031c\u031d\7\31\2\2\u031d\u031e\7\u00d0\2\2\u031e")
|
||||
buf.write("\2\2\2\u031c\u031d\7\32\2\2\u031d\u031e\7\u00d0\2\2\u031e")
|
||||
buf.write("\u0321\5\32\16\2\u031f\u0320\7\u00d2\2\2\u0320\u0322\5")
|
||||
buf.write("\32\16\2\u0321\u031f\3\2\2\2\u0321\u0322\3\2\2\2\u0322")
|
||||
buf.write("\u0323\3\2\2\2\u0323\u0324\7\u00d1\2\2\u0324\u045e\3\2")
|
||||
@@ -5459,8 +5459,8 @@ class MathExprParser ( Parser ):
|
||||
super().__init__(parser)
|
||||
self.copyFrom(ctx)
|
||||
|
||||
def SNORM(self):
|
||||
return self.getToken(MathExprParser.SNORM, 0)
|
||||
def TNORM(self):
|
||||
return self.getToken(MathExprParser.TNORM, 0)
|
||||
def LPAREN(self):
|
||||
return self.getToken(MathExprParser.LPAREN, 0)
|
||||
def expr(self):
|
||||
@@ -7531,11 +7531,11 @@ class MathExprParser ( Parser ):
|
||||
self.state = 440
|
||||
self.match(MathExprParser.RPAREN)
|
||||
pass
|
||||
elif token in [MathExprParser.SNORM]:
|
||||
elif token in [MathExprParser.TNORM]:
|
||||
localctx = MathExprParser.TNormFuncContext(self, localctx)
|
||||
self.enterOuterAlt(localctx, 18)
|
||||
self.state = 442
|
||||
self.match(MathExprParser.SNORM)
|
||||
self.match(MathExprParser.TNORM)
|
||||
self.state = 443
|
||||
self.match(MathExprParser.LPAREN)
|
||||
self.state = 444
|
||||
@@ -8666,8 +8666,8 @@ class MathExprParser ( Parser ):
|
||||
super().__init__(parser)
|
||||
self.copyFrom(ctx)
|
||||
|
||||
def TNORM(self):
|
||||
return self.getToken(MathExprParser.TNORM, 0)
|
||||
def SNORM(self):
|
||||
return self.getToken(MathExprParser.SNORM, 0)
|
||||
def LPAREN(self):
|
||||
return self.getToken(MathExprParser.LPAREN, 0)
|
||||
def expr(self, i:int=None):
|
||||
@@ -9976,11 +9976,11 @@ class MathExprParser ( Parser ):
|
||||
self.state = 792
|
||||
self.match(MathExprParser.RPAREN)
|
||||
pass
|
||||
elif token in [MathExprParser.TNORM]:
|
||||
elif token in [MathExprParser.SNORM]:
|
||||
localctx = MathExprParser.SNormFuncContext(self, localctx)
|
||||
self.enterOuterAlt(localctx, 5)
|
||||
self.state = 794
|
||||
self.match(MathExprParser.TNORM)
|
||||
self.match(MathExprParser.SNORM)
|
||||
self.state = 795
|
||||
self.match(MathExprParser.LPAREN)
|
||||
self.state = 796
|
||||
|
||||
@@ -209,7 +209,7 @@ export const FUNCTION_META = {
|
||||
smin: { minArgs: 1, maxArgs: null, snippet: "smin()", description: "" },
|
||||
smootherstep: { minArgs: 3, maxArgs: 3, snippet: "smootherstep()", description: "" },
|
||||
smoothstep: { minArgs: 3, maxArgs: 3, snippet: "smoothstep()", description: "" },
|
||||
snorm: { minArgs: 1, maxArgs: 1, snippet: "snorm()", description: "snorm(x) - returns a frobenius norm of the tensor as a float number" },
|
||||
snorm: { minArgs: 1, maxArgs: 2, snippet: "snorm()", description: "snorm(x,[dim]) - frobenius norm of tensor. Along dimension if dimension specified. Dimension can be a list" },
|
||||
softmax: { minArgs: 1, maxArgs: 2, snippet: "softmax()", description: "" },
|
||||
softmin: { minArgs: 1, maxArgs: 2, snippet: "softmin()", description: "" },
|
||||
softplus: { minArgs: 1, maxArgs: 1, snippet: "softplus()", description: "" },
|
||||
@@ -234,7 +234,7 @@ export const FUNCTION_META = {
|
||||
timestamp: { minArgs: 0, maxArgs: 0, snippet: "timestamp()", description: "" },
|
||||
tmax: { minArgs: 2, maxArgs: 2, snippet: "tmax()", description: "tmax(x,y) - elementwise maximum of tensor or list. max(x,y) when inputs are floats" },
|
||||
tmin: { minArgs: 2, maxArgs: 2, snippet: "tmin()", description: "" },
|
||||
tnorm: { minArgs: 1, maxArgs: 2, snippet: "tnorm()", description: "tnorm(x,[dim]) - normalises tensor or list by multiplication such that sum(x^2)==1.0 for each slice. The slice is last dimension of the tensor when not provided. If dim = None, it behaves the same as snorm." },
|
||||
tnorm: { minArgs: 1, maxArgs: 1, snippet: "tnorm()", description: "tnorm(x) - normalises tensor or list by multiplication such that sum(x^2)==1.0 for each slice. The slice is last dimension of the tensor." },
|
||||
topk: { minArgs: 2, maxArgs: 2, snippet: "topk()", description: "" },
|
||||
topk_ind: { minArgs: 2, maxArgs: 2, snippet: "topk_ind()", description: "" },
|
||||
topk_indices: { minArgs: 2, maxArgs: 2, snippet: "topk_indices()", description: "" },
|
||||
|
||||
Reference in New Issue
Block a user