UNPKG

nsfwjs-patched

Version:

Detect NSFW content client-side with fixes of buffer and latest packages

410 lines 2.73 MB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).nsfwjs=e()}}((function(){return function e(t,n,r){function a(i,s){if(!n[i]){if(!t[i]){var u="function"==typeof require&&require;if(!s&&u)return u(i,!0);if(o)return o(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[i]={exports:{}};t[i][0].call(l.exports,(function(e){return a(t[i][1][e]||e)}),l,l.exports,e,t,n,r)}return n[i].exports}for(var o="function"==typeof require&&require,i=0;i<r.length;i++)a(r[i]);return a}({1:[function(e,t,n){(function(t){(function(){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var a=Object.getOwnPropertyDescriptor(t,n);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,a)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return a(t,e),t},i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,a,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.return=s(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(u){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(o=0)),o;)try{if(n=1,r&&(a=2&s[0]?r.return:s[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,s[1])).done)return a;switch(r=0,a&&(s=[2&s[0],a.value]),s[0]){case 0:case 1:a=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(a=o.trys,(a=a.length>0&&a[a.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!a||s[1]>a[0]&&s[1]<a[3])){o.label=s[1];break}if(6===s[0]&&o.label<a[1]){o.label=a[1],a=s;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(s);break}a[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],r=0}finally{n=a=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}},u=this&&this.__spreadArray||function(e,t,n){if(n||2===arguments.length)for(var r,a=0,o=t.length;a<o;a++)!r&&a in t||(r||(r=Array.prototype.slice.call(t,0,a)),r[a]=t[a]);return e.concat(r||Array.prototype.slice.call(t))};Object.defineProperty(n,"__esModule",{value:!0}),n.NSFWJS=void 0,n.load=function(e){return i(this,arguments,void 0,(function(e,t){var n,r,a;return void 0===t&&(t={size:f}),s(this,(function(o){switch(o.label){case 0:if(null==c)throw new Error("Cannot find TensorFlow.js. If you are using a <script> tag, please also include @tensorflow/tfjs on the page before using this model.");return void 0===e?(e=d,console.info("%cBy not specifying 'modelOrUrl' parameter, you're using the default model: '".concat(e,"'. See NSFWJS docs for instructions on hosting your own model (https://github.com/infinitered/nsfwjs?tab=readme-ov-file#host-your-own-model)."),"color: lightblue")):g(e)&&(console.info("%cYou're using the model: '".concat(e,"'. See NSFWJS docs for instructions on hosting your own model (https://github.com/infinitered/nsfwjs?tab=readme-ov-file#host-your-own-model)."),"color: lightblue"),t=null!==(a=p[e].options)&&void 0!==a?a:t),t.size=(null==t?void 0:t.size)||f,[4,x(e)];case 1:return n=o.sent(),[4,(r=new k(n,t)).load()];case 2:return o.sent(),[2,r]}}))}))};var c=o(e("@tensorflow/tfjs")),l=e("buffer/"),h=e("./nsfw_classes"),p={MobileNetV2:{numOfWeightBundles:1},MobileNetV2Mid:{numOfWeightBundles:2,options:{type:"graph"}},InceptionV3:{numOfWeightBundles:6,options:{size:299}}},d="MobileNetV2",f=224,m=function(){if("undefined"!=typeof globalThis)return globalThis;if(void 0!==t)return t;if("undefined"!=typeof window)return window;if("undefined"!=typeof self)return self;throw new Error("Unable to locate global object")};function g(e){return!!e&&e in p}var v=function(t){return i(void 0,void 0,void 0,(function(){var n,r;return s(this,(function(a){switch(a.label){case 0:return(n=m().model)?[2,n]:"MobileNetV2"!==t?[3,2]:[4,Promise.resolve().then((function(){return o(e("./model_imports/mobilenet_v2"))}))];case 1:return r=a.sent().modelJson,[3,6];case 2:return"MobileNetV2Mid"!==t?[3,4]:[4,Promise.resolve().then((function(){return o(e("./model_imports/mobilenet_v2_mid"))}))];case 3:return r=a.sent().modelJson,[3,6];case 4:return"InceptionV3"!==t?[3,6]:[4,Promise.resolve().then((function(){return o(e("./model_imports/inception_v3"))}))];case 5:r=a.sent().modelJson,a.label=6;case 6:return[4,r()];case 7:return[2,a.sent().default]}}))}))},y=function(t){return i(void 0,void 0,void 0,(function(){var n,r,a,i,c,l,h,d,f,g;return s(this,(function(s){switch(s.label){case 0:n=p[t].numOfWeightBundles,r=[],a=0,s.label=1;case 1:return a<n?(i="group1-shard".concat(a+1,"of").concat(n),c=i.replace(/-/g,"_"),(l=m()[c])?(r.push(((f={})[i]=l,f)),[3,10]):[3,2]):[3,11];case 2:return h=void 0,"MobileNetV2"!==t?[3,4]:[4,Promise.resolve().then((function(){return o(e("./model_imports/mobilenet_v2"))}))];case 3:return h=s.sent().weightBundles,[3,8];case 4:return"MobileNetV2Mid"!==t?[3,6]:[4,Promise.resolve().then((function(){return o(e("./model_imports/mobilenet_v2_mid"))}))];case 5:return h=s.sent().weightBundles,[3,8];case 6:return"InceptionV3"!==t?[3,8]:[4,Promise.resolve().then((function(){return o(e("./model_imports/inception_v3"))}))];case 7:h=s.sent().weightBundles,s.label=8;case 8:return[4,h[a]()];case 9:d=s.sent().default,r.push(((g={})[i]=d,g)),s.label=10;case 10:return a++,[3,1];case 11:return[2,Object.assign.apply(Object,u([{}],r,!1))]}}))}))};function b(e){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,y(e)];case 1:return[2,t.sent()];case 2:throw t.sent(),new Error("Could not load the weight data. Make sure you are importing the correct shard files from the models directory. Ref: https://github.com/infinitered/nsfwjs?tab=readme-ov-file#browserify");case 3:return[2]}}))}))}function x(e){return i(this,void 0,void 0,(function(){var t,n;return s(this,(function(r){switch(r.label){case 0:if(!g(e))return[2,e];r.label=1;case 1:return r.trys.push([1,4,,5]),[4,v(e)];case 2:return t=r.sent(),[4,b(e)];case 3:return n=r.sent(),[2,new w(t,n)];case 4:throw r.sent(),new Error("Could not load the model. Make sure you are importing the model.min.js bundle. Ref: https://github.com/infinitered/nsfwjs?tab=readme-ov-file#browserify");case 5:return[2]}}))}))}var w=function(){function e(e,t){this.modelJson=e,this.weightDataBase64=t}return e.prototype.arrayBufferFromBase64=function(e){for(var t=l.Buffer.from(e,"base64").toString("binary"),n=t.length,r=new Uint8Array(n),a=0;a<n;a++)r[a]=t.charCodeAt(a);return r.buffer},e.prototype.load=function(){return i(this,void 0,void 0,(function(){var e,t,n,r,a,o,i,u,c,l,h,p,d,f;return s(this,(function(s){if(e={modelTopology:this.modelJson.modelTopology,format:this.modelJson.format,generatedBy:this.modelJson.generatedBy,convertedBy:this.modelJson.convertedBy},null!=this.modelJson.weightsManifest){for(t=[],n=[],r=0,a=this.modelJson.weightsManifest;r<a.length;r++){for(o=a[r],i=0,u=o.paths;i<u.length;i++){if(c=u[i],!(l=this.weightDataBase64[c]))throw new Error("Could not find the weight data. Make sure you are importing the correct weight bundle for the model: ".concat(c,".min.js."));h=this.arrayBufferFromBase64(l),n.push(new Uint8Array(h))}t.push.apply(t,o.weights)}for(e.weightSpecs=t,p=new Uint8Array(n.reduce((function(e,t){return e+t.length}),0)),d=0,f=0;f<n.length;f++)p.set(n[f],d),d+=n[f].byteLength;e.weightData=p.buffer}return null!=this.modelJson.trainingConfig&&(e.trainingConfig=this.modelJson.trainingConfig),null!=this.modelJson.userDefinedMetadata&&(e.userDefinedMetadata=this.modelJson.userDefinedMetadata),[2,e]}))}))},e}(),k=function(){function e(e,t){this.intermediateModels={},this.options=t,this.normalizationOffset=c.scalar(255),this.urlOrIOHandler=e,"string"!=typeof e||e.startsWith("indexeddb://")||e.startsWith("localstorage://")||e.endsWith("model.json")?this.urlOrIOHandler=e:this.urlOrIOHandler="".concat(e,"model.json")}return e.prototype.load=function(){return i(this,void 0,void 0,(function(){var e,t,n,r,a,o=this;return s(this,(function(i){switch(i.label){case 0:return e=this.options,t=e.size,"graph"!==e.type?[3,2]:(n=this,[4,c.loadGraphModel(this.urlOrIOHandler)]);case 1:return n.model=i.sent(),[3,4];case 2:return r=this,[4,c.loadLayersModel(this.urlOrIOHandler)];case 3:r.model=i.sent(),this.endpoints=this.model.layers.map((function(e){return e.name})),i.label=4;case 4:return[4,(a=c.tidy((function(){return o.model.predict(c.zeros([1,t,t,3]))}))).data()];case 5:return i.sent(),a.dispose(),[2]}}))}))},e.prototype.infer=function(e,t){var n=this;if(null!=t&&-1===this.endpoints.indexOf(t))throw new Error("Unknown endpoint ".concat(t,". Available endpoints: ").concat(this.endpoints,"."));return c.tidy((function(){e instanceof c.Tensor||(e=c.browser.fromPixels(e));var r=e.toFloat().div(n.normalizationOffset),a=r,o=n.options.size;if(e.shape[0]!==o||e.shape[1]!==o){a=c.image.resizeBilinear(r,[o,o],!0)}var i,s=a.reshape([1,o,o,3]);if(null==t)i=n.model;else{if(n.model.hasOwnProperty("layers")&&null==n.intermediateModels[t]){var u=n.model.layers.find((function(e){return e.name===t}));n.intermediateModels[t]=c.model({inputs:n.model.inputs,outputs:u.output})}i=n.intermediateModels[t]}return i.predict(s)}))},e.prototype.classify=function(e){return i(this,arguments,void 0,(function(e,t){var n,r;return void 0===t&&(t=5),s(this,(function(a){switch(a.label){case 0:return[4,S(n=this.infer(e),t)];case 1:return r=a.sent(),n.dispose(),[2,r]}}))}))},e}();function S(e,t){return i(this,void 0,void 0,(function(){var n,r,a,o,i,u;return s(this,(function(s){switch(s.label){case 0:return[4,e.data()];case 1:for(n=s.sent(),r=[],u=0;u<n.length;u++)r.push({value:n[u],index:u});for(r.sort((function(e,t){return t.value-e.value})),a=new Float32Array(t),o=new Int32Array(t),u=0;u<t;u++)a[u]=r[u].value,o[u]=r[u].index;for(i=[],u=0;u<o.length;u++)i.push({className:h.NSFW_CLASSES[o[u]],probability:a[u]});return[2,i]}}))}))}n.NSFWJS=k}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./model_imports/inception_v3":2,"./model_imports/mobilenet_v2":3,"./model_imports/mobilenet_v2_mid":4,"./nsfw_classes":5,"@tensorflow/tfjs":13,"buffer/":19}],2:[function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var a=Object.getOwnPropertyDescriptor(t,n);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,a)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return a(t,e),t};Object.defineProperty(n,"__esModule",{value:!0}),n.weightBundles=n.modelJson=void 0;n.modelJson=function(){return Promise.resolve("".concat("../models/inception_v3/model.min.js")).then((function(t){return o(e(t))}))},n.weightBundles=[function(){return Promise.resolve("".concat("../models/inception_v3/group1-shard1of6.min.js")).then((function(t){return o(e(t))}))},function(){return Promise.resolve("".concat("../models/inception_v3/group1-shard2of6.min.js")).then((function(t){return o(e(t))}))},function(){return Promise.resolve("".concat("../models/inception_v3/group1-shard3of6.min.js")).then((function(t){return o(e(t))}))},function(){return Promise.resolve("".concat("../models/inception_v3/group1-shard4of6.min.js")).then((function(t){return o(e(t))}))},function(){return Promise.resolve("".concat("../models/inception_v3/group1-shard5of6.min.js")).then((function(t){return o(e(t))}))},function(){return Promise.resolve("".concat("../models/inception_v3/group1-shard6of6.min.js")).then((function(t){return o(e(t))}))}]},{}],3:[function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var a=Object.getOwnPropertyDescriptor(t,n);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,a)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return a(t,e),t};Object.defineProperty(n,"__esModule",{value:!0}),n.weightBundles=n.modelJson=void 0;n.modelJson=function(){return Promise.resolve("".concat("../models/mobilenet_v2/model.min.js")).then((function(t){return o(e(t))}))},n.weightBundles=[function(){return Promise.resolve("".concat("../models/mobilenet_v2/group1-shard1of1.min.js")).then((function(t){return o(e(t))}))}]},{}],4:[function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var a=Object.getOwnPropertyDescriptor(t,n);a&&!("get"in a?!t.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,a)}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),a=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.prototype.hasOwnProperty.call(e,n)&&r(t,e,n);return a(t,e),t};Object.defineProperty(n,"__esModule",{value:!0}),n.weightBundles=n.modelJson=void 0;n.modelJson=function(){return Promise.resolve("".concat("../models/mobilenet_v2_mid/model.min.js")).then((function(t){return o(e(t))}))},n.weightBundles=[function(){return Promise.resolve("".concat("../models/mobilenet_v2_mid/group1-shard1of2.min.js")).then((function(t){return o(e(t))}))},function(){return Promise.resolve("".concat("../models/mobilenet_v2_mid/group1-shard2of2.min.js")).then((function(t){return o(e(t))}))}]},{}],5:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.NSFW_CLASSES=void 0,n.NSFW_CLASSES={0:"Drawing",1:"Hentai",2:"Neutral",3:"Porn",4:"Sexy"}},{}],6:[function(e,t,n){"use strict";t.exports=e("./index")},{"./index":1}],7:[function(e,t,n){ /** * @license * Copyright 2024 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ "use strict";var r=e("@tensorflow/tfjs-core");function a(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,t}var o=a(e("seedrandom")),i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},i(e,t)};function s(e,t,n,r){return new(n||(n=Promise))((function(a,o){function i(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?a(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}u((r=r.apply(e,t||[])).next())}))}function u(e,t){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(a=2&o[0]?r.return:o[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,o[1])).done)return a;switch(r=0,a&&(o=[2&o[0],a.value]),o[0]){case 0:case 1:a=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,r=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!a||o[1]>a[0]&&o[1]<a[3])){i.label=o[1];break}if(6===o[0]&&i.label<a[1]){i.label=a[1],a=o;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(o);break}a[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],r=0}finally{n=a=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}function c(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function l(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,a,o=n.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)i.push(r.value)}catch(e){a={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(a)throw a.error}}return i}function h(e,t,n){if(n||2===arguments.length)for(var r,a=0,o=t.length;a<o;a++)!r&&a in t||(r||(r=Array.prototype.slice.call(t,0,a)),r[a]=t[a]);return e.concat(r||Array.prototype.slice.call(t))} /** * @license * Copyright 2019 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function p(e,t){Array.isArray(e)||(e=[e]),e.forEach((function(e){null!=e&&r.util.assert("complex64"!==e.dtype,(function(){return"".concat(t," does not support complex64 tensors in the CPU backend.")}))}))}var d=r.kernel_impls.whereImpl,f=function(e){function t(){var t=e.call(this)||this;return t.blockSize=48,t.firstUse=!0,t.data=new r.DataStorage(t,r.engine()),t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t.prototype.nextDataId=function(){return t.nextDataId++},t.prototype.write=function(e,t,n){this.firstUse&&(this.firstUse=!1,r.env().get("IS_NODE")&&r.backend_util.warn("\n============================\nHi, looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, visit https://github.com/tensorflow/tfjs-node for more details. \n============================"));var a={id:this.nextDataId()};return this.data.set(a,{values:e,dtype:n,refCount:1}),a},t.prototype.makeTensorInfo=function(e,t,n){var a;if("string"===t&&null!=n&&n.length>0&&r.util.isString(n[0])){var o=n.map((function(e){return r.util.encodeString(e)}));a=this.write(o,e,t)}else a=this.write(n,e,t);return{dataId:a,shape:e,dtype:t}},t.prototype.refCount=function(e){return this.data.has(e)?this.data.get(e).refCount:0},t.prototype.incRef=function(e){this.data.get(e).refCount++},t.prototype.decRef=function(e){this.data.has(e)&&this.data.get(e).refCount--},t.prototype.move=function(e,t,n,r,a){this.data.set(e,{values:t,dtype:r,refCount:a})},t.prototype.numDataIds=function(){return this.data.numDataIds()},t.prototype.read=function(e){return s(this,void 0,void 0,(function(){return u(this,(function(t){return[2,this.readSync(e)]}))}))},t.prototype.readSync=function(e){var t=this.data.get(e),n=t.dtype,a=t.complexTensorInfos;if("complex64"===n){var o=this.readSync(a.real.dataId),i=this.readSync(a.imag.dataId);return r.backend_util.mergeRealAndImagArrays(o,i)}return r.util.convertBackendValuesAndArrayBuffer(this.data.get(e).values,n)},t.prototype.bufferSync=function(e){var t=this.readSync(e.dataId);if("string"===e.dtype)try{var n=t.map((function(e){return r.util.decodeString(e)}));return r.buffer(e.shape,e.dtype,n)}catch(e){throw new Error("Failed to decode encoded string bytes into utf-8")}return r.buffer(e.shape,e.dtype,t)},t.prototype.makeOutput=function(e,t,n){return r.engine().makeTensorFromTensorInfo(this.makeTensorInfo(t,n,e),this)},t.prototype.disposeData=function(e,t){if(void 0===t&&(t=!1),this.data.has(e)){if(this.data.get(e).refCount--,!t&&this.data.get(e).refCount>0)return!1;var n=this.data.get(e).complexTensorInfos;null!=n&&(this.disposeData(n.real.dataId,!0),this.disposeData(n.imag.dataId,!0)),this.data.delete(e)}return!0},t.prototype.disposeIntermediateTensorInfo=function(e){this.disposeData(e.dataId)},t.prototype.time=function(e){return s(this,void 0,void 0,(function(){var t;return u(this,(function(n){return t=r.util.now(),e(),[2,{kernelMs:r.util.now()-t}]}))}))},t.prototype.memory=function(){return{unreliable:!0,reasons:["The reported memory is an upper bound. Due to automatic garbage collection, the true allocated memory may be less."]}},t.prototype.where=function(e){p([e],"where");var t=this.readSync(e.dataId);return d(e.shape,t)},t.prototype.dispose=function(){},t.prototype.floatPrecision=function(){return 32},t.prototype.epsilon=function(){return e.prototype.epsilon.call(this)},t}(r.KernelBackend); /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ function m(e){for(var t=new Float32Array(e.length),n=0;n<e.length;++n)t[n]=Math.abs(e[n]);return t}f.nextDataId=0;var g={kernelName:r.Abs,backendName:"cpu",kernelFunc:function(e){var t=e.inputs.x,n=e.backend;p(t,"abs");var a=new Float32Array(r.util.sizeFromShape(t.shape));return a=m(n.data.get(t.dataId).values),n.makeOutput(a,t.shape,t.dtype)}}; /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ function v(e){return function(t,n,a,o,i){var s=r.backend_util.assertAndGetBroadcastShape(t,n),u=s.length,c=r.util.computeStrides(s),l=r.util.sizeFromShape(s),h=r.util.getTypedArrayFromDType(i,l),p=t.length,d=n.length,f=r.util.computeStrides(t),m=r.util.computeStrides(n),g=r.backend_util.getBroadcastDims(t,s),v=r.backend_util.getBroadcastDims(n,s);if(g.length+v.length===0)for(var y=0;y<h.length;++y)h[y]=e(a[y%a.length],o[y%o.length]);else{var b=function(t){var n=r.util.indexToLoc(t,u,c),i=n.slice(-p);g.forEach((function(e){return i[e]=0}));var s=r.util.locToIndex(i,p,f),l=n.slice(-d);v.forEach((function(e){return l[e]=0}));var y=r.util.locToIndex(l,d,m);h[t]=e(a[s],o[y])};for(y=0;y<h.length;++y)b(y)}return[h,s]}} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function y(e){var t=e.inputs,n=e.backend,r=t.real,a=t.imag,o=n.data.get(r.dataId).values,i=n.data.get(a.dataId).values,s=n.makeTensorInfo(r.shape,"complex64");return n.data.get(s.dataId).complexTensorInfos={real:n.makeTensorInfo(r.shape,"float32",o),imag:n.makeTensorInfo(a.shape,"float32",i)},s}var b={kernelName:r.Complex,backendName:"cpu",kernelFunc:y}; /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function x(e,t,n){if(void 0===n&&(n="float32"),"complex64"===n)return y({inputs:{real:x(e,t,"float32"),imag:x(e,t,"float32")},backend:e});var a=r.util.makeZerosTypedArray(r.util.sizeFromShape(t),n);return e.makeTensorInfo(t,n,a)} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function w(e){var t=e.inputs,n=e.backend,r=t.x;return n.incRef(r.dataId),{dataId:r.dataId,shape:r.shape,dtype:r.dtype}}var k={kernelName:r.Identity,backendName:"cpu",kernelFunc:w}; /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function S(e){var t=e.inputs,n=e.backend,r=t.input,a=n.data.get(r.dataId).complexTensorInfos.real,o=n.data.get(a.dataId).values;return n.makeTensorInfo(a.shape,a.dtype,o)}var I={kernelName:r.Real,backendName:"cpu",kernelFunc:S};function N(e,t,n,a){if("int32"===a)return[t,"int32",Int32Array.from(e)];if("bool"===a){var o=r.util.toTypedArray([0],n),i=l(v((function(e,t){return e!==t?1:0}))(t,[],e,o,"bool"),2),s=i[0];return[i[1],"bool",s]}throw new Error("Error in Cast: failed to cast ".concat(n," to ").concat(a))}function T(e){var t=e.inputs,n=e.backend,a=e.attrs,o=t.x,i=a.dtype;if("complex64"===i){if("complex64"===o.dtype)return w({inputs:{x:o},backend:n});var s=x(n,o.shape,o.dtype),u=T({inputs:{x:o},backend:n,attrs:{dtype:"float32"}}),c=y({inputs:{real:u,imag:s},backend:n});return n.disposeIntermediateTensorInfo(s),n.disposeIntermediateTensorInfo(u),c}if("complex64"===o.dtype){var h=S({inputs:{input:o},backend:n}),c=T({inputs:{x:h},backend:n,attrs:{dtype:i}});return n.disposeIntermediateTensorInfo(h),c}if(!r.util.hasEncodingLoss(o.dtype,i))return{dataId:(c=w({inputs:{x:o},backend:n})).dataId,shape:c.shape,dtype:i};var p=l(N(n.data.get(o.dataId).values,o.shape,o.dtype,i),3),d=p[0],f=p[1],m=p[2];return n.makeTensorInfo(d,f,m)}var E={kernelName:r.Cast,backendName:"cpu",kernelFunc:T};function C(e,t,n,a){return null==n?function(n){var o=n.inputs,i=n.backend,s=o.a,u=o.b,c=i;p([s,u],e);var h=c.data.get(s.dataId).values,d=c.data.get(u.dataId).values,f="string"===s.dtype?r.backend_util.fromUint8ToStringArray(h):h,m="string"===s.dtype?r.backend_util.fromUint8ToStringArray(d):d,g=a||s.dtype,v=l(t(s.shape,u.shape,f,m,g),2),y=v[0],b=v[1];return c.makeTensorInfo(b,g,y)}:function(e){var r=e.inputs,o=e.backend,i=r.a,s=r.b,u=o;if("complex64"===i.dtype||"complex64"===s.dtype){var c=T({inputs:{x:i},backend:u,attrs:{dtype:"complex64"}}),h=u.data.get(c.dataId),p=h.complexTensorInfos.real,d=h.complexTensorInfos.imag,f=u.data.get(p.dataId).values,m=u.data.get(d.dataId).values,g=T({inputs:{x:s},backend:u,attrs:{dtype:"complex64"}}),v=u.data.get(g.dataId),b=v.complexTensorInfos.real,x=v.complexTensorInfos.imag,w=u.data.get(b.dataId).values,k=u.data.get(x.dataId).values,S=l(n(i.shape,s.shape,f,m,w,k),3),I=S[0],N=S[1],E=S[2],C=u.makeTensorInfo(E,"float32",I),A=u.makeTensorInfo(E,"float32",N),_=y({inputs:{real:C,imag:A},backend:u});return u.disposeIntermediateTensorInfo(c),u.disposeIntermediateTensorInfo(g),u.disposeIntermediateTensorInfo(C),u.disposeIntermediateTensorInfo(A),_}var R=u.data.get(i.dataId).values,F=u.data.get(s.dataId).values,D=a||i.dtype,O=l(t(i.shape,s.shape,R,F,D),2),M=O[0];E=O[1];return u.makeTensorInfo(E,D,M)}}function A(e){return function(t,n,a,o,i,s){var u=r.backend_util.assertAndGetBroadcastShape(t,n),c=r.util.sizeFromShape(u),l=u.length,h=r.util.computeStrides(u),p=r.util.getTypedArrayFromDType("float32",c),d=r.util.getTypedArrayFromDType("float32",c),f=r.backend_util.getBroadcastDims(t,u),m=r.backend_util.getBroadcastDims(n,u),g=r.backend_util.mergeRealAndImagArrays(a,o),v=r.backend_util.mergeRealAndImagArrays(i,s),y=t.length,b=r.util.computeStrides(t),x=n.length,w=r.util.computeStrides(n);if(f.length+m.length===0)for(var k=0;k<p.length;k++){var S=k%g.length,I=k%v.length,N=e(g[2*S],g[2*S+1],v[2*I],v[2*I+1]);p[k]=N.real,d[k]=N.imag}else{var T=function(t){var n=r.util.indexToLoc(t,l,h),a=n.slice(-y);f.forEach((function(e){return a[e]=0}));var o=r.util.locToIndex(a,y,b),i=n.slice(-x);m.forEach((function(e){return i[e]=0}));var s=r.util.locToIndex(i,x,w),u=e(g[2*o],g[2*o+1],v[2*s],v[2*s+1]);p[t]=u.real,d[t]=u.imag};for(k=0;k<p.length;k++)T(k)}return[p,d,u]}} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */var _=v((function(e,t){return e+t})),R=A((function(e,t,n,r){return{real:e+n,imag:t+r}})),F=C(r.Add,_,R),D={kernelName:r.Add,backendName:"cpu",kernelFunc:F}; /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ function O(e,t,n,a,o){for(var i=r.util.sizeFromShape(a),s=r.util.makeZerosTypedArray(o,n),u=0;u<e.length;u++){var c=e[u];if(c<0)throw new Error("Input x must be non-negative!");c>=o||(s[c]+=i>0?t[u]:1)}return s}function M(e,t,n,a){void 0===a&&(a=!1);for(var o=e.shape[0],i=e.shape[1],s=r.buffer([o,n],t.dtype),u=0;u<o;u++)for(var c=0;c<i;c++){var l=e.get(u,c);if(l<0)throw new Error("Input x must be non-negative!");l>=n||(a?s.set(1,u,l):t.size>0?s.set(s.get(u,l)+t.get(u,c),u,l):s.set(s.get(u,l)+1,u,l))}return s} /** * @license * Copyright 2023 Google LLC. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */var z=v((function(e,t){return e&t})),B=C(r.BitwiseAnd,z),L={kernelName:r.BitwiseAnd,backendName:"cpu",kernelFunc:B}; /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ function P(e){return function(t,n,a){for(var o=r.util.getArrayFromDType(n,t.length),i=0;i<t.length;++i)o[i]=e(t[i],a);return o}} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function U(e,t,n){return W(e,P(t),n)}function W(e,t,n){return function(a){var o=a.inputs,i=a.attrs,s=a.backend,u=o.x;p(u,e);var c,l=s,h=l.data.get(u.dataId).values;if("string"===u.dtype){if(!Array.isArray(h))throw new Error("String tensor's value was not an instance of Array");c=r.backend_util.fromUint8ToStringArray(h)}else c=h;var d=n||u.dtype,f=t(c,d,i);return l.makeTensorInfo(u.shape,d,f)}} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */var V=P((function(e){return Math.ceil(e)})),G=W(r.Ceil,V),j={kernelName:r.Ceil,backendName:"cpu",kernelFunc:G}; /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ function q(e,t,n,a){var o=r.util.getArrayFromDType(n,r.util.sizeFromShape(t));if(a&&"string"!==n){var i=0;e.forEach((function(e){var t=r.util.sizeFromShape(e.shape);o.set(e.vals,i),i+=t}))}else{var s=0;e.forEach((function(e){for(var a="string"===n?r.backend_util.fromUint8ToStringArray(e.vals):e.vals,i=0,u=0;u<e.shape[0];++u)for(var c=u*t[1]+s,l=0;l<e.shape[1];++l)o[c+l]=a[i++];s+=e.shape[1]}))}return o} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */var K=v((function(e,t){return e===t?1:0})),H=C(r.Equal,K,null,"bool"),X={kernelName:r.Equal,backendName:"cpu",kernelFunc:H},$=P((function(e){return Math.exp(e)})),Z=W(r.Exp,$,"float32"),J={kernelName:r.Exp,backendName:"cpu",kernelFunc:Z},Y=P((function(e){return Math.expm1(e)})),Q=W(r.Expm1,Y),ee={kernelName:r.Expm1,backendName:"cpu",kernelFunc:Q},te=P((function(e){return Math.floor(e)})),ne=W(r.Floor,te),re={kernelName:r.Floor,backendName:"cpu",kernelFunc:ne},ae=v((function(e,t){return Math.floor(e/t)})),oe=C(r.FloorDiv,ae,null,"int32"),ie={kernelName:r.FloorDiv,backendName:"cpu",kernelFunc:oe};function se(e,t,n,a,o,i,s,u,c){for(var p=r.buffer([a,i],n),d=0;d<a;d++){for(var f=[],m=0,g=0;g<o;g++){var v=e[d*o+g];m+=v*s[g],f.push(v)}if(m<0||m>=c/i)throw new Error("Invalid indices: ".concat(f," does not index into ").concat(u));for(var y=0;y<i;y++)p.values[d*i+y]=t.get.apply(t,h([],l(t.indexToLoc(m*i+y)),!1))}return p} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function ue(e,t,n){for(var a=r.buffer(n,e.dtype),o=0;o<a.size;++o){var i=a.indexToLoc(o).slice(),s=i[0],u=i[2],c=t.locToIndex([s,u]);i[2]=t.values[c];var l=e.locToIndex(i);0<=l&&l<e.values.length&&(a.values[o]=e.values[l])}return a} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */var ce=v((function(e,t){return e>t?1:0})),le=C(r.Greater,ce,null,"bool"),he={kernelName:r.Greater,backendName:"cpu",kernelFunc:le},pe=v((function(e,t){return e>=t?1:0})),de=C(r.GreaterEqual,pe,null,"bool"),fe={kernelName:r.GreaterEqual,backendName:"cpu",kernelFunc:de},me=v((function(e,t){return e<t?1:0})),ge=C(r.Less,me,null,"bool"),ve={kernelName:r.Less,backendName:"cpu",kernelFunc:ge},ye=v((function(e,t){return e<=t?1:0})),be=C(r.LessEqual,ye,null,"bool"),xe={kernelName:r.LessEqual,backendName:"cpu",kernelFunc:be}; /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ function we(e,t,n){var a=(t-e)/(n-1),o=r.util.makeZerosTypedArray(n,"float32");o[0]=e;for(var i=1;i<o.length;i++)o[i]=o[i-1]+a;return o} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */var ke=P((function(e){return Math.log(e)})),Se=W(r.Log,ke),Ie={kernelName:r.Log,backendName:"cpu",kernelFunc:Se}; /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ function Ne(e,t,n,a){for(var o=r.util.getTypedArrayFromDType(a,r.util.sizeFromShape(n)),i=0;i<o.length;++i){for(var s=i*t,u=e[s],c=0;c<t;++c){var l=e[s+c];(Number.isNaN(l)||l>u)&&(u=l)}o[i]=u}return o} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */var Te=v((function(e,t){return Math.max(e,t)})),Ee=C(r.Maximum,Te),Ce={kernelName:r.Maximum,backendName:"cpu",kernelFunc:Ee},Ae=v((function(e,t){return Math.min(e,t)})),_e=C(r.Minimum,Ae),Re={kernelName:r.Minimum,backendName:"cpu",kernelFunc:_e},Fe=v((function(e,t){return e*t})),De=A((function(e,t,n,r){return{real:e*n-t*r,imag:e*r+t*n}})),Oe=C(r.Multiply,Fe,De),Me={kernelName:r.Multiply,backendName:"cpu",kernelFunc:Oe};function ze(e,t,n){var a=r.util.createScalarValue(-1,n);return Fe([],t,a,e,n)}var Be={kernelName:r.Neg,backendName:"cpu",kernelFunc:function(e){var t=e.inputs,n=e.backend,r=t.x;p(r,"neg");var a=l(ze(n.data.get(r.dataId).values,r.shape,r.dtype),2),o=a[0],i=a[1];return n.makeTensorInfo(i,r.dtype,o)}},Le=v((function(e,t){return e!==t?1:0})),Pe=C(r.NotEqual,Le,null,"bool"),Ue={kernelName:r.NotEqual,backendName:"cpu",kernelFunc:Pe}; /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */ function We(e,t,n,a,o){for(var i=t.length,s=r.util.sizeFromShape(t),u=r.util.computeStrides(t),c=r.util.computeStrides(o),l=r.util.getTypedArrayFromDType(n,r.util.sizeFromShape(o)),h=0;h<s;++h){for(var p=r.util.indexToLoc(h,i,u),d=new Array(p.length),f=0;f<d.length;f++)d[f]=p[a[f]];l[r.util.locToIndex(d,i,c)]=e[h]}return l} /** * @license * Copyright 2020 Google LLC. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============================================================================= */function Ve(e){var t=e.inputs,n=e.attrs,r=e.backend,a=t.x,o=n.perm;p(a,"transpose");for(var i=a.shape.length,s=new Array(i),u=0;u<s.length;u++)s[u]=a.shape[o[u]];var