ziko 0.51.0 → 0.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ziko",
3
- "version": "0.51.0",
3
+ "version": "0.51.1",
4
4
  "description": "A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...",
5
5
  "keywords": [
6
6
  "front-end",
@@ -1,4 +1,4 @@
1
- import { Matrix } from "../../math/matrix/Matrix.js"
1
+ import { Matrix } from "../../math/matrix/matrix.js"
2
2
  const csv2arr = (csv, delimiter = ",")=>csv.trim().trimEnd().split("\n").map(n=>n.split(delimiter));
3
3
  const csv2matrix = (csv, delimiter = ",")=>new Matrix(csv2arr(csv,delimiter));
4
4
  const csv2object = (csv, delimiter = ",") => {
@@ -12,7 +12,6 @@ import{
12
12
  sqrt,
13
13
  ln
14
14
  }from "../functions/index.js"
15
- import { Matrix } from "../matrix/index.js";
16
15
  import {sum,prod,deg2rad} from "../utils/index.js";
17
16
  class Complex{
18
17
  constructor(a = 0, b = 0) {
@@ -183,10 +182,10 @@ class Complex{
183
182
  }
184
183
  const complex=(a,b)=>{
185
184
  if((a instanceof Array||ArrayBuffer.isView(a)) && (b instanceof Array||ArrayBuffer.isView(a)))return a.map((n,i)=>complex(a[i],b[i]));
186
- if(a instanceof Matrix && b instanceof Matrix){
185
+ if(a.isMatrix?.() && b.isMatrix?.()){
187
186
  if((a.shape[0]!==b.shape[0])||(a.shape[1]!==b.shape[1]))return Error(0)
188
187
  const arr=a.arr.map((n,i)=>complex(a.arr[i],b.arr[i]))
189
- return new Matrix(a.rows,a.cols,...arr)
188
+ return new a.constructor(a.rows,a.cols,...arr)
190
189
  }
191
190
  return new Complex(a,b)
192
191
  }
@@ -1,5 +1,5 @@
1
1
  import { Complex } from "../../complex/index.js";
2
- import { Matrix } from "../../matrix/Matrix.js";
2
+ import { Matrix } from "../../matrix/matrix.js";
3
3
  const Base={
4
4
  _mode:Number,
5
5
  _map:function(func,number,toBase){
@@ -1,5 +1,5 @@
1
1
  import { Complex } from "../../complex/index.js";
2
- import { Matrix } from "../../matrix/Matrix.js";
2
+ import { Matrix } from "../../matrix/matrix.js";
3
3
  const Logic={
4
4
  _mode:Number,
5
5
  _map:function(func,a,b){
@@ -1,5 +1,4 @@
1
1
  import { Fixed } from "./helper.js";
2
- import { Complex } from "../complex/index.js";
3
2
  import { mapfun } from "../utils/mapfun.js";
4
3
  import {
5
4
  min,
@@ -11,12 +10,12 @@ const sqrt=(...x)=>mapfun(Math.sqrt,...x);
11
10
  const pow=(x,n)=>{
12
11
  if(typeof x === "number"){
13
12
  if(typeof n === "number")return Math.pow(x,n);
14
- else if(n instanceof Complex)return Complex.fromExpo(x**n.a,n.b*ln(x))
13
+ else if(n?.isComplex?.())return n.constructor.fromExpo(x**n.a,n.b*ln(x))
15
14
  else return mapfun(a=>pow(x,a),...n);
16
15
  }
17
- else if(x instanceof Complex){
18
- if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
19
- else if(n instanceof Complex)return Complex.fromExpo(
16
+ else if(x.isComplex?.()){
17
+ if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
18
+ else if(n.isComplex?.())return x.constructor.fromExpo(
20
19
  x.z**n.a*e(-x.phi*n.b),
21
20
  ln(x.z)*n.b+n.a*x.phi
22
21
  )
@@ -38,8 +37,8 @@ const sqrtn=(x,n)=>{
38
37
  if(typeof n === "number")return Math.pow(x,1/n);
39
38
  else return mapfun(a=>sqrtn(x,a),...n);
40
39
  }
41
- else if(x instanceof Complex){
42
- if(typeof n === "number")return Complex.fromExpo(sqrtn(x.z,n),x.phi/n);
40
+ else if(x.isComplex?.()){
41
+ if(typeof n === "number")return x.constructor.fromExpo(sqrtn(x.z,n),x.phi/n);
43
42
  else return mapfun(a=>sqrtn(x,a),...n);
44
43
  }
45
44
  else if(x instanceof Array){
@@ -81,8 +80,8 @@ const atan2=(x,y,rad=true)=>{
81
80
  if(typeof y === "number")return rad?Math.atan2(x,y):Math.atan2(x,y)*180/Math.PI;
82
81
  else return mapfun(a=>atan2(x,a,rad),...y);
83
82
  }
84
- // else if(x instanceof Complex){
85
- // if(typeof n === "number")return Complex.fromExpo(x.z**n,x.phi*n);
83
+ // else if(x.isComplex?.()){
84
+ // if(typeof n === "number")return x.constructor.fromExpo(x.z**n,x.phi*n);
86
85
  // else return mapfun(a=>pow(x,a),...n);
87
86
  // }
88
87
  else if(x instanceof Array){
@@ -0,0 +1,36 @@
1
+ import { add, sub, mul } from "../../utils/index.js";
2
+ import { pow } from "../../functions/index.js";
3
+ export function matrix_det(M) {
4
+ if (!M.isSquare) return new Error("is not square matrix");
5
+ if (M.rows == 1) return M.arr[0][0];
6
+ function determinat(M) {
7
+ if (M.length == 2) {
8
+ if (M.flat(1).some((n) => n?.isMatrix?.())) {
9
+ console.warn("Tensors are not completely supported yet ...");
10
+ return;
11
+ }
12
+ return sub(mul(M[0][0],M[1][1]),mul(M[0][1],M[1][0]))
13
+ }
14
+ var answer = 0;
15
+ for (var i = 0; i < M.length; i++) {
16
+ //console.log(M[0][i]);
17
+ /*answer = answer.add(
18
+ pow(-1, i)
19
+ .mul(M[0][i])
20
+ .mul(determinat(deleteRowAndColumn(M, i)))
21
+ );*/
22
+ //const to_be_added=add(mul(pow(-1, i),mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
23
+ const to_be_added=add(mul(pow(-1, i),mul(M[0][i],determinat(deleteRowAndColumn(M, i)))));
24
+ answer=add(answer,to_be_added)
25
+ }
26
+ return answer;
27
+ }
28
+ return determinat(M.arr);
29
+ }
30
+ function deleteRowAndColumn(M, index) {
31
+ var temp = [];
32
+ for (let i = 0; i < M.length; i++) temp.push(M[i].slice(0));
33
+ temp.splice(0, 1);
34
+ for (let i = 0; i < temp.length; i++) temp[i].splice(index, 1);
35
+ return temp;
36
+ }
@@ -0,0 +1,3 @@
1
+ export * from './inverse.js'
2
+ export * from './det.js'
3
+ export * from './stack.js'
@@ -0,0 +1,52 @@
1
+ export function matrix_inverse(M) {
2
+ if(M.row !== M.cols) throw Error('is not a square matrix"')
3
+ if (M.det === 0) throw Error("determinant should not equal 0");
4
+ const { arr } = M
5
+ if (arr.length !== arr[0].length) return;
6
+ var i = 0, ii = 0, j = 0, dim = arr.length, e = 0;
7
+ var I = [], C = [];
8
+ for (i = 0; i < dim; i += 1) {
9
+ I[I.length] = [];
10
+ C[C.length] = [];
11
+ for (j = 0; j < dim; j += 1) {
12
+ if (i == j) I[i][j] = 1;
13
+ else I[i][j] = 0;
14
+ C[i][j] = arr[i][j];
15
+ }
16
+ }
17
+ for (i = 0; i < dim; i += 1) {
18
+ e = C[i][i];
19
+ if (e == 0) {
20
+ for (ii = i + 1; ii < dim; ii += 1) {
21
+ if (C[ii][i] != 0) {
22
+ for (j = 0; j < dim; j++) {
23
+ e = C[i][j];
24
+ C[i][j] = C[ii][j];
25
+ C[ii][j] = e;
26
+ e = I[i][j];
27
+ I[i][j] = I[ii][j];
28
+ I[ii][j] = e;
29
+ }
30
+ break;
31
+ }
32
+ }
33
+ e = C[i][i];
34
+ if (e == 0) return;
35
+ }
36
+ for (j = 0; j < dim; j++) {
37
+ C[i][j] = C[i][j] / e;
38
+ I[i][j] = I[i][j] / e;
39
+ }
40
+ for (ii = 0; ii < dim; ii++) {
41
+ if (ii == i) {
42
+ continue;
43
+ }
44
+ e = C[ii][i];
45
+ for (j = 0; j < dim; j++) {
46
+ C[ii][j] -= e * C[i][j];
47
+ I[ii][j] -= e * I[i][j];
48
+ }
49
+ }
50
+ }
51
+ return new M.constructor(I);
52
+ }
@@ -0,0 +1,24 @@
1
+ export function hstack(M1, M2){
2
+ M1 = M1.clone()
3
+ M2 = M2.clone()
4
+ if (M1.rows !== M2.rows) return;
5
+ let newArr = M1.arr;
6
+ for (let i = 0; i < M1.rows; i++)
7
+ for (let j = M1.cols; j < M1.cols + M2.cols; j++)
8
+ newArr[i][j] = M2.arr[i][j - M1.cols];
9
+ M1.cols += M2.cols;
10
+ return new M1.constructor(M1.rows, M1.cols, newArr.flat(1));
11
+ }
12
+
13
+ export function vstack(M1, M2){
14
+ M1 = M1.clone()
15
+ M2 = M2.clone()
16
+ if (M1.cols !== M2.cols) return;
17
+ let newArr = M1.arr;
18
+ for (let i = M1.rows; i < M1.rows + M2.rows; i++) {
19
+ newArr[i] = [];
20
+ for (let j = 0; j < M1.cols; j++) newArr[i][j] = M2.arr[i - M1.rows][j];
21
+ }
22
+ M1.rows += M2.rows;
23
+ return new M1.constructor(M1.rows, M1.cols, newArr.flat(1));
24
+ }
@@ -1 +1 @@
1
- export * from "./Matrix.js"
1
+ export * from "./matrix.js"