From 4cfaf36851fef21aac8e8d60ef64a8ec31d3aec0 Mon Sep 17 00:00:00 2001 From: Daniel Martinek Date: Wed, 1 Apr 2026 11:26:32 +0200 Subject: [PATCH] erf,erfinv --- README.md | 2 ++ more_math/Parser/MathExpr.g4 | 4 ++++ more_math/Parser/UnifiedMathVisitor.py | 10 ++++++++++ web/script_text_input.js | 2 +- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f070f2c..f5d47ee 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,8 @@ You can also get the node from comfy manager under the name of More math. - `sigm(x)`: Sigmoid function (1 / (1 + e^-x)). - `softmax(x, dim)`: Softmax normalization along last dimension (converts to probabilities). - `softmin(x, dim)`: Softmin normalization along specified dimension (inverse softmax). +- `erf(x)`: Error function. +- `erfinv(x)`: Inverse error function. ### Interpolation diff --git a/more_math/Parser/MathExpr.g4 b/more_math/Parser/MathExpr.g4 index 5e16b95..a918f8a 100644 --- a/more_math/Parser/MathExpr.g4 +++ b/more_math/Parser/MathExpr.g4 @@ -152,6 +152,8 @@ func1: | ARGMAX LPAREN expr RPAREN # ArgmaxFunc | SOFTMAX LPAREN expr RPAREN # SoftmaxFunc | SOFTMIN LPAREN expr RPAREN # SoftminFunc + | ERF LPAREN expr RPAREN # ErfFunc + | ERFINV LPAREN expr RPAREN # ErfinvFunc | UNIQUE LPAREN expr RPAREN # UniqueFunc | FLATTEN LPAREN expr RPAREN # FlattenFunc | MOTION_MASK LPAREN expr RPAREN # MotionMaskFunc @@ -338,6 +340,8 @@ PERCENTILE: 'percentile' | 'prcnt'; QUANTILE: 'quantile'; DOT: 'dot'; MOMENT: 'moment'; +ERF: 'erf'; +ERFINV: 'erfinv'; ANY: 'any'; ALL: 'all'; diff --git a/more_math/Parser/UnifiedMathVisitor.py b/more_math/Parser/UnifiedMathVisitor.py index 99cb6e0..dff8ce2 100644 --- a/more_math/Parser/UnifiedMathVisitor.py +++ b/more_math/Parser/UnifiedMathVisitor.py @@ -3511,5 +3511,15 @@ class UnifiedMathVisitor(MathExprVisitor): dim = int(dim_val.item()) if self._is_tensor(dim_val) else int(dim_val) return torch.roll(x, shifts=shift, dims=dim) + + def visitErfFunc(self, ctx): + """erf(x) - error function""" + x = self._promote_to_tensor((yield ctx.expr())) + return torch.erf(x) + + def visitErfinvFunc(self, ctx): + """erfinv(x) - inverse error function""" + x = self._promote_to_tensor((yield ctx.expr())) + return torch.erfinv(x) \ No newline at end of file diff --git a/web/script_text_input.js b/web/script_text_input.js index f9de1d8..e82ed64 100644 --- a/web/script_text_input.js +++ b/web/script_text_input.js @@ -12,7 +12,7 @@ const FUNCTIONS = new Set([ "round", "gamma", "pow", "sigm", "clamp", "fft", "ifft", "angle", "print", "print_shape", "pshp", "nvl", "nan_to_num", "lerp", "step", "smoothstep", "fract", "relu", "softplus", "gelu", "sign", "map", "ezconvolution", "ezconv", "convolution", "conv", "swap", "permute", "perm", "reshape", "rshp", "range", "topk", "botk", "pinv", - "sum", "mean", "std", "var", "quartile", "quartil", "percentile", "prcnt", "quantile", "dot", "moment", "any", + "sum", "mean", "std", "var", "quartile", "quartil", "percentile", "prcnt", "quantile", "dot", "moment","erf","erfinv", "any", "all", "edge", "blur", "gaussian", "median", "mode", "cumsum", "cumprod", "topk_ind", "topk_indices", "botk_ind", "botk_indices", "cubic_ease", "cubic", "elastic_ease", "elastic", "sine_ease", "sine", "smootherstep", "dist", "distance", "remap", "cossim", "cosine_similarity", "count", "cnt", "length", "flatten", "append", "get_value",