/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { Base, Number_$type, markType } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { ErrorValue } from "./ErrorValue";
import { arrayGetLength } from "igniteui-angular-core";
/**
 * @hidden
 */
export class MatrixUtilities extends Base {
    static f(a, b, c, d) {
        let e = MatrixUtilities.c(a, b, c, d);
        let f = MatrixUtilities.g(e, b - 1);
        return Math.pow(-1, d + c) * f;
    }
    static g(a, b) {
        if (b == 1) {
            return a[0][0];
        }
        let c = 0;
        for (let d = 0; d < b; d++) {
            let e = MatrixUtilities.f(a, b, d, 0);
            c += a[d][0] * e;
        }
        return c;
    }
    static a(a, b, c) {
        c = null;
        let d = MatrixUtilities.g(a, b);
        if (d == 0) {
            c = ErrorValue.valueRangeOverflow._a();
            return {
                ret: null,
                p2: c
            };
        }
        let e = 1 / d;
        let f = MatrixUtilities.e(Number_$type, a);
        let g = ((() => {
            let $firstRank;
            let $ret = new Array($firstRank = b);
            let $currRet = $ret;
            for (let $rankInit = 0; $rankInit < $firstRank; $rankInit++) {
                $currRet[$rankInit] = new Array(b);
            }
            return $ret;
        })());
        for (let h = 0; h < b; h++) {
            for (let i = 0; i < b; i++) {
                g[h][i] = e * MatrixUtilities.f(f, b, h, i);
            }
        }
        return {
            ret: g,
            p2: c
        };
    }
    static b(a, b, c) {
        c = null;
        let d = a.getLength(0);
        let e = a.getLength(1);
        let f = ((() => {
            let $firstRank;
            let $ret = new Array($firstRank = d);
            let $currRet = $ret;
            for (let $rankInit = 0; $rankInit < $firstRank; $rankInit++) {
                $currRet[$rankInit] = new Array(e);
            }
            return $ret;
        })());
        for (let g = 0; g < e; g++) {
            for (let h = 0; h < d; h++) {
                let i = a.item(h, g);
                if (i.isError) {
                    c = i.toErrorValue();
                    return {
                        ret: null,
                        p2: c
                    };
                }
                if (i.isString || i.isBoolean) {
                    switch (b) {
                        case 0:
                            c = new ExcelCalcErrorValue(1);
                            return {
                                ret: null,
                                p2: c
                            };
                        case 1:
                            f[h][g] = 0;
                            break;
                        case 2:
                            f[h][g] = NaN;
                            break;
                        default: break;
                    }
                }
                else {
                    f[h][g] = i._toDouble3();
                }
            }
        }
        return {
            ret: f,
            p2: c
        };
    }
    static c(a, b, c, d) {
        let e = ((() => {
            let $firstRank;
            let $ret = new Array($firstRank = b - 1);
            let $currRet = $ret;
            for (let $rankInit = 0; $rankInit < $firstRank; $rankInit++) {
                $currRet[$rankInit] = new Array(b - 1);
            }
            return $ret;
        })());
        for (let f = 0, g = 0; f < b; f++, g++) {
            if (f == c) {
                g--;
                continue;
            }
            for (let h = 0, i = 0; h < b; h++, i++) {
                if (h == d) {
                    i--;
                    continue;
                }
                e[g][i] = a[f][h];
            }
        }
        return e;
    }
    static e($t, a) {
        let b = arrayGetLength(a, 0);
        let c = arrayGetLength(a, 1);
        let d = ((() => {
            let $firstRank;
            let $ret = new Array($firstRank = c);
            let $currRet = $ret;
            for (let $rankInit = 0; $rankInit < $firstRank; $rankInit++) {
                $currRet[$rankInit] = new Array(b);
            }
            return $ret;
        })());
        for (let e = 0; e < b; e++) {
            for (let f = 0; f < c; f++) {
                d[f][e] = a[e][f];
            }
        }
        return d;
    }
    static d(a) {
        let b = a.getLength(0);
        let c = a.getLength(1);
        let d = ((() => {
            let $firstRank;
            let $ret = new Array($firstRank = c);
            let $currRet = $ret;
            for (let $rankInit = 0; $rankInit < $firstRank; $rankInit++) {
                $currRet[$rankInit] = new Array(b);
            }
            return $ret;
        })());
        for (let e = 0; e < b; e++) {
            for (let f = 0; f < c; f++) {
                d[f][e] = a.item(e, f);
            }
        }
        return d;
    }
}
MatrixUtilities.$t = markType(MatrixUtilities, 'MatrixUtilities');
//# sourceMappingURL=MatrixUtilities.js.map