ziko 0.0.18 → 0.0.19

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.
Files changed (267) hide show
  1. package/package.json +16 -45
  2. package/src/__helpers__/index.js +61 -61
  3. package/src/app/json-style-sheet.js +64 -64
  4. package/src/app/ziko-app.js +38 -38
  5. package/src/data/api/fetchdom.js +13 -13
  6. package/src/data/api/index.js +3 -3
  7. package/src/data/api/preload.js +10 -10
  8. package/src/data/converter/adoc.js +130 -130
  9. package/src/data/converter/array.js +42 -42
  10. package/src/data/converter/canvas.js +24 -24
  11. package/src/data/converter/css.js +36 -36
  12. package/src/data/converter/csv.js +32 -32
  13. package/src/data/converter/idea.txt +9 -9
  14. package/src/data/converter/index.js +36 -36
  15. package/src/data/converter/json.js +80 -80
  16. package/src/data/converter/markdown.js +95 -95
  17. package/src/data/converter/object.js +69 -69
  18. package/src/data/converter/svg.js +10 -10
  19. package/src/data/index.js +16 -16
  20. package/src/data/parser/xml.js +46 -46
  21. package/src/data/string/patterns.js +11 -11
  22. package/src/data/string/string.js +169 -169
  23. package/src/global/{themes → _themes}/dark.js +884 -884
  24. package/src/global/{themes → _themes}/index.js +10 -10
  25. package/src/global/{themes → _themes}/light.js +254 -254
  26. package/src/global/app/index.js +45 -45
  27. package/src/global/component/index.js +38 -38
  28. package/src/global/globals/index.js +20 -20
  29. package/src/global/index.js +3 -11
  30. package/src/global/params/index.js +39 -39
  31. package/src/global/router/index.js +66 -66
  32. package/src/global/seo/index.js +42 -42
  33. package/src/graphics/canvas/canvas.js +176 -176
  34. package/src/graphics/canvas/elements/{basic → Basic}/arc.js +42 -42
  35. package/src/graphics/canvas/elements/{basic → Basic}/line.js +25 -25
  36. package/src/graphics/canvas/elements/{basic → Basic}/points.js +47 -47
  37. package/src/graphics/canvas/elements/{basic → Basic}/polygon.js +6 -6
  38. package/src/graphics/canvas/elements/{basic → Basic}/rect.js +45 -45
  39. package/src/graphics/canvas/elements/{chart → Chart}/scatter.js +2 -2
  40. package/src/graphics/canvas/elements/{element.js → Element.js} +114 -114
  41. package/src/graphics/canvas/elements/index.js +12 -12
  42. package/src/graphics/canvas/index.js +1 -1
  43. package/src/graphics/canvas/utils/color.js +7 -7
  44. package/src/graphics/canvas/utils/floodFill.js +57 -57
  45. package/src/graphics/index.js +9 -9
  46. package/src/graphics/svg/{elements/basic → Elements/Basic}/circle.js +28 -28
  47. package/src/graphics/svg/{elements/basic → Elements/Basic}/ellipse.js +23 -23
  48. package/src/graphics/svg/{elements/basic → Elements/Basic}/foreign-object.js +35 -35
  49. package/src/graphics/svg/{elements/basic → Elements/Basic}/groupe.js +32 -32
  50. package/src/graphics/svg/{elements/basic → Elements/Basic}/image.js +35 -35
  51. package/src/graphics/svg/{elements/basic → Elements/Basic}/line.js +31 -31
  52. package/src/graphics/svg/{elements/basic → Elements/Basic}/link.js +33 -33
  53. package/src/graphics/svg/{elements/basic → Elements/Basic}/path.js +61 -61
  54. package/src/graphics/svg/{elements/basic → Elements/Basic}/polygon.js +31 -31
  55. package/src/graphics/svg/{elements/basic → Elements/Basic}/polyline.js +6 -6
  56. package/src/graphics/svg/{elements/basic → Elements/Basic}/rect.js +45 -45
  57. package/src/graphics/svg/{elements/basic → Elements/Basic}/text.js +28 -28
  58. package/src/graphics/svg/{elements/derived → Elements/Derived}/grid.js +8 -8
  59. package/src/graphics/svg/{elements → Elements}/index.js +2 -2
  60. package/src/graphics/svg/{elements → Elements}/ziko-svg-element.js +48 -48
  61. package/src/graphics/svg/index.js +1 -1
  62. package/src/graphics/svg/svg.js +68 -68
  63. package/src/index.js +85 -85
  64. package/src/math/calculus/index.js +2 -2
  65. package/src/math/calculus/special-functions/bessel.js +30 -30
  66. package/src/math/calculus/special-functions/beta.js +37 -37
  67. package/src/math/calculus/special-functions/gamma.js +29 -29
  68. package/src/math/calculus/special-functions/index.js +4 -4
  69. package/src/math/complex/index.js +202 -202
  70. package/src/math/const.js +2 -2
  71. package/src/math/discret/Combinaison/index.js +33 -33
  72. package/src/math/discret/Conversion/index.js +85 -85
  73. package/src/math/discret/Logic/index.js +45 -45
  74. package/src/math/discret/Permutation/index.js +30 -30
  75. package/src/math/discret/Set/index.js +1 -1
  76. package/src/math/discret/Set/power-set.js +14 -14
  77. package/src/math/discret/Set/sub-set.js +10 -10
  78. package/src/math/discret/index.js +11 -11
  79. package/src/math/functions/index.js +161 -161
  80. package/src/math/index.js +32 -32
  81. package/src/math/matrix/Decomposition.js +90 -90
  82. package/src/math/matrix/LinearSystem.js +9 -9
  83. package/src/math/matrix/Matrix.js +716 -716
  84. package/src/math/matrix/index.js +2 -2
  85. package/src/math/random/index.js +172 -172
  86. package/src/math/signal/__np.py.txt +39 -39
  87. package/src/math/signal/conv.js +174 -174
  88. package/src/math/signal/fft.js +54 -54
  89. package/src/math/signal/filter.js +38 -38
  90. package/src/math/signal/functions.js +145 -145
  91. package/src/math/signal/index.js +109 -109
  92. package/src/math/statistics/Functions/index.js +99 -99
  93. package/src/math/statistics/index.js +15 -15
  94. package/src/math/utils/arithmetic.js +138 -138
  95. package/src/math/utils/checkers.js +29 -29
  96. package/src/math/utils/conversions.js +19 -19
  97. package/src/math/utils/discret.js +51 -51
  98. package/src/math/utils/index.js +101 -101
  99. package/src/math/utils/mapfun.js +49 -49
  100. package/src/reactivity/events/Input.js +61 -61
  101. package/src/reactivity/events/Pointer.js +231 -231
  102. package/src/reactivity/events/ZikoEvent.js +90 -90
  103. package/src/reactivity/events/click.js +59 -59
  104. package/src/reactivity/events/clipboard.js +87 -87
  105. package/src/reactivity/events/custom-event.js +56 -56
  106. package/src/reactivity/events/drag.js +136 -136
  107. package/src/reactivity/events/focus.js +58 -58
  108. package/src/reactivity/events/hash.js +46 -46
  109. package/src/reactivity/events/index.js +12 -12
  110. package/src/reactivity/events/key.js +101 -101
  111. package/src/reactivity/events/mouse.js +232 -232
  112. package/src/reactivity/events/swipe.js +149 -149
  113. package/src/reactivity/events/wheel.js +46 -46
  114. package/src/reactivity/hooks/{contexte → Contexte}/useSuccesifKeys.js +13 -13
  115. package/src/reactivity/hooks/{decorators → Decorators}/index.js +6 -6
  116. package/src/reactivity/hooks/{decorators → Decorators}/time.js +16 -16
  117. package/src/reactivity/hooks/{decorators → Decorators}/type.js +87 -87
  118. package/src/reactivity/hooks/{head/useCssText.js → Head/_useCssText.js} +20 -20
  119. package/src/reactivity/hooks/{head → Head}/index.js +5 -5
  120. package/src/reactivity/hooks/{head → Head}/useFavIcon.js +37 -37
  121. package/src/reactivity/hooks/{head → Head}/useHead.js +27 -27
  122. package/src/reactivity/hooks/{head → Head}/useMeta.js +52 -52
  123. package/src/reactivity/hooks/{head → Head}/useTitle.js +29 -29
  124. package/src/reactivity/hooks/{interactions/useBluetooth.js → Interactions/_useBluetooth.js} +47 -47
  125. package/src/reactivity/hooks/{interactions → Interactions}/index.js +4 -4
  126. package/src/reactivity/hooks/{interactions → Interactions}/useChannel.js +49 -49
  127. package/src/reactivity/hooks/{interactions → Interactions}/useEventEmmiter.js +63 -63
  128. package/src/reactivity/hooks/{interactions → Interactions}/useThread.js +43 -43
  129. package/src/reactivity/hooks/Sensors/index.js +2 -0
  130. package/src/reactivity/hooks/{sensors → Sensors}/useBattery.js +35 -35
  131. package/src/reactivity/hooks/{sensors → Sensors}/useGeolocation.js +16 -16
  132. package/src/reactivity/hooks/{storage → Storage}/useStorage.js +72 -72
  133. package/src/reactivity/hooks/{ui → UI}/index.js +5 -5
  134. package/src/reactivity/hooks/{ui → UI}/useMediaQuery.js +43 -43
  135. package/src/reactivity/hooks/{ui → UI}/useStyle.js +79 -79
  136. package/src/reactivity/hooks/{ui → UI}/useTheme.js +61 -61
  137. package/src/reactivity/hooks/index.js +7 -7
  138. package/src/reactivity/hooks/todo.md +26 -26
  139. package/src/reactivity/idea +1 -1
  140. package/src/reactivity/index.js +11 -11
  141. package/src/reactivity/observer/attributes.js +28 -28
  142. package/src/reactivity/observer/children.js +36 -36
  143. package/src/reactivity/observer/index.js +6 -6
  144. package/src/reactivity/observer/intersection.js +43 -43
  145. package/src/reactivity/observer/mutation.js +112 -112
  146. package/src/reactivity/observer/resize.js +46 -46
  147. package/src/reactivity/observer/screen.js +44 -44
  148. package/src/reactivity/observer/screen.js.txt +83 -83
  149. package/src/reactivity/observer/screen.txt +12 -12
  150. package/src/time/animation.js +75 -75
  151. package/src/time/index.js +11 -11
  152. package/src/time/loop.js +87 -87
  153. package/src/time/utils/decorators.js +16 -16
  154. package/src/time/utils/ease.js +143 -143
  155. package/src/time/utils/index.js +17 -17
  156. package/src/time/utils/performance.js +15 -15
  157. package/src/time/utils/ui.js +25 -25
  158. package/src/types.js +73 -73
  159. package/src/ui/elements/derived/accordion/accordion.js +42 -42
  160. package/src/ui/elements/derived/accordion/collapsible.js +82 -82
  161. package/src/ui/elements/derived/accordion/index.js +1 -1
  162. package/src/ui/elements/derived/alert/alert.js +80 -80
  163. package/src/ui/elements/derived/alert/palette.js +51 -51
  164. package/src/ui/elements/derived/carousel/index.js +50 -50
  165. package/src/ui/elements/derived/code-note/SubElements.js.txt +104 -104
  166. package/src/ui/elements/derived/code-note/code-cell.js +194 -194
  167. package/src/ui/elements/derived/code-note/code-note.js +71 -71
  168. package/src/ui/elements/derived/code-note/index.js +1 -1
  169. package/src/ui/elements/derived/code-note/sub-elements.js +66 -66
  170. package/src/ui/elements/derived/elements/Swipper.js +3 -3
  171. package/src/ui/elements/derived/elements/index.js +9 -9
  172. package/src/ui/elements/derived/flex/index.js +102 -102
  173. package/src/ui/elements/derived/grid/index.js +32 -32
  174. package/src/ui/elements/derived/index.js +11 -11
  175. package/src/ui/elements/derived/menu/menu3d.js +259 -259
  176. package/src/ui/elements/derived/modal/index.js +91 -91
  177. package/src/ui/elements/derived/pagination/breadcrumbs.js +53 -53
  178. package/src/ui/elements/derived/slider/__ZikoUISlider__.js +111 -111
  179. package/src/ui/elements/derived/slider/hSlider.js +33 -33
  180. package/src/ui/elements/derived/slider/index.js +11 -11
  181. package/src/ui/elements/derived/slider/vSlider.js +26 -26
  182. package/src/ui/elements/derived/splitter/__ZikoUISplitter__.js +61 -61
  183. package/src/ui/elements/derived/splitter/hsplitter.js +39 -39
  184. package/src/ui/elements/derived/splitter/index.js +11 -11
  185. package/src/ui/elements/derived/splitter/vsplitter.js +39 -39
  186. package/src/ui/elements/derived/tabs/index.js +179 -179
  187. package/src/ui/elements/primitives/ZikoUIContainerElement.js +163 -163
  188. package/src/ui/elements/primitives/ZikoUIElement.js +492 -492
  189. package/src/ui/elements/primitives/embaded/html.js +19 -19
  190. package/src/ui/elements/primitives/embaded/index.js +3 -3
  191. package/src/ui/elements/primitives/embaded/pdf.js +16 -16
  192. package/src/ui/elements/primitives/embaded/youtube.js +23 -23
  193. package/src/ui/elements/primitives/index.js +7 -7
  194. package/src/ui/elements/primitives/io/Form/index.js +41 -41
  195. package/src/ui/elements/primitives/io/Form/index.js.txt +104 -104
  196. package/src/ui/elements/primitives/io/Inputs/__helpers__.js +51 -51
  197. package/src/ui/elements/primitives/io/Inputs/index.js +12 -12
  198. package/src/ui/elements/primitives/io/Inputs/input/index.js +98 -98
  199. package/src/ui/elements/primitives/io/Inputs/input-camera/index.js +26 -26
  200. package/src/ui/elements/primitives/io/Inputs/input-checkbox/index.js +25 -25
  201. package/src/ui/elements/primitives/io/Inputs/input-color/index.js +15 -15
  202. package/src/ui/elements/primitives/io/Inputs/input-date-time/index.js +2 -2
  203. package/src/ui/elements/primitives/io/Inputs/input-date-time/input-date-time.js +13 -13
  204. package/src/ui/elements/primitives/io/Inputs/input-date-time/input-date.js +13 -13
  205. package/src/ui/elements/primitives/io/Inputs/input-date-time/input-time.js +13 -13
  206. package/src/ui/elements/primitives/io/Inputs/input-email-password/index.js +1 -1
  207. package/src/ui/elements/primitives/io/Inputs/input-email-password/input-email.js +14 -14
  208. package/src/ui/elements/primitives/io/Inputs/input-email-password/input-password.js +13 -13
  209. package/src/ui/elements/primitives/io/Inputs/input-file/input-image.js +42 -42
  210. package/src/ui/elements/primitives/io/Inputs/input-number/index.js +36 -36
  211. package/src/ui/elements/primitives/io/Inputs/input-radio/index.js +25 -25
  212. package/src/ui/elements/primitives/io/Inputs/input-search/index.js +45 -45
  213. package/src/ui/elements/primitives/io/Inputs/input-slider/index.js +34 -34
  214. package/src/ui/elements/primitives/io/Select/index.js +19 -19
  215. package/src/ui/elements/primitives/io/Textarea/index.js +17 -17
  216. package/src/ui/elements/primitives/io/index.js +3 -3
  217. package/src/ui/elements/primitives/list/index.js +138 -138
  218. package/src/ui/elements/primitives/media/Audio/index.js +16 -16
  219. package/src/ui/elements/primitives/media/Image/figure.js +18 -18
  220. package/src/ui/elements/primitives/media/Image/image.js +36 -36
  221. package/src/ui/elements/primitives/media/Image/index.js +1 -1
  222. package/src/ui/elements/primitives/media/Video/index.js +26 -26
  223. package/src/ui/elements/primitives/media/__ZikoUIDynamicMediaELement__.js +46 -46
  224. package/src/ui/elements/primitives/media/index.js +2 -2
  225. package/src/ui/elements/primitives/misc/index.js +101 -101
  226. package/src/ui/elements/primitives/semantic/index.js +81 -81
  227. package/src/ui/elements/primitives/table/elements.js +93 -93
  228. package/src/ui/elements/primitives/table/index.js +2 -2
  229. package/src/ui/elements/primitives/table/table.js +115 -115
  230. package/src/ui/elements/primitives/table/utils.js +11 -11
  231. package/src/ui/elements/primitives/text/__ZikoUIText__.js +71 -71
  232. package/src/ui/elements/primitives/text/heading.js +35 -35
  233. package/src/ui/elements/primitives/text/index.js +2 -2
  234. package/src/ui/elements/primitives/text/p.js +26 -26
  235. package/src/ui/elements/primitives/text/text.js +80 -80
  236. package/src/ui/index.js +37 -37
  237. package/src/ui/style/index.js +504 -515
  238. package/src/ui/utils/index.js +69 -69
  239. package/starter/bin/index.js +11 -11
  240. package/dist/ziko.cjs +0 -12596
  241. package/dist/ziko.js +0 -13487
  242. package/dist/ziko.min.js +0 -9
  243. package/dist/ziko.mjs +0 -13118
  244. package/src/reactivity/hooks/sensors/index.js +0 -2
  245. /package/{readme.md → README.md} +0 -0
  246. /package/src/graphics/canvas/elements/{basic → Basic}/image.js +0 -0
  247. /package/src/graphics/canvas/elements/{basic → Basic}/path.js +0 -0
  248. /package/src/graphics/canvas/elements/{basic → Basic}/polyline.js +0 -0
  249. /package/src/graphics/canvas/elements/{basic → Basic}/text.js +0 -0
  250. /package/src/graphics/canvas/elements/{chart → Chart}/histogram.js +0 -0
  251. /package/src/graphics/canvas/elements/{chart → Chart}/plot.js +0 -0
  252. /package/src/graphics/canvas/elements/{chart → Chart}/stem.js +0 -0
  253. /package/src/graphics/svg/{elements/basic → Elements/Basic}/index.js +0 -0
  254. /package/src/graphics/svg/{elements/derived → Elements/Derived}/index.js +0 -0
  255. /package/src/reactivity/hooks/{contexte → Contexte}/index.js +0 -0
  256. /package/src/reactivity/hooks/{interactions → Interactions}/useSerial.js +0 -0
  257. /package/src/reactivity/hooks/{interactions → Interactions}/useUsb.js +0 -0
  258. /package/src/reactivity/hooks/{sensors → Sensors}/useCamera.js +0 -0
  259. /package/src/reactivity/hooks/{sensors → Sensors}/useMicro.js +0 -0
  260. /package/src/reactivity/hooks/{sensors → Sensors}/useOrientation.js +0 -0
  261. /package/src/reactivity/hooks/{storage → Storage}/index.js +0 -0
  262. /package/src/reactivity/hooks/{storage → Storage}/useCookie.js +0 -0
  263. /package/src/reactivity/hooks/{storage → Storage}/useIndexedDb.js +0 -0
  264. /package/src/reactivity/hooks/{ui → UI}/useCssLink.js +0 -0
  265. /package/src/reactivity/hooks/{ui → UI}/useLinearGradient.js +0 -0
  266. /package/src/reactivity/hooks/{ui → UI}/useRadialGradient.js +0 -0
  267. /package/src/reactivity/hooks/{ui → UI}/useRoot.js +0 -0
