ziko 0.51.0 → 0.52.0
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/dist/ziko.cjs +1638 -1456
- package/dist/ziko.js +1446 -1385
- package/dist/ziko.min.js +2 -2
- package/dist/ziko.mjs +1446 -1385
- package/package.json +1 -1
- package/src/data/converter/csv.js +1 -1
- package/src/{__helpers__ → helpers}/register/index.js +1 -1
- package/src/hooks/use-ipc.js +1 -3
- package/src/math/adapted/index.js +7 -0
- package/src/math/complex/index.js +7 -5
- package/src/math/discret/Conversion/index.js +1 -1
- package/src/math/discret/Logic/index.js +1 -1
- package/src/math/functions/helper.js +68 -17
- package/src/math/functions/index.js +11 -11
- package/src/math/functions/primitives/index.js +176 -0
- package/src/math/mapfun/index.js +19 -0
- package/src/math/matrix/helpers/det.js +36 -0
- package/src/math/matrix/helpers/index.js +3 -0
- package/src/math/matrix/helpers/inverse.js +52 -0
- package/src/math/matrix/helpers/stack.js +24 -0
- package/src/math/matrix/index.js +1 -1
- package/src/math/matrix/matrix.js +601 -0
- package/src/math/random/index.js +88 -92
- package/src/math/signal/functions.js +23 -25
- package/src/math/utils/arithmetic.js +15 -17
- package/src/math/utils/index.js +1 -1
- package/src/math/utils/mapfun.js +31 -35
- package/src/ui/constructors/UIElement.js +9 -9
- package/src/ui/constructors/UIElementCore.js +2 -2
- package/types/math/adapted/index.d.ts +4 -0
- package/types/math/complex/index.d.ts +1 -1
- package/types/math/mapfun/index.d.ts +87 -0
- package/src/math/matrix/Matrix.js +0 -675
- /package/src/{__helpers__ → helpers}/checkers/index.js +0 -0
- /package/src/{__helpers__ → helpers}/index.js +0 -0
- /package/src/{__helpers__ → helpers}/register/register-to-class.js +0 -0
- /package/src/{__helpers__ → helpers}/register/register-to-instance.js +0 -0
package/dist/ziko.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/*
|
|
3
3
|
Project: ziko.js
|
|
4
4
|
Author: Zakaria Elalaoui
|
|
5
|
-
Date :
|
|
5
|
+
Date : Fri Dec 05 2025 17:08:57 GMT+0100 (UTC+01:00)
|
|
6
6
|
Git-Repo : https://github.com/zakarialaoui10/ziko.js
|
|
7
7
|
Git-Wiki : https://github.com/zakarialaoui10/ziko.js/wiki
|
|
8
8
|
Released under MIT License
|
|
@@ -17,87 +17,318 @@
|
|
|
17
17
|
const { PI: PI$2, E } = Math;
|
|
18
18
|
const EPSILON=Number.EPSILON;
|
|
19
19
|
|
|
20
|
-
const {PI: PI$1, cos: cos$3, sin: sin$3, tan: tan$1,
|
|
20
|
+
const {PI: PI$1, cos: cos$3, sin: sin$3, tan: tan$1, atan: atan$1, cosh: cosh$2, sinh: sinh$2, tanh: tanh$1, acosh: acosh$1, asinh: asinh$1, atanh: atanh$1, log: log$1} = Math;
|
|
21
21
|
let Fixed={
|
|
22
|
-
cos:
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
cos : x=> {
|
|
23
|
+
if(x.isComplex?.()) return new x.constructor(
|
|
24
|
+
cos$3(x.a)*cosh$2(x.b),
|
|
25
|
+
-(sin$3(x.a)*sinh$2(x.b))
|
|
26
|
+
);
|
|
27
|
+
return cos$3(x)
|
|
28
|
+
},
|
|
29
|
+
sin : x=>{
|
|
30
|
+
if(x?.isComplex) return new x.constructor(
|
|
31
|
+
sin$3(x.a)*cosh$2(x.b),
|
|
32
|
+
cos$3(x.a)*sinh$2(x.b)
|
|
33
|
+
);
|
|
34
|
+
return sin$3(x)
|
|
35
|
+
},
|
|
36
|
+
tan : x=>{
|
|
37
|
+
if(x?.isComplex){
|
|
38
|
+
const DEN = cos$3(2*x.a)+cosh$2(2*x.b);
|
|
39
|
+
return new x.constructor(
|
|
40
|
+
sin$3(2*x.a)/DEN,
|
|
41
|
+
sinh$2(2*x.b)/DEN
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return tan$1(x)
|
|
45
|
+
},
|
|
25
46
|
sinc: x => sin$3(PI$1*x)/(PI$1*x),
|
|
26
47
|
sec: x => 1/cos$3(x),
|
|
27
48
|
csc: x => 1/sin$3(x),
|
|
28
49
|
cot: x => 1/tan$1(x),
|
|
29
|
-
acos:
|
|
30
|
-
|
|
31
|
-
|
|
50
|
+
acos: x=>{
|
|
51
|
+
if(x?.isComplex) return
|
|
52
|
+
return sin$3(x)
|
|
53
|
+
},
|
|
54
|
+
asin: x=>{
|
|
55
|
+
if(x?.isComplex) return
|
|
56
|
+
return sin$3(x)
|
|
57
|
+
},
|
|
58
|
+
atan: x=>{
|
|
59
|
+
if(x?.isComplex) return
|
|
60
|
+
return sin$3(x)
|
|
61
|
+
},
|
|
32
62
|
acot: x => PI$1/2-atan$1(x),
|
|
33
|
-
cosh:
|
|
34
|
-
|
|
35
|
-
|
|
63
|
+
cosh: x=>{
|
|
64
|
+
if(x?.isComplex) return new x.constructor(
|
|
65
|
+
cosh$2(x.a)*cos$3(x.b),
|
|
66
|
+
sinh$2(x.a)*sin$3(x.b)
|
|
67
|
+
);
|
|
68
|
+
return cosh$2(x)
|
|
69
|
+
},
|
|
70
|
+
sinh: x=>{
|
|
71
|
+
if(x?.isComplex) return new x.constructor(
|
|
72
|
+
sinh$2(x.a)*cos$3(x.b),
|
|
73
|
+
cosh$2(x.a)*sin$3(x.b)
|
|
74
|
+
);
|
|
75
|
+
return sinh$2(x)
|
|
76
|
+
},
|
|
77
|
+
tanh: x=>{
|
|
78
|
+
if(x?.isComplex){
|
|
79
|
+
const DEN=cosh$2(2*a)+cos$3(2*b);
|
|
80
|
+
return new x.constructor(
|
|
81
|
+
sinh$2(2*a)/DEN,
|
|
82
|
+
sin$3(2*b)/DEN
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
return tanh$1(x)
|
|
86
|
+
},
|
|
36
87
|
coth: n => (1/2*log$1((1+n)/(1-n))),
|
|
37
88
|
acosh: acosh$1,
|
|
38
89
|
asinh: asinh$1,
|
|
39
90
|
atanh: atanh$1,
|
|
40
91
|
};
|
|
41
92
|
|
|
42
|
-
Fixed = new Proxy(Fixed, {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})
|
|
93
|
+
// Fixed = new Proxy(Fixed, {
|
|
94
|
+
// get(target, prop) {
|
|
95
|
+
// if(prop in target){
|
|
96
|
+
// return x => + target[prop](x).toFixed(15);
|
|
97
|
+
// }
|
|
98
|
+
// return undefined;
|
|
99
|
+
// }
|
|
100
|
+
// })
|
|
101
|
+
|
|
102
|
+
const is_primitive = value => typeof value !== 'object' && typeof value !== 'function' || value === null;
|
|
50
103
|
|
|
51
|
-
// To generalise
|
|
52
|
-
|
|
53
104
|
const mapfun$1=(fun,...X)=>{
|
|
54
105
|
const Y=X.map(x=>{
|
|
55
|
-
if(x
|
|
56
|
-
if(["number","string","boolean","bigint","undefined"].includes(typeof x)) return fun(x);
|
|
106
|
+
if(is_primitive(x) || x?.__mapfun__) return fun(x)
|
|
57
107
|
if(x instanceof Array) return x.map(n=>mapfun$1(fun,n));
|
|
58
108
|
if(ArrayBuffer.isView(x)) return x.map(n=>fun(n));
|
|
59
109
|
if(x instanceof Set) return new Set(mapfun$1(fun,...[...x]));
|
|
60
110
|
if(x instanceof Map) return new Map([...x].map(n=>[n[0],mapfun$1(fun,n[1])]));
|
|
61
|
-
if(x
|
|
62
|
-
|
|
111
|
+
if(x.isMatrix?.()) return new x.constructor(x.rows, x.cols, mapfun$1(x.arr.flat(1)))
|
|
112
|
+
else if(x instanceof Object){
|
|
113
|
+
return Object.fromEntries(
|
|
114
|
+
Object.entries(x).map(
|
|
115
|
+
n=>n=[n[0],mapfun$1(fun,n[1])]
|
|
116
|
+
)
|
|
117
|
+
)
|
|
63
118
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
119
|
+
});
|
|
120
|
+
return Y.length==1? Y[0]: Y;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// Mixed calcul
|
|
124
|
+
const sum=(...x)=>{
|
|
125
|
+
if(x.every(n=>typeof n==="number")){
|
|
126
|
+
let s = x[0];
|
|
127
|
+
for (let i = 1; i < x.length; i++) s += x[i];
|
|
128
|
+
return s;
|
|
129
|
+
}
|
|
130
|
+
const Y=[];
|
|
131
|
+
for(let i=0;i<x.length;i++){
|
|
132
|
+
if(x[i] instanceof Array)Y.push(sum(...x[i]));
|
|
133
|
+
else if(x[i] instanceof Object){
|
|
134
|
+
Y.push(sum(...Object.values(x[i])));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return Y.length===1?Y[0]:Y;
|
|
138
|
+
};
|
|
139
|
+
const prod=(...x)=>{
|
|
140
|
+
if(x.every(n=>typeof n==="number")){
|
|
141
|
+
let p = x[0];
|
|
142
|
+
for (let i = 1; i < x.length; i++) p *= x[i];
|
|
143
|
+
return p;
|
|
144
|
+
}
|
|
145
|
+
const Y=[];
|
|
146
|
+
for(let i=0;i<x.length;i++){
|
|
147
|
+
if(x[i] instanceof Array)Y.push(prod(...x[i]));
|
|
148
|
+
else if(x[i] instanceof Object){
|
|
149
|
+
Y.push(prod(...Object.values(x[i])));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return Y.length===1?Y[0]:Y;
|
|
153
|
+
};
|
|
154
|
+
const min=(...num)=>{
|
|
155
|
+
if(num.every(n=>typeof n==="number"))return Math.min(...num);
|
|
156
|
+
const Y=[];
|
|
157
|
+
for(let i=0;i<num.length;i++){
|
|
158
|
+
if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
159
|
+
else if(num[i] instanceof Object){
|
|
160
|
+
Y.push(
|
|
161
|
+
Object.fromEntries(
|
|
162
|
+
[Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
|
|
163
|
+
)
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return Y.length===1?Y[0]:Y;
|
|
168
|
+
};
|
|
169
|
+
const max=(...num)=>{
|
|
170
|
+
if(num.every(n=>typeof n==="number"))return Math.max(...num);
|
|
171
|
+
const Y=[];
|
|
172
|
+
for(let i=0;i<num.length;i++){
|
|
173
|
+
if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
174
|
+
else if(num[i] instanceof Object){
|
|
175
|
+
Y.push(
|
|
176
|
+
Object.fromEntries(
|
|
177
|
+
[Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return Y.length===1?Y[0]:Y;
|
|
183
|
+
};
|
|
184
|
+
const accum=(...num)=>{
|
|
185
|
+
if(num.every(n=>typeof n==="number")){
|
|
186
|
+
let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
|
|
187
|
+
acc.shift();
|
|
188
|
+
return acc;
|
|
189
|
+
}
|
|
190
|
+
const Y=[];
|
|
191
|
+
for(let i=0;i<num.length;i++){
|
|
192
|
+
if(num[i] instanceof Array)Y.push(accum(...num[i]));
|
|
193
|
+
else if(num[i] instanceof Object){
|
|
194
|
+
Y.push(null
|
|
195
|
+
// Object.fromEntries(
|
|
196
|
+
// [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
197
|
+
// )
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return Y.length===1?Y[0]:Y;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
//moy
|
|
205
|
+
//med
|
|
206
|
+
//variance
|
|
207
|
+
//std
|
|
208
|
+
//mode
|
|
209
|
+
//acccum
|
|
210
|
+
//min2max
|
|
211
|
+
//max2min
|
|
212
|
+
//percentile
|
|
213
|
+
|
|
214
|
+
const abs=(...x)=>mapfun$1(Math.abs,...x);
|
|
215
|
+
const sqrt$2=(...x)=>mapfun$1(Math.sqrt,...x);
|
|
216
|
+
const pow$1=(x,n)=>{
|
|
217
|
+
if(typeof x === "number"){
|
|
218
|
+
if(typeof n === "number")return Math.pow(x,n);
|
|
219
|
+
else if(n?.isComplex?.())return n.constructor.fromExpo(x**n.a,n.b*ln(x))
|
|
220
|
+
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
221
|
+
}
|
|
222
|
+
else if(x.isComplex?.()){
|
|
223
|
+
if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
|
|
224
|
+
else if(n.isComplex?.())return x.constructor.fromExpo(
|
|
225
|
+
x.z**n.a*e(-x.phi*n.b),
|
|
226
|
+
ln(x.z)*n.b+n.a*x.phi
|
|
227
|
+
)
|
|
228
|
+
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
229
|
+
}
|
|
230
|
+
else if(x instanceof Array){
|
|
231
|
+
if(typeof n === "number") return mapfun$1(a=>pow$1(a,n),...x);
|
|
232
|
+
else if(n instanceof Array){
|
|
233
|
+
const Y=[];
|
|
234
|
+
for(let i=0;i<x.length;i++){
|
|
235
|
+
Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
|
|
84
236
|
}
|
|
237
|
+
return Y;
|
|
85
238
|
}
|
|
86
|
-
|
|
87
|
-
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
const sqrtn=(x,n)=>{
|
|
242
|
+
if(typeof x === "number"){
|
|
243
|
+
if(typeof n === "number")return Math.pow(x,1/n);
|
|
244
|
+
else return mapfun$1(a=>sqrtn(x,a),...n);
|
|
245
|
+
}
|
|
246
|
+
else if(x.isComplex?.()){
|
|
247
|
+
if(typeof n === "number")return x.constructor.fromExpo(sqrtn(x.z,n),x.phi/n);
|
|
248
|
+
else return mapfun$1(a=>sqrtn(x,a),...n);
|
|
249
|
+
}
|
|
250
|
+
else if(x instanceof Array){
|
|
251
|
+
if(typeof n === "number") return mapfun$1(a=>sqrtn(a,n),...x);
|
|
252
|
+
else if(n instanceof Array){
|
|
253
|
+
const Y=[];
|
|
254
|
+
for(let i=0;i<x.length;i++){
|
|
255
|
+
Y.push(mapfun$1(a=>sqrtn(x[i],a),...n));
|
|
256
|
+
}
|
|
257
|
+
return Y;
|
|
88
258
|
}
|
|
89
|
-
}
|
|
90
|
-
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const e=(...x) => mapfun$1(Math.exp,...x);
|
|
262
|
+
const ln=(...x) => mapfun$1(Math.log,...x);
|
|
263
|
+
const cos$2=(...x) => mapfun$1(Fixed.cos,...x);
|
|
264
|
+
const sin$2=(...x) => mapfun$1(Fixed.sin,...x);
|
|
265
|
+
const tan=(...x) => mapfun$1(Fixed.tan,...x);
|
|
266
|
+
const sec=(...x) => mapfun$1(Fixed.sec,...x);
|
|
267
|
+
const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
|
|
268
|
+
const csc=(...x) => mapfun$1(Fixed.csc,...x);
|
|
269
|
+
const cot=(...x) => mapfun$1(Fixed.cot,...x);
|
|
270
|
+
const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
|
|
271
|
+
const asin=(...x) => mapfun$1(Fixed.asin,...x);
|
|
272
|
+
const atan=(...x) => mapfun$1(Fixed.atan,...x);
|
|
273
|
+
const acot=(...x) => mapfun$1(Fixed.acot,...x);
|
|
274
|
+
const cosh$1=(...x) => mapfun$1(Fixed.cosh,...x);
|
|
275
|
+
const sinh$1=(...x) => mapfun$1(Fixed.sinh,...x);
|
|
276
|
+
const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
|
|
277
|
+
const coth=(...x) => mapfun$1(Fixed.coth,...x);
|
|
278
|
+
const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
|
|
279
|
+
const asinh=(...x) => mapfun$1(Fixed.asinh,...x);
|
|
280
|
+
const atanh=(...x) => mapfun$1(Fixed.atanh,...x);
|
|
281
|
+
const ceil=(...x) => mapfun$1(Math.ceil,...x);
|
|
282
|
+
const floor=(...x) => mapfun$1(Math.floor,...x);
|
|
283
|
+
const round=(...x) => mapfun$1(Math.round,...x);
|
|
284
|
+
const atan2=(x,y,rad=true)=>{
|
|
285
|
+
if(typeof x === "number"){
|
|
286
|
+
if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
|
|
287
|
+
else return mapfun$1(a=>atan2(x,a,rad),...y);
|
|
288
|
+
}
|
|
289
|
+
// else if(x.isComplex?.()){
|
|
290
|
+
// if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
|
|
291
|
+
// else return mapfun(a=>pow(x,a),...n);
|
|
292
|
+
// }
|
|
293
|
+
else if(x instanceof Array){
|
|
294
|
+
if(typeof y === "number") return mapfun$1(a=>atan2(a,y,rad),...x);
|
|
295
|
+
else if(y instanceof Array){
|
|
296
|
+
const Y=[];
|
|
297
|
+
for(let i=0;i<x.length;i++){
|
|
298
|
+
Y.push(mapfun$1(a=>pow$1(x[i],a),...y));
|
|
299
|
+
}
|
|
300
|
+
return Y;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
const fact=(...x)=>mapfun$1(n=> {
|
|
305
|
+
let i,
|
|
306
|
+
y = 1;
|
|
307
|
+
if (n == 0) y = 1;
|
|
308
|
+
else if (n > 0) for (i = 1; i <= n; i++) y *= i;
|
|
309
|
+
else y = NaN;
|
|
310
|
+
return y;
|
|
311
|
+
},...x);
|
|
312
|
+
const sign=(...x)=>mapfun$1(Math.sign,...x);
|
|
313
|
+
|
|
314
|
+
const sig=(...x)=>mapfun$1(n=>1/(1+e(-n)),...x);
|
|
315
|
+
|
|
316
|
+
const hypot=(...x)=>{
|
|
317
|
+
if(x.every(n=>typeof n === "number"))return Math.hypot(...x);
|
|
318
|
+
if(x.every(n=>n instanceof Array))return mapfun$1(
|
|
319
|
+
Math.hypot,
|
|
320
|
+
...x
|
|
321
|
+
)
|
|
91
322
|
};
|
|
92
323
|
|
|
93
324
|
const _add=(a,b)=>{
|
|
94
325
|
if(typeof(a)==="number"){
|
|
95
326
|
if (typeof b == "number") return a + b;
|
|
96
|
-
else if (b
|
|
97
|
-
else if (b
|
|
327
|
+
else if (b.isComplex?.())return new b.constructor(a + b.a, b.b);
|
|
328
|
+
else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).add(b);
|
|
98
329
|
else if (b instanceof Array)return b.map(n=>add(n,a));
|
|
99
330
|
}
|
|
100
|
-
else if(a
|
|
331
|
+
else if(a.isComplex?.()||a.isMatrix?.()){
|
|
101
332
|
if(b instanceof Array)return b.map(n=>a.clone.add(n));
|
|
102
333
|
return a.clone.add(b);
|
|
103
334
|
}
|
|
@@ -113,11 +344,11 @@
|
|
|
113
344
|
const _sub=(a,b)=>{
|
|
114
345
|
if(typeof(a)==="number"){
|
|
115
346
|
if (typeof b == "number") return a - b;
|
|
116
|
-
else if (b
|
|
117
|
-
else if (b
|
|
347
|
+
else if (b.isComplex?.())return new b.constructor(a - b.a, -b.b);
|
|
348
|
+
else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).sub(b);
|
|
118
349
|
else if (b instanceof Array)return b.map(n=>sub(n,a));
|
|
119
350
|
}
|
|
120
|
-
else if(a
|
|
351
|
+
else if(a.isComplex?.()||a.isMatrix?.()){
|
|
121
352
|
if(b instanceof Array)return b.map(n=>a.clone.sub(n));
|
|
122
353
|
return a.clone.sub(b);
|
|
123
354
|
}
|
|
@@ -135,11 +366,11 @@
|
|
|
135
366
|
const _mul=(a,b)=>{
|
|
136
367
|
if(typeof(a)==="number"){
|
|
137
368
|
if (typeof b == "number") return a * b;
|
|
138
|
-
else if (b
|
|
139
|
-
else if (b
|
|
369
|
+
else if (b.isComplex?.())return new b.constructor(a * b.a,a * b.b);
|
|
370
|
+
else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).mul(b);
|
|
140
371
|
else if (b instanceof Array)return b.map(n=>mul(a,n));
|
|
141
372
|
}
|
|
142
|
-
else if(a
|
|
373
|
+
else if(a.isComplex?.()||a.isMatrix?.()){
|
|
143
374
|
if(b instanceof Array)return b.map(n=>a.clone.mul(n));
|
|
144
375
|
return a.clone.mul(b);
|
|
145
376
|
}
|
|
@@ -157,11 +388,11 @@
|
|
|
157
388
|
const _div=(a,b)=>{
|
|
158
389
|
if(typeof(a)==="number"){
|
|
159
390
|
if (typeof b == "number") return a / b;
|
|
160
|
-
else if (b
|
|
161
|
-
else if (b
|
|
391
|
+
else if (b.isComplex?.())return new b.constructor(a / b.a,a / b.b);
|
|
392
|
+
else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).div(b);
|
|
162
393
|
else if (b instanceof Array)return b.map(n=>div(a,n));
|
|
163
394
|
}
|
|
164
|
-
else if(a
|
|
395
|
+
else if(a.isComplex?.()||a.isMatrix?.()){
|
|
165
396
|
if(b instanceof Array)return b.map(n=>a.clone.div(n));
|
|
166
397
|
return a.clone.div(b);
|
|
167
398
|
}
|
|
@@ -179,11 +410,11 @@
|
|
|
179
410
|
const _modulo=(a,b)=>{
|
|
180
411
|
if(typeof(a)==="number"){
|
|
181
412
|
if (typeof b == "number") return a % b;
|
|
182
|
-
else if (b
|
|
183
|
-
else if (b
|
|
413
|
+
else if (b.isComplex?.())return new b.constructor(a % b.a,a % b.b);
|
|
414
|
+
else if (b.isMatrix?.()) return b.constructor.nums(b.rows, b.cols, a).modulo(b);
|
|
184
415
|
else if (b instanceof Array)return b.map(n=>div(a,n));
|
|
185
416
|
}
|
|
186
|
-
else if(a
|
|
417
|
+
else if(a.isComplex?.()||a.isMatrix?.()){
|
|
187
418
|
if(b instanceof Array)return b.map(n=>a.clone.div(n));
|
|
188
419
|
return a.clone.div(b);
|
|
189
420
|
}
|
|
@@ -225,8 +456,8 @@
|
|
|
225
456
|
const nums=(num,n)=>new Array(n).fill(num);
|
|
226
457
|
const norm=(value, min, max)=>{
|
|
227
458
|
if (typeof value === "number") return min !== max ? (value - min) / (max - min) : 0;
|
|
228
|
-
else if (value
|
|
229
|
-
else if (value
|
|
459
|
+
else if (value.isMatrix?.()) return new value.constructor(value.rows, value.cols, norm(value.arr.flat(1), min, max));
|
|
460
|
+
else if (value.isComplex?.()) return new value.constructor(norm(value.a, min, max), norm(value.b, min, max));
|
|
230
461
|
else if (value instanceof Array) {
|
|
231
462
|
if (value.every((n) => typeof (n === "number"))) {
|
|
232
463
|
return value.map((n) => norm(n, min, max));
|
|
@@ -240,8 +471,8 @@
|
|
|
240
471
|
};
|
|
241
472
|
const lerp=(value, min, max)=>{
|
|
242
473
|
if (typeof value === "number") return (max - min) * value + min;
|
|
243
|
-
else if (value
|
|
244
|
-
else if (value
|
|
474
|
+
else if (value.isMatrix?.()) return new value.constructor(value.rows, value.cols, lerp(value.arr.flat(1), min, max));
|
|
475
|
+
else if (value.isComplex?.()) return new value.constructor(lerp(value.a, min, max), lerp(value.b, min, max));
|
|
245
476
|
else if (value instanceof Array) {
|
|
246
477
|
if (value.every((n) => typeof (n === "number"))) {
|
|
247
478
|
return value.map((n) => lerp(n, min, max));
|
|
@@ -253,17 +484,17 @@
|
|
|
253
484
|
}
|
|
254
485
|
}
|
|
255
486
|
};
|
|
256
|
-
const map$1=(
|
|
257
|
-
if (typeof
|
|
258
|
-
else if (
|
|
259
|
-
else if (
|
|
260
|
-
else if (
|
|
261
|
-
if (
|
|
262
|
-
return
|
|
487
|
+
const map$1=(x, a, b, c, d)=>{
|
|
488
|
+
if (typeof x === "number") return lerp(norm(x, a, b), c, d);
|
|
489
|
+
else if (x.isMatrix?.()) return new x.constructor(x.rows, x.cols, map$1(x.arr.flat(1), a, b, c, d));
|
|
490
|
+
else if (x.isComplex?.()) return new x.constructor(map$1(x.a, b, c, d), map$1(x.b, a, b, c, d));
|
|
491
|
+
else if (x instanceof Array) {
|
|
492
|
+
if (x.every((n) => typeof (n === "number"))) {
|
|
493
|
+
return x.map((n) => map$1(n, a, b, c, d));
|
|
263
494
|
} else {
|
|
264
|
-
let y = new Array(
|
|
265
|
-
for (let i = 0; i <
|
|
266
|
-
y[i] = map$1(
|
|
495
|
+
let y = new Array(x.length);
|
|
496
|
+
for (let i = 0; i < x.length; i++) {
|
|
497
|
+
y[i] = map$1(x[i], a, b, c, d);
|
|
267
498
|
}
|
|
268
499
|
}
|
|
269
500
|
}
|
|
@@ -271,8 +502,8 @@
|
|
|
271
502
|
const clamp=(x, a , b)=>{
|
|
272
503
|
const [min_value,max_value]=[min(a,b),max(a,b)];
|
|
273
504
|
if (typeof x === "number") return min(max(x, min_value), max_value);
|
|
274
|
-
else if (x
|
|
275
|
-
else if (x
|
|
505
|
+
else if (x.isMatrix?.()) return new x.constructor(x.rows, x.cols, clamp(x.arr.flat(1), min_value, max_value));
|
|
506
|
+
else if (x.isComplex?.()) return new x.constructor(clamp(x.a, min_value, max_value), clamp(x.b, min_value, max_value));
|
|
276
507
|
else if (x instanceof Array) {
|
|
277
508
|
if (x.every((n) => typeof (n === "number"))) {
|
|
278
509
|
return x.map((n) => clamp(n, min_value, max_value));
|
|
@@ -307,14 +538,14 @@
|
|
|
307
538
|
return Y
|
|
308
539
|
}
|
|
309
540
|
|
|
310
|
-
if([a,b].some(n=>n
|
|
311
|
-
const z1=
|
|
312
|
-
const z2=
|
|
541
|
+
if([a,b].some(n=>n.isComplex?.())){
|
|
542
|
+
const z1 = new n.constructor(a);
|
|
543
|
+
const z2 = new n.constructor(b);
|
|
313
544
|
n=n||Math.abs(z1.a-z2.a)+1;
|
|
314
545
|
const X=linspace(z1.a,z2.a,n,endpoint);
|
|
315
546
|
const Y=linspace(z1.b,z2.b,n,endpoint);
|
|
316
547
|
let Z=new Array(n).fill(null);
|
|
317
|
-
Z=Z.map((n,i)=>
|
|
548
|
+
Z=Z.map((n,i)=> new n.constructor(X[i],Y[i]));
|
|
318
549
|
return Z;
|
|
319
550
|
}
|
|
320
551
|
};
|
|
@@ -334,9 +565,9 @@
|
|
|
334
565
|
return a<b?Y:Y.reverse()
|
|
335
566
|
}
|
|
336
567
|
|
|
337
|
-
if([a,b].some(n=>n
|
|
338
|
-
const z1=
|
|
339
|
-
const z2=
|
|
568
|
+
if([a,b].some(n=>n.isComplex?.())){
|
|
569
|
+
const z1 = new n.constructor(a);
|
|
570
|
+
const z2 = new n.constructor(b);
|
|
340
571
|
n=n||Math.abs(z1.a-z2.a)+1;
|
|
341
572
|
let base;
|
|
342
573
|
endpoint ? base = sqrtn(z2.div(z1),n-1) : base = sqrtn(z2.div(z1),n) ;
|
|
@@ -363,109 +594,18 @@
|
|
|
363
594
|
*/
|
|
364
595
|
const rad2deg = (...rad) => mapfun(x => x / Math.PI * 180, ...rad);
|
|
365
596
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return Y.length===1?Y[0]:Y;
|
|
381
|
-
};
|
|
382
|
-
const prod=(...x)=>{
|
|
383
|
-
if(x.every(n=>typeof n==="number")){
|
|
384
|
-
let p = x[0];
|
|
385
|
-
for (let i = 1; i < x.length; i++) p *= x[i];
|
|
386
|
-
return p;
|
|
387
|
-
}
|
|
388
|
-
const Y=[];
|
|
389
|
-
for(let i=0;i<x.length;i++){
|
|
390
|
-
if(x[i] instanceof Array)Y.push(prod(...x[i]));
|
|
391
|
-
else if(x[i] instanceof Object){
|
|
392
|
-
Y.push(prod(...Object.values(x[i])));
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
return Y.length===1?Y[0]:Y;
|
|
396
|
-
};
|
|
397
|
-
const min=(...num)=>{
|
|
398
|
-
if(num.every(n=>typeof n==="number"))return Math.min(...num);
|
|
399
|
-
const Y=[];
|
|
400
|
-
for(let i=0;i<num.length;i++){
|
|
401
|
-
if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
402
|
-
else if(num[i] instanceof Object){
|
|
403
|
-
Y.push(
|
|
404
|
-
Object.fromEntries(
|
|
405
|
-
[Object.entries(num[i]).sort((a,b)=>a[1]-b[1])[0]]
|
|
406
|
-
)
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
return Y.length===1?Y[0]:Y;
|
|
411
|
-
};
|
|
412
|
-
const max=(...num)=>{
|
|
413
|
-
if(num.every(n=>typeof n==="number"))return Math.max(...num);
|
|
414
|
-
const Y=[];
|
|
415
|
-
for(let i=0;i<num.length;i++){
|
|
416
|
-
if(num[i] instanceof Array)Y.push(min(...num[i]));
|
|
417
|
-
else if(num[i] instanceof Object){
|
|
418
|
-
Y.push(
|
|
419
|
-
Object.fromEntries(
|
|
420
|
-
[Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
421
|
-
)
|
|
422
|
-
);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
return Y.length===1?Y[0]:Y;
|
|
426
|
-
};
|
|
427
|
-
const accum=(...num)=>{
|
|
428
|
-
if(num.every(n=>typeof n==="number")){
|
|
429
|
-
let acc = num.reduce((x, y) => [...x, x[x.length - 1] + y], [0]);
|
|
430
|
-
acc.shift();
|
|
431
|
-
return acc;
|
|
432
|
-
}
|
|
433
|
-
const Y=[];
|
|
434
|
-
for(let i=0;i<num.length;i++){
|
|
435
|
-
if(num[i] instanceof Array)Y.push(accum(...num[i]));
|
|
436
|
-
else if(num[i] instanceof Object){
|
|
437
|
-
Y.push(null
|
|
438
|
-
// Object.fromEntries(
|
|
439
|
-
// [Object.entries(num[i]).sort((a,b)=>b[1]-a[1])[0]]
|
|
440
|
-
// )
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
return Y.length===1?Y[0]:Y;
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
//moy
|
|
448
|
-
//med
|
|
449
|
-
//variance
|
|
450
|
-
//std
|
|
451
|
-
//mode
|
|
452
|
-
//acccum
|
|
453
|
-
//min2max
|
|
454
|
-
//max2min
|
|
455
|
-
//percentile
|
|
456
|
-
|
|
457
|
-
/** @module Math */
|
|
458
|
-
/**
|
|
459
|
-
* Checks if a value is within the specified range.
|
|
460
|
-
* @function
|
|
461
|
-
* @param {number} x - The value to check.
|
|
462
|
-
* @param {number} a - The start of the range.
|
|
463
|
-
* @param {number} b - The end of the range.
|
|
464
|
-
* @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
|
|
465
|
-
*/
|
|
466
|
-
const inRange = (x, a, b) => {
|
|
467
|
-
const [min, max] = [Math.min(a, b), Math.max(a, b)];
|
|
468
|
-
return x >= min && x <= max;
|
|
597
|
+
/** @module Math */
|
|
598
|
+
/**
|
|
599
|
+
* Checks if a value is within the specified range.
|
|
600
|
+
* @function
|
|
601
|
+
* @param {number} x - The value to check.
|
|
602
|
+
* @param {number} a - The start of the range.
|
|
603
|
+
* @param {number} b - The end of the range.
|
|
604
|
+
* @returns {boolean} Returns true if the value is within the range [a, b], otherwise false.
|
|
605
|
+
*/
|
|
606
|
+
const inRange = (x, a, b) => {
|
|
607
|
+
const [min, max] = [Math.min(a, b), Math.max(a, b)];
|
|
608
|
+
return x >= min && x <= max;
|
|
469
609
|
};
|
|
470
610
|
|
|
471
611
|
/**
|
|
@@ -558,385 +698,185 @@
|
|
|
558
698
|
isApproximatlyEqual
|
|
559
699
|
};
|
|
560
700
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
701
|
+
class Complex{
|
|
702
|
+
constructor(a = 0, b = 0) {
|
|
703
|
+
if(a instanceof Complex){
|
|
704
|
+
this.a=a.a;
|
|
705
|
+
this.b=a.b;
|
|
706
|
+
}
|
|
707
|
+
else if(typeof(a)==="object"){
|
|
708
|
+
if(("a" in a && "b" in a)){
|
|
709
|
+
this.a=a.a;
|
|
710
|
+
this.b=a.b;
|
|
711
|
+
}
|
|
712
|
+
else if(("a" in a && "z" in a)){
|
|
713
|
+
this.a=a.a;
|
|
714
|
+
this.b=sqrt$2((a.z**2)-(a.a**2));
|
|
715
|
+
}
|
|
716
|
+
else if(("a" in a && "phi" in a)){
|
|
717
|
+
this.a=a.a;
|
|
718
|
+
this.b=a.a*tan(a.phi);
|
|
719
|
+
}
|
|
720
|
+
else if(("b" in a && "z" in a)){
|
|
721
|
+
this.b=a.b;
|
|
722
|
+
this.a=sqrt$2((a.z**2)-(a.b**2));
|
|
723
|
+
}
|
|
724
|
+
else if(("b" in a && "phi" in a)){
|
|
725
|
+
this.b=b;
|
|
726
|
+
this.a=a.b/tan(a.phi);
|
|
727
|
+
}
|
|
728
|
+
else if(("z" in a && "phi" in a)){
|
|
729
|
+
this.a = +a.z*cos$2(a.phi).toFixed(15);
|
|
730
|
+
this.b = +a.z*sin$2(a.phi).toFixed(15);
|
|
569
731
|
}
|
|
570
732
|
}
|
|
571
|
-
|
|
733
|
+
else if(typeof(a)==="number"&&typeof(b)==="number"){
|
|
734
|
+
this.a = +a.toFixed(32);
|
|
735
|
+
this.b = +b.toFixed(32);
|
|
736
|
+
}
|
|
572
737
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
// const subSet = (...arr) => {
|
|
577
|
-
// let list = arange(0, 2 ** arr.length, 1);
|
|
578
|
-
// let bin = list.map((n) => n.toString(2).padStart(arr.length, '0')).map((n) => n.split("").map((n) => +n));
|
|
579
|
-
// let sub = bin.map((n) => n.map((m, i) => (m === 1 ? arr[i] : null))).map((n) => n.filter((x) => x !== null));
|
|
580
|
-
// return sub;
|
|
581
|
-
// };
|
|
582
|
-
const subSet = null;
|
|
583
|
-
|
|
584
|
-
const Base={
|
|
585
|
-
_mode:Number,
|
|
586
|
-
_map:function(func,number,toBase){
|
|
587
|
-
if (number instanceof Matrix)
|
|
588
|
-
return new Matrix(
|
|
589
|
-
number.rows,
|
|
590
|
-
number.cols,
|
|
591
|
-
number.arr.flat(1).map(n=>func(n,toBase))
|
|
592
|
-
);
|
|
593
|
-
else if (number instanceof Complex) return new Complex(func(number.a,toBase),func(number.b,toBase));
|
|
594
|
-
else if (number instanceof Array) return number.map((n) =>func(n,toBase));
|
|
595
|
-
},
|
|
596
|
-
dec2base(dec,base){
|
|
597
|
-
base<=10?this._mode=Number:this._mode=String;
|
|
598
|
-
//this._mode=String
|
|
599
|
-
if (typeof dec === "number") return this._mode((dec >>> 0).toString(base));
|
|
600
|
-
return this._map(this.dec2base,dec,base)
|
|
601
|
-
},
|
|
602
|
-
dec2bin(dec){
|
|
603
|
-
return this.dec2base(dec,2);
|
|
604
|
-
},
|
|
605
|
-
dec2oct(dec){
|
|
606
|
-
return this.dec2base(dec,8);
|
|
607
|
-
},
|
|
608
|
-
dec2hex(dec){
|
|
609
|
-
return this.dec2base(dec,16);
|
|
610
|
-
},
|
|
611
|
-
bin2base(bin, base) {
|
|
612
|
-
return this.dec2base(this.bin2dec(bin),base)
|
|
613
|
-
},
|
|
614
|
-
bin2dec(bin){
|
|
615
|
-
return this._mode("0b"+bin);
|
|
616
|
-
},
|
|
617
|
-
bin2oct(bin){
|
|
618
|
-
return this.bin2base(bin,8);
|
|
619
|
-
},
|
|
620
|
-
bin2hex(bin){
|
|
621
|
-
return this.bin2base(bin,16);
|
|
622
|
-
},
|
|
623
|
-
oct2dec(oct){
|
|
624
|
-
return this._mode("0o"+oct);
|
|
625
|
-
},
|
|
626
|
-
oct2bin(oct){
|
|
627
|
-
return this.dec2bin(this.oct2dec(oct))
|
|
628
|
-
},
|
|
629
|
-
oct2hex(oct){
|
|
630
|
-
return this.dec2hex(this.oct2dec(oct))
|
|
631
|
-
},
|
|
632
|
-
oct2base(oct, base) {
|
|
633
|
-
return this.dec2base(this.oct2dec(oct),base)
|
|
634
|
-
},
|
|
635
|
-
hex2dec(hex){
|
|
636
|
-
return this._mode("0x"+hex);
|
|
637
|
-
},
|
|
638
|
-
hex2bin(hex){
|
|
639
|
-
return this.dec2bin(this.hex2dec(hex))
|
|
640
|
-
},
|
|
641
|
-
hex2oct(hex){
|
|
642
|
-
return this.dec2oct(this.hex2dec(hex))
|
|
643
|
-
},
|
|
644
|
-
hex2base(hex, base) {
|
|
645
|
-
return this.dec2base(this.hex2dec(hex),base)
|
|
646
|
-
},
|
|
647
|
-
IEEE32toDec(Bin){
|
|
648
|
-
let IEEE32=Bin.split(" ").join("").padEnd(32,"0");
|
|
649
|
-
let s=IEEE32[0];
|
|
650
|
-
let e=2**(+("0b"+IEEE32.slice(1,9))-127);
|
|
651
|
-
let m=IEEE32.slice(9,32).split("").map(n=>+n);
|
|
652
|
-
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
653
|
-
let dec=(-1)**s*(1+M)*e;
|
|
654
|
-
return dec
|
|
655
|
-
},
|
|
656
|
-
IEEE64toDec(Bin){
|
|
657
|
-
let IEEE64=Bin.split(" ").join("").padEnd(64,"0");
|
|
658
|
-
let s=IEEE64[0];
|
|
659
|
-
let e=2**(+("0b"+IEEE64.slice(1,12))-1023);
|
|
660
|
-
let m=IEEE64.slice(13,64).split("").map(n=>+n);
|
|
661
|
-
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
662
|
-
let dec=(-1)**s*(1+M)*e;
|
|
663
|
-
return dec;
|
|
738
|
+
get __mapfun__(){
|
|
739
|
+
return true
|
|
664
740
|
}
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
const Logic$1={
|
|
668
|
-
_mode:Number,
|
|
669
|
-
_map:function(func,a,b){
|
|
670
|
-
if (a instanceof Matrix)
|
|
671
|
-
return new Matrix(
|
|
672
|
-
a.rows,
|
|
673
|
-
a.cols,
|
|
674
|
-
a.arr.flat(1).map((n) => func(n, b))
|
|
675
|
-
);
|
|
676
|
-
else if (a instanceof Complex) return new Complex(func(a.a, b), func(a.b, b));
|
|
677
|
-
else if (a instanceof Array) return a.map((n) => func(n, b));
|
|
678
|
-
},
|
|
679
|
-
not:function(input){
|
|
680
|
-
if(["number","boolean"].includes(typeof input)) return Logic$1._mode(!input);
|
|
681
|
-
else return this._map(this.not,input)
|
|
682
|
-
},
|
|
683
|
-
and:function(a, ...b){
|
|
684
|
-
if(["number","boolean"].includes(typeof a))return Logic$1._mode(b.reduce((n, m) => (n &= m), a));
|
|
685
|
-
else return this._map(this.and,a,b)
|
|
686
|
-
},
|
|
687
|
-
or:function(a, ...b) {
|
|
688
|
-
if(["number","boolean"].includes(typeof a)) return Logic$1._mode(b.reduce((n, m) => (n |= m), a));
|
|
689
|
-
else return this._map(this.or,a,b);
|
|
690
|
-
},
|
|
691
|
-
nand:function(a, ...b) {
|
|
692
|
-
return this.not(this.and(a, b));
|
|
693
|
-
},
|
|
694
|
-
nor:function(a, ...b) {
|
|
695
|
-
return this.not(this.or(a, b));
|
|
696
|
-
},
|
|
697
|
-
xor:function(a,...b){
|
|
698
|
-
let arr=[a,...b];
|
|
699
|
-
if(["number","boolean"].includes(typeof a))return this._mode(arr.reduce((length,cur)=>{
|
|
700
|
-
if(+cur===1)length+=1;
|
|
701
|
-
return length;
|
|
702
|
-
},0)===1);
|
|
703
|
-
else return this._map(this.xor,a,b);
|
|
704
|
-
},
|
|
705
|
-
xnor:function(a,...b){
|
|
706
|
-
return Logic$1.not(Logic$1.xor(a,b))
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
class Permutation {
|
|
712
|
-
static withDiscount(arr, l = arr.length) {
|
|
713
|
-
if (l === 1) return arr.map((n) => [n]);
|
|
714
|
-
const permutations = [];
|
|
715
|
-
let smallerPermutations;
|
|
716
|
-
smallerPermutations = this.withDiscount(arr, l - 1);
|
|
717
|
-
arr.forEach((currentOption) => {
|
|
718
|
-
smallerPermutations.forEach((smallerPermutation) => {
|
|
719
|
-
permutations.push([currentOption].concat(smallerPermutation));
|
|
720
|
-
});
|
|
721
|
-
});
|
|
722
|
-
return permutations;
|
|
723
|
-
}
|
|
724
|
-
static withoutDiscount(arr) {
|
|
725
|
-
const l = arr.length;
|
|
726
|
-
if (l === 1) return arr.map((n) => [n]);
|
|
727
|
-
const permutations = [];
|
|
728
|
-
const smallerPermutations = this.withoutDiscount(arr.slice(1));
|
|
729
|
-
const firstOption = arr[0];
|
|
730
|
-
for (let i = 0; i < smallerPermutations.length; i++) {
|
|
731
|
-
const smallerPermutation = smallerPermutations[i];
|
|
732
|
-
for (let j = 0; j <= smallerPermutation.length; j++) {
|
|
733
|
-
const permutationPrefix = smallerPermutation.slice(0, j);
|
|
734
|
-
const permutationSuffix = smallerPermutation.slice(j);
|
|
735
|
-
permutations.push(permutationPrefix.concat([firstOption], permutationSuffix));
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
return permutations;
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
class Combinaison {
|
|
743
|
-
static withDiscount(comboOptions, comboLength) {
|
|
744
|
-
if (comboLength === 1) {
|
|
745
|
-
return comboOptions.map((comboOption) => [comboOption]);
|
|
746
|
-
}
|
|
747
|
-
const combos = [];
|
|
748
|
-
comboOptions.forEach((currentOption, optionIndex) => {
|
|
749
|
-
const smallerCombos = this.withDiscount(comboOptions.slice(optionIndex), comboLength - 1);
|
|
750
|
-
smallerCombos.forEach((smallerCombo) => {
|
|
751
|
-
combos.push([currentOption].concat(smallerCombo));
|
|
752
|
-
});
|
|
753
|
-
});
|
|
754
|
-
return combos;
|
|
755
|
-
}
|
|
756
|
-
static withoutDiscount(comboOptions, comboLength) {
|
|
757
|
-
if (comboLength === 1) {
|
|
758
|
-
return comboOptions.map((comboOption) => [comboOption]);
|
|
759
|
-
}
|
|
760
|
-
const combos = [];
|
|
761
|
-
comboOptions.forEach((currentOption, optionIndex) => {
|
|
762
|
-
const smallerCombos = this.withoutDiscount(comboOptions.slice(optionIndex + 1), comboLength - 1);
|
|
763
|
-
smallerCombos.forEach((smallerCombo) => {
|
|
764
|
-
combos.push([currentOption].concat(smallerCombo));
|
|
765
|
-
});
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
return combos;
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
const combinaison=(comboOptions, comboLength, discount=false)=>Combinaison[discount?"withDiscount":"withoutDiscount"](comboOptions, comboLength);
|
|
772
|
-
|
|
773
|
-
class Random {
|
|
774
|
-
static float(a = 1, b) {
|
|
775
|
-
return b ? Math.random() * (b - a) + a : a * Math.random();
|
|
776
|
-
}
|
|
777
|
-
static int(a, b) {
|
|
778
|
-
return Math.floor(this.float(a, b));
|
|
779
|
-
}
|
|
780
|
-
static char(upperCase){
|
|
781
|
-
upperCase=upperCase??this.bool();
|
|
782
|
-
const Char=String.fromCharCode(this.int(97,120));
|
|
783
|
-
return upperCase?Char.toUpperCase():Char;
|
|
784
|
-
}
|
|
785
|
-
static bool(){
|
|
786
|
-
return [false,true][Math.floor(Math.random()*2)];
|
|
787
|
-
}
|
|
788
|
-
static string(length,upperCase){
|
|
789
|
-
return length instanceof Array?
|
|
790
|
-
new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
|
|
791
|
-
new Array(length).fill(0).map(() => this.char(upperCase)).join("");
|
|
792
|
-
}
|
|
793
|
-
static bin() {
|
|
794
|
-
return this.int(2);
|
|
795
|
-
}
|
|
796
|
-
static oct() {
|
|
797
|
-
return this.int(8);
|
|
798
|
-
}
|
|
799
|
-
static dec() {
|
|
800
|
-
return this.int(8);
|
|
801
|
-
}
|
|
802
|
-
static hex() {
|
|
803
|
-
return this.int(16);
|
|
804
|
-
}
|
|
805
|
-
static choice(choices = [1, 2, 3], p = new Array(choices.length).fill(1 / choices.length)) {
|
|
806
|
-
let newchoice = new Array(100);
|
|
807
|
-
p=Utils.accum(...p).map(n=>n*100);
|
|
808
|
-
newchoice.fill(choices[0], 0, p[0]);
|
|
809
|
-
for (let i = 1; i < choices.length; i++) newchoice.fill(choices[i], p[i - 1], p[i]);
|
|
810
|
-
return newchoice[this.int(newchoice.length - 1)];
|
|
811
|
-
}
|
|
812
|
-
static shuffleArr(arr){
|
|
813
|
-
return arr.sort(()=>0.5-Math.random())
|
|
814
|
-
}
|
|
815
|
-
static shuffleMatrix(M){
|
|
816
|
-
const {rows,cols,arr}=M;
|
|
817
|
-
return matrix(rows,cols,arr.flat().sort(()=>0.5-Math.random()))
|
|
741
|
+
isComplex(){
|
|
742
|
+
return true
|
|
818
743
|
}
|
|
819
|
-
|
|
820
|
-
|
|
744
|
+
toString(){
|
|
745
|
+
let str = "";
|
|
746
|
+
if (this.a !== 0)
|
|
747
|
+
this.b >= 0
|
|
748
|
+
? (str = `${this.a}+${this.b}*i`)
|
|
749
|
+
: (str = `${this.a}-${Math.abs(this.b)}*i`);
|
|
750
|
+
else
|
|
751
|
+
this.b >= 0
|
|
752
|
+
? (str = `${this.b}*i`)
|
|
753
|
+
: (str = `-${Math.abs(this.b)}*i`);
|
|
754
|
+
return str;
|
|
821
755
|
}
|
|
822
|
-
|
|
823
|
-
|
|
756
|
+
|
|
757
|
+
get clone() {
|
|
758
|
+
return new Complex(this.a, this.b);
|
|
824
759
|
}
|
|
825
|
-
|
|
826
|
-
return
|
|
760
|
+
get z(){
|
|
761
|
+
return hypot(this.a,this.b);
|
|
827
762
|
}
|
|
828
|
-
|
|
829
|
-
return
|
|
763
|
+
get phi(){
|
|
764
|
+
return atan2(this.b , this.a);
|
|
830
765
|
}
|
|
831
|
-
static
|
|
832
|
-
return new
|
|
766
|
+
static Zero() {
|
|
767
|
+
return new Complex(0, 0);
|
|
833
768
|
}
|
|
834
|
-
|
|
835
|
-
return new
|
|
769
|
+
get conj() {
|
|
770
|
+
return new Complex(this.a, -this.b);
|
|
836
771
|
}
|
|
837
|
-
|
|
838
|
-
return new
|
|
772
|
+
get inv() {
|
|
773
|
+
return new Complex(this.a / (pow$1(this.a, 2) + pow$1(this.b, 2)), -this.b / (pow$1(this.a, 2) + pow$1(this.b, 2)));
|
|
839
774
|
}
|
|
840
|
-
|
|
841
|
-
|
|
775
|
+
add(...z) {
|
|
776
|
+
for (let i = 0; i < z.length; i++) {
|
|
777
|
+
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
778
|
+
}
|
|
779
|
+
let re = z.map((n) => n.a);
|
|
780
|
+
let im = z.map((n) => n.b);
|
|
781
|
+
this.a+=+sum(...re).toFixed(15);
|
|
782
|
+
this.b+=+sum(...im).toFixed(15);
|
|
783
|
+
return this;
|
|
842
784
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
785
|
+
sub(...z) {
|
|
786
|
+
for (let i = 0; i < z.length; i++) {
|
|
787
|
+
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
788
|
+
}
|
|
789
|
+
let re = z.map((n) => n.a);
|
|
790
|
+
let im = z.map((n) => n.b);
|
|
791
|
+
this.a-=+sum(...re).toFixed(15);
|
|
792
|
+
this.b-=+sum(...im).toFixed(15);
|
|
793
|
+
return this;
|
|
846
794
|
}
|
|
847
|
-
|
|
848
|
-
|
|
795
|
+
mul(...z){
|
|
796
|
+
for (let i = 0; i < z.length; i++) {
|
|
797
|
+
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
798
|
+
}
|
|
799
|
+
let Z=+prod(this.z,...z.map(n=>n.z)).toFixed(15);
|
|
800
|
+
let phi=+sum(this.phi,...z.map(n=>n.phi)).toFixed(15);
|
|
801
|
+
this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(14);
|
|
802
|
+
this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(14);
|
|
803
|
+
return this;
|
|
849
804
|
}
|
|
850
|
-
|
|
851
|
-
|
|
805
|
+
div(...z) {
|
|
806
|
+
for (let i = 0; i < z.length; i++) {
|
|
807
|
+
if (typeof z[i] === "number") z[i] = new Complex(z[i], 0);
|
|
808
|
+
}
|
|
809
|
+
let Z=+(this.z/prod(...z.map(n=>n.z))).toFixed(15);
|
|
810
|
+
let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
|
|
811
|
+
this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(15);
|
|
812
|
+
this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(15);
|
|
813
|
+
return this;
|
|
852
814
|
}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
this.
|
|
857
|
-
this.
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
)
|
|
862
|
-
|
|
815
|
+
pow(n) {
|
|
816
|
+
if (floor(n) === n && n > 0) {
|
|
817
|
+
let z=+(this.z**n).toFixed(15);
|
|
818
|
+
let phi=+(this.phi*n).toFixed(15);
|
|
819
|
+
this.a=+(z*cos$2(phi).toFixed(15)).toFixed(15);
|
|
820
|
+
this.b=+(z*sin$2(phi).toFixed(15)).toFixed(15);
|
|
821
|
+
}
|
|
822
|
+
return this;
|
|
863
823
|
}
|
|
864
|
-
static
|
|
824
|
+
static fromExpo(z, phi) {
|
|
865
825
|
return new Complex(
|
|
866
|
-
|
|
867
|
-
|
|
826
|
+
+(z * cos$2(phi)).toFixed(13),
|
|
827
|
+
+(z * sin$2(phi)).toFixed(13)
|
|
868
828
|
);
|
|
869
829
|
}
|
|
870
|
-
|
|
871
|
-
return
|
|
872
|
-
}
|
|
873
|
-
static complexOct() {
|
|
874
|
-
return new Complex(...this.octs(2));
|
|
875
|
-
}
|
|
876
|
-
static complexDec() {
|
|
877
|
-
return new Complex(...this.decs(10));
|
|
878
|
-
}
|
|
879
|
-
static complexHex() {
|
|
880
|
-
return new Complex(...this.octs(2));
|
|
881
|
-
}
|
|
882
|
-
static complexes(n, a = 0, b = 1) {
|
|
883
|
-
return new Array(n).fill(0).map(() => this.complex(a, b));
|
|
884
|
-
}
|
|
885
|
-
static complexesInt(n, a = 0, b = 1) {
|
|
886
|
-
return new Array(n).fill(0).map(() => this.complexInt(a, b));
|
|
887
|
-
}
|
|
888
|
-
static complexesBin(n) {
|
|
889
|
-
return new Array(n).fill(0).map(() => this.complexBin());
|
|
890
|
-
}
|
|
891
|
-
static complexesOct(n) {
|
|
892
|
-
return new Array(n).fill(0).map(() => this.complexOct());
|
|
893
|
-
}
|
|
894
|
-
static complexesDec(n) {
|
|
895
|
-
return new Array(n).fill(0).map(() => this.complexDec());
|
|
896
|
-
}
|
|
897
|
-
static complexesHex(n) {
|
|
898
|
-
return new Array(n).fill(0).map(() => this.complexHex());
|
|
830
|
+
get expo() {
|
|
831
|
+
return [this.z, this.phi];
|
|
899
832
|
}
|
|
900
|
-
static
|
|
901
|
-
return
|
|
833
|
+
static add(c,...z) {
|
|
834
|
+
return c.clone.add(...z);
|
|
902
835
|
}
|
|
903
|
-
static
|
|
904
|
-
return
|
|
836
|
+
static sub(c,...z) {
|
|
837
|
+
return c.clone.sub(...z);
|
|
905
838
|
}
|
|
906
|
-
static
|
|
907
|
-
return
|
|
839
|
+
static mul(c,...z) {
|
|
840
|
+
return c.clone.mul(...z);
|
|
908
841
|
}
|
|
909
|
-
static
|
|
910
|
-
return
|
|
842
|
+
static div(c,...z) {
|
|
843
|
+
return c.clone.div(...z);
|
|
911
844
|
}
|
|
912
|
-
static
|
|
913
|
-
return
|
|
845
|
+
static pow(z,n){
|
|
846
|
+
return z.clone.pow(n);
|
|
914
847
|
}
|
|
915
|
-
static
|
|
916
|
-
return
|
|
848
|
+
static xpowZ(x){
|
|
849
|
+
return complex((x**this.a)*cos$2(this.b*ln(x)),(x**this.a)*sin$2(this.b*ln(x)));
|
|
917
850
|
}
|
|
918
|
-
|
|
919
|
-
return
|
|
851
|
+
sqrtn(n=2){
|
|
852
|
+
return complex(sqrtn(this.z,n)*cos$2(this.phi/n),sqrtn(this.z,n)*sin$2(this.phi/n));
|
|
920
853
|
}
|
|
921
|
-
|
|
922
|
-
return
|
|
854
|
+
get sqrt(){
|
|
855
|
+
return this.sqrtn(2);
|
|
923
856
|
}
|
|
924
|
-
|
|
925
|
-
return
|
|
857
|
+
get log(){
|
|
858
|
+
return complex(this.z,this.phi);
|
|
926
859
|
}
|
|
927
|
-
|
|
928
|
-
return
|
|
860
|
+
get cos(){
|
|
861
|
+
return complex(cos$2(this.a)*cosh$1(this.b),sin$2(this.a)*sinh$1(this.b))
|
|
929
862
|
}
|
|
930
|
-
|
|
931
|
-
return
|
|
863
|
+
get sin(){
|
|
864
|
+
return complex(sin$2(this.a)*cosh$1(this.b),cos$2(this.a)*sinh$1(this.b))
|
|
932
865
|
}
|
|
933
|
-
|
|
934
|
-
|
|
866
|
+
get tan(){
|
|
867
|
+
const de=cos$2(this.a*2)+cosh$1(this.b*2);
|
|
868
|
+
return complex(sin$2(2*this.a)/de,sinh$1(2*this.b)/de);
|
|
935
869
|
}
|
|
936
|
-
|
|
937
|
-
|
|
870
|
+
}
|
|
871
|
+
const complex=(a,b)=>{
|
|
872
|
+
if((a instanceof Array||ArrayBuffer.isView(a)) && (b instanceof Array||ArrayBuffer.isView(a)))return a.map((n,i)=>complex(a[i],b[i]));
|
|
873
|
+
if(a.isMatrix?.() && b.isMatrix?.()){
|
|
874
|
+
if((a.shape[0]!==b.shape[0])||(a.shape[1]!==b.shape[1]))return Error(0)
|
|
875
|
+
const arr=a.arr.map((n,i)=>complex(a.arr[i],b.arr[i]));
|
|
876
|
+
return new a.constructor(a.rows,a.cols,...arr)
|
|
938
877
|
}
|
|
939
|
-
|
|
878
|
+
return new Complex(a,b)
|
|
879
|
+
};
|
|
940
880
|
|
|
941
881
|
const preload=(url)=>{
|
|
942
882
|
const xhr = new XMLHttpRequest();
|
|
@@ -1090,8 +1030,37 @@
|
|
|
1090
1030
|
|
|
1091
1031
|
// globalThis.node = (node) => new UINode(node);
|
|
1092
1032
|
|
|
1093
|
-
|
|
1094
|
-
|
|
1033
|
+
function parseQueryParams$1(queryString) {
|
|
1034
|
+
const params = {};
|
|
1035
|
+
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
1036
|
+
const [key, value] = match.split('=');
|
|
1037
|
+
params[key] = value;
|
|
1038
|
+
});
|
|
1039
|
+
return params;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
function defineParamsGetter$1(target ){
|
|
1043
|
+
Object.defineProperties(target, {
|
|
1044
|
+
'QueryParams': {
|
|
1045
|
+
get: function() {
|
|
1046
|
+
return parseQueryParams$1(globalThis.location.search.substring(1));
|
|
1047
|
+
},
|
|
1048
|
+
configurable: false,
|
|
1049
|
+
enumerable: true
|
|
1050
|
+
},
|
|
1051
|
+
'HashParams': {
|
|
1052
|
+
get: function() {
|
|
1053
|
+
const hash = globalThis.location.hash.substring(1);
|
|
1054
|
+
return hash.split("#");
|
|
1055
|
+
},
|
|
1056
|
+
configurable: false,
|
|
1057
|
+
enumerable: true
|
|
1058
|
+
}
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
class UIStore extends Array {
|
|
1063
|
+
constructor(...args) {
|
|
1095
1064
|
super(...args);
|
|
1096
1065
|
}
|
|
1097
1066
|
clear(){
|
|
@@ -1123,202 +1092,6 @@
|
|
|
1123
1092
|
// create the singleton
|
|
1124
1093
|
const __UI__ = new UIStore();
|
|
1125
1094
|
|
|
1126
|
-
// __init__global__()
|
|
1127
|
-
class UIElementCore extends UINode{
|
|
1128
|
-
constructor(){
|
|
1129
|
-
super();
|
|
1130
|
-
}
|
|
1131
|
-
init(element, name, type, render){
|
|
1132
|
-
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
1133
|
-
if(typeof element === "string") {
|
|
1134
|
-
switch(type){
|
|
1135
|
-
case "html" : {
|
|
1136
|
-
element = globalThis?.document?.createElement(element);
|
|
1137
|
-
// console.log('1')
|
|
1138
|
-
} break;
|
|
1139
|
-
case "svg" : {
|
|
1140
|
-
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
1141
|
-
// console.log('2')
|
|
1142
|
-
} break;
|
|
1143
|
-
default : throw Error("Not supported")
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
else this.target = element?.parentElement;
|
|
1147
|
-
Object.assign(this.cache, {
|
|
1148
|
-
name,
|
|
1149
|
-
isInteractive : false,
|
|
1150
|
-
parent:null,
|
|
1151
|
-
isBody:false,
|
|
1152
|
-
isRoot:false,
|
|
1153
|
-
isHidden: false,
|
|
1154
|
-
isFrozzen:false,
|
|
1155
|
-
legacyParent : null,
|
|
1156
|
-
attributes: {},
|
|
1157
|
-
filters: {},
|
|
1158
|
-
temp:{}
|
|
1159
|
-
});
|
|
1160
|
-
this.events = {
|
|
1161
|
-
ptr:null,
|
|
1162
|
-
mouse:null,
|
|
1163
|
-
wheel:null,
|
|
1164
|
-
key:null,
|
|
1165
|
-
drag:null,
|
|
1166
|
-
drop:null,
|
|
1167
|
-
click:null,
|
|
1168
|
-
clipboard:null,
|
|
1169
|
-
focus:null,
|
|
1170
|
-
swipe:null,
|
|
1171
|
-
custom:null,
|
|
1172
|
-
};
|
|
1173
|
-
this.observer={
|
|
1174
|
-
resize:null,
|
|
1175
|
-
intersection:null
|
|
1176
|
-
};
|
|
1177
|
-
if(element) Object.assign(this.cache,{element});
|
|
1178
|
-
// useDefaultStyle && this.style({
|
|
1179
|
-
// position: "relative",
|
|
1180
|
-
// boxSizing:"border-box",
|
|
1181
|
-
// margin:0,
|
|
1182
|
-
// padding:0,
|
|
1183
|
-
// width : "auto",
|
|
1184
|
-
// height : "auto"
|
|
1185
|
-
// });
|
|
1186
|
-
this.items = new UIStore();
|
|
1187
|
-
globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
1188
|
-
element && render && this?.render?.();
|
|
1189
|
-
globalThis.__Ziko__.__UI__.push(this);
|
|
1190
|
-
}
|
|
1191
|
-
get element(){
|
|
1192
|
-
return this.cache.element;
|
|
1193
|
-
}
|
|
1194
|
-
[Symbol.iterator]() {
|
|
1195
|
-
return this.items[Symbol.iterator]();
|
|
1196
|
-
}
|
|
1197
|
-
maintain() {
|
|
1198
|
-
for (let i = 0; i < this.items.length; i++) {
|
|
1199
|
-
Object.defineProperty(this, i, {
|
|
1200
|
-
value: this.items[i],
|
|
1201
|
-
writable: true,
|
|
1202
|
-
configurable: true,
|
|
1203
|
-
enumerable: false
|
|
1204
|
-
});
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
isInteractive(){
|
|
1208
|
-
return this.cache.isInteractive;
|
|
1209
|
-
}
|
|
1210
|
-
isUIElement(){
|
|
1211
|
-
return true;
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
function register_to_class(target, ...mixins){
|
|
1216
|
-
mixins.forEach(n => _register_to_class_(target, n));
|
|
1217
|
-
}
|
|
1218
|
-
function _register_to_class_(target, mixin) {
|
|
1219
|
-
const descriptors = Object.getOwnPropertyDescriptors(mixin);
|
|
1220
|
-
for (const key of Reflect.ownKeys(descriptors)) {
|
|
1221
|
-
const desc = descriptors[key];
|
|
1222
|
-
if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
|
|
1223
|
-
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1224
|
-
} else if (typeof desc.value === 'function') {
|
|
1225
|
-
if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
|
|
1226
|
-
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
// export function mount(target = this.target) {
|
|
1233
|
-
// if(this.isBody) return ;
|
|
1234
|
-
// if(target?.isUIElement)target=target.element;
|
|
1235
|
-
// this.target=target;
|
|
1236
|
-
// this.target?.appendChild(this.element);
|
|
1237
|
-
// return this;
|
|
1238
|
-
// }
|
|
1239
|
-
// export function unmount(){
|
|
1240
|
-
// if(this.cache.parent)this.cache.parent.remove(this);
|
|
1241
|
-
// else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
|
|
1242
|
-
// return this;
|
|
1243
|
-
// }
|
|
1244
|
-
|
|
1245
|
-
// export function mountAfter(target = this.target, t = 1) {
|
|
1246
|
-
// setTimeout(() => this.mount(), t);
|
|
1247
|
-
// return this;
|
|
1248
|
-
// }
|
|
1249
|
-
// export function unmountAfter(t = 1) {
|
|
1250
|
-
// setTimeout(() => this.unmount(), t);
|
|
1251
|
-
// return this;
|
|
1252
|
-
// }
|
|
1253
|
-
|
|
1254
|
-
function mount(target = this.target, delay = 0) {
|
|
1255
|
-
if (delay > 0) {
|
|
1256
|
-
setTimeout(() => this.mount(target, 0), delay);
|
|
1257
|
-
return this;
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
if (this.isBody) return this;
|
|
1261
|
-
|
|
1262
|
-
if (target?.isUIElement) target = target.element;
|
|
1263
|
-
this.target = target;
|
|
1264
|
-
|
|
1265
|
-
this.target?.appendChild(this.element);
|
|
1266
|
-
return this;
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
function unmount(delay = 0) {
|
|
1270
|
-
if (delay > 0) {
|
|
1271
|
-
setTimeout(() => this.unmount(0), delay);
|
|
1272
|
-
return this;
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
if (this.cache.parent) {
|
|
1276
|
-
this.cache.parent.remove(this);
|
|
1277
|
-
} else if (
|
|
1278
|
-
this.target?.children?.length &&
|
|
1279
|
-
[...this.target.children].includes(this.element)
|
|
1280
|
-
) {
|
|
1281
|
-
this.target.removeChild(this.element);
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
return this;
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
1288
|
-
__proto__: null,
|
|
1289
|
-
mount: mount,
|
|
1290
|
-
unmount: unmount
|
|
1291
|
-
});
|
|
1292
|
-
|
|
1293
|
-
function parseQueryParams$1(queryString) {
|
|
1294
|
-
const params = {};
|
|
1295
|
-
queryString.replace(/[A-Z0-9]+?=([\w|:|\/\.]*)/gi, (match) => {
|
|
1296
|
-
const [key, value] = match.split('=');
|
|
1297
|
-
params[key] = value;
|
|
1298
|
-
});
|
|
1299
|
-
return params;
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
function defineParamsGetter$1(target ){
|
|
1303
|
-
Object.defineProperties(target, {
|
|
1304
|
-
'QueryParams': {
|
|
1305
|
-
get: function() {
|
|
1306
|
-
return parseQueryParams$1(globalThis.location.search.substring(1));
|
|
1307
|
-
},
|
|
1308
|
-
configurable: false,
|
|
1309
|
-
enumerable: true
|
|
1310
|
-
},
|
|
1311
|
-
'HashParams': {
|
|
1312
|
-
get: function() {
|
|
1313
|
-
const hash = globalThis.location.hash.substring(1);
|
|
1314
|
-
return hash.split("#");
|
|
1315
|
-
},
|
|
1316
|
-
configurable: false,
|
|
1317
|
-
enumerable: true
|
|
1318
|
-
}
|
|
1319
|
-
});
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
1095
|
const __Config__ = {
|
|
1323
1096
|
default:{
|
|
1324
1097
|
target:null,
|
|
@@ -1373,7 +1146,7 @@
|
|
|
1373
1146
|
this.#channel = new BroadcastChannel(name);
|
|
1374
1147
|
this.#eventData = new Map();
|
|
1375
1148
|
this.#handlers = new Map(); // Map<event, Array<{fn, rooms}>>
|
|
1376
|
-
this.#uuid = "ziko-channel:" +
|
|
1149
|
+
this.#uuid = "ziko-channel:" + (Math.random()*10e16); // To Be Replaced by UUID
|
|
1377
1150
|
this.#subscribers = new Set([this.#uuid]);
|
|
1378
1151
|
this.#currentRooms = new Set();
|
|
1379
1152
|
this.#channel.addEventListener("message", (e) => {
|
|
@@ -1572,36 +1345,203 @@
|
|
|
1572
1345
|
}
|
|
1573
1346
|
}
|
|
1574
1347
|
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1348
|
+
__init__global__();
|
|
1349
|
+
class UIElementCore extends UINode{
|
|
1350
|
+
constructor(){
|
|
1351
|
+
super();
|
|
1352
|
+
}
|
|
1353
|
+
init(element, name, type, render){
|
|
1354
|
+
this.target = globalThis.__Ziko__.__Config__.default.target||globalThis?.document?.body;
|
|
1355
|
+
if(typeof element === "string") {
|
|
1356
|
+
switch(type){
|
|
1357
|
+
case "html" : {
|
|
1358
|
+
element = globalThis?.document?.createElement(element);
|
|
1359
|
+
// console.log('1')
|
|
1360
|
+
} break;
|
|
1361
|
+
case "svg" : {
|
|
1362
|
+
element = globalThis?.document?.createElementNS("http://www.w3.org/2000/svg", element);
|
|
1363
|
+
// console.log('2')
|
|
1364
|
+
} break;
|
|
1365
|
+
default : throw Error("Not supported")
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
else this.target = element?.parentElement;
|
|
1369
|
+
Object.assign(this.cache, {
|
|
1370
|
+
name,
|
|
1371
|
+
isInteractive : false,
|
|
1372
|
+
parent:null,
|
|
1373
|
+
isBody:false,
|
|
1374
|
+
isRoot:false,
|
|
1375
|
+
isHidden: false,
|
|
1376
|
+
isFrozzen:false,
|
|
1377
|
+
legacyParent : null,
|
|
1378
|
+
attributes: {},
|
|
1379
|
+
filters: {},
|
|
1380
|
+
temp:{}
|
|
1381
|
+
});
|
|
1382
|
+
this.events = {
|
|
1383
|
+
ptr:null,
|
|
1384
|
+
mouse:null,
|
|
1385
|
+
wheel:null,
|
|
1386
|
+
key:null,
|
|
1387
|
+
drag:null,
|
|
1388
|
+
drop:null,
|
|
1389
|
+
click:null,
|
|
1390
|
+
clipboard:null,
|
|
1391
|
+
focus:null,
|
|
1392
|
+
swipe:null,
|
|
1393
|
+
custom:null,
|
|
1394
|
+
};
|
|
1395
|
+
this.observer={
|
|
1396
|
+
resize:null,
|
|
1397
|
+
intersection:null
|
|
1398
|
+
};
|
|
1399
|
+
if(element) Object.assign(this.cache,{element});
|
|
1400
|
+
// useDefaultStyle && this.style({
|
|
1401
|
+
// position: "relative",
|
|
1402
|
+
// boxSizing:"border-box",
|
|
1403
|
+
// margin:0,
|
|
1404
|
+
// padding:0,
|
|
1405
|
+
// width : "auto",
|
|
1406
|
+
// height : "auto"
|
|
1407
|
+
// });
|
|
1408
|
+
this.items = new UIStore();
|
|
1409
|
+
globalThis.__Ziko__.__UI__[this.cache.name]?globalThis.__Ziko__.__UI__[this.cache.name]?.push(this):globalThis.__Ziko__.__UI__[this.cache.name]=[this];
|
|
1410
|
+
element && render && this?.render?.();
|
|
1411
|
+
globalThis.__Ziko__.__UI__.push(this);
|
|
1412
|
+
}
|
|
1413
|
+
get element(){
|
|
1414
|
+
return this.cache.element;
|
|
1415
|
+
}
|
|
1416
|
+
[Symbol.iterator]() {
|
|
1417
|
+
return this.items[Symbol.iterator]();
|
|
1418
|
+
}
|
|
1419
|
+
maintain() {
|
|
1420
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
1421
|
+
Object.defineProperty(this, i, {
|
|
1422
|
+
value: this.items[i],
|
|
1423
|
+
writable: true,
|
|
1424
|
+
configurable: true,
|
|
1425
|
+
enumerable: false
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
isInteractive(){
|
|
1430
|
+
return this.cache.isInteractive;
|
|
1431
|
+
}
|
|
1432
|
+
isUIElement(){
|
|
1433
|
+
return true;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
function register_to_class(target, ...mixins){
|
|
1438
|
+
mixins.forEach(n => _register_to_class_(target, n));
|
|
1439
|
+
}
|
|
1440
|
+
function _register_to_class_(target, mixin) {
|
|
1441
|
+
const descriptors = Object.getOwnPropertyDescriptors(mixin);
|
|
1442
|
+
for (const key of Reflect.ownKeys(descriptors)) {
|
|
1443
|
+
const desc = descriptors[key];
|
|
1444
|
+
if ('get' in desc || 'set' in desc || typeof desc.value !== 'function') {
|
|
1445
|
+
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1446
|
+
} else if (typeof desc.value === 'function') {
|
|
1447
|
+
if (!Object.getPrototypeOf(target).hasOwnProperty(key)) {
|
|
1448
|
+
Object.defineProperty(Object.getPrototypeOf(target), key, desc);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// export function mount(target = this.target) {
|
|
1455
|
+
// if(this.isBody) return ;
|
|
1456
|
+
// if(target?.isUIElement)target=target.element;
|
|
1457
|
+
// this.target=target;
|
|
1458
|
+
// this.target?.appendChild(this.element);
|
|
1459
|
+
// return this;
|
|
1460
|
+
// }
|
|
1461
|
+
// export function unmount(){
|
|
1462
|
+
// if(this.cache.parent)this.cache.parent.remove(this);
|
|
1463
|
+
// else if(this.target?.children?.length && [...this.target?.children].includes(this.element)) this.target.removeChild(this.element);
|
|
1464
|
+
// return this;
|
|
1465
|
+
// }
|
|
1466
|
+
|
|
1467
|
+
// export function mountAfter(target = this.target, t = 1) {
|
|
1468
|
+
// setTimeout(() => this.mount(), t);
|
|
1469
|
+
// return this;
|
|
1470
|
+
// }
|
|
1471
|
+
// export function unmountAfter(t = 1) {
|
|
1472
|
+
// setTimeout(() => this.unmount(), t);
|
|
1473
|
+
// return this;
|
|
1474
|
+
// }
|
|
1475
|
+
|
|
1476
|
+
function mount(target = this.target, delay = 0) {
|
|
1477
|
+
if (delay > 0) {
|
|
1478
|
+
setTimeout(() => this.mount(target, 0), delay);
|
|
1479
|
+
return this;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
if (this.isBody) return this;
|
|
1483
|
+
|
|
1484
|
+
if (target?.isUIElement) target = target.element;
|
|
1485
|
+
this.target = target;
|
|
1486
|
+
|
|
1487
|
+
this.target?.appendChild(this.element);
|
|
1488
|
+
return this;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
function unmount(delay = 0) {
|
|
1492
|
+
if (delay > 0) {
|
|
1493
|
+
setTimeout(() => this.unmount(0), delay);
|
|
1494
|
+
return this;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
if (this.cache.parent) {
|
|
1498
|
+
this.cache.parent.remove(this);
|
|
1499
|
+
} else if (
|
|
1500
|
+
this.target?.children?.length &&
|
|
1501
|
+
[...this.target.children].includes(this.element)
|
|
1502
|
+
) {
|
|
1503
|
+
this.target.removeChild(this.element);
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
return this;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
var LifecycleMethods = /*#__PURE__*/Object.freeze({
|
|
1510
|
+
__proto__: null,
|
|
1511
|
+
mount: mount,
|
|
1512
|
+
unmount: unmount
|
|
1513
|
+
});
|
|
1514
|
+
|
|
1515
|
+
if(!globalThis.__Ziko__) __init__global__();
|
|
1516
|
+
|
|
1517
|
+
function useState(initialValue) {
|
|
1518
|
+
|
|
1519
|
+
const {store, index} = __Ziko__.__State__;
|
|
1520
|
+
__Ziko__.__State__.register({
|
|
1521
|
+
value : initialValue,
|
|
1522
|
+
subscribers : new Set(),
|
|
1523
|
+
paused : false
|
|
1524
|
+
});
|
|
1525
|
+
|
|
1526
|
+
let current = store.get(index);
|
|
1527
|
+
|
|
1528
|
+
function getValue() {
|
|
1529
|
+
return {
|
|
1530
|
+
value: current.value,
|
|
1531
|
+
isStateGetter: () => true,
|
|
1532
|
+
_subscribe: (fn) => current.subscribers.add(fn),
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
function setValue(newValue) {
|
|
1537
|
+
if (current.paused) return;
|
|
1538
|
+
if (typeof newValue === "function") {
|
|
1539
|
+
newValue = newValue(current.value);
|
|
1540
|
+
}
|
|
1541
|
+
if (newValue !== current.value) {
|
|
1542
|
+
current.value = newValue;
|
|
1543
|
+
current.subscribers.forEach(fn => fn(current.value));
|
|
1544
|
+
__Ziko__.__State__.update(index, newValue);
|
|
1605
1545
|
}
|
|
1606
1546
|
}
|
|
1607
1547
|
|
|
@@ -2568,6 +2508,14 @@
|
|
|
2568
2508
|
style: style
|
|
2569
2509
|
});
|
|
2570
2510
|
|
|
2511
|
+
// import {
|
|
2512
|
+
// // useCustomEvent,
|
|
2513
|
+
// // useSwipeEvent,
|
|
2514
|
+
// // watchIntersection,
|
|
2515
|
+
// // watchSize,
|
|
2516
|
+
// // watchAttr,
|
|
2517
|
+
// // watchChildren
|
|
2518
|
+
// } from "../../--reactivity-deprecated/events/custom-event.js"
|
|
2571
2519
|
let UIElement$1 = class UIElement extends UIElementCore{
|
|
2572
2520
|
constructor({element, name ='', type='html', render = __Ziko__.__Config__.default.render}={}){
|
|
2573
2521
|
super();
|
|
@@ -3314,6 +3262,119 @@
|
|
|
3314
3262
|
}, Array.isArray(obj) ? [] : {});
|
|
3315
3263
|
}
|
|
3316
3264
|
|
|
3265
|
+
function matrix_inverse(M) {
|
|
3266
|
+
if(M.row !== M.cols) throw Error('is not a square matrix"')
|
|
3267
|
+
if (M.det === 0) throw Error("determinant should not equal 0");
|
|
3268
|
+
const { arr } = M;
|
|
3269
|
+
if (arr.length !== arr[0].length) return;
|
|
3270
|
+
var i = 0, ii = 0, j = 0, dim = arr.length, e = 0;
|
|
3271
|
+
var I = [], C = [];
|
|
3272
|
+
for (i = 0; i < dim; i += 1) {
|
|
3273
|
+
I[I.length] = [];
|
|
3274
|
+
C[C.length] = [];
|
|
3275
|
+
for (j = 0; j < dim; j += 1) {
|
|
3276
|
+
if (i == j) I[i][j] = 1;
|
|
3277
|
+
else I[i][j] = 0;
|
|
3278
|
+
C[i][j] = arr[i][j];
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
for (i = 0; i < dim; i += 1) {
|
|
3282
|
+
e = C[i][i];
|
|
3283
|
+
if (e == 0) {
|
|
3284
|
+
for (ii = i + 1; ii < dim; ii += 1) {
|
|
3285
|
+
if (C[ii][i] != 0) {
|
|
3286
|
+
for (j = 0; j < dim; j++) {
|
|
3287
|
+
e = C[i][j];
|
|
3288
|
+
C[i][j] = C[ii][j];
|
|
3289
|
+
C[ii][j] = e;
|
|
3290
|
+
e = I[i][j];
|
|
3291
|
+
I[i][j] = I[ii][j];
|
|
3292
|
+
I[ii][j] = e;
|
|
3293
|
+
}
|
|
3294
|
+
break;
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
e = C[i][i];
|
|
3298
|
+
if (e == 0) return;
|
|
3299
|
+
}
|
|
3300
|
+
for (j = 0; j < dim; j++) {
|
|
3301
|
+
C[i][j] = C[i][j] / e;
|
|
3302
|
+
I[i][j] = I[i][j] / e;
|
|
3303
|
+
}
|
|
3304
|
+
for (ii = 0; ii < dim; ii++) {
|
|
3305
|
+
if (ii == i) {
|
|
3306
|
+
continue;
|
|
3307
|
+
}
|
|
3308
|
+
e = C[ii][i];
|
|
3309
|
+
for (j = 0; j < dim; j++) {
|
|
3310
|
+
C[ii][j] -= e * C[i][j];
|
|
3311
|
+
I[ii][j] -= e * I[i][j];
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
}
|
|
3315
|
+
return new M.constructor(I);
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
function matrix_det(M) {
|
|
3319
|
+
if (!M.isSquare) return new Error("is not square matrix");
|
|
3320
|
+
if (M.rows == 1) return M.arr[0][0];
|
|
3321
|
+
function determinat(M) {
|
|
3322
|
+
if (M.length == 2) {
|
|
3323
|
+
if (M.flat(1).some((n) => n?.isMatrix?.())) {
|
|
3324
|
+
console.warn("Tensors are not completely supported yet ...");
|
|
3325
|
+
return;
|
|
3326
|
+
}
|
|
3327
|
+
return sub(mul(M[0][0],M[1][1]),mul(M[0][1],M[1][0]))
|
|
3328
|
+
}
|
|
3329
|
+
var answer = 0;
|
|
3330
|
+
for (var i = 0; i < M.length; i++) {
|
|
3331
|
+
//console.log(M[0][i]);
|
|
3332
|
+
/*answer = answer.add(
|
|
3333
|
+
pow(-1, i)
|
|
3334
|
+
.mul(M[0][i])
|
|
3335
|
+
.mul(determinat(deleteRowAndColumn(M, i)))
|
|
3336
|
+
);*/
|
|
3337
|
+
//const to_be_added=add(mul(pow(-1, i),mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
3338
|
+
const to_be_added=add(mul(pow$1(-1, i),mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
3339
|
+
answer=add(answer,to_be_added);
|
|
3340
|
+
}
|
|
3341
|
+
return answer;
|
|
3342
|
+
}
|
|
3343
|
+
return determinat(M.arr);
|
|
3344
|
+
}
|
|
3345
|
+
function deleteRowAndColumn(M, index) {
|
|
3346
|
+
var temp = [];
|
|
3347
|
+
for (let i = 0; i < M.length; i++) temp.push(M[i].slice(0));
|
|
3348
|
+
temp.splice(0, 1);
|
|
3349
|
+
for (let i = 0; i < temp.length; i++) temp[i].splice(index, 1);
|
|
3350
|
+
return temp;
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
function hstack(M1, M2){
|
|
3354
|
+
M1 = M1.clone();
|
|
3355
|
+
M2 = M2.clone();
|
|
3356
|
+
if (M1.rows !== M2.rows) return;
|
|
3357
|
+
let newArr = M1.arr;
|
|
3358
|
+
for (let i = 0; i < M1.rows; i++)
|
|
3359
|
+
for (let j = M1.cols; j < M1.cols + M2.cols; j++)
|
|
3360
|
+
newArr[i][j] = M2.arr[i][j - M1.cols];
|
|
3361
|
+
M1.cols += M2.cols;
|
|
3362
|
+
return new M1.constructor(M1.rows, M1.cols, newArr.flat(1));
|
|
3363
|
+
}
|
|
3364
|
+
|
|
3365
|
+
function vstack(M1, M2){
|
|
3366
|
+
M1 = M1.clone();
|
|
3367
|
+
M2 = M2.clone();
|
|
3368
|
+
if (M1.cols !== M2.cols) return;
|
|
3369
|
+
let newArr = M1.arr;
|
|
3370
|
+
for (let i = M1.rows; i < M1.rows + M2.rows; i++) {
|
|
3371
|
+
newArr[i] = [];
|
|
3372
|
+
for (let j = 0; j < M1.cols; j++) newArr[i][j] = M2.arr[i - M1.rows][j];
|
|
3373
|
+
}
|
|
3374
|
+
M1.rows += M2.rows;
|
|
3375
|
+
return new M1.constructor(M1.rows, M1.cols, newArr.flat(1));
|
|
3376
|
+
}
|
|
3377
|
+
|
|
3317
3378
|
class Matrix{
|
|
3318
3379
|
constructor(rows, cols, element = [] ) {
|
|
3319
3380
|
if(rows instanceof Matrix){
|
|
@@ -3322,9 +3383,7 @@
|
|
|
3322
3383
|
this.cols=rows.cols;
|
|
3323
3384
|
}
|
|
3324
3385
|
else {
|
|
3325
|
-
let arr = [],
|
|
3326
|
-
i,
|
|
3327
|
-
j;
|
|
3386
|
+
let arr = [], i, j;
|
|
3328
3387
|
if (arguments[0] instanceof Array) {
|
|
3329
3388
|
rows = arguments[0].length;
|
|
3330
3389
|
cols = arguments[0][0].length;
|
|
@@ -3344,29 +3403,25 @@
|
|
|
3344
3403
|
this.arr = arr;
|
|
3345
3404
|
}
|
|
3346
3405
|
this.#maintain();
|
|
3347
|
-
//Object.seal(this);
|
|
3348
3406
|
}
|
|
3349
|
-
|
|
3350
|
-
return
|
|
3407
|
+
isMatrix(){
|
|
3408
|
+
return true
|
|
3351
3409
|
}
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
if(j==undefined) return this.arr[i];
|
|
3355
|
-
if(j<0)j=this.cols+j;
|
|
3356
|
-
return this.arr[i][j];
|
|
3410
|
+
clone() {
|
|
3411
|
+
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3357
3412
|
}
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
if (check) return new Matrix(newRows, newCols, this.arr.flat(1));
|
|
3361
|
-
else console.error("Err");
|
|
3362
|
-
}
|
|
3363
|
-
static eye(size) {
|
|
3364
|
-
let result = new Matrix(size, size);
|
|
3365
|
-
for (let i = 0; i < size; i++) for (let j = 0; j < size; j++) i === j ? (result.arr[i][j] = 1) : (result.arr[i][j] = 0);
|
|
3366
|
-
return result;
|
|
3413
|
+
[Symbol.iterator]() {
|
|
3414
|
+
return this.arr[Symbol.iterator]();
|
|
3367
3415
|
}
|
|
3368
|
-
|
|
3369
|
-
|
|
3416
|
+
#maintain() {
|
|
3417
|
+
for (let i = 0; i < this.arr.length; i++) {
|
|
3418
|
+
Object.defineProperty(this, i, {
|
|
3419
|
+
value: this.arr[i],
|
|
3420
|
+
writable: true,
|
|
3421
|
+
configurable: true,
|
|
3422
|
+
enumerable: false
|
|
3423
|
+
});
|
|
3424
|
+
}
|
|
3370
3425
|
}
|
|
3371
3426
|
get size() {
|
|
3372
3427
|
return this.rows * this.cols;
|
|
@@ -3374,214 +3429,287 @@
|
|
|
3374
3429
|
get shape() {
|
|
3375
3430
|
return [this.rows, this.cols];
|
|
3376
3431
|
}
|
|
3377
|
-
|
|
3378
|
-
return
|
|
3379
|
-
}
|
|
3380
|
-
get imag() {
|
|
3381
|
-
return new Matrix(this.cols, this.rows, this.arr.flat(1).imag);
|
|
3382
|
-
}
|
|
3383
|
-
[Symbol.iterator]() {
|
|
3384
|
-
return this.arr[Symbol.iterator]();
|
|
3385
|
-
}
|
|
3386
|
-
#maintain() {
|
|
3387
|
-
for (let i = 0; i < this.arr.length; i++) {
|
|
3388
|
-
Object.defineProperty(this, i, {
|
|
3389
|
-
value: this.arr[i],
|
|
3390
|
-
writable: true,
|
|
3391
|
-
configurable: true,
|
|
3392
|
-
enumerable: false
|
|
3393
|
-
});
|
|
3394
|
-
}
|
|
3432
|
+
toString(){
|
|
3433
|
+
return arr2str(this.arr);
|
|
3395
3434
|
}
|
|
3396
|
-
|
|
3397
|
-
if (
|
|
3398
|
-
|
|
3399
|
-
|
|
3435
|
+
at(i = 0, j = undefined) {
|
|
3436
|
+
if (i < 0) i += this.rows;
|
|
3437
|
+
if (i < 0 || i >= this.rows) throw new Error('Row index out of bounds');
|
|
3438
|
+
if (j === undefined) return this.arr[i];
|
|
3439
|
+
if (j < 0) j += this.cols;
|
|
3440
|
+
if (j < 0 || j >= this.cols) throw new Error('Column index out of bounds');
|
|
3441
|
+
return this.arr[i][j];
|
|
3400
3442
|
}
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3443
|
+
slice(r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
|
|
3444
|
+
let newRow = r1 - r0,
|
|
3445
|
+
newCol = c1 - c0;
|
|
3446
|
+
let newArr = new Array(newCol);
|
|
3447
|
+
for (let i = 0; i < newRow; i++) {
|
|
3448
|
+
newArr[i] = [];
|
|
3449
|
+
for (let j = 0; j < newCol; j++) newArr[i][j] = this.arr[i + r0][j + c0];
|
|
3408
3450
|
}
|
|
3409
|
-
return (
|
|
3410
|
-
}
|
|
3411
|
-
get isSquare() {
|
|
3412
|
-
return this.rows / this.cols === 1;
|
|
3413
|
-
}
|
|
3414
|
-
get isSym() {
|
|
3415
|
-
if (!this.isSquare) return false;
|
|
3416
|
-
const T = this.T;
|
|
3417
|
-
const M = this.clone;
|
|
3418
|
-
return Matrix.sub(M, T).max == 0 && Matrix.sub(M, T).min == 0;
|
|
3419
|
-
}
|
|
3420
|
-
get isAntiSym() {
|
|
3421
|
-
if (!this.isSquare) return false;
|
|
3422
|
-
const T = this.T;
|
|
3423
|
-
const M = this.clone;
|
|
3424
|
-
return Matrix.add(M, T).max == 0 && Matrix.add(M, T).min == 0;
|
|
3425
|
-
}
|
|
3426
|
-
get isDiag() {
|
|
3427
|
-
if (!this.isSquare) return false;
|
|
3428
|
-
const T = this.T;
|
|
3429
|
-
const M = this.clone;
|
|
3430
|
-
const MT = Matrix.mul(M, T);
|
|
3431
|
-
const TM = Matrix.dot(T, M);
|
|
3432
|
-
return Matrix.sub(MT, TM).max == 0 && Matrix.sub(MT, TM).min == 0;
|
|
3451
|
+
return new Matrix(newRow, newCol, newArr.flat(1));
|
|
3433
3452
|
}
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
return this.isDiag && (this.det == 1 || this.det == -1);
|
|
3453
|
+
static slice(m1,r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
|
|
3454
|
+
return m1.slice(r0, c0, r1, c1);
|
|
3437
3455
|
}
|
|
3438
|
-
|
|
3439
|
-
if
|
|
3440
|
-
|
|
3441
|
-
const MM = Matrix.dot(M, M);
|
|
3442
|
-
return Matrix.sub(MM, M).max == 0 && Matrix.sub(MM, M).min == 0;
|
|
3456
|
+
reshape(newRows, newCols) {
|
|
3457
|
+
if(!(newRows * newCols === this.rows * this.cols)) throw Error('size not matched')
|
|
3458
|
+
return new Matrix(newRows, newCols, this.arr.flat(1));
|
|
3443
3459
|
}
|
|
3444
3460
|
get T() {
|
|
3445
3461
|
let transpose = [];
|
|
3446
3462
|
for (let i = 0; i < this.arr[0].length; i++) {
|
|
3447
3463
|
transpose[i] = [];
|
|
3448
|
-
for (let j = 0; j < this.arr.length; j++)
|
|
3464
|
+
for (let j = 0; j < this.arr.length; j++)
|
|
3449
3465
|
transpose[i][j] = this.arr[j][i];
|
|
3450
|
-
}
|
|
3451
3466
|
}
|
|
3452
3467
|
return new Matrix(this.cols, this.rows, transpose.flat(1));
|
|
3453
3468
|
}
|
|
3454
3469
|
get det() {
|
|
3455
|
-
|
|
3456
|
-
if (this.rows == 1) return this.arr[0][0];
|
|
3457
|
-
function determinat(M) {
|
|
3458
|
-
if (M.length == 2) {
|
|
3459
|
-
if (M.flat(1).some((n) => n instanceof Matrix)) {
|
|
3460
|
-
console.warn("Tensors are not completely supported yet ...");
|
|
3461
|
-
return;
|
|
3462
|
-
}
|
|
3463
|
-
return Utils.sub(Utils.mul(M[0][0],M[1][1]),Utils.mul(M[0][1],M[1][0]))
|
|
3464
|
-
}
|
|
3465
|
-
var answer = 0;
|
|
3466
|
-
for (var i = 0; i < M.length; i++) {
|
|
3467
|
-
//console.log(M[0][i]);
|
|
3468
|
-
/*answer = answer.add(
|
|
3469
|
-
pow(-1, i)
|
|
3470
|
-
.mul(M[0][i])
|
|
3471
|
-
.mul(determinat(deleteRowAndColumn(M, i)))
|
|
3472
|
-
);*/
|
|
3473
|
-
//const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
3474
|
-
const to_be_added=Utils.add(Utils.mul(pow$1(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
|
|
3475
|
-
answer=Utils.add(answer,to_be_added);
|
|
3476
|
-
}
|
|
3477
|
-
return answer;
|
|
3478
|
-
}
|
|
3479
|
-
function deleteRowAndColumn(M, index) {
|
|
3480
|
-
var temp = [];
|
|
3481
|
-
for (let i = 0; i < M.length; i++) temp.push(M[i].slice(0));
|
|
3482
|
-
temp.splice(0, 1);
|
|
3483
|
-
for (let i = 0; i < temp.length; i++) temp[i].splice(index, 1);
|
|
3484
|
-
return temp;
|
|
3485
|
-
}
|
|
3486
|
-
return determinat(this.arr);
|
|
3470
|
+
return matrix_det(this)
|
|
3487
3471
|
}
|
|
3488
3472
|
get inv() {
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3473
|
+
return matrix_inverse(this)
|
|
3474
|
+
}
|
|
3475
|
+
static eye(size) {
|
|
3476
|
+
let result = new Matrix(size, size);
|
|
3477
|
+
for (let i = 0; i < size; i++)
|
|
3478
|
+
for (let j = 0; j < size; j++) i === j ? (result.arr[i][j] = 1) : (result.arr[i][j] = 0);
|
|
3479
|
+
return result;
|
|
3493
3480
|
}
|
|
3494
3481
|
static zeros(rows, cols) {
|
|
3495
3482
|
let result = new Matrix(rows, cols);
|
|
3496
|
-
for (let i = 0; i < rows; i++)
|
|
3483
|
+
for (let i = 0; i < rows; i++)
|
|
3484
|
+
for (var j = 0; j < cols; j++) result.arr[i][j] = 0;
|
|
3497
3485
|
return result;
|
|
3498
3486
|
}
|
|
3499
3487
|
static ones(rows, cols) {
|
|
3500
3488
|
let result = new Matrix(rows, cols);
|
|
3501
|
-
for (let i = 0; i < rows; i++)
|
|
3489
|
+
for (let i = 0; i < rows; i++)
|
|
3490
|
+
for (let j = 0; j < cols; j++) result.arr[i][j] = 1;
|
|
3502
3491
|
return result;
|
|
3503
3492
|
}
|
|
3504
3493
|
static nums(rows, cols, number) {
|
|
3505
3494
|
let result = new Matrix(rows, cols);
|
|
3506
|
-
for (let i = 0; i < rows; i++)
|
|
3495
|
+
for (let i = 0; i < rows; i++)
|
|
3496
|
+
for (let j = 0; j < cols; j++) result.arr[i][j] = number;
|
|
3507
3497
|
return result;
|
|
3508
3498
|
}
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3499
|
+
hstack(...matrices) {
|
|
3500
|
+
const M=[this, ...matrices].reduce((a,b)=>hstack(a, b));
|
|
3501
|
+
Object.assign(this, M);
|
|
3502
|
+
this.#maintain();
|
|
3503
|
+
return this;
|
|
3504
|
+
}
|
|
3505
|
+
static hstack(matrix,...matrices) {
|
|
3506
|
+
return matrix.clone().hstack(...matrices);
|
|
3507
|
+
}
|
|
3508
|
+
vstack(...matrices){
|
|
3509
|
+
const M=[this, ...matrices].reduce((a,b)=>vstack(a, b));
|
|
3510
|
+
Object.assign(this, M);
|
|
3511
|
+
this.#maintain();
|
|
3512
|
+
return this;
|
|
3513
|
+
}
|
|
3514
|
+
static vstack(matrix,...matrices) {
|
|
3515
|
+
return matrix.clone().vstack(...matrices);
|
|
3516
|
+
}
|
|
3517
|
+
hqueue(...matrices){
|
|
3518
|
+
const M=[this, ...matrices].reverse().reduce((a,b)=>hstack(a, b));
|
|
3519
|
+
Object.assign(this, M);
|
|
3520
|
+
return this;
|
|
3521
|
+
}
|
|
3522
|
+
static hqueue(matrix,...matrices) {
|
|
3523
|
+
return matrix.clone().hqueue(...matrices);
|
|
3524
|
+
}
|
|
3525
|
+
vqueue(...matrices){
|
|
3526
|
+
const M=[this,...matrices].reverse().reduce((a, b)=>vstack(a, b));
|
|
3527
|
+
Object.assign(this, M);
|
|
3528
|
+
return this;
|
|
3529
|
+
}
|
|
3530
|
+
static vqueue(matrix,...matrices) {
|
|
3531
|
+
return matrix.clone().vqueue(...matrices);
|
|
3532
|
+
}
|
|
3533
|
+
shuffle(){
|
|
3534
|
+
this.arr = this.arr.sort(()=>0.5-Math.random());
|
|
3535
|
+
return this;
|
|
3536
|
+
}
|
|
3537
|
+
static shuffle(M){
|
|
3538
|
+
return M.clone().shuffle()
|
|
3539
|
+
}
|
|
3540
|
+
// get reel() {
|
|
3541
|
+
// return new Matrix(this.cols, this.rows, this.arr.flat(1).reel);
|
|
3542
|
+
// }
|
|
3543
|
+
// get imag() {
|
|
3544
|
+
// return new Matrix(this.cols, this.rows, this.arr.flat(1).imag);
|
|
3545
|
+
// }
|
|
3546
|
+
|
|
3547
|
+
// Checkers
|
|
3548
|
+
get isSquare() {
|
|
3549
|
+
return this.rows === this.cols;
|
|
3550
|
+
}
|
|
3551
|
+
get isSym() {
|
|
3552
|
+
if (!this.isSquare) return false;
|
|
3553
|
+
for (let i = 0; i < this.rows; i++) {
|
|
3554
|
+
for (let j = i + 1; j < this.cols; j++) {
|
|
3555
|
+
if (this.arr[i][j] !== this.arr[j][i]) return false;
|
|
3556
|
+
}
|
|
3557
|
+
}
|
|
3558
|
+
return true;
|
|
3559
|
+
}
|
|
3560
|
+
get isAntiSym() {
|
|
3561
|
+
if (!this.isSquare) return false;
|
|
3562
|
+
const n = this.rows;
|
|
3563
|
+
for (let i = 0; i < n; i++) {
|
|
3564
|
+
if (this.arr[i][i] !== 0) return false;
|
|
3565
|
+
for (let j = i + 1; j < n; j++) {
|
|
3566
|
+
if (this.arr[i][j] !== -this.arr[j][i]) return false;
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
return true;
|
|
3570
|
+
}
|
|
3571
|
+
get isDiag() {
|
|
3572
|
+
if (!this.isSquare) return false;
|
|
3573
|
+
const n = this.rows;
|
|
3574
|
+
for (let i = 0; i < n; i++) {
|
|
3575
|
+
for (let j = i + 1; j < n; j++) {
|
|
3576
|
+
if (this.arr[i][j] !== 0 || this.arr[j][i] !== 0) return false;
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
return true;
|
|
3580
|
+
}
|
|
3581
|
+
get isOrtho() {
|
|
3582
|
+
if (!this.isSquare) return false;
|
|
3583
|
+
return this.isDiag && (this.det == 1 || this.det == -1);
|
|
3584
|
+
}
|
|
3585
|
+
get isIdemp() {
|
|
3586
|
+
if (!this.isSquare) return false;
|
|
3587
|
+
const n = this.rows;
|
|
3588
|
+
const A = this.arr;
|
|
3589
|
+
// Compute A * A
|
|
3590
|
+
const MM = [];
|
|
3591
|
+
for (let i = 0; i < n; i++) {
|
|
3592
|
+
MM[i] = [];
|
|
3593
|
+
for (let j = 0; j < n; j++) {
|
|
3594
|
+
let sum = 0;
|
|
3595
|
+
for (let k = 0; k < n; k++) {
|
|
3596
|
+
sum += A[i][k] * A[k][j];
|
|
3527
3597
|
}
|
|
3528
|
-
|
|
3529
|
-
}
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
permutation:(rows,cols,arr)=>{
|
|
3536
|
-
//return new Matrix(rows, cols, Random.permutation(...arr))
|
|
3598
|
+
MM[i][j] = sum;
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
// Check if A * A == A
|
|
3602
|
+
for (let i = 0; i < n; i++) {
|
|
3603
|
+
for (let j = 0; j < n; j++) {
|
|
3604
|
+
if (MM[i][j] !== A[i][j]) return false;
|
|
3537
3605
|
}
|
|
3538
3606
|
}
|
|
3607
|
+
return true;
|
|
3539
3608
|
}
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3609
|
+
|
|
3610
|
+
get isUpperTri() {
|
|
3611
|
+
if (!this.isSquare) return false;
|
|
3612
|
+
const n = this.rows;
|
|
3613
|
+
for (let i = 1; i < n; i++) {
|
|
3614
|
+
for (let j = 0; j < i; j++) {
|
|
3615
|
+
if (this.arr[i][j] !== 0) return false;
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
return true;
|
|
3619
|
+
}
|
|
3620
|
+
get isLowerTri() {
|
|
3621
|
+
if (!this.isSquare) return false;
|
|
3622
|
+
const n = this.rows;
|
|
3623
|
+
for (let i = 0; i < n - 1; i++) {
|
|
3624
|
+
for (let j = i + 1; j < n; j++) {
|
|
3625
|
+
if (this.arr[i][j] !== 0) return false;
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
3628
|
+
return true;
|
|
3544
3629
|
}
|
|
3630
|
+
|
|
3631
|
+
// static get rand(){
|
|
3632
|
+
// return {
|
|
3633
|
+
// int:(rows, cols, a, b)=>{
|
|
3634
|
+
// let result = new Matrix(rows, cols);
|
|
3635
|
+
// for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randInt(a, b);
|
|
3636
|
+
// return result;
|
|
3637
|
+
// },
|
|
3638
|
+
// bin:(rows,cols)=>{
|
|
3639
|
+
// let result = new Matrix(rows, cols);
|
|
3640
|
+
// for (let i = 0; i < rows; i++) {
|
|
3641
|
+
// for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randBin;
|
|
3642
|
+
// }
|
|
3643
|
+
// return result;
|
|
3644
|
+
// },
|
|
3645
|
+
// hex:(rows,cols)=>{
|
|
3646
|
+
// let result = new Matrix(rows, cols);
|
|
3647
|
+
// for (let i = 0; i < rows; i++) {
|
|
3648
|
+
// for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randHex;
|
|
3649
|
+
// }
|
|
3650
|
+
// return result;
|
|
3651
|
+
// },
|
|
3652
|
+
// choices:(rows, cols, choices, p)=>{
|
|
3653
|
+
// let result = new Matrix(rows, cols);
|
|
3654
|
+
// for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.choice(choices, p);
|
|
3655
|
+
// return result
|
|
3656
|
+
// },
|
|
3657
|
+
// permutation:(rows,cols,arr)=>{
|
|
3658
|
+
// //return new Matrix(rows, cols, Random.permutation(...arr))
|
|
3659
|
+
// }
|
|
3660
|
+
// }
|
|
3661
|
+
// }
|
|
3662
|
+
// static rands(rows, cols, a = 1, b) {
|
|
3663
|
+
// let result = new Matrix(rows, cols);
|
|
3664
|
+
// for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.rand(a, b);
|
|
3665
|
+
// return result;
|
|
3666
|
+
// }
|
|
3545
3667
|
map(Imin, Imax, Fmin, Fmax) {
|
|
3546
|
-
|
|
3668
|
+
this.arr = map$1(this.arr, Imin, Imax, Fmin, Fmax);
|
|
3669
|
+
return this;
|
|
3547
3670
|
}
|
|
3548
3671
|
lerp(min, max) {
|
|
3549
|
-
|
|
3672
|
+
this.arr = lerp(this.arr, min, max);
|
|
3673
|
+
return this;
|
|
3550
3674
|
}
|
|
3551
3675
|
norm(min, max) {
|
|
3552
|
-
|
|
3676
|
+
this.arr = norm(this.arr, min, max);
|
|
3677
|
+
return this;
|
|
3553
3678
|
}
|
|
3554
3679
|
clamp(min, max) {
|
|
3555
|
-
|
|
3680
|
+
this.arr = clamp(this.arr, min, max);
|
|
3681
|
+
return this;
|
|
3556
3682
|
}
|
|
3557
|
-
static map(
|
|
3558
|
-
return
|
|
3683
|
+
static map(M, Imin, Imax, Fmin, Fmax) {
|
|
3684
|
+
return M.clone().map(Imin, Imax, Fmin, Fmax)
|
|
3559
3685
|
}
|
|
3560
|
-
static lerp(
|
|
3561
|
-
return
|
|
3686
|
+
static lerp(M, min, max) {
|
|
3687
|
+
return M.clone().lerp(min, max)
|
|
3562
3688
|
}
|
|
3563
|
-
static norm(
|
|
3564
|
-
return
|
|
3689
|
+
static norm(M, min, max) {
|
|
3690
|
+
return M.clone().norm(min, max)
|
|
3565
3691
|
}
|
|
3566
|
-
static clamp(
|
|
3567
|
-
return
|
|
3692
|
+
static clamp(M, min, max) {
|
|
3693
|
+
return M.clone().clamp(min, max)
|
|
3568
3694
|
}
|
|
3569
3695
|
toPrecision(p) {
|
|
3570
|
-
for (let i = 0; i < this.cols; i++)
|
|
3696
|
+
for (let i = 0; i < this.cols; i++)
|
|
3697
|
+
for (let j = 0; j < this.rows; j++)
|
|
3698
|
+
this.arr[i][j] = +this.arr[i][j].toPrecision(p);
|
|
3571
3699
|
return this;
|
|
3572
3700
|
}
|
|
3573
|
-
get toBin() {
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
}
|
|
3577
|
-
get toOct() {
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
}
|
|
3581
|
-
get toHex() {
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
}
|
|
3701
|
+
// get toBin() {
|
|
3702
|
+
// let newArr = this.arr.flat(1).toBin;
|
|
3703
|
+
// return new Matrix(this.rows, this.cols, newArr);
|
|
3704
|
+
// }
|
|
3705
|
+
// get toOct() {
|
|
3706
|
+
// let newArr = this.arr.flat(1).toOct;
|
|
3707
|
+
// return new Matrix(this.rows, this.cols, newArr);
|
|
3708
|
+
// }
|
|
3709
|
+
// get toHex() {
|
|
3710
|
+
// let newArr = this.arr.flat(1).toHex;
|
|
3711
|
+
// return new Matrix(this.rows, this.cols, newArr);
|
|
3712
|
+
// }
|
|
3585
3713
|
/*get isOdd() {
|
|
3586
3714
|
let newArr = this.arr.flat(1).isOdd;
|
|
3587
3715
|
return new Matrix(this.rows, this.cols, newArr);
|
|
@@ -3621,72 +3749,11 @@
|
|
|
3621
3749
|
count(n) {
|
|
3622
3750
|
return this.arr.flat(1).count(n);
|
|
3623
3751
|
}
|
|
3624
|
-
toBase(n) {
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
}
|
|
3628
|
-
|
|
3629
|
-
if (this.rows !== matrix.rows) return;
|
|
3630
|
-
let newArr = this.arr;
|
|
3631
|
-
for (let i = 0; i < this.rows; i++) for (let j = this.cols; j < this.cols + matrix.cols; j++) newArr[i][j] = matrix.arr[i][j - this.cols];
|
|
3632
|
-
this.cols += matrix.cols;
|
|
3633
|
-
return new Matrix(this.rows, this.cols, newArr.flat(1));
|
|
3634
|
-
}
|
|
3635
|
-
hstack(...matrices) {
|
|
3636
|
-
const M=[this,...matrices].reduce((a,b)=>a.#hstack(b));
|
|
3637
|
-
Object.assign(this,M);
|
|
3638
|
-
return this;
|
|
3639
|
-
}
|
|
3640
|
-
static hstack(matrix,...matrices) {
|
|
3641
|
-
return matrix.clone.hstack(...matrices);
|
|
3642
|
-
}
|
|
3643
|
-
#vstack(matrix) {
|
|
3644
|
-
if (this.cols !== matrix.cols) return;
|
|
3645
|
-
let newArr = this.arr;
|
|
3646
|
-
for (let i = this.rows; i < this.rows + matrix.rows; i++) {
|
|
3647
|
-
newArr[i] = [];
|
|
3648
|
-
for (let j = 0; j < this.cols; j++) newArr[i][j] = matrix.arr[i - this.rows][j];
|
|
3649
|
-
}
|
|
3650
|
-
this.rows += matrix.rows;
|
|
3651
|
-
return new Matrix(this.rows, this.cols, newArr.flat(1));
|
|
3652
|
-
}
|
|
3653
|
-
vstack(...matrices) {
|
|
3654
|
-
const M=[this,...matrices].reduce((a,b)=>a.#vstack(b));
|
|
3655
|
-
Object.assign(this,M);
|
|
3656
|
-
return this;
|
|
3657
|
-
}
|
|
3658
|
-
static vstack(matrix,...matrices) {
|
|
3659
|
-
return matrix.clone.vstack(...matrices);
|
|
3660
|
-
}
|
|
3661
|
-
hqueue(...matrices){
|
|
3662
|
-
const M=[this,...matrices].reverse().reduce((a,b)=>a.#hstack(b));
|
|
3663
|
-
Object.assign(this,M);
|
|
3664
|
-
return this;
|
|
3665
|
-
}
|
|
3666
|
-
vqueue(...matrices){
|
|
3667
|
-
const M=[this,...matrices].reverse().reduce((a,b)=>a.#vstack(b));
|
|
3668
|
-
Object.assign(this,M);
|
|
3669
|
-
return this;
|
|
3670
|
-
}
|
|
3671
|
-
static hqueue(matrix,...matrices) {
|
|
3672
|
-
return matrix.clone.hqueue(...matrices);
|
|
3673
|
-
}
|
|
3674
|
-
static vqueue(matrix,...matrices) {
|
|
3675
|
-
return matrix.clone.vqueue(...matrices);
|
|
3676
|
-
}
|
|
3677
|
-
slice(r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
|
|
3678
|
-
let newRow = r1 - r0,
|
|
3679
|
-
newCol = c1 - c0;
|
|
3680
|
-
let newArr = new Array(newCol);
|
|
3681
|
-
for (let i = 0; i < newRow; i++) {
|
|
3682
|
-
newArr[i] = [];
|
|
3683
|
-
for (let j = 0; j < newCol; j++) newArr[i][j] = this.arr[i + r0][j + c0];
|
|
3684
|
-
}
|
|
3685
|
-
return new Matrix(newRow, newCol, newArr.flat(1));
|
|
3686
|
-
}
|
|
3687
|
-
static slice(m1,r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
|
|
3688
|
-
return m1.slice(r0, c0, r1, c1);
|
|
3689
|
-
}
|
|
3752
|
+
// toBase(n) {
|
|
3753
|
+
// let newArr = this.arr.flat(1).toBase(n);
|
|
3754
|
+
// return new Matrix(this.rows, this.cols, newArr);
|
|
3755
|
+
// }
|
|
3756
|
+
|
|
3690
3757
|
splice(r0,c0,deleteCount,...items){
|
|
3691
3758
|
|
|
3692
3759
|
}
|
|
@@ -3705,52 +3772,54 @@
|
|
|
3705
3772
|
add(...matr) {
|
|
3706
3773
|
for (let k = 0; k < matr.length; k++) {
|
|
3707
3774
|
if (typeof matr[k] == "number"||matr[k] instanceof Complex) matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3708
|
-
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] =
|
|
3775
|
+
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = add(this.arr[i][j],matr[k].arr[i][j]);
|
|
3709
3776
|
}
|
|
3710
3777
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3711
3778
|
}
|
|
3712
3779
|
sub(...matr) {
|
|
3713
3780
|
for (let k = 0; k < matr.length; k++) {
|
|
3714
3781
|
if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3715
|
-
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] =
|
|
3782
|
+
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = sub(this.arr[i][j],matr[k].arr[i][j]);
|
|
3716
3783
|
}
|
|
3717
3784
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3718
3785
|
}
|
|
3719
3786
|
static add(m1, ...m2) {
|
|
3720
|
-
return m1.clone.add(...m2);
|
|
3787
|
+
return m1.clone().add(...m2);
|
|
3721
3788
|
}
|
|
3722
3789
|
static sub(m1, ...m2) {
|
|
3723
|
-
return m1.clone.sub(...m2);
|
|
3790
|
+
return m1.clone().sub(...m2);
|
|
3724
3791
|
}
|
|
3725
3792
|
mul(...matr) {
|
|
3726
3793
|
for (let k = 0; k < matr.length; k++) {
|
|
3727
3794
|
if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3728
|
-
for (var i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] =
|
|
3795
|
+
for (var i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = mul(this.arr[i][j],matr[k].arr[i][j]);
|
|
3729
3796
|
}
|
|
3730
3797
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3731
3798
|
}
|
|
3732
3799
|
div(...matr) {
|
|
3733
3800
|
for (let k = 0; k < matr.length; k++) {
|
|
3734
3801
|
if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3735
|
-
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] =
|
|
3802
|
+
for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = div(this.arr[i][j],matr[k].arr[i][j]);
|
|
3736
3803
|
}
|
|
3737
3804
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3738
3805
|
}
|
|
3739
3806
|
static div(m1, ...m2) {
|
|
3740
|
-
return m1.clone.div(...m2);
|
|
3807
|
+
return m1.clone().div(...m2);
|
|
3741
3808
|
}
|
|
3742
3809
|
static mul(m1, ...m2) {
|
|
3743
|
-
return m1.clone.mul(...m2);
|
|
3810
|
+
return m1.clone().mul(...m2);
|
|
3744
3811
|
}
|
|
3745
3812
|
modulo(...matr) {
|
|
3746
3813
|
for (let k = 0; k < matr.length; k++) {
|
|
3747
3814
|
if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
|
|
3748
|
-
for (let i = 0; i < this.rows; i++)
|
|
3815
|
+
for (let i = 0; i < this.rows; i++)
|
|
3816
|
+
for (var j = 0; j < this.cols; j++)
|
|
3817
|
+
this.arr[i][j]=modulo(this.arr[i][j],matr[k].arr[i][j]);
|
|
3749
3818
|
}
|
|
3750
3819
|
return new Matrix(this.rows, this.cols, this.arr.flat(1));
|
|
3751
3820
|
}
|
|
3752
3821
|
static modulo(m1, ...m2) {
|
|
3753
|
-
return m1.clone.modulo(...m2);
|
|
3822
|
+
return m1.clone().modulo(...m2);
|
|
3754
3823
|
}
|
|
3755
3824
|
dot(matrix) {
|
|
3756
3825
|
var res = [];
|
|
@@ -3759,9 +3828,9 @@
|
|
|
3759
3828
|
for (var j = 0; j < matrix.arr[0].length; j++) {
|
|
3760
3829
|
res[i][j] = 0;
|
|
3761
3830
|
for (var k = 0; k < this.arr[0].length; k++) {
|
|
3762
|
-
res[i][j] =
|
|
3831
|
+
res[i][j] = add(
|
|
3763
3832
|
res[i][j],
|
|
3764
|
-
|
|
3833
|
+
mul(this.arr[i][k],matrix.arr[k][j])
|
|
3765
3834
|
);
|
|
3766
3835
|
}
|
|
3767
3836
|
}
|
|
@@ -3772,52 +3841,52 @@
|
|
|
3772
3841
|
return matrix1.dot(matrix2);
|
|
3773
3842
|
}
|
|
3774
3843
|
pow(n) {
|
|
3775
|
-
let a = this.clone,
|
|
3776
|
-
p = this.clone;
|
|
3844
|
+
let a = this.clone(),
|
|
3845
|
+
p = this.clone();
|
|
3777
3846
|
for (let i = 0; i < n - 1; i++) p = p.dot(a);
|
|
3778
3847
|
return p;
|
|
3779
3848
|
}
|
|
3780
3849
|
static pow(m, n) {
|
|
3781
|
-
return m.clone.pow(n);
|
|
3850
|
+
return m.clone().pow(n);
|
|
3782
3851
|
}
|
|
3783
3852
|
get somme() {
|
|
3784
3853
|
let S = 0;
|
|
3785
3854
|
for (let i = 0; i < this.rows; i++) for (let j = 0; j < this.cols; j++) S += this.arr[i][j];
|
|
3786
3855
|
return S;
|
|
3787
3856
|
}
|
|
3788
|
-
get
|
|
3857
|
+
get hasComplex() {
|
|
3789
3858
|
return this.arr.flat(Infinity).some((n) => n instanceof Complex);
|
|
3790
3859
|
}
|
|
3791
3860
|
get min() {
|
|
3792
|
-
if (this.
|
|
3861
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3793
3862
|
let minRow = [];
|
|
3794
3863
|
for (let i = 0; i < this.rows; i++) minRow.push(min(...this.arr[i]));
|
|
3795
3864
|
return min(...minRow);
|
|
3796
3865
|
}
|
|
3797
3866
|
get max() {
|
|
3798
|
-
if (this.
|
|
3867
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3799
3868
|
let maxRow = [];
|
|
3800
3869
|
for (let i = 0; i < this.rows; i++) maxRow.push(max(...this.arr[i]));
|
|
3801
3870
|
return max(...maxRow);
|
|
3802
3871
|
}
|
|
3803
3872
|
get minRows() {
|
|
3804
|
-
if (this.
|
|
3873
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3805
3874
|
let minRow = [];
|
|
3806
3875
|
for (let i = 0; i < this.rows; i++) minRow.push(min(...this.arr[i]));
|
|
3807
3876
|
return minRow;
|
|
3808
3877
|
}
|
|
3809
3878
|
get maxRows() {
|
|
3810
|
-
if (this.
|
|
3879
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3811
3880
|
let maxRow = [];
|
|
3812
3881
|
for (let i = 0; i < this.rows; i++) maxRow.push(max(...this.arr[i]));
|
|
3813
3882
|
return maxRow;
|
|
3814
3883
|
}
|
|
3815
3884
|
get minCols() {
|
|
3816
|
-
if (this.
|
|
3885
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3817
3886
|
return this.T.minRows;
|
|
3818
3887
|
}
|
|
3819
3888
|
get maxCols() {
|
|
3820
|
-
if (this.
|
|
3889
|
+
if (this.hasComplex) console.error("Complex numbers are not comparable");
|
|
3821
3890
|
return this.T.maxRows;
|
|
3822
3891
|
}
|
|
3823
3892
|
static fromVector(v) {
|
|
@@ -3832,53 +3901,15 @@
|
|
|
3832
3901
|
}
|
|
3833
3902
|
return arr;
|
|
3834
3903
|
}
|
|
3835
|
-
get print() {
|
|
3836
|
-
//"pretty print" the matrix
|
|
3837
|
-
let fstring = "[";
|
|
3838
|
-
for (let i = 0; i < this.arr.length; i++) {
|
|
3839
|
-
fstring += (i != 0 ? " " : "") + ` [${this.arr[i].map((n) => " " + n.toString() + " ")}],\n`;
|
|
3840
|
-
}
|
|
3841
|
-
console.log(fstring.substring(0, fstring.length - 2) + " ]");
|
|
3842
|
-
document.write(fstring.substring(0, fstring.length - 2) + " ]");
|
|
3843
|
-
}
|
|
3844
|
-
get table() {
|
|
3845
|
-
console.table(this.arr);
|
|
3846
|
-
}
|
|
3847
3904
|
get serialize() {
|
|
3848
3905
|
return JSON.stringify(this);
|
|
3849
3906
|
}
|
|
3850
3907
|
static deserialize(data) {
|
|
3851
|
-
if (typeof data == "string")
|
|
3852
|
-
data = JSON.parse(data);
|
|
3853
|
-
}
|
|
3908
|
+
if (typeof data == "string") data = JSON.parse(data);
|
|
3854
3909
|
let matrix = new Matrix(data.rows, data.cols);
|
|
3855
3910
|
matrix.arr = data.arr;
|
|
3856
3911
|
return matrix;
|
|
3857
3912
|
}
|
|
3858
|
-
|
|
3859
|
-
toTable() {
|
|
3860
|
-
var table = new DocumentFragment();
|
|
3861
|
-
var Tr = new Array(this.rows).fill(null).map(() => document?.createElement("tr"));
|
|
3862
|
-
var Td = this.arr.map((n) => n.map(() => document?.createElement("td")));
|
|
3863
|
-
for (let i = 0; i < Td.length; i++) {
|
|
3864
|
-
for (let j = 0; j < Td[0].length; j++) {
|
|
3865
|
-
Td[i][j].innerHTML = this.arr[i][j];
|
|
3866
|
-
Tr[i].appendChild(Td[i][j]);
|
|
3867
|
-
}
|
|
3868
|
-
}
|
|
3869
|
-
Tr.map((n) => table.appendChild(n));
|
|
3870
|
-
return table;
|
|
3871
|
-
}
|
|
3872
|
-
toGrid(element, style = {}) {
|
|
3873
|
-
let a = Grid();
|
|
3874
|
-
a.append(
|
|
3875
|
-
...this.map(element)
|
|
3876
|
-
.arr.flat(1)
|
|
3877
|
-
.map((n) => n.style(style))
|
|
3878
|
-
);
|
|
3879
|
-
a.Columns(this.cols);
|
|
3880
|
-
return a;
|
|
3881
|
-
}
|
|
3882
3913
|
sortTable(n=0,{type="num",order="asc"}={}) {
|
|
3883
3914
|
var obj=this.T.arr.map(n=>n.map((n,i)=>Object.assign({},{x:n,y:i})));
|
|
3884
3915
|
var newObj=this.T.arr.map(n=>n.map((n,i)=>Object.assign({},{x:n,y:i})));
|
|
@@ -3910,68 +3941,7 @@
|
|
|
3910
3941
|
}
|
|
3911
3942
|
}
|
|
3912
3943
|
|
|
3913
|
-
|
|
3914
|
-
if (M.length !== M[0].length) {
|
|
3915
|
-
return;
|
|
3916
|
-
}
|
|
3917
|
-
var i = 0,
|
|
3918
|
-
ii = 0,
|
|
3919
|
-
j = 0,
|
|
3920
|
-
dim = M.length,
|
|
3921
|
-
e = 0;
|
|
3922
|
-
//t = 0;
|
|
3923
|
-
var I = [],
|
|
3924
|
-
C = [];
|
|
3925
|
-
for (i = 0; i < dim; i += 1) {
|
|
3926
|
-
I[I.length] = [];
|
|
3927
|
-
C[C.length] = [];
|
|
3928
|
-
for (j = 0; j < dim; j += 1) {
|
|
3929
|
-
if (i == j) {
|
|
3930
|
-
I[i][j] = 1;
|
|
3931
|
-
} else {
|
|
3932
|
-
I[i][j] = 0;
|
|
3933
|
-
}
|
|
3934
|
-
C[i][j] = M[i][j];
|
|
3935
|
-
}
|
|
3936
|
-
}
|
|
3937
|
-
for (i = 0; i < dim; i += 1) {
|
|
3938
|
-
e = C[i][i];
|
|
3939
|
-
if (e == 0) {
|
|
3940
|
-
for (ii = i + 1; ii < dim; ii += 1) {
|
|
3941
|
-
if (C[ii][i] != 0) {
|
|
3942
|
-
for (j = 0; j < dim; j++) {
|
|
3943
|
-
e = C[i][j];
|
|
3944
|
-
C[i][j] = C[ii][j];
|
|
3945
|
-
C[ii][j] = e;
|
|
3946
|
-
e = I[i][j];
|
|
3947
|
-
I[i][j] = I[ii][j];
|
|
3948
|
-
I[ii][j] = e;
|
|
3949
|
-
}
|
|
3950
|
-
break;
|
|
3951
|
-
}
|
|
3952
|
-
}
|
|
3953
|
-
e = C[i][i];
|
|
3954
|
-
if (e == 0) {
|
|
3955
|
-
return;
|
|
3956
|
-
}
|
|
3957
|
-
}
|
|
3958
|
-
for (j = 0; j < dim; j++) {
|
|
3959
|
-
C[i][j] = C[i][j] / e;
|
|
3960
|
-
I[i][j] = I[i][j] / e;
|
|
3961
|
-
}
|
|
3962
|
-
for (ii = 0; ii < dim; ii++) {
|
|
3963
|
-
if (ii == i) {
|
|
3964
|
-
continue;
|
|
3965
|
-
}
|
|
3966
|
-
e = C[ii][i];
|
|
3967
|
-
for (j = 0; j < dim; j++) {
|
|
3968
|
-
C[ii][j] -= e * C[i][j];
|
|
3969
|
-
I[ii][j] -= e * I[i][j];
|
|
3970
|
-
}
|
|
3971
|
-
}
|
|
3972
|
-
}
|
|
3973
|
-
return I;
|
|
3974
|
-
}
|
|
3944
|
+
|
|
3975
3945
|
/**
|
|
3976
3946
|
* @returns {Matrix}
|
|
3977
3947
|
*/
|
|
@@ -3980,292 +3950,383 @@
|
|
|
3980
3950
|
const matrix3=(...element)=>new Matrix(3, 3, element);
|
|
3981
3951
|
const matrix4=(...element)=>new Matrix(4, 4, element);
|
|
3982
3952
|
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
this.a=a.a;
|
|
3992
|
-
this.b=a.b;
|
|
3993
|
-
}
|
|
3994
|
-
else if(("a" in a && "z" in a)){
|
|
3995
|
-
this.a=a.a;
|
|
3996
|
-
this.b=sqrt$2((a.z**2)-(a.a**2));
|
|
3997
|
-
}
|
|
3998
|
-
else if(("a" in a && "phi" in a)){
|
|
3999
|
-
this.a=a.a;
|
|
4000
|
-
this.b=a.a*tan(a.phi);
|
|
4001
|
-
}
|
|
4002
|
-
else if(("b" in a && "z" in a)){
|
|
4003
|
-
this.b=a.b;
|
|
4004
|
-
this.a=sqrt$2((a.z**2)-(a.b**2));
|
|
4005
|
-
}
|
|
4006
|
-
else if(("b" in a && "phi" in a)){
|
|
4007
|
-
this.b=b;
|
|
4008
|
-
this.a=a.b/tan(a.phi);
|
|
4009
|
-
}
|
|
4010
|
-
else if(("z" in a && "phi" in a)){
|
|
4011
|
-
this.a=a.z*cos$2(a.phi);
|
|
4012
|
-
this.a=a.z*sin$2(a.phi);
|
|
3953
|
+
const powerSet=originalSet=>{
|
|
3954
|
+
const subSets = [];
|
|
3955
|
+
const NUMBER_OF_COMBINATIONS = 2 ** originalSet.length;
|
|
3956
|
+
for (let i = 0; i < NUMBER_OF_COMBINATIONS; i += 1) {
|
|
3957
|
+
const subSet = [];
|
|
3958
|
+
for (let j = 0; j < originalSet.length; j += 1) {
|
|
3959
|
+
if (i & (1 << j)) {
|
|
3960
|
+
subSet.push(originalSet[j]);
|
|
4013
3961
|
}
|
|
4014
3962
|
}
|
|
4015
|
-
|
|
4016
|
-
this.a = +a.toFixed(32);
|
|
4017
|
-
this.b = +b.toFixed(32);
|
|
4018
|
-
}
|
|
4019
|
-
}
|
|
4020
|
-
isComplex(){
|
|
4021
|
-
return true
|
|
4022
|
-
}
|
|
4023
|
-
toString(){
|
|
4024
|
-
let str = "";
|
|
4025
|
-
if (this.a !== 0)
|
|
4026
|
-
this.b >= 0
|
|
4027
|
-
? (str = `${this.a}+${this.b}*i`)
|
|
4028
|
-
: (str = `${this.a}-${Math.abs(this.b)}*i`);
|
|
4029
|
-
else
|
|
4030
|
-
this.b >= 0
|
|
4031
|
-
? (str = `${this.b}*i`)
|
|
4032
|
-
: (str = `-${Math.abs(this.b)}*i`);
|
|
4033
|
-
return str;
|
|
4034
|
-
}
|
|
4035
|
-
|
|
4036
|
-
get clone() {
|
|
4037
|
-
return new Complex(this.a, this.b);
|
|
4038
|
-
}
|
|
4039
|
-
get z(){
|
|
4040
|
-
return hypot(this.a,this.b);
|
|
4041
|
-
}
|
|
4042
|
-
get phi(){
|
|
4043
|
-
return atan2(this.b , this.a);
|
|
4044
|
-
}
|
|
4045
|
-
static Zero() {
|
|
4046
|
-
return new Complex(0, 0);
|
|
4047
|
-
}
|
|
4048
|
-
get conj() {
|
|
4049
|
-
return new Complex(this.a, -this.b);
|
|
4050
|
-
}
|
|
4051
|
-
get inv() {
|
|
4052
|
-
return new Complex(this.a / (pow$1(this.a, 2) + pow$1(this.b, 2)), -this.b / (pow$1(this.a, 2) + pow$1(this.b, 2)));
|
|
3963
|
+
subSets.push(subSet);
|
|
4053
3964
|
}
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
3965
|
+
return subSets;
|
|
3966
|
+
};
|
|
3967
|
+
|
|
3968
|
+
// const subSet = (...arr) => {
|
|
3969
|
+
// let list = arange(0, 2 ** arr.length, 1);
|
|
3970
|
+
// let bin = list.map((n) => n.toString(2).padStart(arr.length, '0')).map((n) => n.split("").map((n) => +n));
|
|
3971
|
+
// let sub = bin.map((n) => n.map((m, i) => (m === 1 ? arr[i] : null))).map((n) => n.filter((x) => x !== null));
|
|
3972
|
+
// return sub;
|
|
3973
|
+
// };
|
|
3974
|
+
const subSet = null;
|
|
3975
|
+
|
|
3976
|
+
const Base={
|
|
3977
|
+
_mode:Number,
|
|
3978
|
+
_map:function(func,number,toBase){
|
|
3979
|
+
if (number instanceof Matrix)
|
|
3980
|
+
return new Matrix(
|
|
3981
|
+
number.rows,
|
|
3982
|
+
number.cols,
|
|
3983
|
+
number.arr.flat(1).map(n=>func(n,toBase))
|
|
3984
|
+
);
|
|
3985
|
+
else if (number instanceof Complex) return new Complex(func(number.a,toBase),func(number.b,toBase));
|
|
3986
|
+
else if (number instanceof Array) return number.map((n) =>func(n,toBase));
|
|
3987
|
+
},
|
|
3988
|
+
dec2base(dec,base){
|
|
3989
|
+
base<=10?this._mode=Number:this._mode=String;
|
|
3990
|
+
//this._mode=String
|
|
3991
|
+
if (typeof dec === "number") return this._mode((dec >>> 0).toString(base));
|
|
3992
|
+
return this._map(this.dec2base,dec,base)
|
|
3993
|
+
},
|
|
3994
|
+
dec2bin(dec){
|
|
3995
|
+
return this.dec2base(dec,2);
|
|
3996
|
+
},
|
|
3997
|
+
dec2oct(dec){
|
|
3998
|
+
return this.dec2base(dec,8);
|
|
3999
|
+
},
|
|
4000
|
+
dec2hex(dec){
|
|
4001
|
+
return this.dec2base(dec,16);
|
|
4002
|
+
},
|
|
4003
|
+
bin2base(bin, base) {
|
|
4004
|
+
return this.dec2base(this.bin2dec(bin),base)
|
|
4005
|
+
},
|
|
4006
|
+
bin2dec(bin){
|
|
4007
|
+
return this._mode("0b"+bin);
|
|
4008
|
+
},
|
|
4009
|
+
bin2oct(bin){
|
|
4010
|
+
return this.bin2base(bin,8);
|
|
4011
|
+
},
|
|
4012
|
+
bin2hex(bin){
|
|
4013
|
+
return this.bin2base(bin,16);
|
|
4014
|
+
},
|
|
4015
|
+
oct2dec(oct){
|
|
4016
|
+
return this._mode("0o"+oct);
|
|
4017
|
+
},
|
|
4018
|
+
oct2bin(oct){
|
|
4019
|
+
return this.dec2bin(this.oct2dec(oct))
|
|
4020
|
+
},
|
|
4021
|
+
oct2hex(oct){
|
|
4022
|
+
return this.dec2hex(this.oct2dec(oct))
|
|
4023
|
+
},
|
|
4024
|
+
oct2base(oct, base) {
|
|
4025
|
+
return this.dec2base(this.oct2dec(oct),base)
|
|
4026
|
+
},
|
|
4027
|
+
hex2dec(hex){
|
|
4028
|
+
return this._mode("0x"+hex);
|
|
4029
|
+
},
|
|
4030
|
+
hex2bin(hex){
|
|
4031
|
+
return this.dec2bin(this.hex2dec(hex))
|
|
4032
|
+
},
|
|
4033
|
+
hex2oct(hex){
|
|
4034
|
+
return this.dec2oct(this.hex2dec(hex))
|
|
4035
|
+
},
|
|
4036
|
+
hex2base(hex, base) {
|
|
4037
|
+
return this.dec2base(this.hex2dec(hex),base)
|
|
4038
|
+
},
|
|
4039
|
+
IEEE32toDec(Bin){
|
|
4040
|
+
let IEEE32=Bin.split(" ").join("").padEnd(32,"0");
|
|
4041
|
+
let s=IEEE32[0];
|
|
4042
|
+
let e=2**(+("0b"+IEEE32.slice(1,9))-127);
|
|
4043
|
+
let m=IEEE32.slice(9,32).split("").map(n=>+n);
|
|
4044
|
+
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
4045
|
+
let dec=(-1)**s*(1+M)*e;
|
|
4046
|
+
return dec
|
|
4047
|
+
},
|
|
4048
|
+
IEEE64toDec(Bin){
|
|
4049
|
+
let IEEE64=Bin.split(" ").join("").padEnd(64,"0");
|
|
4050
|
+
let s=IEEE64[0];
|
|
4051
|
+
let e=2**(+("0b"+IEEE64.slice(1,12))-1023);
|
|
4052
|
+
let m=IEEE64.slice(13,64).split("").map(n=>+n);
|
|
4053
|
+
let M=m.map((n,i)=>n*(2**(-i-1))).reduce((a,b)=>a+b,0);
|
|
4054
|
+
let dec=(-1)**s*(1+M)*e;
|
|
4055
|
+
return dec;
|
|
4063
4056
|
}
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4057
|
+
};
|
|
4058
|
+
|
|
4059
|
+
const Logic$1={
|
|
4060
|
+
_mode:Number,
|
|
4061
|
+
_map:function(func,a,b){
|
|
4062
|
+
if (a instanceof Matrix)
|
|
4063
|
+
return new Matrix(
|
|
4064
|
+
a.rows,
|
|
4065
|
+
a.cols,
|
|
4066
|
+
a.arr.flat(1).map((n) => func(n, b))
|
|
4067
|
+
);
|
|
4068
|
+
else if (a instanceof Complex) return new Complex(func(a.a, b), func(a.b, b));
|
|
4069
|
+
else if (a instanceof Array) return a.map((n) => func(n, b));
|
|
4070
|
+
},
|
|
4071
|
+
not:function(input){
|
|
4072
|
+
if(["number","boolean"].includes(typeof input)) return Logic$1._mode(!input);
|
|
4073
|
+
else return this._map(this.not,input)
|
|
4074
|
+
},
|
|
4075
|
+
and:function(a, ...b){
|
|
4076
|
+
if(["number","boolean"].includes(typeof a))return Logic$1._mode(b.reduce((n, m) => (n &= m), a));
|
|
4077
|
+
else return this._map(this.and,a,b)
|
|
4078
|
+
},
|
|
4079
|
+
or:function(a, ...b) {
|
|
4080
|
+
if(["number","boolean"].includes(typeof a)) return Logic$1._mode(b.reduce((n, m) => (n |= m), a));
|
|
4081
|
+
else return this._map(this.or,a,b);
|
|
4082
|
+
},
|
|
4083
|
+
nand:function(a, ...b) {
|
|
4084
|
+
return this.not(this.and(a, b));
|
|
4085
|
+
},
|
|
4086
|
+
nor:function(a, ...b) {
|
|
4087
|
+
return this.not(this.or(a, b));
|
|
4088
|
+
},
|
|
4089
|
+
xor:function(a,...b){
|
|
4090
|
+
let arr=[a,...b];
|
|
4091
|
+
if(["number","boolean"].includes(typeof a))return this._mode(arr.reduce((length,cur)=>{
|
|
4092
|
+
if(+cur===1)length+=1;
|
|
4093
|
+
return length;
|
|
4094
|
+
},0)===1);
|
|
4095
|
+
else return this._map(this.xor,a,b);
|
|
4096
|
+
},
|
|
4097
|
+
xnor:function(a,...b){
|
|
4098
|
+
return Logic$1.not(Logic$1.xor(a,b))
|
|
4073
4099
|
}
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4100
|
+
|
|
4101
|
+
};
|
|
4102
|
+
|
|
4103
|
+
class Permutation {
|
|
4104
|
+
static withDiscount(arr, l = arr.length) {
|
|
4105
|
+
if (l === 1) return arr.map((n) => [n]);
|
|
4106
|
+
const permutations = [];
|
|
4107
|
+
let smallerPermutations;
|
|
4108
|
+
smallerPermutations = this.withDiscount(arr, l - 1);
|
|
4109
|
+
arr.forEach((currentOption) => {
|
|
4110
|
+
smallerPermutations.forEach((smallerPermutation) => {
|
|
4111
|
+
permutations.push([currentOption].concat(smallerPermutation));
|
|
4112
|
+
});
|
|
4113
|
+
});
|
|
4114
|
+
return permutations;
|
|
4083
4115
|
}
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4116
|
+
static withoutDiscount(arr) {
|
|
4117
|
+
const l = arr.length;
|
|
4118
|
+
if (l === 1) return arr.map((n) => [n]);
|
|
4119
|
+
const permutations = [];
|
|
4120
|
+
const smallerPermutations = this.withoutDiscount(arr.slice(1));
|
|
4121
|
+
const firstOption = arr[0];
|
|
4122
|
+
for (let i = 0; i < smallerPermutations.length; i++) {
|
|
4123
|
+
const smallerPermutation = smallerPermutations[i];
|
|
4124
|
+
for (let j = 0; j <= smallerPermutation.length; j++) {
|
|
4125
|
+
const permutationPrefix = smallerPermutation.slice(0, j);
|
|
4126
|
+
const permutationSuffix = smallerPermutation.slice(j);
|
|
4127
|
+
permutations.push(permutationPrefix.concat([firstOption], permutationSuffix));
|
|
4128
|
+
}
|
|
4087
4129
|
}
|
|
4088
|
-
|
|
4089
|
-
let phi=+(this.phi-sum(...z.map(n=>n.phi))).toFixed(15);
|
|
4090
|
-
this.a=+(Z*cos$2(phi).toFixed(15)).toFixed(15);
|
|
4091
|
-
this.b=+(Z*sin$2(phi).toFixed(15)).toFixed(15);
|
|
4092
|
-
return this;
|
|
4130
|
+
return permutations;
|
|
4093
4131
|
}
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4132
|
+
}
|
|
4133
|
+
|
|
4134
|
+
class Combinaison {
|
|
4135
|
+
static withDiscount(comboOptions, comboLength) {
|
|
4136
|
+
if (comboLength === 1) {
|
|
4137
|
+
return comboOptions.map((comboOption) => [comboOption]);
|
|
4100
4138
|
}
|
|
4101
|
-
|
|
4139
|
+
const combos = [];
|
|
4140
|
+
comboOptions.forEach((currentOption, optionIndex) => {
|
|
4141
|
+
const smallerCombos = this.withDiscount(comboOptions.slice(optionIndex), comboLength - 1);
|
|
4142
|
+
smallerCombos.forEach((smallerCombo) => {
|
|
4143
|
+
combos.push([currentOption].concat(smallerCombo));
|
|
4144
|
+
});
|
|
4145
|
+
});
|
|
4146
|
+
return combos;
|
|
4102
4147
|
}
|
|
4103
|
-
static
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4148
|
+
static withoutDiscount(comboOptions, comboLength) {
|
|
4149
|
+
if (comboLength === 1) {
|
|
4150
|
+
return comboOptions.map((comboOption) => [comboOption]);
|
|
4151
|
+
}
|
|
4152
|
+
const combos = [];
|
|
4153
|
+
comboOptions.forEach((currentOption, optionIndex) => {
|
|
4154
|
+
const smallerCombos = this.withoutDiscount(comboOptions.slice(optionIndex + 1), comboLength - 1);
|
|
4155
|
+
smallerCombos.forEach((smallerCombo) => {
|
|
4156
|
+
combos.push([currentOption].concat(smallerCombo));
|
|
4157
|
+
});
|
|
4158
|
+
});
|
|
4159
|
+
|
|
4160
|
+
return combos;
|
|
4108
4161
|
}
|
|
4109
|
-
|
|
4110
|
-
|
|
4162
|
+
}
|
|
4163
|
+
const combinaison=(comboOptions, comboLength, discount=false)=>Combinaison[discount?"withDiscount":"withoutDiscount"](comboOptions, comboLength);
|
|
4164
|
+
|
|
4165
|
+
class Random {
|
|
4166
|
+
static float(a = 1, b) {
|
|
4167
|
+
return b ? Math.random() * (b - a) + a : a * Math.random();
|
|
4111
4168
|
}
|
|
4112
|
-
static
|
|
4113
|
-
return
|
|
4169
|
+
static int(a, b) {
|
|
4170
|
+
return Math.floor(this.float(a, b));
|
|
4114
4171
|
}
|
|
4115
|
-
static
|
|
4116
|
-
|
|
4172
|
+
static char(upperCase){
|
|
4173
|
+
upperCase=upperCase??this.bool();
|
|
4174
|
+
const Char=String.fromCharCode(this.int(97,120));
|
|
4175
|
+
return upperCase?Char.toUpperCase():Char;
|
|
4117
4176
|
}
|
|
4118
|
-
static
|
|
4119
|
-
return
|
|
4177
|
+
static bool(){
|
|
4178
|
+
return [false,true][Math.floor(Math.random()*2)];
|
|
4120
4179
|
}
|
|
4121
|
-
static
|
|
4122
|
-
return
|
|
4180
|
+
static string(length,upperCase){
|
|
4181
|
+
return length instanceof Array?
|
|
4182
|
+
new Array(this.int(...length)).fill(0).map(() => this.char(upperCase)).join(""):
|
|
4183
|
+
new Array(length).fill(0).map(() => this.char(upperCase)).join("");
|
|
4123
4184
|
}
|
|
4124
|
-
static
|
|
4125
|
-
return
|
|
4185
|
+
static bin() {
|
|
4186
|
+
return this.int(2);
|
|
4126
4187
|
}
|
|
4127
|
-
static
|
|
4128
|
-
return
|
|
4188
|
+
static oct() {
|
|
4189
|
+
return this.int(8);
|
|
4129
4190
|
}
|
|
4130
|
-
|
|
4131
|
-
return
|
|
4191
|
+
static dec() {
|
|
4192
|
+
return this.int(8);
|
|
4132
4193
|
}
|
|
4133
|
-
|
|
4134
|
-
return this.
|
|
4194
|
+
static hex() {
|
|
4195
|
+
return this.int(16);
|
|
4135
4196
|
}
|
|
4136
|
-
|
|
4137
|
-
|
|
4197
|
+
static choice(choices = [1, 2, 3], p = new Array(choices.length).fill(1 / choices.length)) {
|
|
4198
|
+
let newchoice = new Array(100);
|
|
4199
|
+
p=Utils.accum(...p).map(n=>n*100);
|
|
4200
|
+
newchoice.fill(choices[0], 0, p[0]);
|
|
4201
|
+
for (let i = 1; i < choices.length; i++) newchoice.fill(choices[i], p[i - 1], p[i]);
|
|
4202
|
+
return newchoice[this.int(newchoice.length - 1)];
|
|
4138
4203
|
}
|
|
4139
|
-
|
|
4140
|
-
return
|
|
4204
|
+
static shuffleArr(arr){
|
|
4205
|
+
return arr.sort(()=>0.5-Math.random())
|
|
4141
4206
|
}
|
|
4142
|
-
|
|
4143
|
-
return
|
|
4207
|
+
static floats(n, a, b) {
|
|
4208
|
+
return new Array(n).fill(0).map(() => this.float(a, b));
|
|
4144
4209
|
}
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
return complex(sin$2(2*this.a)/de,sinh$1(2*this.b)/de);
|
|
4210
|
+
static ints(n, a, b) {
|
|
4211
|
+
return new Array(n).fill(0).map(() => this.int(a, b));
|
|
4148
4212
|
}
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
if((a instanceof Array||ArrayBuffer.isView(a)) && (b instanceof Array||ArrayBuffer.isView(a)))return a.map((n,i)=>complex(a[i],b[i]));
|
|
4152
|
-
if(a instanceof Matrix && b instanceof Matrix){
|
|
4153
|
-
if((a.shape[0]!==b.shape[0])||(a.shape[1]!==b.shape[1]))return Error(0)
|
|
4154
|
-
const arr=a.arr.map((n,i)=>complex(a.arr[i],b.arr[i]));
|
|
4155
|
-
return new Matrix(a.rows,a.cols,...arr)
|
|
4213
|
+
static bools(n){
|
|
4214
|
+
return new Array(n).fill(0).map(() => this.bool());
|
|
4156
4215
|
}
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
const abs=(...x)=>mapfun$1(Math.abs,...x);
|
|
4161
|
-
const sqrt$2=(...x)=>mapfun$1(Math.sqrt,...x);
|
|
4162
|
-
const pow$1=(x,n)=>{
|
|
4163
|
-
if(typeof x === "number"){
|
|
4164
|
-
if(typeof n === "number")return Math.pow(x,n);
|
|
4165
|
-
else if(n instanceof Complex)return Complex.fromExpo(x**n.a,n.b*ln(x))
|
|
4166
|
-
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
4216
|
+
static bins(n) {
|
|
4217
|
+
return new Array(n).fill(0).map(() => this.int(2));
|
|
4167
4218
|
}
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
else if(n instanceof Complex)return Complex.fromExpo(
|
|
4171
|
-
x.z**n.a*e(-x.phi*n.b),
|
|
4172
|
-
ln(x.z)*n.b+n.a*x.phi
|
|
4173
|
-
)
|
|
4174
|
-
else return mapfun$1(a=>pow$1(x,a),...n);
|
|
4219
|
+
static octs(n) {
|
|
4220
|
+
return new Array(n).fill(0).map(() => this.int(8));
|
|
4175
4221
|
}
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
else if(n instanceof Array){
|
|
4179
|
-
const Y=[];
|
|
4180
|
-
for(let i=0;i<x.length;i++){
|
|
4181
|
-
Y.push(mapfun$1(a=>pow$1(x[i],a),...n));
|
|
4182
|
-
}
|
|
4183
|
-
return Y;
|
|
4184
|
-
}
|
|
4222
|
+
static decs(n) {
|
|
4223
|
+
return new Array(n).fill(0).map(() => this.int(10));
|
|
4185
4224
|
}
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
if(typeof x === "number"){
|
|
4189
|
-
if(typeof n === "number")return Math.pow(x,1/n);
|
|
4190
|
-
else return mapfun$1(a=>sqrtn(x,a),...n);
|
|
4225
|
+
static hexs(n) {
|
|
4226
|
+
return new Array(n).fill(0).map(() => this.int(16));
|
|
4191
4227
|
}
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
else return mapfun$1(a=>sqrtn(x,a),...n);
|
|
4228
|
+
static choices(n, choices, p) {
|
|
4229
|
+
return new Array(n).fill(0).map(() => this.choice(choices, p));
|
|
4195
4230
|
}
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
const Y=[];
|
|
4200
|
-
for(let i=0;i<x.length;i++){
|
|
4201
|
-
Y.push(mapfun$1(a=>sqrtn(x[i],a),...n));
|
|
4202
|
-
}
|
|
4203
|
-
return Y;
|
|
4204
|
-
}
|
|
4231
|
+
static perm(...arr) {
|
|
4232
|
+
// permutation
|
|
4233
|
+
return arr.permS[this.int(arr.length)];
|
|
4205
4234
|
}
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
const ln=(...x) => mapfun$1(Math.log,...x);
|
|
4209
|
-
const cos$2=(...x) => mapfun$1(Fixed.cos,...x);
|
|
4210
|
-
const sin$2=(...x) => mapfun$1(Fixed.sin,...x);
|
|
4211
|
-
const tan=(...x) => mapfun$1(Fixed.tan,...x);
|
|
4212
|
-
const sec=(...x) => mapfun$1(Fixed.sec,...x);
|
|
4213
|
-
const sinc=(...x) => mapfun$1(Fixed.sinc,...x);
|
|
4214
|
-
const csc=(...x) => mapfun$1(Fixed.csc,...x);
|
|
4215
|
-
const cot=(...x) => mapfun$1(Fixed.cot,...x);
|
|
4216
|
-
const acos$1=(...x) => mapfun$1(Fixed.acos,...x);
|
|
4217
|
-
const asin=(...x) => mapfun$1(Fixed.asin,...x);
|
|
4218
|
-
const atan=(...x) => mapfun$1(Fixed.atan,...x);
|
|
4219
|
-
const acot=(...x) => mapfun$1(Fixed.acot,...x);
|
|
4220
|
-
const cosh$1=(...x) => mapfun$1(Fixed.cosh,...x);
|
|
4221
|
-
const sinh$1=(...x) => mapfun$1(Fixed.sinh,...x);
|
|
4222
|
-
const tanh=(...x) => mapfun$1(Fixed.tanh,...x);
|
|
4223
|
-
const coth=(...x) => mapfun$1(Fixed.coth,...x);
|
|
4224
|
-
const acosh=(...x) => mapfun$1(Fixed.acosh,...x);
|
|
4225
|
-
const asinh=(...x) => mapfun$1(Fixed.asinh,...x);
|
|
4226
|
-
const atanh=(...x) => mapfun$1(Fixed.atanh,...x);
|
|
4227
|
-
const ceil=(...x) => mapfun$1(Math.ceil,...x);
|
|
4228
|
-
const floor=(...x) => mapfun$1(Math.floor,...x);
|
|
4229
|
-
const round=(...x) => mapfun$1(Math.round,...x);
|
|
4230
|
-
const atan2=(x,y,rad=true)=>{
|
|
4231
|
-
if(typeof x === "number"){
|
|
4232
|
-
if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
|
|
4233
|
-
else return mapfun$1(a=>atan2(x,a,rad),...y);
|
|
4235
|
+
static color() {
|
|
4236
|
+
return "#" + Base.dec2hex(this.float(16777216)).padStart(6,0);
|
|
4234
4237
|
}
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
// else return mapfun(a=>pow(x,a),...n);
|
|
4238
|
-
// }
|
|
4239
|
-
else if(x instanceof Array){
|
|
4240
|
-
if(typeof y === "number") return mapfun$1(a=>atan2(a,y,rad),...x);
|
|
4241
|
-
else if(y instanceof Array){
|
|
4242
|
-
const Y=[];
|
|
4243
|
-
for(let i=0;i<x.length;i++){
|
|
4244
|
-
Y.push(mapfun$1(a=>pow$1(x[i],a),...y));
|
|
4245
|
-
}
|
|
4246
|
-
return Y;
|
|
4247
|
-
}
|
|
4238
|
+
static colors(n) {
|
|
4239
|
+
return new Array(n).fill(null).map(()=>this.color());
|
|
4248
4240
|
}
|
|
4249
|
-
};
|
|
4250
|
-
const fact=(...x)=>mapfun$1(n=> {
|
|
4251
|
-
let i,
|
|
4252
|
-
y = 1;
|
|
4253
|
-
if (n == 0) y = 1;
|
|
4254
|
-
else if (n > 0) for (i = 1; i <= n; i++) y *= i;
|
|
4255
|
-
else y = NaN;
|
|
4256
|
-
return y;
|
|
4257
|
-
},...x);
|
|
4258
|
-
const sign=(...x)=>mapfun$1(Math.sign,...x);
|
|
4259
4241
|
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4242
|
+
// Should be Moved to Matrix and Complex to avoid Circular dependencies
|
|
4243
|
+
// static complex(a = [0,1], b = [0,1]) {
|
|
4244
|
+
// return a instanceof Array?
|
|
4245
|
+
// new Complex(
|
|
4246
|
+
// this.float(a[0], a[1]),
|
|
4247
|
+
// this.float(b[0], b[1])
|
|
4248
|
+
// ):
|
|
4249
|
+
// new Complex(
|
|
4250
|
+
// ...this.floats(2,a,b)
|
|
4251
|
+
// )
|
|
4252
|
+
|
|
4253
|
+
// }
|
|
4254
|
+
// static complexInt(a = [0,1], b = [0,1]) {
|
|
4255
|
+
// return new Complex(
|
|
4256
|
+
// this.int(a[0], a[1]),
|
|
4257
|
+
// this.int(b[0], b[1])
|
|
4258
|
+
// );
|
|
4259
|
+
// }
|
|
4260
|
+
// static complexBin() {
|
|
4261
|
+
// return new Complex(...this.bins(2));
|
|
4262
|
+
// }
|
|
4263
|
+
// static complexOct() {
|
|
4264
|
+
// return new Complex(...this.octs(2));
|
|
4265
|
+
// }
|
|
4266
|
+
// static complexDec() {
|
|
4267
|
+
// return new Complex(...this.decs(10));
|
|
4268
|
+
// }
|
|
4269
|
+
// static complexHex() {
|
|
4270
|
+
// return new Complex(...this.octs(2));
|
|
4271
|
+
// }
|
|
4272
|
+
// static complexes(n, a = 0, b = 1) {
|
|
4273
|
+
// return new Array(n).fill(0).map(() => this.complex(a, b));
|
|
4274
|
+
// }
|
|
4275
|
+
// static complexesInt(n, a = 0, b = 1) {
|
|
4276
|
+
// return new Array(n).fill(0).map(() => this.complexInt(a, b));
|
|
4277
|
+
// }
|
|
4278
|
+
// static complexesBin(n) {
|
|
4279
|
+
// return new Array(n).fill(0).map(() => this.complexBin());
|
|
4280
|
+
// }
|
|
4281
|
+
// static complexesOct(n) {
|
|
4282
|
+
// return new Array(n).fill(0).map(() => this.complexOct());
|
|
4283
|
+
// }
|
|
4284
|
+
// static complexesDec(n) {
|
|
4285
|
+
// return new Array(n).fill(0).map(() => this.complexDec());
|
|
4286
|
+
// }
|
|
4287
|
+
// static complexesHex(n) {
|
|
4288
|
+
// return new Array(n).fill(0).map(() => this.complexHex());
|
|
4289
|
+
// }
|
|
4290
|
+
// static matrix(r,c,min,max){
|
|
4291
|
+
// return matrix(r,c,this.floats(r*c,min,max))
|
|
4292
|
+
// }
|
|
4293
|
+
// static matrixInt(r,c,min,max){
|
|
4294
|
+
// return matrix(r,c,this.ints(r*c,min,max))
|
|
4295
|
+
// }
|
|
4296
|
+
// static matrixBin(r,c){
|
|
4297
|
+
// return matrix(r,c,this.bins(r*c))
|
|
4298
|
+
// }
|
|
4299
|
+
// static matrixOct(r,c){
|
|
4300
|
+
// return matrix(r,c,this.octs(r*c))
|
|
4301
|
+
// }
|
|
4302
|
+
// static matrixDec(r,c){
|
|
4303
|
+
// return matrix(r,c,this.decs(r*c))
|
|
4304
|
+
// }
|
|
4305
|
+
// static matrixHex(r,c){
|
|
4306
|
+
// return matrix(r,c,this.hex(r*c))
|
|
4307
|
+
// }
|
|
4308
|
+
// static matrixColor(r,c){
|
|
4309
|
+
// return matrix(r,c,this.colors(r*c))
|
|
4310
|
+
// }
|
|
4311
|
+
// static matrixComplex(r,c,a,b){
|
|
4312
|
+
// return matrix(r,c,this.complexes(r*c,a,b))
|
|
4313
|
+
// }
|
|
4314
|
+
// static matrixComplexInt(r,c,a,b){
|
|
4315
|
+
// return matrix(r,c,this.complexesInt(r*c,a,b))
|
|
4316
|
+
// }
|
|
4317
|
+
// static matrixComplexBin(r,c){
|
|
4318
|
+
// return matrix(r,c,this.complexesBin(r*c))
|
|
4319
|
+
// }
|
|
4320
|
+
// static matrixComplexOct(r,c){
|
|
4321
|
+
// return matrix(r,c,this.complexesBin(r*c))
|
|
4322
|
+
// }
|
|
4323
|
+
// static matrixComplexDec(r,c){
|
|
4324
|
+
// return matrix(r,c,this.complexesBin(r*c))
|
|
4325
|
+
// }
|
|
4326
|
+
// static matrixComplexHex(r,c){
|
|
4327
|
+
// return matrix(r,c,this.complexesBin(r*c))
|
|
4328
|
+
// }
|
|
4329
|
+
}
|
|
4269
4330
|
|
|
4270
4331
|
const { PI, sqrt: sqrt$1, cos: cos$1, sin: sin$1, acos, pow } = Math;
|
|
4271
4332
|
|