/*
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 * as tslib_1 from "tslib";
import { Base, Number_$type, markType } from "igniteui-angular-core";
import { ExcelCalcErrorValue } from "./ExcelCalcErrorValue";
import { ErrorValue } from "./ErrorValue";
import { arrayGetLength } from "igniteui-angular-core";
/**
 * @hidden
 */
var MatrixUtilities = /** @class */ (function (_super) {
    tslib_1.__extends(MatrixUtilities, _super);
    function MatrixUtilities() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MatrixUtilities.f = function (a, b, c, d) {
        var e = MatrixUtilities.c(a, b, c, d);
        var f = MatrixUtilities.g(e, b - 1);
        return Math.pow(-1, d + c) * f;
    };
    MatrixUtilities.g = function (a, b) {
        if (b == 1) {
            return a[0][0];
        }
        var c = 0;
        for (var d = 0; d < b; d++) {
            var e = MatrixUtilities.f(a, b, d, 0);
            c += a[d][0] * e;
        }
        return c;
    };
    MatrixUtilities.a = function (a, b, c) {
        c = null;
        var d = MatrixUtilities.g(a, b);
        if (d == 0) {
            c = ErrorValue.valueRangeOverflow._a();
            return {
                ret: null,
                p2: c
            };
        }
        var e = 1 / d;
        var f = MatrixUtilities.e(Number_$type, a);
        var g = ((function () {
            var $firstRank;
            var $ret = new Array($firstRank = b);
            var $currRet = $ret;
            for (var $rankInit = 0; $rankInit < $firstRank; $rankInit++) {
                $currRet[$rankInit] = new Array(b);
            }
            return $ret;
        })());
        for (var h = 0; h < b; h++) {
            for (var i = 0; i < b; i++) {
                g[h][i] = e * MatrixUtilities.f(f, b, h, i);
            }
        }
        return {
            ret: g,
            p2: c
        };
    };
    MatrixUtilities.b = function (a, b, c) {
        c = null;
        var d = a.getLength(0);
        var e = a.getLength(1);
        var f = ((function () {
            var $firstRank;
            var $ret = new Array($firstRank = d);
            var $currRet = $ret;
            for (var $rankInit = 0; $rankInit < $firstRank; $rankInit++) {
                $currRet[$rankInit] = new Array(e);
            }
            return $ret;
        })());
        for (var g = 0; g < e; g++) {
            for (var h = 0; h < d; h++) {
                var 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
        };
    };
    MatrixUtilities.c = function (a, b, c, d) {
        var e = ((function () {
            var $firstRank;
            var $ret = new Array($firstRank = b - 1);
            var $currRet = $ret;
            for (var $rankInit = 0; $rankInit < $firstRank; $rankInit++) {
                $currRet[$rankInit] = new Array(b - 1);
            }
            return $ret;
        })());
        for (var f = 0, g = 0; f < b; f++, g++) {
            if (f == c) {
                g--;
                continue;
            }
            for (var h = 0, i = 0; h < b; h++, i++) {
                if (h == d) {
                    i--;
                    continue;
                }
                e[g][i] = a[f][h];
            }
        }
        return e;
    };
    MatrixUtilities.e = function ($t, a) {
        var b = arrayGetLength(a, 0);
        var c = arrayGetLength(a, 1);
        var d = ((function () {
            var $firstRank;
            var $ret = new Array($firstRank = c);
            var $currRet = $ret;
            for (var $rankInit = 0; $rankInit < $firstRank; $rankInit++) {
                $currRet[$rankInit] = new Array(b);
            }
            return $ret;
        })());
        for (var e = 0; e < b; e++) {
            for (var f = 0; f < c; f++) {
                d[f][e] = a[e][f];
            }
        }
        return d;
    };
    MatrixUtilities.d = function (a) {
        var b = a.getLength(0);
        var c = a.getLength(1);
        var d = ((function () {
            var $firstRank;
            var $ret = new Array($firstRank = c);
            var $currRet = $ret;
            for (var $rankInit = 0; $rankInit < $firstRank; $rankInit++) {
                $currRet[$rankInit] = new Array(b);
            }
            return $ret;
        })());
        for (var e = 0; e < b; e++) {
            for (var f = 0; f < c; f++) {
                d[f][e] = a.item(e, f);
            }
        }
        return d;
    };
    MatrixUtilities.$t = markType(MatrixUtilities, 'MatrixUtilities');
    return MatrixUtilities;
}(Base));
export { MatrixUtilities };
//# sourceMappingURL=MatrixUtilities.js.map