ziko 0.0.17 → 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/README.md +91 -200
  2. package/package.json +17 -46
  3. package/src/__helpers__/index.js +61 -61
  4. package/src/app/json-style-sheet.js +64 -64
  5. package/src/app/spa-file-based-routing.js +0 -1
  6. package/src/app/ziko-app.js +38 -38
  7. package/src/data/api/fetchdom.js +13 -13
  8. package/src/data/api/index.js +3 -3
  9. package/src/data/api/preload.js +10 -10
  10. package/src/data/converter/adoc.js +130 -130
  11. package/src/data/converter/array.js +42 -42
  12. package/src/data/converter/canvas.js +24 -24
  13. package/src/data/converter/css.js +36 -36
  14. package/src/data/converter/csv.js +32 -32
  15. package/src/data/converter/idea.txt +9 -9
  16. package/src/data/converter/index.js +36 -36
  17. package/src/data/converter/json.js +80 -80
  18. package/src/data/converter/markdown.js +95 -95
  19. package/src/data/converter/object.js +69 -69
  20. package/src/data/converter/svg.js +10 -10
  21. package/src/data/datatypes/color.js +11 -0
  22. package/src/data/index.js +16 -16
  23. package/src/data/parser/xml.js +46 -46
  24. package/src/data/string/patterns.js +11 -11
  25. package/src/data/string/string.js +169 -169
  26. package/src/global/{themes → _themes}/dark.js +884 -884
  27. package/src/global/{themes → _themes}/index.js +10 -10
  28. package/src/global/{themes → _themes}/light.js +254 -254
  29. package/src/global/app/index.js +45 -45
  30. package/src/global/component/index.js +38 -38
  31. package/src/global/globals/index.js +20 -20
  32. package/src/global/index.js +3 -11
  33. package/src/global/params/index.js +39 -39
  34. package/src/global/router/index.js +66 -66
  35. package/src/global/seo/index.js +42 -42
  36. package/src/graphics/canvas/canvas.js +176 -189
  37. package/src/graphics/canvas/elements/Basic/arc.js +42 -42
  38. package/src/graphics/canvas/elements/Basic/line.js +25 -25
  39. package/src/graphics/canvas/elements/Basic/points.js +47 -47
  40. package/src/graphics/canvas/elements/Basic/polygon.js +6 -6
  41. package/src/graphics/canvas/elements/Basic/rect.js +45 -45
  42. package/src/graphics/canvas/elements/Chart/scatter.js +2 -2
  43. package/src/graphics/canvas/elements/Element.js +114 -114
  44. package/src/graphics/canvas/elements/index.js +13 -13
  45. package/src/graphics/canvas/index.js +2 -15
  46. package/src/graphics/canvas/utils/color.js +7 -7
  47. package/src/graphics/canvas/utils/floodFill.js +57 -57
  48. package/src/graphics/index.js +10 -69
  49. package/src/graphics/svg/Elements/Basic/circle.js +29 -26
  50. package/src/graphics/svg/Elements/Basic/ellipse.js +24 -21
  51. package/src/graphics/svg/Elements/Basic/{foreignObject.js → foreign-object.js} +36 -33
  52. package/src/graphics/svg/Elements/Basic/groupe.js +32 -29
  53. package/src/graphics/svg/Elements/Basic/image.js +36 -33
  54. package/src/graphics/svg/Elements/Basic/index.js +11 -0
  55. package/src/graphics/svg/Elements/Basic/line.js +32 -29
  56. package/src/graphics/svg/Elements/Basic/link.js +33 -30
  57. package/src/graphics/svg/Elements/Basic/path.js +62 -59
  58. package/src/graphics/svg/Elements/Basic/polygon.js +31 -31
  59. package/src/graphics/svg/Elements/Basic/polyline.js +7 -4
  60. package/src/graphics/svg/Elements/Basic/rect.js +46 -43
  61. package/src/graphics/svg/Elements/Basic/text.js +29 -26
  62. package/src/graphics/svg/Elements/Derived/grid.js +8 -8
  63. package/src/graphics/svg/Elements/Derived/index.js +1 -0
  64. package/src/graphics/svg/Elements/index.js +2 -14
  65. package/src/graphics/svg/Elements/{ZikoSvgElement.js → ziko-svg-element.js} +48 -46
  66. package/src/graphics/svg/index.js +2 -2
  67. package/src/graphics/svg/svg.js +68 -114
  68. package/src/index.js +85 -84
  69. package/src/math/calculus/index.js +2 -2
  70. package/src/math/calculus/special-functions/bessel.js +30 -30
  71. package/src/math/calculus/special-functions/beta.js +37 -37
  72. package/src/math/calculus/special-functions/gamma.js +29 -29
  73. package/src/math/calculus/special-functions/index.js +4 -4
  74. package/src/math/complex/index.js +202 -202
  75. package/src/math/const.js +2 -2
  76. package/src/math/discret/Combinaison/index.js +33 -33
  77. package/src/math/discret/Conversion/index.js +85 -85
  78. package/src/math/discret/Logic/index.js +45 -45
  79. package/src/math/discret/Permutation/index.js +30 -30
  80. package/src/math/discret/Set/index.js +1 -1
  81. package/src/math/discret/Set/power-set.js +14 -14
  82. package/src/math/discret/Set/sub-set.js +10 -10
  83. package/src/math/discret/index.js +11 -11
  84. package/src/math/functions/index.js +161 -161
  85. package/src/math/index.js +32 -32
  86. package/src/math/matrix/Decomposition.js +90 -90
  87. package/src/math/matrix/LinearSystem.js +9 -9
  88. package/src/math/matrix/Matrix.js +716 -716
  89. package/src/math/matrix/index.js +2 -2
  90. package/src/math/random/index.js +172 -172
  91. package/src/math/signal/__np.py.txt +39 -39
  92. package/src/math/signal/conv.js +174 -174
  93. package/src/math/signal/fft.js +54 -54
  94. package/src/math/signal/filter.js +38 -38
  95. package/src/math/signal/functions.js +145 -145
  96. package/src/math/signal/index.js +109 -109
  97. package/src/math/statistics/Functions/index.js +99 -99
  98. package/src/math/statistics/index.js +15 -15
  99. package/src/math/utils/arithmetic.js +138 -138
  100. package/src/math/utils/checkers.js +29 -29
  101. package/src/math/utils/conversions.js +19 -19
  102. package/src/math/utils/discret.js +51 -51
  103. package/src/math/utils/index.js +101 -101
  104. package/src/math/utils/mapfun.js +49 -49
  105. package/src/reactivity/events/Input.js +61 -61
  106. package/src/reactivity/events/Pointer.js +231 -231
  107. package/src/reactivity/events/ZikoEvent.js +90 -90
  108. package/src/reactivity/events/click.js +59 -59
  109. package/src/reactivity/events/clipboard.js +87 -87
  110. package/src/reactivity/events/custom-event.js +56 -56
  111. package/src/reactivity/events/drag.js +136 -136
  112. package/src/reactivity/events/focus.js +58 -58
  113. package/src/reactivity/events/hash.js +46 -46
  114. package/src/reactivity/events/index.js +12 -63
  115. package/src/reactivity/events/key.js +101 -101
  116. package/src/reactivity/events/mouse.js +232 -232
  117. package/src/reactivity/events/swipe.js +149 -149
  118. package/src/reactivity/events/wheel.js +46 -46
  119. package/src/reactivity/hooks/{contexte → Contexte}/useSuccesifKeys.js +13 -13
  120. package/src/reactivity/hooks/{decorators → Decorators}/index.js +6 -6
  121. package/src/reactivity/hooks/{decorators → Decorators}/time.js +16 -16
  122. package/src/reactivity/hooks/{decorators → Decorators}/type.js +87 -87
  123. package/src/reactivity/hooks/{head/useCssText.js → Head/_useCssText.js} +20 -20
  124. package/src/reactivity/hooks/{head → Head}/index.js +5 -5
  125. package/src/reactivity/hooks/{head → Head}/useFavIcon.js +37 -37
  126. package/src/reactivity/hooks/{head → Head}/useHead.js +27 -27
  127. package/src/reactivity/hooks/{head → Head}/useMeta.js +52 -52
  128. package/src/reactivity/hooks/{head → Head}/useTitle.js +29 -29
  129. package/src/reactivity/hooks/{interactions/useBluetooth.js → Interactions/_useBluetooth.js} +47 -47
  130. package/src/reactivity/hooks/{interactions → Interactions}/index.js +4 -4
  131. package/src/reactivity/hooks/{interactions → Interactions}/useChannel.js +49 -49
  132. package/src/reactivity/hooks/{interactions → Interactions}/useEventEmmiter.js +63 -63
  133. package/src/reactivity/hooks/{interactions → Interactions}/useThread.js +43 -43
  134. package/src/reactivity/hooks/Sensors/index.js +2 -0
  135. package/src/reactivity/hooks/{sensors → Sensors}/useBattery.js +35 -35
  136. package/src/reactivity/hooks/{sensors → Sensors}/useGeolocation.js +16 -16
  137. package/src/reactivity/hooks/{storage → Storage}/useStorage.js +72 -72
  138. package/src/reactivity/hooks/{ui → UI}/index.js +6 -5
  139. package/src/reactivity/hooks/{ui → UI}/useMediaQuery.js +43 -43
  140. package/src/reactivity/hooks/UI/useRoot.js +39 -0
  141. package/src/reactivity/hooks/{ui → UI}/useStyle.js +79 -79
  142. package/src/reactivity/hooks/{ui → UI}/useTheme.js +61 -61
  143. package/src/reactivity/hooks/index.js +8 -91
  144. package/src/reactivity/hooks/todo.md +26 -26
  145. package/src/reactivity/idea +1 -1
  146. package/src/reactivity/index.js +11 -11
  147. package/src/reactivity/observer/attributes.js +28 -28
  148. package/src/reactivity/observer/children.js +36 -36
  149. package/src/reactivity/observer/index.js +6 -6
  150. package/src/reactivity/observer/intersection.js +43 -43
  151. package/src/reactivity/observer/mutation.js +112 -112
  152. package/src/reactivity/observer/resize.js +46 -46
  153. package/src/reactivity/observer/screen.js +44 -44
  154. package/src/reactivity/observer/screen.js.txt +83 -83
  155. package/src/reactivity/observer/screen.txt +12 -12
  156. package/src/time/animation.js +75 -75
  157. package/src/time/index.js +11 -11
  158. package/src/time/loop.js +87 -87
  159. package/src/time/utils/decorators.js +16 -16
  160. package/src/time/utils/ease.js +143 -143
  161. package/src/time/utils/index.js +17 -17
  162. package/src/time/utils/performance.js +15 -15
  163. package/src/time/utils/ui.js +25 -25
  164. package/src/types.js +73 -73
  165. package/src/ui/elements/derived/accordion/accordion.js +42 -42
  166. package/src/ui/elements/derived/accordion/collapsible.js +82 -82
  167. package/src/ui/elements/derived/accordion/index.js +1 -1
  168. package/src/ui/elements/derived/alert/alert.js +80 -80
  169. package/src/ui/elements/derived/alert/palette.js +51 -51
  170. package/src/ui/elements/derived/carousel/index.js +50 -50
  171. package/src/ui/elements/derived/code-note/SubElements.js.txt +104 -104
  172. package/src/ui/elements/derived/code-note/code-cell.js +194 -194
  173. package/src/ui/elements/derived/code-note/code-note.js +71 -71
  174. package/src/ui/elements/derived/code-note/index.js +1 -1
  175. package/src/ui/elements/derived/code-note/sub-elements.js +66 -66
  176. package/src/ui/elements/derived/elements/Swipper.js +3 -3
  177. package/src/ui/elements/derived/elements/index.js +9 -9
  178. package/src/ui/elements/derived/flex/index.js +102 -102
  179. package/src/ui/elements/derived/grid/index.js +32 -32
  180. package/src/ui/elements/derived/index.js +11 -11
  181. package/src/ui/elements/derived/menu/menu3d.js +259 -259
  182. package/src/ui/elements/derived/modal/index.js +91 -91
  183. package/src/ui/elements/derived/pagination/breadcrumbs.js +53 -53
  184. package/src/ui/elements/derived/slider/__ZikoUISlider__.js +111 -111
  185. package/src/ui/elements/derived/slider/hSlider.js +33 -33
  186. package/src/ui/elements/derived/slider/index.js +11 -11
  187. package/src/ui/elements/derived/slider/vSlider.js +26 -26
  188. package/src/ui/elements/derived/splitter/__ZikoUISplitter__.js +61 -61
  189. package/src/ui/elements/derived/splitter/hsplitter.js +39 -39
  190. package/src/ui/elements/derived/splitter/index.js +11 -11
  191. package/src/ui/elements/derived/splitter/vsplitter.js +39 -39
  192. package/src/ui/elements/derived/tabs/index.js +179 -179
  193. package/src/ui/elements/primitives/ZikoUIContainerElement.js +163 -126
  194. package/src/ui/elements/primitives/ZikoUIElement.js +492 -492
  195. package/src/ui/elements/primitives/embaded/html.js +19 -19
  196. package/src/ui/elements/primitives/embaded/index.js +3 -3
  197. package/src/ui/elements/primitives/embaded/pdf.js +16 -16
  198. package/src/ui/elements/primitives/embaded/youtube.js +23 -23
  199. package/src/ui/elements/primitives/index.js +7 -7
  200. package/src/ui/elements/primitives/io/Form/index.js +41 -41
  201. package/src/ui/elements/primitives/io/Form/index.js.txt +104 -104
  202. package/src/ui/elements/primitives/io/Inputs/__helpers__.js +51 -51
  203. package/src/ui/elements/primitives/io/Inputs/index.js +12 -12
  204. package/src/ui/elements/primitives/io/Inputs/input/index.js +98 -98
  205. package/src/ui/elements/primitives/io/Inputs/input-camera/index.js +26 -26
  206. package/src/ui/elements/primitives/io/Inputs/input-checkbox/index.js +25 -25
  207. package/src/ui/elements/primitives/io/Inputs/input-color/index.js +15 -15
  208. package/src/ui/elements/primitives/io/Inputs/input-date-time/index.js +2 -2
  209. package/src/ui/elements/primitives/io/Inputs/input-date-time/input-date-time.js +13 -13
  210. package/src/ui/elements/primitives/io/Inputs/input-date-time/input-date.js +13 -13
  211. package/src/ui/elements/primitives/io/Inputs/input-date-time/input-time.js +13 -13
  212. package/src/ui/elements/primitives/io/Inputs/input-email-password/index.js +1 -1
  213. package/src/ui/elements/primitives/io/Inputs/input-email-password/input-email.js +14 -14
  214. package/src/ui/elements/primitives/io/Inputs/input-email-password/input-password.js +13 -13
  215. package/src/ui/elements/primitives/io/Inputs/input-file/input-image.js +42 -42
  216. package/src/ui/elements/primitives/io/Inputs/input-number/index.js +36 -36
  217. package/src/ui/elements/primitives/io/Inputs/input-radio/index.js +25 -25
  218. package/src/ui/elements/primitives/io/Inputs/input-search/index.js +45 -45
  219. package/src/ui/elements/primitives/io/Inputs/input-slider/index.js +34 -34
  220. package/src/ui/elements/primitives/io/Select/index.js +19 -19
  221. package/src/ui/elements/primitives/io/Textarea/index.js +17 -17
  222. package/src/ui/elements/primitives/io/index.js +3 -3
  223. package/src/ui/elements/primitives/list/index.js +138 -138
  224. package/src/ui/elements/primitives/media/Audio/index.js +16 -16
  225. package/src/ui/elements/primitives/media/Image/figure.js +18 -18
  226. package/src/ui/elements/primitives/media/Image/image.js +36 -36
  227. package/src/ui/elements/primitives/media/Image/index.js +1 -1
  228. package/src/ui/elements/primitives/media/Video/index.js +26 -26
  229. package/src/ui/elements/primitives/media/__ZikoUIDynamicMediaELement__.js +46 -46
  230. package/src/ui/elements/primitives/media/index.js +2 -2
  231. package/src/ui/elements/primitives/misc/index.js +101 -101
  232. package/src/ui/elements/primitives/misc/xml-wrapper.js +3 -2
  233. package/src/ui/elements/primitives/semantic/index.js +81 -81
  234. package/src/ui/elements/primitives/table/elements.js +93 -93
  235. package/src/ui/elements/primitives/table/index.js +2 -2
  236. package/src/ui/elements/primitives/table/table.js +115 -115
  237. package/src/ui/elements/primitives/table/utils.js +11 -11
  238. package/src/ui/elements/primitives/text/__ZikoUIText__.js +71 -71
  239. package/src/ui/elements/primitives/text/heading.js +35 -35
  240. package/src/ui/elements/primitives/text/index.js +2 -2
  241. package/src/ui/elements/primitives/text/p.js +26 -26
  242. package/src/ui/elements/primitives/text/text.js +80 -80
  243. package/src/ui/index.js +37 -37
  244. package/src/ui/style/index.js +504 -515
  245. package/src/ui/utils/index.js +69 -69
  246. package/starter/bin/index.js +11 -11
  247. package/dist/ziko.cjs +0 -14018
  248. package/dist/ziko.js +0 -14028
  249. package/dist/ziko.min.js +0 -9
  250. package/dist/ziko.mjs +0 -13688
  251. package/src/graphics/canvas/elements/Groupe.js +0 -0
  252. package/src/graphics/canvas/elements/grid.js +0 -0
  253. package/src/graphics/canvas/filter/index.js +0 -0
  254. package/src/graphics/canvas/paint/index.js +0 -0
  255. package/src/reactivity/hooks/sensors/index.js +0 -2
  256. /package/src/reactivity/hooks/{contexte → Contexte}/index.js +0 -0
  257. /package/src/reactivity/hooks/{interactions → Interactions}/useSerial.js +0 -0
  258. /package/src/reactivity/hooks/{interactions → Interactions}/useUsb.js +0 -0
  259. /package/src/reactivity/hooks/{sensors → Sensors}/useCamera.js +0 -0
  260. /package/src/reactivity/hooks/{sensors → Sensors}/useMicro.js +0 -0
  261. /package/src/reactivity/hooks/{sensors → Sensors}/useOrientation.js +0 -0
  262. /package/src/reactivity/hooks/{storage → Storage}/index.js +0 -0
  263. /package/src/reactivity/hooks/{storage → Storage}/useCookie.js +0 -0
  264. /package/src/reactivity/hooks/{storage → Storage}/useIndexedDb.js +0 -0
  265. /package/src/reactivity/hooks/{ui → UI}/useCssLink.js +0 -0
  266. /package/src/reactivity/hooks/{ui → UI}/useLinearGradient.js +0 -0
  267. /package/src/reactivity/hooks/{ui → UI}/useRadialGradient.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}