Skip to content

Commit 90532ef

Browse files
zafaralitargos
authored andcommitted
feat(det): add determinant based on LU decomposition
1 parent b82ac3c commit 90532ef

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/abstractMatrix.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
module.exports = abstractMatrix;
44

5+
var LuDecomposition = require('./dc/lu');
56
var arrayUtils = require('ml-array-utils');
67
var util = require('./util');
78
var MatrixTransposeView = require('./views/transpose');
@@ -1511,7 +1512,6 @@ function abstractMatrix(superCtor) {
15111512
*
15121513
* @return {number}
15131514
*/
1514-
15151515
det(){
15161516
if(this.isSquare()){
15171517
if(this.columns === 2){
@@ -1539,9 +1539,8 @@ function abstractMatrix(superCtor) {
15391539
return a * subMatrix0.det() - b * subMatrix1.det() + c * subMatrix2.det();
15401540

15411541
}else{
1542-
// general purpose determinant
1543-
1544-
throw Error('Not implemented yet');
1542+
// general purpose determinant using the LU decomposition
1543+
return new LuDecomposition(this, {skipCheck:true}).determinant;
15451544
}
15461545

15471546
}else{

src/dc/lu.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
var Matrix = require('../matrix');
44

55
// https://github.com/lutzroeder/Mapack/blob/master/Source/LuDecomposition.cs
6-
function LuDecomposition(matrix) {
6+
function LuDecomposition(matrix, options) {
77
if (!(this instanceof LuDecomposition)) {
88
return new LuDecomposition(matrix);
99
}
10-
matrix = Matrix.checkMatrix(matrix);
10+
11+
options = options || {};
12+
13+
if(!options.skipCheck){
14+
matrix = Matrix.checkMatrix(matrix);
15+
}
1116

1217
var lu = matrix.clone(),
1318
rows = lu.rows,

0 commit comments

Comments
 (0)