@@ -1447,6 +1447,37 @@ var staticMethodWithArgs = `
1447
1447
})
1448
1448
` ;
1449
1449
1450
+ var inplaceMethodWithOneArgScalar = `
1451
+ (function %name%S(%args%) {
1452
+ for (var i = 0; i < this.rows; i++) {
1453
+ for (var j = 0; j < this.columns; j++) {
1454
+ this[i][j] = %method%(this[i][j], %args%);
1455
+ }
1456
+ }
1457
+ return this;
1458
+ })
1459
+ ` ;
1460
+ var inplaceMethodWithOneArgMatrix = `
1461
+ (function %name%M(%args%) {
1462
+ checkDimensions(this, %args%);
1463
+ for (var i = 0; i < this.rows; i++) {
1464
+ for (var j = 0; j < this.columns; j++) {
1465
+ this[i][j] = %method%(this[i][j], %args%[i][j]);
1466
+ }
1467
+ }
1468
+ return this;
1469
+ })
1470
+ ` ;
1471
+
1472
+ var inplaceMethodWithOneArg = `
1473
+ (function %name%(value) {
1474
+ if (typeof value === 'number') return this.%name%S(value);
1475
+ return this.%name%M(value);
1476
+ })
1477
+ ` ;
1478
+
1479
+ var staticMethodWithOneArg = staticMethodWithArgs ;
1480
+
1450
1481
var operators = [
1451
1482
// Arithmetic operators
1452
1483
[ '+' , 'add' ] ,
@@ -1506,15 +1537,35 @@ for (var methodWithArg of methodsWithArgs) {
1506
1537
for ( var i = 1 ; i < methodWithArg [ 1 ] ; i ++ ) {
1507
1538
args += `, arg${ i } ` ;
1508
1539
}
1509
- var inplaceMethWithArgs = eval ( fillTemplateFunction ( inplaceMethodWithArgs , {
1510
- name : methodWithArg [ 2 ] ,
1511
- method : methodWithArg [ 0 ] ,
1512
- args : args
1513
- } ) ) ;
1514
- var staticMethWithArgs = eval ( fillTemplateFunction ( staticMethodWithArgs , { name : methodWithArg [ 2 ] , args : args } ) ) ;
1515
- for ( var i = 2 ; i < methodWithArg . length ; i ++ ) {
1516
- Matrix . prototype [ methodWithArg [ i ] ] = inplaceMethWithArgs ;
1517
- Matrix [ methodWithArg [ i ] ] = staticMethWithArgs ;
1540
+ if ( methodWithArg [ 1 ] !== 1 ) {
1541
+ var inplaceMethWithArgs = eval ( fillTemplateFunction ( inplaceMethodWithArgs , {
1542
+ name : methodWithArg [ 2 ] ,
1543
+ method : methodWithArg [ 0 ] ,
1544
+ args : args
1545
+ } ) ) ;
1546
+ var staticMethWithArgs = eval ( fillTemplateFunction ( staticMethodWithArgs , { name : methodWithArg [ 2 ] , args : args } ) ) ;
1547
+ for ( var i = 2 ; i < methodWithArg . length ; i ++ ) {
1548
+ Matrix . prototype [ methodWithArg [ i ] ] = inplaceMethWithArgs ;
1549
+ Matrix [ methodWithArg [ i ] ] = staticMethWithArgs ;
1550
+ }
1551
+ } else {
1552
+ var tmplVar = {
1553
+ name : methodWithArg [ 2 ] ,
1554
+ args : args ,
1555
+ method : methodWithArg [ 0 ]
1556
+ } ;
1557
+ console . log ( tmplVar ) ;
1558
+ let inplaceMethod = eval ( fillTemplateFunction ( inplaceMethodWithOneArg , tmplVar ) ) ;
1559
+ let inplaceMethodS = eval ( fillTemplateFunction ( inplaceMethodWithOneArgScalar , tmplVar ) ) ;
1560
+ let inplaceMethodM = eval ( fillTemplateFunction ( inplaceMethodWithOneArgMatrix , tmplVar ) ) ;
1561
+ console . log ( fillTemplateFunction ( staticMethodWithOneArg , tmplVar ) ) ;
1562
+ let staticMethod = eval ( fillTemplateFunction ( staticMethodWithOneArg , tmplVar ) ) ;
1563
+ for ( var i = 2 ; i < methodWithArg . length ; i ++ ) {
1564
+ Matrix . prototype [ methodWithArg [ i ] ] = inplaceMethod ;
1565
+ Matrix . prototype [ methodWithArg [ i ] + 'M' ] = inplaceMethodM ;
1566
+ Matrix . prototype [ methodWithArg [ i ] + 'S' ] = inplaceMethodS ;
1567
+ Matrix [ methodWithArg [ i ] ] = staticMethod ;
1568
+ }
1518
1569
}
1519
1570
}
1520
1571
0 commit comments