lib/ops.js
function eig(A) {
    if (A.shape.length !== 2) {
        throw new Error('Input is not matrix');
    }
    if (A.shape[0] !== A.shape[1]) {
        throw new Error('Input is not square matrix');
    }
    var n = A.shape[0];
    var copyA = A.clone();
    copyA.swapOrder();
    var _a = lapack.geev(copyA.data, n, true, true), WR = _a[0], WI = _a[1], VL = _a[2], VR = _a[3];
    var eigval = new common_1.NDArray({ shape: [n] });
    var eigvecL = new common_1.NDArray({ shape: [n, n] });
    var eigvecR = new common_1.NDArray({ shape: [n, n] });
    for (var i = 0; i < n; i++) {
        if (common_1.iszero(WI[i])) {
            eigval.set(i, WR[i]);
        }
        else {
            eigval.set(i, new common_1.Complex(WR[i], WI[i]));
        }
    }
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < n;) {
            if (common_1.iszero(WI[j])) {
                // We want to extract eigen-vectors in i'th column of VL and VR
                eigvecL.set(i, j, VL[j * n + i]);
                eigvecR.set(i, j, VR[j * n + i]);
                j += 1;
            }
            else {
                // i-th eigen vector will be complex and
                // i+1-th eigen vector will be its conjugate
                // There are n eigen-vectors for i'th eigen-value
                eigvecL.set(i, j, new common_1.Complex(VL[j * n + i], VL[(j + 1) * n + i]));
                eigvecL.set(i, j + 1, new common_1.Complex(VL[j * n + i], -VL[(j + 1) * n + i]));
                eigvecR.set(i, j, new common_1.Complex(VR[j * n + i], VR[(j + 1) * n + i]));
                eigvecR.set(i, j + 1, new common_1.Complex(VR[j * n + i], -VR[(j + 1) * n + i]));
                j += 2;
            }
        }
    }
    return [eigval, eigvecL, eigvecR];
}
function eig(A) {
    if (A.shape.length !== 2) {
        throw new Error('Input is not matrix');
    }
    if (A.shape[0] !== A.shape[1]) {
        throw new Error('Input is not square matrix');
    }
    var n = A.shape[0];
    var copyA = A.clone();
    copyA.swapOrder();
    var _a = lapack.geev(copyA.data, n, true, true), WR = _a[0], WI = _a[1], VL = _a[2], VR = _a[3];
    var eigval = new common_1.NDArray({ shape: [n] });
    var eigvecL = new common_1.NDArray({ shape: [n, n] });
    var eigvecR = new common_1.NDArray({ shape: [n, n] });
    for (var i = 0; i < n; i++) {
        if (common_1.iszero(WI[i])) {
            eigval.set(i, WR[i]);
        }
        else {
            eigval.set(i, new common_1.Complex(WR[i], WI[i]));
        }
    }
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < n;) {
            if (common_1.iszero(WI[j])) {
                // We want to extract eigen-vectors in i'th column of VL and VR
                eigvecL.set(i, j, VL[j * n + i]);
                eigvecR.set(i, j, VR[j * n + i]);
                j += 1;
            }
            else {
                // i-th eigen vector will be complex and
                // i+1-th eigen vector will be its conjugate
                // There are n eigen-vectors for i'th eigen-value
                eigvecL.set(i, j, new common_1.Complex(VL[j * n + i], VL[(j + 1) * n + i]));
                eigvecL.set(i, j + 1, new common_1.Complex(VL[j * n + i], -VL[(j + 1) * n + i]));
                eigvecR.set(i, j, new common_1.Complex(VR[j * n + i], VR[(j + 1) * n + i]));
                eigvecR.set(i, j + 1, new common_1.Complex(VR[j * n + i], -VR[(j + 1) * n + i]));
                j += 2;
            }
        }
    }
    return [eigval, eigvecL, eigvecR];
}
function eig ( A ) { if ( A . shape . length !== 2 ) { throw new Error ( 'Input is not matrix' ) ; } if ( A . shape [ 0 ] !== A . shape [ 1 ] ) { throw new Error ( 'Input is not square matrix' ) ; } var n = A . shape [ 0 ] ; var copyA = A . clone ( ) ; copyA . swapOrder ( ) ; var _a = lapack . geev ( copyA . data , n , true , true ) , WR = _a [ 0 ] , WI = _a [ 1 ] , VL = _a [ 2 ] , VR = _a [ 3 ] ; var eigval = new common_1 . NDArray ( { shape : [ n ] } ) ; var eigvecL = new common_1 . NDArray ( { shape : [ n , n ] } ) ; var eigvecR = new common_1 . NDArray ( { shape : [ n , n ] } ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( common_1 . iszero ( WI [ i ] ) ) { eigval . set ( i , WR [ i ] ) ; } else { eigval . set ( i , new common_1 . Complex ( WR [ i ] , WI [ i ] ) ) ; } } for ( var i = 0 ; i < n ; i ++ ) { for ( var j = 0 ; j < n ; ) { if ( common_1 . iszero ( WI [ j ] ) ) { // We want to extract eigen-vectors in i'th column of VL and VR eigvecL . set ( i , j , VL [ j * n + i ] ) ; eigvecR . set ( i , j , VR [ j * n + i ] ) ; j += 1 ; } else { // i-th eigen vector will be complex and // i+1-th eigen vector will be its conjugate // There are n eigen-vectors for i'th eigen-value eigvecL . set ( i , j , new common_1 . Complex ( VL [ j * n + i ] , VL [ ( j + 1 ) * n + i ] ) ) ; eigvecL . set ( i , j + 1 , new common_1 . Complex ( VL [ j * n + i ] , - VL [ ( j + 1 ) * n + i ] ) ) ; eigvecR . set ( i , j , new common_1 . Complex ( VR [ j * n + i ] , VR [ ( j + 1 ) * n + i ] ) ) ; eigvecR . set ( i , j + 1 , new common_1 . Complex ( VR [ j * n + i ] , - VR [ ( j + 1 ) * n + i ] ) ) ; j += 2 ; } } } return [ eigval , eigvecL , eigvecR ] ; }
Compute Eigen values and left, right eigen vectors of given Matrix
Compute Eigen values and left right eigen vectors of given Matrix