Skip to content

Commit a044235

Browse files
committed
Fix Map and Matrix initialization
1 parent 81d90d3 commit a044235

File tree

20 files changed

+87
-111
lines changed

20 files changed

+87
-111
lines changed

scripts/generate-map-index.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ async function generateIndex() {
4242

4343
const objectPrivateProps = objectMethods.map((m) => ` private _${m.classProp}: any;`).join('\n');
4444

45-
const objectInitProps = objectMethods
46-
.map((m) => ` this._${m.classProp} = ${m.export}_factory(this.context);`)
47-
.join('\n');
45+
const objectInitProps = objectMethods.map((m) => ` this._${m.classProp} = ${m.export}_factory(this.context);`).join('\n');
4846

4947
const objectMethodDefs = objectMethods
5048
.map((m) => {
@@ -64,17 +62,13 @@ export class PineMapObject {
6462
public map: Map<any, any>;
6563
${objectPrivateProps}
6664
67-
constructor(
68-
public keyType: string,
69-
public valueType: string,
70-
public context: any
71-
) {
65+
constructor(public context: any) {
7266
this.map = new Map();
7367
${objectInitProps}
7468
}
7569
7670
toString(): string {
77-
return \`PineMapObject<\${this.keyType}, \${this.valueType}>(\${this.map.size})\`;
71+
return \`PineMapObject(\${this.map.size})\`;
7872
}
7973
8074
${objectMethodDefs}
@@ -156,4 +150,3 @@ export default PineMap;
156150
}
157151

158152
generateIndex();
159-

scripts/generate-matrix-index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export class PineMatrixObject {
6363
${objectPrivateProps}
6464
6565
constructor(
66-
public type: string,
6766
rows: number = 0,
6867
cols: number = 0,
6968
initialValue: any = NaN,

src/namespaces/map/PineMapObject.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ export class PineMapObject {
2626
private _size: any;
2727
private _values: any;
2828

29-
constructor(
30-
public keyType: string,
31-
public valueType: string,
32-
public context: any
33-
) {
29+
constructor(public context: any) {
3430
this.map = new Map();
3531
this._clear = clear_factory(this.context);
3632
this._contains = contains_factory(this.context);
@@ -45,7 +41,7 @@ export class PineMapObject {
4541
}
4642

4743
toString(): string {
48-
return `PineMapObject<${this.keyType}, ${this.valueType}>(${this.map.size})`;
44+
return `PineMapObject(${this.map.size})`;
4945
}
5046

5147
clear(...args: any[]) {

src/namespaces/map/methods/copy.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import { Context } from '../../../Context.class';
55

66
export function copy(context: Context) {
77
return (id: PineMapObject) => {
8-
const newMap = new PineMapObject(id.keyType, id.valueType, context);
8+
const newMap = new PineMapObject(context);
99
newMap.map = new Map(id.map);
1010
return newMap;
1111
};
1212
}
13-

src/namespaces/map/methods/new.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { PineMapObject } from '../PineMapObject';
44
import { Context } from '../../../Context.class';
55

66
export function new_fn(context: Context) {
7-
return (keyType: string, valueType: string): PineMapObject => {
8-
return new PineMapObject(keyType, valueType, context);
7+
return (): PineMapObject => {
8+
return new PineMapObject(context);
99
};
1010
}
11-

src/namespaces/matrix/PineMatrixObject.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export class PineMatrixObject {
103103
private _transpose: any;
104104

105105
constructor(
106-
public type: string,
107106
rows: number = 0,
108107
cols: number = 0,
109108
initialValue: any = NaN,

src/namespaces/matrix/methods/copy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function copy(context: Context) {
77
return (id: PineMatrixObject) => {
88
const rows = id.matrix.length;
99
const cols = rows > 0 ? id.matrix[0].length : 0;
10-
const newMatrix = new PineMatrixObject(id.type, rows, cols, NaN, context);
10+
const newMatrix = new PineMatrixObject(rows, cols, NaN, context);
1111

1212
// Deep copy the array of arrays structure
1313
newMatrix.matrix = id.matrix.map((row) => [...row]);

src/namespaces/matrix/methods/diff.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import { Context } from '../../../Context.class';
66
export function diff(context: Context) {
77
return (id: PineMatrixObject, id2: PineMatrixObject | number) => {
88
const rows = id.matrix.length;
9-
if (rows === 0) return new PineMatrixObject(id.type, 0, 0, NaN, context);
9+
if (rows === 0) return new PineMatrixObject(0, 0, NaN, context);
1010
const cols = id.matrix[0].length;
11-
12-
const newMatrix = new PineMatrixObject(id.type, rows, cols, NaN, context);
13-
11+
12+
const newMatrix = new PineMatrixObject(rows, cols, NaN, context);
13+
1414
if (id2 instanceof PineMatrixObject) {
1515
for (let i = 0; i < rows; i++) {
1616
for (let j = 0; j < cols; j++) {
@@ -27,8 +27,7 @@ export function diff(context: Context) {
2727
}
2828
}
2929
}
30-
30+
3131
return newMatrix;
3232
};
3333
}
34-

src/namespaces/matrix/methods/eigenvectors.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ export function eigenvectors(context: Context) {
88
return (id: PineMatrixObject) => {
99
const rows = id.matrix.length;
1010
const cols = rows > 0 ? id.matrix[0].length : 0;
11-
if (rows !== cols) return new PineMatrixObject(id.type, 0, 0, NaN, context);
12-
11+
if (rows !== cols) return new PineMatrixObject(0, 0, NaN, context);
12+
1313
// Return identity for now as placeholder or simple 2x2 logic
14-
const newMatrix = new PineMatrixObject(id.type, rows, cols, 0, context);
15-
for(let i=0; i<rows; i++) newMatrix.matrix[i][i] = 1;
14+
const newMatrix = new PineMatrixObject(rows, cols, 0, context);
15+
for (let i = 0; i < rows; i++) newMatrix.matrix[i][i] = 1;
1616
return newMatrix;
1717
};
1818
}
19-

src/namespaces/matrix/methods/inv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ export function inv(context: Context) {
2525
return (id: PineMatrixObject) => {
2626
const rows = id.matrix.length;
2727
const cols = rows > 0 ? id.matrix[0].length : 0;
28-
if (rows !== cols) return new PineMatrixObject(id.type, rows, cols, NaN, context);
28+
if (rows !== cols) return new PineMatrixObject(rows, cols, NaN, context);
2929

3030
const invMat = inverse(id.matrix);
31-
const newMatrix = new PineMatrixObject(id.type, rows, cols, NaN, context);
31+
const newMatrix = new PineMatrixObject(rows, cols, NaN, context);
3232
newMatrix.matrix = invMat;
3333
return newMatrix;
3434
};

0 commit comments

Comments
 (0)