@@ -1,717 +1,717 @@
1
- import ZikoMath from "../absract.js";
2
- import{
3
- pow,
4
- min,
5
- max,
6
- } from "../functions/index.js"
7
- import {Utils} from "../utils/index.js";
8
- import {Complex } from "../complex/index.js";
9
- import {Random} from "../random/index.js"
10
- import {
11
- luDecomposition,
12
- qrDecomposition,
13
- choleskyDecomposition
14
- } from "./Decomposition.js";
15
- import { arr2str } from "../../data/index.js";
16
- class Matrix extends ZikoMath{
17
- constructor(rows, cols, element = [] ) {
18
- super()
19
- if(rows instanceof Matrix){
20
- this.arr=rows.arr;
21
- this.rows=rows.rows;
22
- this.cols=rows.cols;
23
- }
24
- else {
25
- let arr = [],
26
- i,
27
- j;
28
- if (arguments[0] instanceof Array) {
29
- rows = arguments[0].length;
30
- cols = arguments[0][0].length;
31
- arr = arguments[0];
32
- } else {
33
- for (i = 0; i < rows; i++) {
34
- arr.push([]);
35
- arr[i].push(new Array(cols));
36
- for (j = 0; j < cols; j++) {
37
- arr[i][j] = element[i * cols + j];
38
- if (element[i * cols + j] == undefined) arr[i][j] = 0;
39
- }
40
- }
41
- }
42
- this.rows = rows;
43
- this.cols = cols;
44
- this.arr = arr;
45
- }
46
- this._maintain();
47
- //Object.seal(this);
48
- }
49
- toString(){
50
- return arr2str(this.arr,false);
51
- }
52
- at(i=0,j=undefined){
53
- if(i<0)i=this.rows+i;
54
- if(j==undefined) return this.arr[i];
55
- if(j<0)j=this.cols+j;
56
- return this.arr[i][j];
57
- }
58
- reshape(newRows, newCols) {
59
- let check = newRows * newCols === this.rows * this.cols;
60
- if (check) return new Matrix(newRows, newCols, this.arr.flat(1));
61
- else console.error("Err");
62
- }
63
- static eye(size) {
64
- let result = new Matrix(size, size);
65
- 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);
66
- return result;
67
- }
68
- get clone() {
69
- return new Matrix(this.rows, this.cols, this.arr.flat(1));
70
- }
71
- get size() {
72
- return this.rows * this.cols;
73
- }
74
- get shape() {
75
- return [this.rows, this.cols];
76
- }
77
- get reel() {
78
- return new Matrix(this.cols, this.rows, this.arr.flat(1).reel);
79
- }
80
- get imag() {
81
- return new Matrix(this.cols, this.rows, this.arr.flat(1).imag);
82
- }
83
- _maintain(){
84
- for(let i=0;i<this.arr.length;i++)Object.assign(this,{[[i]]:this.arr[i]});
85
- return this;
86
- }
87
- get(row = 0, col = 0) {
88
- if (col == -1) return this.arr[row];
89
- else if (row == -1) return this.arr.map((n) => n[col]);
90
- else return this.arr[row][col];
91
- }
92
- set(row = 0, col = 0, value) {
93
- if (col == -1) return (this.arr[row] = value);
94
- else if (row == -1) {
95
- for (let i = 0; i < this.cols; i++) {
96
- this.arr[i][col] = value[i] || 0;
97
- }
98
- return this.arr;
99
- }
100
- return (this.arr[row][col] = value);
101
- }
102
- get isSquare() {
103
- return this.rows / this.cols === 1;
104
- }
105
- get isSym() {
106
- if (!this.isSquare) return false;
107
- const T = this.T;
108
- const M = this.clone;
109
- return Matrix.sub(M, T).max == 0 && Matrix.sub(M, T).min == 0;
110
- }
111
- get isAntiSym() {
112
- if (!this.isSquare) return false;
113
- const T = this.T;
114
- const M = this.clone;
115
- return Matrix.add(M, T).max == 0 && Matrix.add(M, T).min == 0;
116
- }
117
- get isDiag() {
118
- if (!this.isSquare) return false;
119
- const T = this.T;
120
- const M = this.clone;
121
- const MT = Matrix.mul(M, T);
122
- const TM = Matrix.dot(T, M);
123
- return Matrix.sub(MT, TM).max == 0 && Matrix.sub(MT, TM).min == 0;
124
- }
125
- get isOrtho() {
126
- if (!this.isSquare) return false;
127
- return this.isDiag && (this.det == 1 || this.det == -1);
128
- }
129
- get isIdemp() {
130
- if (!this.isSquare) return false;
131
- const M = this.clone;
132
- const MM = Matrix.dot(M, M);
133
- return Matrix.sub(MM, M).max == 0 && Matrix.sub(MM, M).min == 0;
134
- }
135
- get T() {
136
- let transpose = [];
137
- for (let i = 0; i < this.arr[0].length; i++) {
138
- transpose[i] = [];
139
- for (let j = 0; j < this.arr.length; j++) {
140
- transpose[i][j] = this.arr[j][i];
141
- }
142
- }
143
- return new Matrix(this.cols, this.rows, transpose.flat(1));
144
- }
145
- get det() {
146
- if (!this.isSquare) return new Error("is not square matrix");
147
- if (this.rows == 1) return this.arr[0][0];
148
- function determinat(M) {
149
- if (M.length == 2) {
150
- if (M.flat(1).some((n) => n instanceof Matrix)) {
151
- console.warn("Tensors are not completely supported yet ...");
152
- return;
153
- }
154
- return Utils.sub(Utils.mul(M[0][0],M[1][1]),Utils.mul(M[0][1],M[1][0]))
155
- }
156
- var answer = 0;
157
- for (var i = 0; i < M.length; i++) {
158
- //console.log(M[0][i]);
159
- /*answer = answer.add(
160
- pow(-1, i)
161
- .mul(M[0][i])
162
- .mul(determinat(deleteRowAndColumn(M, i)))
163
- );*/
164
- //const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
165
- const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
166
- answer=Utils.add(answer,to_be_added)
167
- }
168
- return answer;
169
- }
170
- function deleteRowAndColumn(M, index) {
171
- var temp = [];
172
- for (let i = 0; i < M.length; i++) temp.push(M[i].slice(0));
173
- temp.splice(0, 1);
174
- for (let i = 0; i < temp.length; i++) temp[i].splice(index, 1);
175
- return temp;
176
- }
177
- return determinat(this.arr);
178
- }
179
- get inv() {
180
- if (!this.isSquare) return new Error("is not square matrix");
181
- if (this.det === 0) return "determinat = 0 !!!";
182
- let A = InverseMatrixe(this.arr);
183
- return new Matrix(this.rows, this.cols, A.flat(1));
184
- }
185
- static zeros(rows, cols) {
186
- let result = new Matrix(rows, cols);
187
- for (let i = 0; i < rows; i++) for (var j = 0; j < cols; j++) result.arr[i][j] = 0;
188
- return result;
189
- }
190
- static ones(rows, cols) {
191
- let result = new Matrix(rows, cols);
192
- for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = 1;
193
- return result;
194
- }
195
- static nums(rows, cols, number) {
196
- let result = new Matrix(rows, cols);
197
- for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = number;
198
- return result;
199
- }
200
- static get rand(){
201
- return {
202
- int:(rows, cols, a, b)=>{
203
- let result = new Matrix(rows, cols);
204
- for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randInt(a, b);
205
- return result;
206
- },
207
- bin:(rows,cols)=>{
208
- let result = new Matrix(rows, cols);
209
- for (let i = 0; i < rows; i++) {
210
- for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randBin;
211
- }
212
- return result;
213
- },
214
- hex:(rows,cols)=>{
215
- let result = new Matrix(rows, cols);
216
- for (let i = 0; i < rows; i++) {
217
- for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randHex;
218
- }
219
- return result;
220
- },
221
- choices:(rows, cols, choices, p)=>{
222
- let result = new Matrix(rows, cols);
223
- for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.choice(choices, p);
224
- return result
225
- },
226
- permutation:(rows,cols,arr)=>{
227
- //return new Matrix(rows, cols, Random.permutation(...arr))
228
- }
229
- }
230
- }
231
- static rands(rows, cols, a = 1, b) {
232
- let result = new Matrix(rows, cols);
233
- for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.rand(a, b);
234
- return result;
235
- }
236
- map(Imin, Imax, Fmin, Fmax) {
237
- return Utils.map(this, Imin, Imax, Fmin, Fmax);
238
- }
239
- lerp(min, max) {
240
- return Utils.lerp(this, min, max);
241
- }
242
- norm(min, max) {
243
- return Utils.norm(this, min, max);
244
- }
245
- clamp(min, max) {
246
- return Utils.clamp(this, min, max);
247
- }
248
- static map(matrix, Imin, Imax, Fmin, Fmax) {
249
- return Utils.map(matrix, Imin, Imax, Fmin, Fmax);
250
- }
251
- static lerp(matrix, min, max) {
252
- return Utils.lerp(matrix, min, max);
253
- }
254
- static norm(matrix, min, max) {
255
- return Utils.norm(matrix, min, max);
256
- }
257
- static clamp(m, min, max) {
258
- return Utils.clamp(matrix, min, max);
259
- }
260
- toPrecision(p) {
261
- for (let i = 0; i < this.cols; i++) for (let j = 0; j < this.rows; j++) this.arr[i][j] = +this.arr[i][j].toPrecision(p);
262
- return this;
263
- }
264
- get toBin() {
265
- let newArr = this.arr.flat(1).toBin;
266
- return new Matrix(this.rows, this.cols, newArr);
267
- }
268
- get toOct() {
269
- let newArr = this.arr.flat(1).toOct;
270
- return new Matrix(this.rows, this.cols, newArr);
271
- }
272
- get toHex() {
273
- let newArr = this.arr.flat(1).toHex;
274
- return new Matrix(this.rows, this.cols, newArr);
275
- }
276
- /*get isOdd() {
277
- let newArr = this.arr.flat(1).isOdd;
278
- return new Matrix(this.rows, this.cols, newArr);
279
- }*/
280
- max2min() {
281
- let newArr = this.arr.flat(1).max2min;
282
- return new Matrix(this.rows, this.cols, newArr);
283
- }
284
- min2max() {
285
- let newArr = this.arr.flat(1).min2max;
286
- return new Matrix(this.rows, this.cols, newArr);
287
- }
288
- sortRows(calback=undefined){
289
- let newArr=this.arr.map(n=>n.sort(calback)).flat(1);
290
- return new Matrix(this.rows, this.cols, newArr);
291
- }
292
- sortCols(calback=undefined){
293
- let m=this.T;
294
- let newArr=m.arr.map(n=>n.sort(calback)).flat(1);
295
- return new Matrix(this.rows, this.cols, newArr).T;
296
- }
297
- filterByRows(item){
298
- var truth=this.arr.map(n=>n.map(m=>+(""+m).includes(item)))
299
- var mask=truth.map(n=>!!Logic.or(...n))
300
- var filtredArray=this.arr.filter((n,i)=>mask[i]===true)
301
- if(filtredArray.length===0)filtredArray.push([])
302
- console.log(filtredArray)
303
- return new Matrix(filtredArray)
304
- }
305
- filterByCols(item){
306
- return new Matrix(this.T.arr.filter(n=>n.includes(item)))
307
- }
308
- sortAll(calback=undefined){
309
- let newArr=this.arr.flat(1).sort(calback);
310
- return new Matrix(this.rows, this.cols, newArr);
311
- }
312
- count(n) {
313
- return this.arr.flat(1).count(n);
314
- }
315
- toBase(n) {
316
- let newArr = this.arr.flat(1).toBase(n);
317
- return new Matrix(this.rows, this.cols, newArr);
318
- }
319
- #hstack(matrix){
320
- if (this.rows !== matrix.rows) return;
321
- let newArr = this.arr;
322
- 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];
323
- this.cols += matrix.cols;
324
- return new Matrix(this.rows, this.cols, newArr.flat(1));
325
- }
326
- hstack(...matrices) {
327
- const M=[this,...matrices].reduce((a,b)=>a.#hstack(b));
328
- Object.assign(this,M)
329
- return this;
330
- }
331
- static hstack(matrix,...matrices) {
332
- return matrix.clone.hstack(...matrices);
333
- }
334
- #vstack(matrix) {
335
- if (this.cols !== matrix.cols) return;
336
- let newArr = this.arr;
337
- for (let i = this.rows; i < this.rows + matrix.rows; i++) {
338
- newArr[i] = [];
339
- for (let j = 0; j < this.cols; j++) newArr[i][j] = matrix.arr[i - this.rows][j];
340
- }
341
- this.rows += matrix.rows;
342
- return new Matrix(this.rows, this.cols, newArr.flat(1));
343
- }
344
- vstack(...matrices) {
345
- const M=[this,...matrices].reduce((a,b)=>a.#vstack(b));
346
- Object.assign(this,M)
347
- return this;
348
- }
349
- static vstack(matrix,...matrices) {
350
- return matrix.clone.vstack(...matrices);
351
- }
352
- hqueue(...matrices){
353
- const M=[this,...matrices].reverse().reduce((a,b)=>a.#hstack(b));
354
- Object.assign(this,M)
355
- return this;
356
- }
357
- vqueue(...matrices){
358
- const M=[this,...matrices].reverse().reduce((a,b)=>a.#vstack(b));
359
- Object.assign(this,M)
360
- return this;
361
- }
362
- static hqueue(matrix,...matrices) {
363
- return matrix.clone.hqueue(...matrices);
364
- }
365
- static vqueue(matrix,...matrices) {
366
- return matrix.clone.vqueue(...matrices);
367
- }
368
- slice(r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
369
- let newRow = r1 - r0,
370
- newCol = c1 - c0;
371
- let newArr = new Array(newCol);
372
- for (let i = 0; i < newRow; i++) {
373
- newArr[i] = [];
374
- for (let j = 0; j < newCol; j++) newArr[i][j] = this.arr[i + r0][j + c0];
375
- }
376
- return new Matrix(newRow, newCol, newArr.flat(1));
377
- }
378
- static slice(m1,r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
379
- return m1.slice(r0, c0, r1, c1);
380
- }
381
- splice(r0,c0,deleteCount,...items){
382
-
383
- }
384
- getRows(ri, rf = ri + 1) {
385
- return this.slice(ri, 0, rf, this.cols);
386
- }
387
- getCols(ci, cf = ci + 1) {
388
- return this.slice(0, ci, this.rows, cf);
389
- }
390
- static getRows(m, ri, rf = ri + 1) {
391
- return m.slice(ri, 0, rf, m.cols);
392
- }
393
- static getCols(m, ci, cf = ci + 1) {
394
- return m.slice(0, ci, m.rows, cf);
395
- }
396
- add(...matr) {
397
- for (let k = 0; k < matr.length; k++) {
398
- if (typeof matr[k] == "number"||matr[k] instanceof Complex) matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
399
- for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = Utils.add(this.arr[i][j],matr[k].arr[i][j]);
400
- }
401
- return new Matrix(this.rows, this.cols, this.arr.flat(1));
402
- }
403
- sub(...matr) {
404
- for (let k = 0; k < matr.length; k++) {
405
- if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
406
- for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = Utils.sub(this.arr[i][j],matr[k].arr[i][j]);
407
- }
408
- return new Matrix(this.rows, this.cols, this.arr.flat(1));
409
- }
410
- static add(m1, ...m2) {
411
- return m1.clone.add(...m2);
412
- }
413
- static sub(m1, ...m2) {
414
- return m1.clone.sub(...m2);
415
- }
416
- mul(...matr) {
417
- for (let k = 0; k < matr.length; k++) {
418
- if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
419
- for (var i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = Utils.mul(this.arr[i][j],matr[k].arr[i][j]);
420
- }
421
- return new Matrix(this.rows, this.cols, this.arr.flat(1));
422
- }
423
- div(...matr) {
424
- for (let k = 0; k < matr.length; k++) {
425
- if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
426
- for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = Utils.div(this.arr[i][j],matr[k].arr[i][j]);
427
- }
428
- return new Matrix(this.rows, this.cols, this.arr.flat(1));
429
- }
430
- static div(m1, ...m2) {
431
- return m1.clone.div(...m2);
432
- }
433
- static mul(m1, ...m2) {
434
- return m1.clone.mul(...m2);
435
- }
436
- modulo(...matr) {
437
- for (let k = 0; k < matr.length; k++) {
438
- if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
439
- for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++)this.arr[i][j]=Utils.modulo(this.arr[i][j],matr[k].arr[i][j]);
440
- }
441
- return new Matrix(this.rows, this.cols, this.arr.flat(1));
442
- }
443
- static modulo(m1, ...m2) {
444
- return m1.clone.modulo(...m2);
445
- }
446
- dot(matrix) {
447
- var res = [];
448
- for (var i = 0; i < this.arr.length; i++) {
449
- res[i] = [];
450
- for (var j = 0; j < matrix.arr[0].length; j++) {
451
- res[i][j] = 0;
452
- for (var k = 0; k < this.arr[0].length; k++) {
453
- res[i][j] = Utils.add(
454
- res[i][j],
455
- Utils.mul(this.arr[i][k],matrix.arr[k][j])
456
- )
457
- }
458
- }
459
- }
460
- return new Matrix(this.arr.length, matrix.arr[0].length, res.flat(1));
461
- }
462
- static dot(matrix1, matrix2) {
463
- return matrix1.dot(matrix2);
464
- }
465
- pow(n) {
466
- let a = this.clone,
467
- p = this.clone;
468
- for (let i = 0; i < n - 1; i++) p = p.dot(a);
469
- return p;
470
- }
471
- static pow(m, n) {
472
- return m.clone.pow(n);
473
- }
474
- get somme() {
475
- let S = 0;
476
- for (let i = 0; i < this.rows; i++) for (let j = 0; j < this.cols; j++) S += this.arr[i][j];
477
- return S;
478
- }
479
- get DoesItContainComplexNumbers() {
480
- return this.arr.flat(Infinity).some((n) => n instanceof Complex);
481
- }
482
- get min() {
483
- if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
484
- let minRow = [];
485
- for (let i = 0; i < this.rows; i++) minRow.push(min(...this.arr[i]));
486
- return min(...minRow);
487
- }
488
- get max() {
489
- if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
490
- let maxRow = [];
491
- for (let i = 0; i < this.rows; i++) maxRow.push(max(...this.arr[i]));
492
- return max(...maxRow);
493
- }
494
- get minRows() {
495
- if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
496
- let minRow = [];
497
- for (let i = 0; i < this.rows; i++) minRow.push(min(...this.arr[i]));
498
- return minRow;
499
- }
500
- get maxRows() {
501
- if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
502
- let maxRow = [];
503
- for (let i = 0; i < this.rows; i++) maxRow.push(max(...this.arr[i]));
504
- return maxRow;
505
- }
506
- get minCols() {
507
- if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
508
- return this.T.minRows;
509
- }
510
- get maxCols() {
511
- if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
512
- return this.T.maxRows;
513
- }
514
- static fromVector(v) {
515
- return new Matrix(v.length, 1, v);
516
- }
517
- get toArray() {
518
- let arr = [];
519
- for (let i = 0; i < this.rows; i++) {
520
- for (let j = 0; j < this.cols; j++) {
521
- arr.push(this.arr[i][j]);
522
- }
523
- }
524
- return arr;
525
- }
526
- get print() {
527
- //"pretty print" the matrix
528
- let fstring = "[";
529
- for (let i = 0; i < this.arr.length; i++) {
530
- fstring += (i != 0 ? " " : "") + ` [${this.arr[i].map((n) => " " + n.toString() + " ")}],\n`;
531
- }
532
- console.log(fstring.substring(0, fstring.length - 2) + " ]");
533
- document.write(fstring.substring(0, fstring.length - 2) + " ]");
534
- }
535
- get table() {
536
- console.table(this.arr);
537
- }
538
- get serialize() {
539
- return JSON.stringify(this);
540
- }
541
- static deserialize(data) {
542
- if (typeof data == "string") {
543
- data = JSON.parse(data);
544
- }
545
- let matrix = new Matrix(data.rows, data.cols);
546
- matrix.arr = data.arr;
547
- return matrix;
548
- }
549
- DecompositionLU(){
550
- const [L,U]=luDecomposition(this);
551
- return {
552
- L,
553
- U
554
- }
555
- }
556
- static DecompositionLU(...M){
557
- const Decomposition=M.map(n=>n.clone.LU());
558
- return Decomposition.length===1?Decomposition[0]:Decomposition;
559
- }
560
- DecompositionQR(){
561
- const [Q,R]=qrDecomposition(this);
562
- return {
563
- Q,
564
- R
565
- }
566
- }
567
- static DecompositionQR(...M){
568
- const Decomposition=M.map(n=>n.clone.DecompositionQr());
569
- return Decomposition.length===1?Decomposition[0]:Decomposition;
570
- }
571
- DecompositionCholesky(){
572
- return {
573
- L:choleskyDecomposition(this)
574
- }
575
- }
576
- static DecompositionCholesky(...M){
577
- const Decomposition=M.map(n=>n.clone.DecompositionCholesky());
578
- return Decomposition.length===1?Decomposition[0]:Decomposition;
579
- }
580
- get decomposition(){
581
- return{
582
- LU:()=>this.DecompositionLU(),
583
- QR:()=>this.DecompositionQR(),
584
- Cholesky:()=>this.DecompositionCholesky()
585
- }
586
- }
587
- static get decomposition(){
588
- return{
589
- LU:(...M)=>Matrix.LU(...M),
590
- QR:(...M)=>Matrix.QR(...M),
591
- CHOLESKY:(...M)=>Matrix.CHOLESKY(...M)
592
- }
593
- }
594
- toTable() {
595
- var table = new DocumentFragment();
596
- var Tr = new Array(this.rows).fill(null).map(() => document?.createElement("tr"));
597
- var Td = this.arr.map((n) => n.map(() => document?.createElement("td")));
598
- for (let i = 0; i < Td.length; i++) {
599
- for (let j = 0; j < Td[0].length; j++) {
600
- Td[i][j].innerHTML = this.arr[i][j];
601
- Tr[i].appendChild(Td[i][j]);
602
- }
603
- }
604
- Tr.map((n) => table.appendChild(n));
605
- return table;
606
- }
607
- toGrid(element, style = {}) {
608
- let a = Grid();
609
- a.append(
610
- ...this.map(element)
611
- .arr.flat(1)
612
- .map((n) => n.style(style))
613
- );
614
- a.Columns(this.cols);
615
- return a;
616
- }
617
- sortTable(n=0,{type="num",order="asc"}={}) {
618
- var obj=this.T.arr.map(n=>n.map((n,i)=>Object.assign({},{x:n,y:i})));
619
- var newObj=this.T.arr.map(n=>n.map((n,i)=>Object.assign({},{x:n,y:i})));
620
- if(type==="num"){
621
- if(order==="asc")obj[n].sort((a,b)=>a.x-b.x);
622
- else if(order==="desc")obj[n].sort((a,b)=>b.x-a.x);
623
- else if(order==="toggle"){
624
- // console.log(obj[n][0])
625
- //console.log(obj[n][1])
626
- if(obj[n][0].x>obj[n][1].x)obj[n].sort((a,b)=>b.x-a.x);
627
- else obj[n].sort((a,b)=>a.x-b.x);
628
- }
629
- }
630
- else if(type==="alpha"){
631
- if(order==="asc")obj[n].sort((a,b)=>(""+a.x).localeCompare(""+b.x));
632
- else if(order==="desc")obj[n].sort((a,b)=>(""+b.x).localeCompare(""+a.x));
633
- }
634
- //var order=obj[n].map(n=>n.y);
635
- order=obj[n].map(n=>n.y);
636
- for(let i=0;i<obj.length;i++){
637
- if(i!==n)obj[i].map((n,j)=>n.y=order[j]);
638
- }
639
- for(let i=0;i<obj.length;i++){
640
- if(i!==n)newObj[i].map((n,j)=>n.x=obj[i][order[j]].x)
641
- }
642
- newObj[n]=obj[n];
643
- var newArr=newObj.map(n=>n.map(m=>m.x));
644
- return new Matrix(newArr).T;
645
- }
646
- }
647
-
648
- function InverseMatrixe(M) {
649
- if (M.length !== M[0].length) {
650
- return;
651
- }
652
- var i = 0,
653
- ii = 0,
654
- j = 0,
655
- dim = M.length,
656
- e = 0;
657
- //t = 0;
658
- var I = [],
659
- C = [];
660
- for (i = 0; i < dim; i += 1) {
661
- I[I.length] = [];
662
- C[C.length] = [];
663
- for (j = 0; j < dim; j += 1) {
664
- if (i == j) {
665
- I[i][j] = 1;
666
- } else {
667
- I[i][j] = 0;
668
- }
669
- C[i][j] = M[i][j];
670
- }
671
- }
672
- for (i = 0; i < dim; i += 1) {
673
- e = C[i][i];
674
- if (e == 0) {
675
- for (ii = i + 1; ii < dim; ii += 1) {
676
- if (C[ii][i] != 0) {
677
- for (j = 0; j < dim; j++) {
678
- e = C[i][j];
679
- C[i][j] = C[ii][j];
680
- C[ii][j] = e;
681
- e = I[i][j];
682
- I[i][j] = I[ii][j];
683
- I[ii][j] = e;
684
- }
685
- break;
686
- }
687
- }
688
- e = C[i][i];
689
- if (e == 0) {
690
- return;
691
- }
692
- }
693
- for (j = 0; j < dim; j++) {
694
- C[i][j] = C[i][j] / e;
695
- I[i][j] = I[i][j] / e;
696
- }
697
- for (ii = 0; ii < dim; ii++) {
698
- if (ii == i) {
699
- continue;
700
- }
701
- e = C[ii][i];
702
- for (j = 0; j < dim; j++) {
703
- C[ii][j] -= e * C[i][j];
704
- I[ii][j] -= e * I[i][j];
705
- }
706
- }
707
- }
708
- return I;
709
- }
710
- /**
711
- * @returns {Matrix}
712
- */
713
- const matrix=(r, c, element)=>new Matrix(r, c, element);
714
- const matrix2=(...element)=>new Matrix(2, 2, element);
715
- const matrix3=(...element)=>new Matrix(3, 3, element);
716
- const matrix4=(...element)=>new Matrix(4, 4, element);
1
+ import ZikoMath from "../absract.js";
2
+ import{
3
+ pow,
4
+ min,
5
+ max,
6
+ } from "../functions/index.js"
7
+ import {Utils} from "../utils/index.js";
8
+ import {Complex } from "../complex/index.js";
9
+ import {Random} from "../random/index.js"
10
+ import {
11
+ luDecomposition,
12
+ qrDecomposition,
13
+ choleskyDecomposition
14
+ } from "./Decomposition.js";
15
+ import { arr2str } from "../../data/index.js";
16
+ class Matrix extends ZikoMath{
17
+ constructor(rows, cols, element = [] ) {
18
+ super()
19
+ if(rows instanceof Matrix){
20
+ this.arr=rows.arr;
21
+ this.rows=rows.rows;
22
+ this.cols=rows.cols;
23
+ }
24
+ else {
25
+ let arr = [],
26
+ i,
27
+ j;
28
+ if (arguments[0] instanceof Array) {
29
+ rows = arguments[0].length;
30
+ cols = arguments[0][0].length;
31
+ arr = arguments[0];
32
+ } else {
33
+ for (i = 0; i < rows; i++) {
34
+ arr.push([]);
35
+ arr[i].push(new Array(cols));
36
+ for (j = 0; j < cols; j++) {
37
+ arr[i][j] = element[i * cols + j];
38
+ if (element[i * cols + j] == undefined) arr[i][j] = 0;
39
+ }
40
+ }
41
+ }
42
+ this.rows = rows;
43
+ this.cols = cols;
44
+ this.arr = arr;
45
+ }
46
+ this._maintain();
47
+ //Object.seal(this);
48
+ }
49
+ toString(){
50
+ return arr2str(this.arr,false);
51
+ }
52
+ at(i=0,j=undefined){
53
+ if(i<0)i=this.rows+i;
54
+ if(j==undefined) return this.arr[i];
55
+ if(j<0)j=this.cols+j;
56
+ return this.arr[i][j];
57
+ }
58
+ reshape(newRows, newCols) {
59
+ let check = newRows * newCols === this.rows * this.cols;
60
+ if (check) return new Matrix(newRows, newCols, this.arr.flat(1));
61
+ else console.error("Err");
62
+ }
63
+ static eye(size) {
64
+ let result = new Matrix(size, size);
65
+ 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);
66
+ return result;
67
+ }
68
+ get clone() {
69
+ return new Matrix(this.rows, this.cols, this.arr.flat(1));
70
+ }
71
+ get size() {
72
+ return this.rows * this.cols;
73
+ }
74
+ get shape() {
75
+ return [this.rows, this.cols];
76
+ }
77
+ get reel() {
78
+ return new Matrix(this.cols, this.rows, this.arr.flat(1).reel);
79
+ }
80
+ get imag() {
81
+ return new Matrix(this.cols, this.rows, this.arr.flat(1).imag);
82
+ }
83
+ _maintain(){
84
+ for(let i=0;i<this.arr.length;i++)Object.assign(this,{[[i]]:this.arr[i]});
85
+ return this;
86
+ }
87
+ get(row = 0, col = 0) {
88
+ if (col == -1) return this.arr[row];
89
+ else if (row == -1) return this.arr.map((n) => n[col]);
90
+ else return this.arr[row][col];
91
+ }
92
+ set(row = 0, col = 0, value) {
93
+ if (col == -1) return (this.arr[row] = value);
94
+ else if (row == -1) {
95
+ for (let i = 0; i < this.cols; i++) {
96
+ this.arr[i][col] = value[i] || 0;
97
+ }
98
+ return this.arr;
99
+ }
100
+ return (this.arr[row][col] = value);
101
+ }
102
+ get isSquare() {
103
+ return this.rows / this.cols === 1;
104
+ }
105
+ get isSym() {
106
+ if (!this.isSquare) return false;
107
+ const T = this.T;
108
+ const M = this.clone;
109
+ return Matrix.sub(M, T).max == 0 && Matrix.sub(M, T).min == 0;
110
+ }
111
+ get isAntiSym() {
112
+ if (!this.isSquare) return false;
113
+ const T = this.T;
114
+ const M = this.clone;
115
+ return Matrix.add(M, T).max == 0 && Matrix.add(M, T).min == 0;
116
+ }
117
+ get isDiag() {
118
+ if (!this.isSquare) return false;
119
+ const T = this.T;
120
+ const M = this.clone;
121
+ const MT = Matrix.mul(M, T);
122
+ const TM = Matrix.dot(T, M);
123
+ return Matrix.sub(MT, TM).max == 0 && Matrix.sub(MT, TM).min == 0;
124
+ }
125
+ get isOrtho() {
126
+ if (!this.isSquare) return false;
127
+ return this.isDiag && (this.det == 1 || this.det == -1);
128
+ }
129
+ get isIdemp() {
130
+ if (!this.isSquare) return false;
131
+ const M = this.clone;
132
+ const MM = Matrix.dot(M, M);
133
+ return Matrix.sub(MM, M).max == 0 && Matrix.sub(MM, M).min == 0;
134
+ }
135
+ get T() {
136
+ let transpose = [];
137
+ for (let i = 0; i < this.arr[0].length; i++) {
138
+ transpose[i] = [];
139
+ for (let j = 0; j < this.arr.length; j++) {
140
+ transpose[i][j] = this.arr[j][i];
141
+ }
142
+ }
143
+ return new Matrix(this.cols, this.rows, transpose.flat(1));
144
+ }
145
+ get det() {
146
+ if (!this.isSquare) return new Error("is not square matrix");
147
+ if (this.rows == 1) return this.arr[0][0];
148
+ function determinat(M) {
149
+ if (M.length == 2) {
150
+ if (M.flat(1).some((n) => n instanceof Matrix)) {
151
+ console.warn("Tensors are not completely supported yet ...");
152
+ return;
153
+ }
154
+ return Utils.sub(Utils.mul(M[0][0],M[1][1]),Utils.mul(M[0][1],M[1][0]))
155
+ }
156
+ var answer = 0;
157
+ for (var i = 0; i < M.length; i++) {
158
+ //console.log(M[0][i]);
159
+ /*answer = answer.add(
160
+ pow(-1, i)
161
+ .mul(M[0][i])
162
+ .mul(determinat(deleteRowAndColumn(M, i)))
163
+ );*/
164
+ //const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
165
+ const to_be_added=Utils.add(Utils.mul(pow(-1, i),Utils.mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
166
+ answer=Utils.add(answer,to_be_added)
167
+ }
168
+ return answer;
169
+ }
170
+ function deleteRowAndColumn(M, index) {
171
+ var temp = [];
172
+ for (let i = 0; i < M.length; i++) temp.push(M[i].slice(0));
173
+ temp.splice(0, 1);
174
+ for (let i = 0; i < temp.length; i++) temp[i].splice(index, 1);
175
+ return temp;
176
+ }
177
+ return determinat(this.arr);
178
+ }
179
+ get inv() {
180
+ if (!this.isSquare) return new Error("is not square matrix");
181
+ if (this.det === 0) return "determinat = 0 !!!";
182
+ let A = InverseMatrixe(this.arr);
183
+ return new Matrix(this.rows, this.cols, A.flat(1));
184
+ }
185
+ static zeros(rows, cols) {
186
+ let result = new Matrix(rows, cols);
187
+ for (let i = 0; i < rows; i++) for (var j = 0; j < cols; j++) result.arr[i][j] = 0;
188
+ return result;
189
+ }
190
+ static ones(rows, cols) {
191
+ let result = new Matrix(rows, cols);
192
+ for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = 1;
193
+ return result;
194
+ }
195
+ static nums(rows, cols, number) {
196
+ let result = new Matrix(rows, cols);
197
+ for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = number;
198
+ return result;
199
+ }
200
+ static get rand(){
201
+ return {
202
+ int:(rows, cols, a, b)=>{
203
+ let result = new Matrix(rows, cols);
204
+ for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randInt(a, b);
205
+ return result;
206
+ },
207
+ bin:(rows,cols)=>{
208
+ let result = new Matrix(rows, cols);
209
+ for (let i = 0; i < rows; i++) {
210
+ for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randBin;
211
+ }
212
+ return result;
213
+ },
214
+ hex:(rows,cols)=>{
215
+ let result = new Matrix(rows, cols);
216
+ for (let i = 0; i < rows; i++) {
217
+ for (let j = 0; j < cols; j++) result.arr[i][j] = Random.randHex;
218
+ }
219
+ return result;
220
+ },
221
+ choices:(rows, cols, choices, p)=>{
222
+ let result = new Matrix(rows, cols);
223
+ for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.choice(choices, p);
224
+ return result
225
+ },
226
+ permutation:(rows,cols,arr)=>{
227
+ //return new Matrix(rows, cols, Random.permutation(...arr))
228
+ }
229
+ }
230
+ }
231
+ static rands(rows, cols, a = 1, b) {
232
+ let result = new Matrix(rows, cols);
233
+ for (let i = 0; i < rows; i++) for (let j = 0; j < cols; j++) result.arr[i][j] = Random.rand(a, b);
234
+ return result;
235
+ }
236
+ map(Imin, Imax, Fmin, Fmax) {
237
+ return Utils.map(this, Imin, Imax, Fmin, Fmax);
238
+ }
239
+ lerp(min, max) {
240
+ return Utils.lerp(this, min, max);
241
+ }
242
+ norm(min, max) {
243
+ return Utils.norm(this, min, max);
244
+ }
245
+ clamp(min, max) {
246
+ return Utils.clamp(this, min, max);
247
+ }
248
+ static map(matrix, Imin, Imax, Fmin, Fmax) {
249
+ return Utils.map(matrix, Imin, Imax, Fmin, Fmax);
250
+ }
251
+ static lerp(matrix, min, max) {
252
+ return Utils.lerp(matrix, min, max);
253
+ }
254
+ static norm(matrix, min, max) {
255
+ return Utils.norm(matrix, min, max);
256
+ }
257
+ static clamp(m, min, max) {
258
+ return Utils.clamp(matrix, min, max);
259
+ }
260
+ toPrecision(p) {
261
+ for (let i = 0; i < this.cols; i++) for (let j = 0; j < this.rows; j++) this.arr[i][j] = +this.arr[i][j].toPrecision(p);
262
+ return this;
263
+ }
264
+ get toBin() {
265
+ let newArr = this.arr.flat(1).toBin;
266
+ return new Matrix(this.rows, this.cols, newArr);
267
+ }
268
+ get toOct() {
269
+ let newArr = this.arr.flat(1).toOct;
270
+ return new Matrix(this.rows, this.cols, newArr);
271
+ }
272
+ get toHex() {
273
+ let newArr = this.arr.flat(1).toHex;
274
+ return new Matrix(this.rows, this.cols, newArr);
275
+ }
276
+ /*get isOdd() {
277
+ let newArr = this.arr.flat(1).isOdd;
278
+ return new Matrix(this.rows, this.cols, newArr);
279
+ }*/
280
+ max2min() {
281
+ let newArr = this.arr.flat(1).max2min;
282
+ return new Matrix(this.rows, this.cols, newArr);
283
+ }
284
+ min2max() {
285
+ let newArr = this.arr.flat(1).min2max;
286
+ return new Matrix(this.rows, this.cols, newArr);
287
+ }
288
+ sortRows(calback=undefined){
289
+ let newArr=this.arr.map(n=>n.sort(calback)).flat(1);
290
+ return new Matrix(this.rows, this.cols, newArr);
291
+ }
292
+ sortCols(calback=undefined){
293
+ let m=this.T;
294
+ let newArr=m.arr.map(n=>n.sort(calback)).flat(1);
295
+ return new Matrix(this.rows, this.cols, newArr).T;
296
+ }
297
+ filterByRows(item){
298
+ var truth=this.arr.map(n=>n.map(m=>+(""+m).includes(item)))
299
+ var mask=truth.map(n=>!!Logic.or(...n))
300
+ var filtredArray=this.arr.filter((n,i)=>mask[i]===true)
301
+ if(filtredArray.length===0)filtredArray.push([])
302
+ console.log(filtredArray)
303
+ return new Matrix(filtredArray)
304
+ }
305
+ filterByCols(item){
306
+ return new Matrix(this.T.arr.filter(n=>n.includes(item)))
307
+ }
308
+ sortAll(calback=undefined){
309
+ let newArr=this.arr.flat(1).sort(calback);
310
+ return new Matrix(this.rows, this.cols, newArr);
311
+ }
312
+ count(n) {
313
+ return this.arr.flat(1).count(n);
314
+ }
315
+ toBase(n) {
316
+ let newArr = this.arr.flat(1).toBase(n);
317
+ return new Matrix(this.rows, this.cols, newArr);
318
+ }
319
+ #hstack(matrix){
320
+ if (this.rows !== matrix.rows) return;
321
+ let newArr = this.arr;
322
+ 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];
323
+ this.cols += matrix.cols;
324
+ return new Matrix(this.rows, this.cols, newArr.flat(1));
325
+ }
326
+ hstack(...matrices) {
327
+ const M=[this,...matrices].reduce((a,b)=>a.#hstack(b));
328
+ Object.assign(this,M)
329
+ return this;
330
+ }
331
+ static hstack(matrix,...matrices) {
332
+ return matrix.clone.hstack(...matrices);
333
+ }
334
+ #vstack(matrix) {
335
+ if (this.cols !== matrix.cols) return;
336
+ let newArr = this.arr;
337
+ for (let i = this.rows; i < this.rows + matrix.rows; i++) {
338
+ newArr[i] = [];
339
+ for (let j = 0; j < this.cols; j++) newArr[i][j] = matrix.arr[i - this.rows][j];
340
+ }
341
+ this.rows += matrix.rows;
342
+ return new Matrix(this.rows, this.cols, newArr.flat(1));
343
+ }
344
+ vstack(...matrices) {
345
+ const M=[this,...matrices].reduce((a,b)=>a.#vstack(b));
346
+ Object.assign(this,M)
347
+ return this;
348
+ }
349
+ static vstack(matrix,...matrices) {
350
+ return matrix.clone.vstack(...matrices);
351
+ }
352
+ hqueue(...matrices){
353
+ const M=[this,...matrices].reverse().reduce((a,b)=>a.#hstack(b));
354
+ Object.assign(this,M)
355
+ return this;
356
+ }
357
+ vqueue(...matrices){
358
+ const M=[this,...matrices].reverse().reduce((a,b)=>a.#vstack(b));
359
+ Object.assign(this,M)
360
+ return this;
361
+ }
362
+ static hqueue(matrix,...matrices) {
363
+ return matrix.clone.hqueue(...matrices);
364
+ }
365
+ static vqueue(matrix,...matrices) {
366
+ return matrix.clone.vqueue(...matrices);
367
+ }
368
+ slice(r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
369
+ let newRow = r1 - r0,
370
+ newCol = c1 - c0;
371
+ let newArr = new Array(newCol);
372
+ for (let i = 0; i < newRow; i++) {
373
+ newArr[i] = [];
374
+ for (let j = 0; j < newCol; j++) newArr[i][j] = this.arr[i + r0][j + c0];
375
+ }
376
+ return new Matrix(newRow, newCol, newArr.flat(1));
377
+ }
378
+ static slice(m1,r0=0, c0=0, r1=this.rows-1, c1=this.cols-1) {
379
+ return m1.slice(r0, c0, r1, c1);
380
+ }
381
+ splice(r0,c0,deleteCount,...items){
382
+
383
+ }
384
+ getRows(ri, rf = ri + 1) {
385
+ return this.slice(ri, 0, rf, this.cols);
386
+ }
387
+ getCols(ci, cf = ci + 1) {
388
+ return this.slice(0, ci, this.rows, cf);
389
+ }
390
+ static getRows(m, ri, rf = ri + 1) {
391
+ return m.slice(ri, 0, rf, m.cols);
392
+ }
393
+ static getCols(m, ci, cf = ci + 1) {
394
+ return m.slice(0, ci, m.rows, cf);
395
+ }
396
+ add(...matr) {
397
+ for (let k = 0; k < matr.length; k++) {
398
+ if (typeof matr[k] == "number"||matr[k] instanceof Complex) matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
399
+ for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = Utils.add(this.arr[i][j],matr[k].arr[i][j]);
400
+ }
401
+ return new Matrix(this.rows, this.cols, this.arr.flat(1));
402
+ }
403
+ sub(...matr) {
404
+ for (let k = 0; k < matr.length; k++) {
405
+ if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
406
+ for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = Utils.sub(this.arr[i][j],matr[k].arr[i][j]);
407
+ }
408
+ return new Matrix(this.rows, this.cols, this.arr.flat(1));
409
+ }
410
+ static add(m1, ...m2) {
411
+ return m1.clone.add(...m2);
412
+ }
413
+ static sub(m1, ...m2) {
414
+ return m1.clone.sub(...m2);
415
+ }
416
+ mul(...matr) {
417
+ for (let k = 0; k < matr.length; k++) {
418
+ if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
419
+ for (var i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = Utils.mul(this.arr[i][j],matr[k].arr[i][j]);
420
+ }
421
+ return new Matrix(this.rows, this.cols, this.arr.flat(1));
422
+ }
423
+ div(...matr) {
424
+ for (let k = 0; k < matr.length; k++) {
425
+ if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
426
+ for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++) this.arr[i][j] = Utils.div(this.arr[i][j],matr[k].arr[i][j]);
427
+ }
428
+ return new Matrix(this.rows, this.cols, this.arr.flat(1));
429
+ }
430
+ static div(m1, ...m2) {
431
+ return m1.clone.div(...m2);
432
+ }
433
+ static mul(m1, ...m2) {
434
+ return m1.clone.mul(...m2);
435
+ }
436
+ modulo(...matr) {
437
+ for (let k = 0; k < matr.length; k++) {
438
+ if (typeof matr[k] == "number") matr[k] = Matrix.nums(this.rows, this.cols, matr[k]);
439
+ for (let i = 0; i < this.rows; i++) for (var j = 0; j < this.cols; j++)this.arr[i][j]=Utils.modulo(this.arr[i][j],matr[k].arr[i][j]);
440
+ }
441
+ return new Matrix(this.rows, this.cols, this.arr.flat(1));
442
+ }
443
+ static modulo(m1, ...m2) {
444
+ return m1.clone.modulo(...m2);
445
+ }
446
+ dot(matrix) {
447
+ var res = [];
448
+ for (var i = 0; i < this.arr.length; i++) {
449
+ res[i] = [];
450
+ for (var j = 0; j < matrix.arr[0].length; j++) {
451
+ res[i][j] = 0;
452
+ for (var k = 0; k < this.arr[0].length; k++) {
453
+ res[i][j] = Utils.add(
454
+ res[i][j],
455
+ Utils.mul(this.arr[i][k],matrix.arr[k][j])
456
+ )
457
+ }
458
+ }
459
+ }
460
+ return new Matrix(this.arr.length, matrix.arr[0].length, res.flat(1));
461
+ }
462
+ static dot(matrix1, matrix2) {
463
+ return matrix1.dot(matrix2);
464
+ }
465
+ pow(n) {
466
+ let a = this.clone,
467
+ p = this.clone;
468
+ for (let i = 0; i < n - 1; i++) p = p.dot(a);
469
+ return p;
470
+ }
471
+ static pow(m, n) {
472
+ return m.clone.pow(n);
473
+ }
474
+ get somme() {
475
+ let S = 0;
476
+ for (let i = 0; i < this.rows; i++) for (let j = 0; j < this.cols; j++) S += this.arr[i][j];
477
+ return S;
478
+ }
479
+ get DoesItContainComplexNumbers() {
480
+ return this.arr.flat(Infinity).some((n) => n instanceof Complex);
481
+ }
482
+ get min() {
483
+ if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
484
+ let minRow = [];
485
+ for (let i = 0; i < this.rows; i++) minRow.push(min(...this.arr[i]));
486
+ return min(...minRow);
487
+ }
488
+ get max() {
489
+ if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
490
+ let maxRow = [];
491
+ for (let i = 0; i < this.rows; i++) maxRow.push(max(...this.arr[i]));
492
+ return max(...maxRow);
493
+ }
494
+ get minRows() {
495
+ if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
496
+ let minRow = [];
497
+ for (let i = 0; i < this.rows; i++) minRow.push(min(...this.arr[i]));
498
+ return minRow;
499
+ }
500
+ get maxRows() {
501
+ if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
502
+ let maxRow = [];
503
+ for (let i = 0; i < this.rows; i++) maxRow.push(max(...this.arr[i]));
504
+ return maxRow;
505
+ }
506
+ get minCols() {
507
+ if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
508
+ return this.T.minRows;
509
+ }
510
+ get maxCols() {
511
+ if (this.DoesItContainComplexNumbers) console.error("Complex numbers are not comparable");
512
+ return this.T.maxRows;
513
+ }
514
+ static fromVector(v) {
515
+ return new Matrix(v.length, 1, v);
516
+ }
517
+ get toArray() {
518
+ let arr = [];
519
+ for (let i = 0; i < this.rows; i++) {
520
+ for (let j = 0; j < this.cols; j++) {
521
+ arr.push(this.arr[i][j]);
522
+ }
523
+ }
524
+ return arr;
525
+ }
526
+ get print() {
527
+ //"pretty print" the matrix
528
+ let fstring = "[";
529
+ for (let i = 0; i < this.arr.length; i++) {
530
+ fstring += (i != 0 ? " " : "") + ` [${this.arr[i].map((n) => " " + n.toString() + " ")}],\n`;
531
+ }
532
+ console.log(fstring.substring(0, fstring.length - 2) + " ]");
533
+ document.write(fstring.substring(0, fstring.length - 2) + " ]");
534
+ }
535
+ get table() {
536
+ console.table(this.arr);
537
+ }
538
+ get serialize() {
539
+ return JSON.stringify(this);
540
+ }
541
+ static deserialize(data) {
542
+ if (typeof data == "string") {
543
+ data = JSON.parse(data);
544
+ }
545
+ let matrix = new Matrix(data.rows, data.cols);
546
+ matrix.arr = data.arr;
547
+ return matrix;
548
+ }
549
+ DecompositionLU(){
550
+ const [L,U]=luDecomposition(this);
551
+ return {
552
+ L,
553
+ U
554
+ }
555
+ }
556
+ static DecompositionLU(...M){
557
+ const Decomposition=M.map(n=>n.clone.LU());
558
+ return Decomposition.length===1?Decomposition[0]:Decomposition;
559
+ }
560
+ DecompositionQR(){
561
+ const [Q,R]=qrDecomposition(this);
562
+ return {
563
+ Q,
564
+ R
565
+ }
566
+ }
567
+ static DecompositionQR(...M){
568
+ const Decomposition=M.map(n=>n.clone.DecompositionQr());
569
+ return Decomposition.length===1?Decomposition[0]:Decomposition;
570
+ }
571
+ DecompositionCholesky(){
572
+ return {
573
+ L:choleskyDecomposition(this)
574
+ }
575
+ }
576
+ static DecompositionCholesky(...M){
577
+ const Decomposition=M.map(n=>n.clone.DecompositionCholesky());
578
+ return Decomposition.length===1?Decomposition[0]:Decomposition;
579
+ }
580
+ get decomposition(){
581
+ return{
582
+ LU:()=>this.DecompositionLU(),
583
+ QR:()=>this.DecompositionQR(),
584
+ Cholesky:()=>this.DecompositionCholesky()
585
+ }
586
+ }
587
+ static get decomposition(){
588
+ return{
589
+ LU:(...M)=>Matrix.LU(...M),
590
+ QR:(...M)=>Matrix.QR(...M),
591
+ CHOLESKY:(...M)=>Matrix.CHOLESKY(...M)
592
+ }
593
+ }
594
+ toTable() {
595
+ var table = new DocumentFragment();
596
+ var Tr = new Array(this.rows).fill(null).map(() => document?.createElement("tr"));
597
+ var Td = this.arr.map((n) => n.map(() => document?.createElement("td")));
598
+ for (let i = 0; i < Td.length; i++) {
599
+ for (let j = 0; j < Td[0].length; j++) {
600
+ Td[i][j].innerHTML = this.arr[i][j];
601
+ Tr[i].appendChild(Td[i][j]);
602
+ }
603
+ }
604
+ Tr.map((n) => table.appendChild(n));
605
+ return table;
606
+ }
607
+ toGrid(element, style = {}) {
608
+ let a = Grid();
609
+ a.append(
610
+ ...this.map(element)
611
+ .arr.flat(1)
612
+ .map((n) => n.style(style))
613
+ );
614
+ a.Columns(this.cols);
615
+ return a;
616
+ }
617
+ sortTable(n=0,{type="num",order="asc"}={}) {
618
+ var obj=this.T.arr.map(n=>n.map((n,i)=>Object.assign({},{x:n,y:i})));
619
+ var newObj=this.T.arr.map(n=>n.map((n,i)=>Object.assign({},{x:n,y:i})));
620
+ if(type==="num"){
621
+ if(order==="asc")obj[n].sort((a,b)=>a.x-b.x);
622
+ else if(order==="desc")obj[n].sort((a,b)=>b.x-a.x);
623
+ else if(order==="toggle"){
624
+ // console.log(obj[n][0])
625
+ //console.log(obj[n][1])
626
+ if(obj[n][0].x>obj[n][1].x)obj[n].sort((a,b)=>b.x-a.x);
627
+ else obj[n].sort((a,b)=>a.x-b.x);
628
+ }
629
+ }
630
+ else if(type==="alpha"){
631
+ if(order==="asc")obj[n].sort((a,b)=>(""+a.x).localeCompare(""+b.x));
632
+ else if(order==="desc")obj[n].sort((a,b)=>(""+b.x).localeCompare(""+a.x));
633
+ }
634
+ //var order=obj[n].map(n=>n.y);
635
+ order=obj[n].map(n=>n.y);
636
+ for(let i=0;i<obj.length;i++){
637
+ if(i!==n)obj[i].map((n,j)=>n.y=order[j]);
638
+ }
639
+ for(let i=0;i<obj.length;i++){
640
+ if(i!==n)newObj[i].map((n,j)=>n.x=obj[i][order[j]].x)
641
+ }
642
+ newObj[n]=obj[n];
643
+ var newArr=newObj.map(n=>n.map(m=>m.x));
644
+ return new Matrix(newArr).T;
645
+ }
646
+ }
647
+
648
+ function InverseMatrixe(M) {
649
+ if (M.length !== M[0].length) {
650
+ return;
651
+ }
652
+ var i = 0,
653
+ ii = 0,
654
+ j = 0,
655
+ dim = M.length,
656
+ e = 0;
657
+ //t = 0;
658
+ var I = [],
659
+ C = [];
660
+ for (i = 0; i < dim; i += 1) {
661
+ I[I.length] = [];
662
+ C[C.length] = [];
663
+ for (j = 0; j < dim; j += 1) {
664
+ if (i == j) {
665
+ I[i][j] = 1;
666
+ } else {
667
+ I[i][j] = 0;
668
+ }
669
+ C[i][j] = M[i][j];
670
+ }
671
+ }
672
+ for (i = 0; i < dim; i += 1) {
673
+ e = C[i][i];
674
+ if (e == 0) {
675
+ for (ii = i + 1; ii < dim; ii += 1) {
676
+ if (C[ii][i] != 0) {
677
+ for (j = 0; j < dim; j++) {
678
+ e = C[i][j];
679
+ C[i][j] = C[ii][j];
680
+ C[ii][j] = e;
681
+ e = I[i][j];
682
+ I[i][j] = I[ii][j];
683
+ I[ii][j] = e;
684
+ }
685
+ break;
686
+ }
687
+ }
688
+ e = C[i][i];
689
+ if (e == 0) {
690
+ return;
691
+ }
692
+ }
693
+ for (j = 0; j < dim; j++) {
694
+ C[i][j] = C[i][j] / e;
695
+ I[i][j] = I[i][j] / e;
696
+ }
697
+ for (ii = 0; ii < dim; ii++) {
698
+ if (ii == i) {
699
+ continue;
700
+ }
701
+ e = C[ii][i];
702
+ for (j = 0; j < dim; j++) {
703
+ C[ii][j] -= e * C[i][j];
704
+ I[ii][j] -= e * I[i][j];
705
+ }
706
+ }
707
+ }
708
+ return I;
709
+ }
710
+ /**
711
+ * @returns {Matrix}
712
+ */
713
+ const matrix=(r, c, element)=>new Matrix(r, c, element);
714
+ const matrix2=(...element)=>new Matrix(2, 2, element);
715
+ const matrix3=(...element)=>new Matrix(3, 3, element);
716
+ const matrix4=(...element)=>new Matrix(4, 4, element);
717
717
  export{Matrix,matrix,matrix2,matrix3,matrix4}