@bian-womp/spark-graph 0.1.24 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.cjs CHANGED
@@ -1992,6 +1992,16 @@ function setupBasicGraphRegistry() {
1992
1992
  { value: 13, label: "Avg" },
1993
1993
  { value: 14, label: "MinAll" },
1994
1994
  { value: 15, label: "MaxAll" },
1995
+ // Trig and other unary functions on A
1996
+ { value: 16, label: "Sin" },
1997
+ { value: 17, label: "Cos" },
1998
+ { value: 18, label: "Tan" },
1999
+ { value: 19, label: "ASin" },
2000
+ { value: 20, label: "ACos" },
2001
+ { value: 21, label: "ATan" },
2002
+ { value: 22, label: "Sqrt" },
2003
+ { value: 23, label: "Exp" },
2004
+ { value: 24, label: "Log" },
1995
2005
  ],
1996
2006
  });
1997
2007
  // Enums: Compare Operation
@@ -2134,30 +2144,35 @@ function setupBasicGraphRegistry() {
2134
2144
  const b = ins.B === undefined ? [] : asArray(ins.B);
2135
2145
  const op = Number(ins.Operation ?? 0) | 0;
2136
2146
  // Unary ops on A
2137
- if (op === 8)
2138
- return { Result: a.map((x) => Math.round(Number(x))) };
2139
- if (op === 9)
2140
- return { Result: a.map((x) => Math.floor(Number(x))) };
2141
- if (op === 10)
2142
- return { Result: a.map((x) => Math.ceil(Number(x))) };
2143
- if (op === 11)
2144
- return { Result: a.map((x) => Math.abs(Number(x))) };
2147
+ const unary = {
2148
+ 8: (x) => Math.round(x),
2149
+ 9: (x) => Math.floor(x),
2150
+ 10: (x) => Math.ceil(x),
2151
+ 11: (x) => Math.abs(x),
2152
+ 16: (x) => Math.sin(x),
2153
+ 17: (x) => Math.cos(x),
2154
+ 18: (x) => Math.tan(x),
2155
+ 19: (x) => Math.asin(x),
2156
+ 20: (x) => Math.acos(x),
2157
+ 21: (x) => Math.atan(x),
2158
+ 22: (x) => Math.sqrt(x),
2159
+ 23: (x) => Math.exp(x),
2160
+ 24: (x) => Math.log(x),
2161
+ };
2162
+ if (op in unary)
2163
+ return { Result: a.map((x) => unary[op](Number(x))) };
2145
2164
  // Aggregate ops on A -> single-element array
2146
- if (op === 12)
2147
- return { Result: [a.reduce((s, x) => s + Number(x || 0), 0)] };
2148
- if (op === 13) {
2149
- const sum = a.reduce((s, x) => s + Number(x || 0), 0);
2150
- const avg = a.length ? sum / a.length : 0;
2151
- return { Result: [avg] };
2152
- }
2153
- if (op === 14)
2154
- return {
2155
- Result: [a.length ? Math.min(...a.map((x) => Number(x))) : 0],
2156
- };
2157
- if (op === 15)
2158
- return {
2159
- Result: [a.length ? Math.max(...a.map((x) => Number(x))) : 0],
2160
- };
2165
+ const aggregates = {
2166
+ 12: (arr) => arr.reduce((s, x) => s + Number(x || 0), 0),
2167
+ 13: (arr) => {
2168
+ const sum = arr.reduce((s, x) => s + Number(x || 0), 0);
2169
+ return arr.length ? sum / arr.length : 0;
2170
+ },
2171
+ 14: (arr) => (arr.length ? Math.min(...arr.map((x) => Number(x))) : 0),
2172
+ 15: (arr) => (arr.length ? Math.max(...arr.map((x) => Number(x))) : 0),
2173
+ };
2174
+ if (op in aggregates)
2175
+ return { Result: [aggregates[op](a)] };
2161
2176
  // Binary ops A (broadcast) B
2162
2177
  const len = Math.max(a.length, b.length);
2163
2178
  const ops = [