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