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Ed,CACI,aAAoB,eAA+B,IAAnB,EAAS,MACzC,aAAoB,UAAY,EAAS,OAE7C,EACK,OAAO,UAAU,KACV,CAAC,EAAG,EAAG,EAAG,GAAG,SAAS,KACtB,OAAO,UAAU,GACzB,UAAU,qCAEd,CACwB,mBAAb,EACP,UAAU,oCAGlB,GAAI,EACA,OAAO,EAAS,EAAW,MAE/B,UAAU,KAAK,CACX,MAAO,KAAK,MACZ,IAAK,EAAS,OACd,KAAM,EACN,MAAO,EACP,SAAU,GAElB,EACO,CACX,CApGkB,GA0GlB,SAAS,QAAQ,GACb,IAAI,EAAY,cAAc,CAC1B,CACoB,iBAAT,EACP,UAAU,EAAO,cAAgB,EAAO,gCAE5C,EACK,GAAG,WAAW,GACf,UAAU,EAAO,sBAGzB,IACI,OAAO,IAAI,YAAY,GAAa,IAAI,IAAI,SAAS,GACzD,CACA,MAAO,GACH,OAAO,IAAI,YAAY,EAC3B,CACJ,CACA,QAAQ,QAAU","file":"/npm/@bonniernews/xgboost@2.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@bonniernews/xgboost@2.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar bindings = require(\"bindings\");\nvar fs = require(\"fs\");\nvar async = require(\"async\");\nvar xgb = bindings('xgboost');\nfunction validateInput(input, typeInvalid, typeError) {\n    var value;\n    var error;\n    if (input instanceof Error) {\n        // input is an error, pass though error\n        value = undefined;\n        error = input;\n    }\n    else if (input === undefined || typeInvalid === true) {\n        // invalid input type, return type error\n        value = undefined;\n        error = typeError;\n    }\n    else {\n        value = input;\n        error = undefined;\n    }\n    return {\n        value: value,\n        error: error\n    };\n}\n// Result Object\n/**\n * @property value {Float32Array | number | undefined} - prediction result or method result\n * @property error {Error} - error status\n */\nvar Result = (function () {\n    function Result(input) {\n        var result = validateInput(input, !(input instanceof Float32Array) && typeof input !== 'number', TypeError('result should be Float32Array or number'));\n        this.value = result.value;\n        this.error = result.error;\n    }\n    return Result;\n}());\n// XGMatrix Object\n/**\n * @property matrix {internal} - readonly property\n * @property error {Error} - error status\n */\nvar XGMatrix = (function () {\n    function XGMatrix(input) {\n        var result = validateInput(input, !(input instanceof xgb.CXGMatrix), TypeError('input should be xgb.CXGMatrix'));\n        this.matrix = result.value;\n        this.error = result.error;\n    }\n    // Matrix column size\n    /**\n     * @return {Result} column size\n     */\n    XGMatrix.prototype.col = function () {\n        if (this.error) {\n            return new Result(this.error);\n        }\n        try {\n            return new Result(this.matrix.col());\n        }\n        catch (err) {\n            return new Result(err);\n        }\n    };\n    // Matrix row size\n    /**\n     * @return {Result} row size\n     */\n    XGMatrix.prototype.row = function () {\n        if (this.error) {\n            return new Result(this.error);\n        }\n        try {\n            return new Result(this.matrix.row());\n        }\n        catch (err) {\n            return new Result(err);\n        }\n    };\n    return XGMatrix;\n}());\nfunction typeCheckList(inputList) {\n    for (var _i = 0, inputList_1 = inputList; _i < inputList_1.length; _i++) {\n        var value = inputList_1[_i];\n        if (value[0])\n            return value[1];\n    }\n    return undefined;\n}\n// Create xgboost matrix from array\n/**\n * @param data {Float32Array} - input matrix with row-major order\n * @param row {Integer} - matrix row\n * @param col {Integer} - matrix col\n * @param missing {Number}[NaN] - missing value place holder\n * @return {XGMatrix} xgboost matrix\n */\nfunction matrix(data, row, col, missing) {\n    if (missing === void 0) { missing = NaN; }\n    var typeError = typeCheckList([\n        [\n            !(data instanceof Float32Array),\n            TypeError('data should be Float32Array')\n        ],\n        [\n            !(typeof missing === 'number'),\n            TypeError('missing should be Number')\n        ],\n        [\n            !Number.isInteger(col) || !Number.isInteger(row),\n            TypeError('col and row should be Integer')\n        ],\n        [\n            col * row !== data.length,\n            TypeError(\"col*row \" + col * row + \" != input length \" + data.length)\n        ]\n    ]);\n    try {\n        return new XGMatrix(typeError\n            || new xgb.CXGMatrix(0, data, row, col, missing));\n    }\n    catch (err) {\n        return new XGMatrix(err);\n    }\n}\nexports.matrix = matrix;\n// Create xgboost matrix from file\n/**\n * @param file {string} - input matrix file path\n * @return {XGMatrix} xgboost matrix\n */\nfunction restoreMatrix(file) {\n    var typeError = typeCheckList([\n        [\n            typeof file !== 'string',\n            TypeError(file + \" is \" + typeof file + \", but it should be a string\")\n        ],\n        [\n            !fs.existsSync(file),\n            TypeError(file + \" does not exist\")\n        ],\n    ]);\n    try {\n        return new XGMatrix(typeError || new xgb.CXGMatrix(1, file));\n    }\n    catch (err) {\n        return new XGMatrix(err);\n    }\n}\nexports.restoreMatrix = restoreMatrix;\nfunction checkCSCR(data, indptr, indices, n) {\n    return typeCheckList([\n        [\n            !(data instanceof Float32Array),\n            TypeError('data should be Float32Array'),\n        ],\n        [\n            !(indptr instanceof Uint32Array),\n            TypeError('indptr should be Uint32Array'),\n        ],\n        [\n            !(indices instanceof Uint32Array),\n            TypeError('indices should be Uint32Array'),\n        ],\n        [\n            !Number.isInteger(n),\n            TypeError('n should be Integer'),\n        ],\n    ]);\n}\n// Create xgboost matrix from CSC format\n/**\n * @param data {Float32Array} - input matrix\n * @param indptr {Uint32Array} -  pointer to col headers\n * @param indices {Uint32Array} - findex\n * @param n {Integer}[0] - number of rows; when it's set to 0, then guess from data\n * @return {XGMatrix} xgboost matrix\n */\nfunction matrixFromCSC(data, indptr, indices, n) {\n    if (n === void 0) { n = 0; }\n    var typeError = checkCSCR(data, indptr, indices, n);\n    try {\n        return new XGMatrix(typeError || new xgb.CXGMatrix(2, data, indptr, indices, indptr.length, data.length, n));\n    }\n    catch (err) {\n        return new XGMatrix(err);\n    }\n}\nexports.matrixFromCSC = matrixFromCSC;\n// Create xgboost matrix from CSC format\n/**\n * @param data {Float32Array} - input matrix\n * @param indptr {Uint32Array} -  pointer to row headers\n * @param indices {Uint32Array} - findex\n * @param n {Integer}[0] - number of columns; when it's set to 0, then guess from data\n * @return {XGMatrix} xgboost matrix\n */\nfunction matrixFromCSR(data, indptr, indices, n) {\n    if (n === void 0) { n = 0; }\n    var typeError = checkCSCR(data, indptr, indices, n);\n    try {\n        return new XGMatrix(typeError ||\n            new xgb.CXGMatrix(3, data, indptr, indices, indptr.length, data.length, n));\n    }\n    catch (err) {\n        return new XGMatrix(err);\n    }\n}\nexports.matrixFromCSR = matrixFromCSR;\n// queue for xgboost task, libuv thread is not safe for xgboost\nvar taskQueue = function setupQueue() {\n    return async.queue(function (task, callback) {\n        task.model.predictAsync(task.mat, task.mask, task.ntree, function (err, res) {\n            task.callback(err, res);\n            task = undefined;\n            callback();\n        });\n    }, 1);\n}();\n// XGModel Object\n/**\n * @property model {internal} - private property\n * @property error {Error} - error status\n */\nvar XGModelBase = (function () {\n    function XGModelBase(model) {\n        var result = validateInput(model, !(model instanceof xgb.CXGModel), TypeError('model should be xgb.CXGModel'));\n        this.model = result.value;\n        this.error = result.error;\n    }\n    // Predict result\n    /**\n     * @param xgmatrix {XGMatrix} - input data, created from dataFrom*() functions\n     * @param mask {Integer}[0] - options taken in prediction, possible values\n     *          0:normal prediction\n     *          1:output margin instead of transformed value\n     *          2:output leaf index of trees instead of leaf value, note leaf index is unique per tree\n     *          4:output feature contributions to individual predictions\n     * @param ntree {Integer}[0] - limit number of trees used for prediction, this is only valid for boosted trees\n     * when the parameter is set to 0, we will use all the trees\n     * @return {Result} predicted values\n     */\n    XGModelBase.prototype.predict = function (xgmatrix, mask, ntree) {\n        if (mask === void 0) { mask = 0; }\n        if (ntree === void 0) { ntree = 0; }\n        var typeError = typeCheckList([\n            [\n                this.error !== undefined,\n                this.error,\n            ],\n            [\n                !(xgmatrix instanceof XGMatrix),\n                TypeError('input should be XGMatrix'),\n            ],\n            [\n                xgmatrix instanceof XGMatrix && xgmatrix.error !== undefined,\n                xgmatrix instanceof XGMatrix && xgmatrix.error,\n            ],\n            [\n                !Number.isInteger(mask)\n                    || ![0, 1, 2, 4].includes(mask)\n                    || !Number.isInteger(ntree),\n                TypeError('mask and ntree should be Integer'),\n            ],\n        ]);\n        try {\n            return new Result(typeError\n                || this.model.predict(xgmatrix.matrix, mask, ntree));\n        }\n        catch (err) {\n            return new Result(err);\n        }\n    };\n    // Predict result - Async\n    /**\n     * @param xgmatrix {XGMatrix} - input data, created from dataFrom*() functions\n     * @param mask {Integer}[0] - options taken in prediction, possible values\n     *          0:normal prediction\n     *          1:output margin instead of transformed value\n     *          2:output leaf index of trees instead of leaf value, note leaf index is unique per tree\n     *          4:output feature contributions to individual predictions\n     * @param ntree {Integer}[0] - limit number of trees used for prediction, this is only valid for boosted trees\n     * when the parameter is set to 0, we will use all the trees\n     * @param callback {Function} - callback function\n     */\n    XGModelBase.prototype.predictAsync = function (xgmatrix, mask, ntree, callback) {\n        if (mask === void 0) { mask = 0; }\n        if (ntree === void 0) { ntree = 0; }\n        var typeError = typeCheckList([\n            [\n                this.error !== undefined,\n                this.error,\n            ],\n            [\n                !(xgmatrix instanceof XGMatrix),\n                TypeError('input should be XGMatrix'),\n            ],\n            [\n                xgmatrix instanceof XGMatrix && xgmatrix.error !== undefined,\n                xgmatrix instanceof XGMatrix && xgmatrix.error,\n            ],\n            [\n                !Number.isInteger(mask)\n                    || ![0, 1, 2, 4].includes(mask)\n                    || !Number.isInteger(ntree),\n                TypeError('mask and ntree should be Integer'),\n            ],\n            [\n                typeof callback !== 'function',\n                TypeError('callback should be a Function'),\n            ],\n        ]);\n        if (typeError) {\n            return callback(typeError, null);\n        }\n        taskQueue.push({\n            model: this.model,\n            mat: xgmatrix.matrix,\n            mask: mask,\n            ntree: ntree,\n            callback: callback,\n        });\n    };\n    return XGModelBase;\n}());\n// Create xgboost model from file\n/**\n * @param file {string} - model file path\n * @return {XGModel} xgboost model\n */\nfunction XGModel(file) {\n    var typeError = typeCheckList([\n        [\n            typeof file !== 'string',\n            TypeError(file + \" is \" + typeof file + \", but it should be a string\"),\n        ],\n        [\n            !fs.existsSync(file),\n            TypeError(file + \" does not exist\"),\n        ],\n    ]);\n    try {\n        return new XGModelBase(typeError || new xgb.CXGModel(file));\n    }\n    catch (err) {\n        return new XGModelBase(err);\n    }\n}\nexports.XGModel = XGModel;\n"]}