@@ -756,20 +756,14 @@ export class AbstractMatrix {
756
756
757
757
mmul ( other ) {
758
758
other = Matrix . checkMatrix ( other ) ;
759
- if ( this . columns !== other . rows ) {
760
- // eslint-disable-next-line no-console
761
- console . warn (
762
- 'Number of columns of left matrix are not equal to number of rows of right matrix.'
763
- ) ;
764
- }
765
759
766
760
var m = this . rows ;
767
761
var n = this . columns ;
768
762
var p = other . columns ;
769
763
770
764
var result = new Matrix ( m , p ) ;
771
765
772
- var Bcolj = new Array ( n ) ;
766
+ var Bcolj = new Float64Array ( n ) ;
773
767
for ( var j = 0 ; j < p ; j ++ ) {
774
768
for ( var k = 0 ; k < n ; k ++ ) {
775
769
Bcolj [ k ] = other . get ( k , j ) ;
@@ -1434,10 +1428,7 @@ export default class Matrix extends AbstractMatrix {
1434
1428
this . data = [ ] ;
1435
1429
if ( Number . isInteger ( nColumns ) && nColumns > 0 ) {
1436
1430
for ( let i = 0 ; i < nRows ; i ++ ) {
1437
- this . data . push ( [ ] ) ;
1438
- for ( let j = 0 ; j < nColumns ; j ++ ) {
1439
- this . data [ i ] . push ( 0 ) ;
1440
- }
1431
+ this . data . push ( new Float64Array ( nColumns ) ) ;
1441
1432
}
1442
1433
} else {
1443
1434
throw new TypeError ( 'nColumns must be a positive integer' ) ;
@@ -1457,7 +1448,7 @@ export default class Matrix extends AbstractMatrix {
1457
1448
if ( arrayData [ i ] . length !== nColumns ) {
1458
1449
throw new RangeError ( 'Inconsistent array dimensions' ) ;
1459
1450
}
1460
- this . data . push ( arrayData [ i ] . slice ( ) ) ;
1451
+ this . data . push ( Float64Array . from ( arrayData [ i ] ) ) ;
1461
1452
}
1462
1453
} else {
1463
1454
throw new TypeError (
@@ -1494,7 +1485,7 @@ export default class Matrix extends AbstractMatrix {
1494
1485
index = this . rows ;
1495
1486
}
1496
1487
checkRowIndex ( this , index , true ) ;
1497
- array = checkRowVector ( this , array , true ) ;
1488
+ array = Float64Array . from ( checkRowVector ( this , array , true ) ) ;
1498
1489
this . data . splice ( index , 0 , array ) ;
1499
1490
this . rows += 1 ;
1500
1491
return this ;
@@ -1506,7 +1497,14 @@ export default class Matrix extends AbstractMatrix {
1506
1497
throw new RangeError ( 'A matrix cannot have less than one column' ) ;
1507
1498
}
1508
1499
for ( var i = 0 ; i < this . rows ; i ++ ) {
1509
- this . data [ i ] . splice ( index , 1 ) ;
1500
+ const newRow = new Float64Array ( this . columns - 1 ) ;
1501
+ for ( let j = 0 ; j < index ; j ++ ) {
1502
+ newRow [ j ] = this . data [ i ] [ j ] ;
1503
+ }
1504
+ for ( let j = index + 1 ; j < this . columns ; j ++ ) {
1505
+ newRow [ j - 1 ] = this . data [ i ] [ j ] ;
1506
+ }
1507
+ this . data [ i ] = newRow ;
1510
1508
}
1511
1509
this . columns -= 1 ;
1512
1510
return this ;
@@ -1520,7 +1518,16 @@ export default class Matrix extends AbstractMatrix {
1520
1518
checkColumnIndex ( this , index , true ) ;
1521
1519
array = checkColumnVector ( this , array ) ;
1522
1520
for ( var i = 0 ; i < this . rows ; i ++ ) {
1523
- this . data [ i ] . splice ( index , 0 , array [ i ] ) ;
1521
+ const newRow = new Float64Array ( this . columns + 1 ) ;
1522
+ let j = 0 ;
1523
+ for ( ; j < index ; j ++ ) {
1524
+ newRow [ j ] = this . data [ i ] [ j ] ;
1525
+ }
1526
+ newRow [ j ++ ] = array [ i ] ;
1527
+ for ( ; j < this . columns + 1 ; j ++ ) {
1528
+ newRow [ j ] = this . data [ i ] [ j - 1 ] ;
1529
+ }
1530
+ this . data [ i ] = newRow ;
1524
1531
}
1525
1532
this . columns += 1 ;
1526
1533
return this ;
0 commit comments