-
Notifications
You must be signed in to change notification settings - Fork 1
/
df22bba5d9b0d3a9ea33ea19cbf2f7cd.map
1 lines (1 loc) · 951 KB
/
df22bba5d9b0d3a9ea33ea19cbf2f7cd.map
1
{"version":3,"sources":["node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/device_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/doc.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/tensor_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/axis_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/concat_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/operation.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/concat.js","node_modules/tfjs-tsne/node_modules/seedrandom/lib/alea.js","node_modules/tfjs-tsne/node_modules/seedrandom/lib/xor128.js","node_modules/tfjs-tsne/node_modules/seedrandom/lib/xorwow.js","node_modules/tfjs-tsne/node_modules/seedrandom/lib/xorshift7.js","node_modules/tfjs-tsne/node_modules/seedrandom/lib/xor4096.js","node_modules/tfjs-tsne/node_modules/seedrandom/lib/tychei.js","node_modules/tfjs-tsne/node_modules/seedrandom/seedrandom.js","node_modules/tfjs-tsne/node_modules/seedrandom/index.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/rand.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/reduction_ops.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/array_ops.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/broadcast_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/batchnorm.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/types.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/binary_ops.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/compare.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/conv_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/conv.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/image_ops.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/tracking.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/linalg_ops.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/logical_ops.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/loss_ops.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/lrn.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/lstm.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/matmul.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/moving_average.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/norm.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/pool.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/reverse.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/slice_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/slice.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/softmax.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/transpose.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/selu_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/unary_ops.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/ops.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/tensor.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/gradients.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/globals.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/profiler.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/tape.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/engine.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/environment.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/reduce_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/backend_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/argminmax_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/avg_pool_backprop_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/batchnorm_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/binaryop_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/clip_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/concat_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/conv_backprop_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/conv_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/conv_gpu_depthwise.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/from_pixels_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/tex_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/shader_compiler.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/gather_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/webgl_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/gpgpu_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/gpgpu_context.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/gpgpu_math.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/logical_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/lrn_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/max_pool_backprop_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/mulmat_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/multinomial_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/onehot_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/pad_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/pool_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/reduce_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/resize_bilinear_backprop_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/resize_bilinear_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/resize_nearest_neighbor_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/reverse_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/slice_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/texture_manager.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/tile_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/transpose_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/ops/erf_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/webgl/unaryop_gpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/backend_webgl.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/kernels/backend_cpu.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/browser_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/io/types.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/io/io_utils.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/io/router_registry.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/io/indexed_db.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/io/local_storage.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/io/browser_files.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/io/browser_http.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/io/weights_loader.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/io/io.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/serialization.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/test_util.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/version.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/webgl.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/optimizers/optimizer.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/optimizers/adadelta_optimizer.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/optimizers/adagrad_optimizer.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/optimizers/adam_optimizer.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/optimizers/adamax_optimizer.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/optimizers/sgd_optimizer.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/optimizers/momentum_optimizer.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/optimizers/rmsprop_optimizer.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/optimizers/optimizer_constructors.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/train.js","node_modules/tfjs-tsne/node_modules/@tensorflow/tfjs-core/dist/index.js","node_modules/tfjs-tsne/dist/gl_util.js","node_modules/tfjs-tsne/dist/dataset_util.js","node_modules/tfjs-tsne/dist/drawer_util.js","node_modules/tfjs-tsne/dist/drawer.js","node_modules/tfjs-tsne/dist/knn_util.js","node_modules/tfjs-tsne/dist/knn.js","node_modules/tfjs-tsne/dist/tsne_optimizer_util.js","node_modules/tfjs-tsne/dist/tsne_optimizer.js","node_modules/tfjs-tsne/dist/tensor_to_data_texture.js","node_modules/tfjs-tsne/dist/tsne.js","node_modules/tfjs-tsne/dist/index.js","index.js"],"names":["tf_tsne","console","log","iterations","alphaViz","maxExaggeration","exaggerationMult","init","iterateChkBx","document","getElementById","textureChkBx","alphaSlider","numPoints","tsne","TSNEOptimizer","drawer","EmbeddingDrawer","pntsPerRow","pointsPerRow","numRows","numNeighPerRow","backend","tfc","ENV","findBackend","canvas","getCanvas","appendChild","height","width","gpgpu","getGPGPUContext","webglContext","gl","webgl","webgl_util","bindCanvasToFramebuffer","clearColor","clear","COLOR_BUFFER_BIT","offsets","probabilities","neighIds","colors","mnistTexture","tempTexture","gl_util","createAndConfigureInterpolatedTexture","draw","embedding","minX","maxX","minY","maxY","embeddingTexture","numberOfPointsPerRow","numberOfRows","numberOfPoints","checked","drawTexturedPoints","textureNormalization","Math","sqrt","normalizationQ","drawColoredPoints","drawPointsAndSplatTexture","splatTexture","iterate","initializeNeighbors","requestAnimationFrame","exaggeration","addEventListener","resetBtn","initializeEmbedding","Number","value","max","loadOffsets","Promise","resolve","reject","oReqOffsets","XMLHttpRequest","open","href","responseType","onload","oEvent","status","arrayBufferOffsets","response","byteArrayOffsets","Float32Array","createAndConfigureTexture","statusText","onerror","send","loadColors","oReqColors","arrayBufferColors","byteArrayColors","loadProbabilities","oReqProbabilities","arrayBufferProb","byteArrayProb","loadNeighIds","oReqNeighIds","arrayBufferNeighIds","byteArrayNeighIds","then","loadMNIST","showControls","url","texture","createTexture","bindTexture","TEXTURE_2D","level","internalFormat","RGBA8","border","srcFormat","RGBA","srcType","UNSIGNED_BYTE","pixel","Uint8Array","texImage2D","image","Image","texParameteri","TEXTURE_WRAP_S","CLAMP_TO_EDGE","TEXTURE_WRAP_T","TEXTURE_MIN_FILTER","NEAREST","TEXTURE_MAG_FILTER","src","hiddenIterDiv","querySelector","classList","remove","dataLoadingDiv"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACXA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClJA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;ACvGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzuBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5VA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjJA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC3DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC7EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC3HA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACnDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC3CA;AACA;AACA;AACA;AACA;;ACJA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9dA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC12BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACnGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;ACnUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACnCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC7OA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjTA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxTA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzRA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACnCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACpBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACXA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACRA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACn3BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC96CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACTA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC7LA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACpLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtGA;AACA;AACA;AACA;AACA;;ACJA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACpDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACpHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC3IA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC7DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC7OA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACpLA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtqBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1NA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;ACCA;;IAAYA;;;;AAjBZ;;;;;;;;;;;;;;;;;AAoBAC,QAAQC,GAAR,CAAY,iCAAZ;;AAEA;AACA,IAAIC,aAAa,CAAjB;AACA,IAAIC,WAAW,IAAf;AACA,IAAMC,kBAAkB,CAAxB;AACA,IAAIC,mBAAmB,CAAvB;;AAEA,IAAIC,OAAO,KAAX;;AAEA;AACA,IAAMC,eAAeC,SAASC,cAAT,CAAwB,cAAxB,CAArB;AACA,IAAMC,eAAeF,SAASC,cAAT,CAAwB,cAAxB,CAArB;AACA,IAAME,cAAcH,SAASC,cAAT,CAAwB,aAAxB,CAApB;;AAEA;AACA,IAAMG,YAAY,KAAlB;;AAEA;AACA,IAAMC,OAAO,IAAId,QAAQe,aAAZ,CAA0BF,SAA1B,EAAqC,KAArC,CAAb;AACA,IAAMG,SAAS,IAAIhB,QAAQiB,eAAZ,CAA4BJ,SAA5B,CAAf;;AAEA;AACA;AACA,IAAMK,aAAaJ,KAAKK,YAAxB;AACA,IAAMC,UAAUN,KAAKM,OAArB;AACA,IAAMC,iBAAiB,IAAvB;;AAEA;AACA;AACA,IAAMC,UAAUC,cAAIC,GAAJ,CAAQC,WAAR,CAAoB,OAApB,CAAhB;AACA,IAAMC,SAASJ,QAAQK,SAAR,EAAf;AACAlB,SAASC,cAAT,CAAwB,YAAxB,EAAsCkB,WAAtC,CAAkDF,MAAlD;AACAA,OAAOG,MAAP,GAAgB,GAAhB;AACAH,OAAOI,KAAP,GAAe,GAAf;;AAEA,IAAMC,QAAQT,QAAQU,eAAR,EAAd;AACA,IAAMC,eAAeX,QAAQU,eAAR,GAA0BE,EAA/C;AACAX,cAAIY,KAAJ,CAAUC,UAAV,CAAqBC,uBAArB,CAA6CJ,YAA7C;AACAA,aAAaK,UAAb,CAAwB,CAAxB,EAA2B,CAA3B,EAA8B,CAA9B,EAAiC,CAAjC;AACAL,aAAaM,KAAb,CAAmBN,aAAaO,gBAAhC;;AAEA;AACA,IAAIC,gBAAJ;AACA,IAAIC,sBAAJ;AACA,IAAIC,iBAAJ;AACA,IAAIC,eAAJ;AACA,IAAIC,qBAAJ;;AAEA;AACA,IAAMC,cAAc9C,QAAQ+C,OAAR,CAAgBC,qCAAhB,CAChBjB,MAAMG,EADU,EACN,GADM,EACD,GADC,EACI,CADJ,CAApB;;AAGA;;;AAGA,SAASe,IAAT,GAAgB;AACd,MAAMC,YAAY;AAChBC,UAAOrC,KAAKqC,IADI;AAEhBC,UAAOtC,KAAKsC,IAFI;AAGhBC,UAAOvC,KAAKuC,IAHI;AAIhBC,UAAOxC,KAAKwC,IAJI;AAKhBC,sBAAmBzC,KAAKyC,gBALR;AAMhBrC,gBAAaJ,KAAK0C,oBANF;AAOhBpC,aAAUN,KAAK2C,YAPC;AAQhB5C,eAAYC,KAAK4C;AARD,GAAlB;AAUA,MAAI/C,aAAagD,OAAb,KAAyB,KAA7B,EAAoC;AAClC3C,WAAO4C,kBAAP,CAA0BV,SAA1B,EAAqC9C,QAArC,EAA+CyC,YAA/C,EAA6D,EAA7D,EAAiED,MAAjE;AACD,GAFD,MAEO;AACL,QAAMiB,uBAAuBC,KAAKC,IAAL,CAAUjD,KAAKkD,cAAf,CAA7B;AACAhD,WAAOiD,iBAAP,CAAyBf,SAAzB,EAAoC9C,QAApC,EAA8CwC,MAA9C,EAAsDE,WAAtD;AACA9B,WAAOkD,yBAAP,CAAiChB,SAAjC,EAA4CpC,KAAKqD,YAAjD,EAA+DrB,WAA/D,EACiCe,oBADjC;AAED;AACF;;AAED;;;AAGA,SAASO,OAAT,GAAmB;AACjB,MAAI7D,SAAS,KAAb,EAAoB;AAClBO,SAAKuD,mBAAL,CAAyBhD,cAAzB,EAAyCoB,OAAzC,EAAkDC,aAAlD,EAAiEC,QAAjE;AACApC,WAAO,IAAP;AACD;AACD,MAAIC,aAAamD,OAAb,KAAyB,IAA7B,EAAmC;AACjCW,0BAAsBF,OAAtB;AACD;;AAED;AACA;AACA,MAAIjE,cAAc,GAAlB,EAAuB;AACrBW,SAAKyD,YAAL,GAAoB,EAApB;AACD,GAFD,MAEO,IAAIpE,cAAc,GAAlB,EAAuB;AAC5BW,SAAKyD,YAAL,GACIlE,kBAAkB,CAACA,kBAAkB,CAAnB,KAAyBF,aAAa,IAAtC,IAA8C,IADpE;AAED,GAHM,MAGA;AACLW,SAAKyD,YAAL,GAAoBlE,eAApB;AACD;AACDS,OAAKyD,YAAL,IAAqBjE,gBAArB;;AAEAQ,OAAKsD,OAAL;AACA,IAAEjE,UAAF;AACA,MAAIA,aAAa,GAAb,KAAqB,CAAzB,EAA4B;AAC1BF,YAAQC,GAAR,CAAY,WAAWC,UAAvB;AACD;;AAED,MAAIA,eAAe,IAAnB,EAAyB;AACvBF,YAAQC,GAAR,CAAY,mDAAZ;AACAM,iBAAamD,OAAb,GAAuB,KAAvB;AACD;;AAEDV;AACD;;AAEDzC,aAAagE,gBAAb,CAA8B,OAA9B,EAAuC,YAAM;AAAEJ;AAAY,CAA3D;;AAEAzD,aAAa6D,gBAAb,CAA8B,OAA9B,EAAuC,YAAM;AAAEvB;AAAS,CAAxD;;AAEA,IAAMwB,WAAWhE,SAASC,cAAT,CAAwB,UAAxB,CAAjB;AACA+D,SAASD,gBAAT,CAA0B,OAA1B,EAAmC,YAAM;AACvCvE,UAAQC,GAAR,CAAY,QAAZ;AACAY,OAAK4D,mBAAL;AACAvE,eAAa,CAAb;AACAG,qBAAmB,CAAnB;AACA8D;AACAA;AACA5D,eAAamD,OAAb,GAAuB,KAAvB;AACD,CARD;;AAUA/C,YAAY4D,gBAAZ,CAA6B,OAA7B,EAAsC,YAAM;AAC1C,MAAIhE,aAAamD,OAAb,KAAyB,KAA7B,EAAoC;AAClCW,0BAAsBrB,IAAtB;AACD;AACD7C,aAAWuE,OAAO/D,YAAYgE,KAAnB,IAA4BD,OAAO/D,YAAYiE,GAAnB,CAA5B,GAAsD,EAAjE;AACD,CALD;;AAOA;AACA;AACA;AACA;;AAEA;;;AAGA,SAASC,WAAT,GAAuB;AACrB,SAAO,IAAIC,OAAJ,CAAY,UAASC,OAAT,EAAkBC,MAAlB,EAA0B;AAC3C,QAAMC,cAAc,IAAIC,cAAJ,EAApB;AACAD,gBAAYE,IAAZ,CAAiB,KAAjB,EAAwB3E,SAASC,cAAT,CAAwB,SAAxB,EAAmC2E,IAA3D,EAAiE,IAAjE;AACAH,gBAAYI,YAAZ,GAA2B,aAA3B;AACAJ,gBAAYK,MAAZ,GAAqB,UAACC,MAAD,EAAY;AAC/B,UAAIN,YAAYO,MAAZ,IAAsB,GAAtB,IAA6BP,YAAYO,MAAZ,GAAqB,GAAtD,EAA2D;AACzD,YAAMC,qBAAqBR,YAAYS,QAAvC;AACA,YAAID,kBAAJ,EAAwB;AACtB,cAAME,mBAAmB,IAAIC,YAAJ,CAAiBH,kBAAjB,CAAzB;AACAjD,oBAAUzC,QAAQ+C,OAAR,CAAgB+C,yBAAhB,CACN/D,MAAMG,EADA,EACIhB,UADJ,EACgBE,OADhB,EACyB,CADzB,EAC4B;AAClCwE,0BAFM,CAAV;AAGD;AACDZ,gBAAQE,YAAYS,QAApB;AACD,OATD,MASO;AACLV,eACI,EAACQ,QAASP,YAAYO,MAAtB,EAA8BM,YAAab,YAAYa,UAAvD,EADJ;AAED;AACF,KAdD;AAeAb,gBAAYc,OAAZ,GAAsB,YAAW;AAC/Bf,aACI,EAACQ,QAASP,YAAYO,MAAtB,EAA8BM,YAAab,YAAYa,UAAvD,EADJ;AAED,KAHD;AAIAb,gBAAYe,IAAZ;AACD,GAxBM,CAAP;AAyBD;;AAED;;;AAGA,SAASC,UAAT,GAAsB;AACpB,SAAO,IAAInB,OAAJ,CAAY,UAASC,OAAT,EAAkBC,MAAlB,EAA0B;AAC3C,QAAMkB,aAAa,IAAIhB,cAAJ,EAAnB;AACAgB,eAAWf,IAAX,CAAgB,KAAhB,EAAuB3E,SAASC,cAAT,CAAwB,QAAxB,EAAkC2E,IAAzD,EAA+D,IAA/D;AACAc,eAAWb,YAAX,GAA0B,aAA1B;AACAa,eAAWZ,MAAX,GAAoB,UAACC,MAAD,EAAY;AAC9B,UAAIW,WAAWV,MAAX,IAAqB,GAArB,IAA4BU,WAAWV,MAAX,GAAoB,GAApD,EAAyD;AACvD,YAAMW,oBAAoBD,WAAWR,QAArC;AACA,YAAIS,iBAAJ,EAAuB;AACrB,cAAMC,kBAAkB,IAAIR,YAAJ,CAAiBO,iBAAjB,CAAxB;AACAxD,mBAAS5C,QAAQ+C,OAAR,CAAgB+C,yBAAhB,CACL/D,MAAMG,EADD,EACKhB,UADL,EACiBE,OADjB,EAC0B,CAD1B,EAC6BiF,eAD7B,CAAT;AAED;AACDrB,gBAAQmB,WAAWR,QAAnB;AACD,OARD,MAQO;AACLV,eACI,EAACQ,QAASU,WAAWV,MAArB,EAA6BM,YAAaI,WAAWJ,UAArD,EADJ;AAED;AACF,KAbD;AAcAI,eAAWH,OAAX,GAAqB,YAAW;AAC9Bf,aAAO,EAACQ,QAASU,WAAWV,MAArB,EAA6BM,YAAaI,WAAWJ,UAArD,EAAP;AACD,KAFD;AAGAI,eAAWF,IAAX;AACD,GAtBM,CAAP;AAuBD;;AAED;;;AAGA,SAASK,iBAAT,GAA6B;AAC3B,SAAO,IAAIvB,OAAJ,CAAY,UAASC,OAAT,EAAkBC,MAAlB,EAA0B;AAC3C,QAAMsB,oBAAoB,IAAIpB,cAAJ,EAA1B;AACAoB,sBAAkBnB,IAAlB,CAAuB,KAAvB,EAA8B3E,SAASC,cAAT,CAAwB,eAAxB,EAAyC2E,IAAvE,EACuB,IADvB;AAEAkB,sBAAkBjB,YAAlB,GAAiC,aAAjC;AACAiB,sBAAkBhB,MAAlB,GAA2B,UAACC,MAAD,EAAY;AACrC,UAAIe,kBAAkBd,MAAlB,IAA4B,GAA5B,IAAmCc,kBAAkBd,MAAlB,GAA2B,GAAlE,EAAuE;AACrE,YAAMe,kBAAkBD,kBAAkBZ,QAA1C;AACA,YAAIa,eAAJ,EAAqB;AACnB,cAAMC,gBAAgB,IAAIZ,YAAJ,CAAiBW,eAAjB,CAAtB;AACA9D,0BAAgB1C,QAAQ+C,OAAR,CAAgB+C,yBAAhB,CACZ/D,MAAMG,EADM,EACFb,cADE,EACcA,cADd,EAC8B,CAD9B,EACiCoF,aADjC,CAAhB;AAED;AACDzB,gBAAQuB,kBAAkBZ,QAA1B;AACD,OARD,MAQO;AACLV,eAAO;AACLQ,kBAASc,kBAAkBd,MADtB;AAELM,sBAAaQ,kBAAkBR;AAF1B,SAAP;AAID;AACF,KAfD;AAgBAQ,sBAAkBP,OAAlB,GAA4B,YAAW;AACrCf,aAAO;AACLQ,gBAASc,kBAAkBd,MADtB;AAELM,oBAAaQ,kBAAkBR;AAF1B,OAAP;AAID,KALD;AAMAQ,sBAAkBN,IAAlB;AACD,GA5BM,CAAP;AA6BD;;AAED;;;AAGA,SAASS,YAAT,GAAwB;AACtB,SAAO,IAAI3B,OAAJ,CAAY,UAASC,OAAT,EAAkBC,MAAlB,EAA0B;AAC3C,QAAM0B,eAAe,IAAIxB,cAAJ,EAArB;AACAwB,iBAAavB,IAAb,CAAkB,KAAlB,EAAyB3E,SAASC,cAAT,CAAwB,UAAxB,EAAoC2E,IAA7D,EAAmE,IAAnE;AACAsB,iBAAarB,YAAb,GAA4B,aAA5B;AACAqB,iBAAapB,MAAb,GAAsB,UAACC,MAAD,EAAY;AAChC,UAAImB,aAAalB,MAAb,IAAuB,GAAvB,IAA8BkB,aAAalB,MAAb,GAAsB,GAAxD,EAA6D;AAC3D,YAAMmB,sBAAsBD,aAAahB,QAAzC;AACA,YAAIiB,mBAAJ,EAAyB;AACvB,cAAMC,oBAAoB,IAAIhB,YAAJ,CAAiBe,mBAAjB,CAA1B;AACAjE,qBAAW3C,QAAQ+C,OAAR,CAAgB+C,yBAAhB,CACP/D,MAAMG,EADC,EACGb,cADH,EACmBA,cADnB,EACmC,CADnC,EACsCwF,iBADtC,CAAX;AAED;AACD7B,gBAAQ2B,aAAahB,QAArB;AACD,OARD,MAQO;AACLV,eAAO;AACLQ,kBAASkB,aAAalB,MADjB;AAELM,sBAAaY,aAAaZ;AAFrB,SAAP;AAID;AACF,KAfD;AAgBAY,iBAAaX,OAAb,GAAuB,YAAW;AAChCf,aACI,EAACQ,QAASkB,aAAalB,MAAvB,EAA+BM,YAAaY,aAAaZ,UAAzD,EADJ;AAED,KAHD;AAIAY,iBAAaV,IAAb;AACD,GAzBM,CAAP;AA0BD;AACDS,eAAeI,IAAf,CACI,YAAM;AAACC,YAAU9E,YAAV,EAAwBxB,SAASC,cAAT,CAAwB,UAAxB,EAAoC2E,IAA5D,EACKyB,IADL,CACU,YAAM;AAAChC,kBAAcgC,IAAd,CACH,YAAM;AAACR,0BAAoBQ,IAApB,CACH,YAAM;AAACZ,qBAAaY,IAAb,CAAkB,YAAW;AAClC1C;AACA4C;AACD,SAHM;AAGJ,OAJA;AAIE,KALN;AAKQ,GANzB;AAM2B,CAPtC;;AASA;;;;;;AAMA,SAASD,SAAT,CAAmB7E,EAAnB,EAAuB+E,GAAvB,EAA4B;AAC1B,SAAO,IAAIlC,OAAJ,CAAY,UAASC,OAAT,EAAkBC,MAAlB,EAA0B;AAC3C,QAAMiC,UAAUhF,GAAGiF,aAAH,EAAhB;AACAjF,OAAGkF,WAAH,CAAelF,GAAGmF,UAAlB,EAA8BH,OAA9B;AACA,QAAMI,QAAQ,CAAd;AACA;AACA,QAAMC,iBAAiBrF,GAAGsF,KAA1B;AACA,QAAMC,SAAS,CAAf;AACA;AACA,QAAMC,YAAYxF,GAAGyF,IAArB;AACA,QAAMC,UAAU1F,GAAG2F,aAAnB;AACA,QAAMC,QAAQ,IAAIC,UAAJ,CAAe,CAAE,CAAF,EAAK,CAAL,EAAQ,GAAR,EAAa,GAAb,CAAf,CAAd;AACA7F,OAAG8F,UAAH,CAAc9F,GAAGmF,UAAjB,EAA6BC,KAA7B,EAAoCC,cAApC,EAAoD,CAApD,EAAuD,CAAvD,EAA0DE,MAA1D,EAAkEC,SAAlE,EACcE,OADd,EACuBE,KADvB;;AAGA,QAAMG,QAAQ,IAAIC,KAAJ,EAAd;AACAD,UAAM1C,MAAN,GAAe,YAAM;AACnBrD,SAAGkF,WAAH,CAAelF,GAAGmF,UAAlB,EAA8BH,OAA9B;AACAhF,SAAG8F,UAAH,CAAc9F,GAAGmF,UAAjB,EAA6BC,KAA7B,EAAoCC,cAApC,EAAoDG,SAApD,EAA+DE,OAA/D,EACcK,KADd;AAEA/F,SAAGiG,aAAH,CAAiBjG,GAAGmF,UAApB,EAAgCnF,GAAGkG,cAAnC,EAAmDlG,GAAGmG,aAAtD;AACAnG,SAAGiG,aAAH,CAAiBjG,GAAGmF,UAApB,EAAgCnF,GAAGoG,cAAnC,EAAmDpG,GAAGmG,aAAtD;AACAnG,SAAGiG,aAAH,CAAiBjG,GAAGmF,UAApB,EAAgCnF,GAAGqG,kBAAnC,EAAuDrG,GAAGsG,OAA1D;AACAtG,SAAGiG,aAAH,CAAiBjG,GAAGmF,UAApB,EAAgCnF,GAAGuG,kBAAnC,EAAuDvG,GAAGsG,OAA1D;AACD,KARD;AASAP,UAAMS,GAAN,GAAYzB,GAAZ;AACApE,mBAAeqE,OAAf;AACAlC;AACD,GA3BM,CAAP;AA4BD;;AAED;;AAEA,SAASgC,YAAT,GAAwB;AACtB,MAAM2B,gBAAgBlI,SAASmI,aAAT,CAAuB,kBAAvB,CAAtB;AACAD,gBAAcE,SAAd,CAAwBC,MAAxB,CAA+B,QAA/B;;AAEA,MAAMC,iBAAiBtI,SAASmI,aAAT,CAAuB,mBAAvB,CAAvB;AACAG,iBAAeD,MAAf;AACD","file":"df22bba5d9b0d3a9ea33ea19cbf2f7cd.map","sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nfunction isMobile() {\n var a = navigator.userAgent || navigator.vendor || window.opera;\n return /(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i\n .test(a) ||\n /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\\-|your|zeto|zte\\-/i\n .test(a.substr(0, 4));\n}\nexports.isMobile = isMobile;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nfunction doc(info) {\n return function () {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n };\n}\nexports.doc = doc;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tensor_1 = require(\"./tensor\");\nfunction assertArgumentIsTensor(x, argName, functionName) {\n assert(x instanceof tensor_1.Tensor, \"Argument '\" + argName + \"' passed to '\" + functionName + \"' must be a Tensor, \" +\n (\"but got \" + typeof x + \".\"));\n}\nfunction assertArgumentsAreTensors(args, functionName) {\n var _loop_1 = function (argName) {\n var arg = args[argName];\n if (Array.isArray(arg)) {\n arg.forEach(function (t, i) {\n assertArgumentIsTensor(t, argName + \"[\" + i + \"]\", functionName);\n });\n }\n else {\n assertArgumentIsTensor(arg, argName, functionName);\n }\n };\n for (var argName in args) {\n _loop_1(argName);\n }\n}\nexports.assertArgumentsAreTensors = assertArgumentsAreTensors;\nfunction shuffle(array) {\n var counter = array.length;\n var temp = 0;\n var index = 0;\n while (counter > 0) {\n index = (Math.random() * counter) | 0;\n counter--;\n temp = array[counter];\n array[counter] = array[index];\n array[index] = temp;\n }\n}\nexports.shuffle = shuffle;\nfunction clamp(min, x, max) {\n return Math.max(min, Math.min(x, max));\n}\nexports.clamp = clamp;\nfunction randUniform(a, b) {\n return Math.random() * (b - a) + a;\n}\nexports.randUniform = randUniform;\nfunction distSquared(a, b) {\n var result = 0;\n for (var i = 0; i < a.length; i++) {\n var diff = Number(a[i]) - Number(b[i]);\n result += diff * diff;\n }\n return result;\n}\nexports.distSquared = distSquared;\nfunction assert(expr, msg) {\n if (!expr) {\n throw new Error(msg);\n }\n}\nexports.assert = assert;\nfunction assertShapesMatch(shapeA, shapeB, errorMessagePrefix) {\n if (errorMessagePrefix === void 0) { errorMessagePrefix = ''; }\n assert(arraysEqual(shapeA, shapeB), errorMessagePrefix + (\" Shapes \" + shapeA + \" and \" + shapeB + \" must match\"));\n}\nexports.assertShapesMatch = assertShapesMatch;\nfunction assertTypesMatch(a, b) {\n assert(a.dtype === b.dtype, \" The dtypes of the first(\" + a.dtype + \") and\" +\n (\" second(\" + b.dtype + \") input must match\"));\n}\nexports.assertTypesMatch = assertTypesMatch;\nfunction flatten(arr, ret) {\n if (ret === void 0) { ret = []; }\n if (Array.isArray(arr)) {\n for (var i = 0; i < arr.length; ++i) {\n flatten(arr[i], ret);\n }\n }\n else {\n ret.push(arr);\n }\n return ret;\n}\nexports.flatten = flatten;\nfunction inferShape(val) {\n if (isTypedArray(val)) {\n return [val.length];\n }\n if (!Array.isArray(val)) {\n return [];\n }\n var shape = [];\n while (val instanceof Array) {\n shape.push(val.length);\n val = val[0];\n }\n return shape;\n}\nexports.inferShape = inferShape;\nfunction sizeFromShape(shape) {\n if (shape.length === 0) {\n return 1;\n }\n var size = shape[0];\n for (var i = 1; i < shape.length; i++) {\n size *= shape[i];\n }\n return size;\n}\nexports.sizeFromShape = sizeFromShape;\nfunction isScalarShape(shape) {\n return shape.length === 0;\n}\nexports.isScalarShape = isScalarShape;\nfunction arraysEqual(n1, n2) {\n if (n1.length !== n2.length) {\n return false;\n }\n for (var i = 0; i < n1.length; i++) {\n if (n1[i] !== n2[i]) {\n return false;\n }\n }\n return true;\n}\nexports.arraysEqual = arraysEqual;\nfunction isInt(a) {\n return a % 1 === 0;\n}\nexports.isInt = isInt;\nfunction tanh(x) {\n if (Math.tanh != null) {\n return Math.tanh(x);\n }\n if (x === Infinity) {\n return 1;\n }\n else if (x === -Infinity) {\n return -1;\n }\n else {\n var e2x = Math.exp(2 * x);\n return (e2x - 1) / (e2x + 1);\n }\n}\nexports.tanh = tanh;\nfunction sizeToSquarishShape(size) {\n for (var a = Math.floor(Math.sqrt(size)); a > 1; --a) {\n if (size % a === 0) {\n return [a, size / a];\n }\n }\n return [1, size];\n}\nexports.sizeToSquarishShape = sizeToSquarishShape;\nfunction createShuffledIndices(n) {\n var shuffledIndices = new Uint32Array(n);\n for (var i = 0; i < n; ++i) {\n shuffledIndices[i] = i;\n }\n shuffle(shuffledIndices);\n return shuffledIndices;\n}\nexports.createShuffledIndices = createShuffledIndices;\nfunction rightPad(a, size) {\n if (size <= a.length) {\n return a;\n }\n return a + ' '.repeat(size - a.length);\n}\nexports.rightPad = rightPad;\nfunction repeatedTry(checkFn, delayFn, maxCounter) {\n if (delayFn === void 0) { delayFn = function (counter) { return 0; }; }\n return new Promise(function (resolve, reject) {\n var tryCount = 0;\n var tryFn = function () {\n if (checkFn()) {\n resolve();\n return;\n }\n tryCount++;\n var nextBackoff = delayFn(tryCount);\n if (maxCounter != null && tryCount >= maxCounter) {\n reject();\n return;\n }\n setTimeout(tryFn, nextBackoff);\n };\n setTimeout(tryFn, 0);\n });\n}\nexports.repeatedTry = repeatedTry;\nfunction getQueryParams(queryString) {\n var params = {};\n queryString.replace(/[?&]([^=?&]+)(?:=([^&]*))?/g, function (s) {\n var t = [];\n for (var _i = 1; _i < arguments.length; _i++) {\n t[_i - 1] = arguments[_i];\n }\n decodeParam(params, t[0], t[1]);\n return t.join('=');\n });\n return params;\n}\nexports.getQueryParams = getQueryParams;\nfunction decodeParam(params, name, value) {\n params[decodeURIComponent(name)] = decodeURIComponent(value || '');\n}\nfunction inferFromImplicitShape(shape, size) {\n var shapeProd = 1;\n var implicitIdx = -1;\n for (var i = 0; i < shape.length; ++i) {\n if (shape[i] > 0) {\n shapeProd *= shape[i];\n }\n else if (shape[i] === -1) {\n if (implicitIdx !== -1) {\n throw Error(\"Shapes can only have 1 implicit size. \" +\n (\"Found - 1 at dim \" + implicitIdx + \" and dim \" + i));\n }\n implicitIdx = i;\n }\n else if (shape[i] <= 0) {\n throw Error(\"Shapes can not be <= 0. Found \" + shape[i] + \" at dim \" + i);\n }\n }\n if (implicitIdx === -1) {\n if (size > 0 && size !== shapeProd) {\n throw Error(\"Size(\" + size + \") must match the product of shape \" + shape);\n }\n return shape;\n }\n if (size % shapeProd !== 0) {\n throw Error(\"The implicit shape can't be a fractional number. \" +\n (\"Got \" + size + \" / \" + shapeProd));\n }\n var newShape = shape.slice();\n newShape[implicitIdx] = size / shapeProd;\n return newShape;\n}\nexports.inferFromImplicitShape = inferFromImplicitShape;\nfunction squeezeShape(shape, axis) {\n var newShape = [];\n var keptDims = [];\n var j = 0;\n for (var i = 0; i < shape.length; ++i) {\n if (axis != null) {\n if (axis[j] === i && shape[i] > 1) {\n throw new Error(\"Can't squeeze axis \" + i + \" since its dim '\" + shape[i] + \"' is not 1\");\n }\n if ((axis[j] == null || axis[j] > i) && shape[i] === 1) {\n newShape.push(shape[i]);\n keptDims.push(i);\n }\n if (axis[j] <= i) {\n j++;\n }\n }\n if (shape[i] > 1) {\n newShape.push(shape[i]);\n keptDims.push(i);\n }\n }\n return { newShape: newShape, keptDims: keptDims };\n}\nexports.squeezeShape = squeezeShape;\nfunction getTypedArrayFromDType(dtype, size) {\n var values = null;\n if (dtype == null || dtype === 'float32') {\n values = new Float32Array(size);\n }\n else if (dtype === 'int32') {\n values = new Int32Array(size);\n }\n else if (dtype === 'bool') {\n values = new Uint8Array(size);\n }\n else {\n throw new Error(\"Unknown data type \" + dtype);\n }\n return values;\n}\nexports.getTypedArrayFromDType = getTypedArrayFromDType;\nfunction isTensorInList(tensor, tensorList) {\n for (var i = 0; i < tensorList.length; i++) {\n if (tensorList[i].id === tensor.id) {\n return true;\n }\n }\n return false;\n}\nexports.isTensorInList = isTensorInList;\nfunction checkForNaN(vals, dtype, name) {\n if (dtype !== 'float32') {\n return;\n }\n for (var i = 0; i < vals.length; i++) {\n if (isNaN(vals[i])) {\n throw Error(\"The result of the '\" + name + \"' has NaNs.\");\n }\n }\n}\nexports.checkForNaN = checkForNaN;\nfunction flattenNameArrayMap(nameArrayMap, keys) {\n var xs = [];\n if (nameArrayMap instanceof tensor_1.Tensor) {\n xs.push(nameArrayMap);\n }\n else {\n var xMap = nameArrayMap;\n for (var i = 0; i < keys.length; i++) {\n xs.push(xMap[keys[i]]);\n }\n }\n return xs;\n}\nexports.flattenNameArrayMap = flattenNameArrayMap;\nfunction unflattenToNameArrayMap(keys, flatArrays) {\n if (keys.length !== flatArrays.length) {\n throw new Error(\"Cannot unflatten Tensor[], keys and arrays are not of same length.\");\n }\n var result = {};\n for (var i = 0; i < keys.length; i++) {\n result[keys[i]] = flatArrays[i];\n }\n return result;\n}\nexports.unflattenToNameArrayMap = unflattenToNameArrayMap;\nfunction hasEncodingLoss(oldType, newType) {\n if (newType === 'float32') {\n return false;\n }\n if (newType === 'int32' && oldType !== 'float32') {\n return false;\n }\n if (newType === 'bool' && oldType === 'bool') {\n return false;\n }\n return true;\n}\nexports.hasEncodingLoss = hasEncodingLoss;\nfunction copyTypedArray(array, dtype) {\n if (dtype == null || dtype === 'float32') {\n return new Float32Array(array);\n }\n else if (dtype === 'int32') {\n return new Int32Array(array);\n }\n else if (dtype === 'bool') {\n var bool = new Uint8Array(array.length);\n for (var i = 0; i < bool.length; ++i) {\n if (Math.round(array[i]) !== 0) {\n bool[i] = 1;\n }\n }\n return bool;\n }\n else {\n throw new Error(\"Unknown data type \" + dtype);\n }\n}\nexports.copyTypedArray = copyTypedArray;\nfunction isTypedArray(a) {\n return a instanceof Float32Array || a instanceof Int32Array ||\n a instanceof Uint8Array;\n}\nexports.isTypedArray = isTypedArray;\nfunction bytesPerElement(dtype) {\n if (dtype === 'float32' || dtype === 'int32') {\n return 4;\n }\n else if (dtype === 'bool') {\n return 1;\n }\n else {\n throw new Error(\"Unknown dtype \" + dtype);\n }\n}\nexports.bytesPerElement = bytesPerElement;\nfunction isFunction(f) {\n return !!(f && f.constructor && f.call && f.apply);\n}\nexports.isFunction = isFunction;\nfunction extractTensorsFromContainer(result) {\n return extractTensorsFromAny(result);\n}\nexports.extractTensorsFromContainer = extractTensorsFromContainer;\nfunction extractTensorsFromAny(result) {\n if (result == null) {\n return [];\n }\n if (result instanceof tensor_1.Tensor) {\n return [result];\n }\n var list = [];\n var resultObj = result;\n if (!isIterable(resultObj)) {\n return [];\n }\n for (var k in resultObj) {\n var sublist = flatten(resultObj[k]).filter(function (x) { return x instanceof tensor_1.Tensor; });\n list.push.apply(list, sublist);\n }\n return list;\n}\nexports.extractTensorsFromAny = extractTensorsFromAny;\nfunction isIterable(obj) {\n return Array.isArray(obj) || typeof obj === 'object';\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar util = require(\"./util\");\nvar FORMAT_LIMIT_NUM_VALS = 20;\nvar FORMAT_NUM_FIRST_LAST_VALS = 3;\nvar FORMAT_NUM_SIG_DIGITS = 7;\nfunction tensorToString(t, verbose) {\n var vals = t.dataSync();\n var padPerCol = computeMaxSizePerColumn(t);\n var valsLines = subTensorToString(vals, t.shape, t.strides, padPerCol);\n var lines = ['Tensor'];\n if (verbose) {\n lines.push(\" dtype: \" + t.dtype);\n lines.push(\" rank: \" + t.rank);\n lines.push(\" shape: [\" + t.shape + \"]\");\n lines.push(\" values:\");\n }\n lines.push(valsLines.map(function (l) { return ' ' + l; }).join('\\n'));\n return lines.join('\\n');\n}\nexports.tensorToString = tensorToString;\nfunction computeMaxSizePerColumn(t) {\n var vals = t.dataSync();\n var n = t.size;\n var numCols = t.strides[t.strides.length - 1];\n var padPerCol = new Array(numCols).fill(0);\n if (t.rank > 1) {\n for (var row = 0; row < n / numCols; row++) {\n var offset = row * numCols;\n for (var j = 0; j < numCols; j++) {\n padPerCol[j] =\n Math.max(padPerCol[j], valToString(vals[offset + j], 0).length);\n }\n }\n }\n return padPerCol;\n}\nfunction valToString(val, pad) {\n return util.rightPad(parseFloat(val.toFixed(FORMAT_NUM_SIG_DIGITS)).toString(), pad);\n}\nfunction subTensorToString(vals, shape, strides, padPerCol, isLast) {\n if (isLast === void 0) { isLast = true; }\n var size = shape[0];\n var rank = shape.length;\n if (rank === 0) {\n return [vals[0].toString()];\n }\n if (rank === 1) {\n if (size > FORMAT_LIMIT_NUM_VALS) {\n var firstVals = Array.from(vals.subarray(0, FORMAT_NUM_FIRST_LAST_VALS));\n var lastVals = Array.from(vals.subarray(size - FORMAT_NUM_FIRST_LAST_VALS, size));\n return [\n '[' + firstVals.map(function (x, i) { return valToString(x, padPerCol[i]); }).join(', ') +\n ', ..., ' +\n lastVals\n .map(function (x, i) { return valToString(x, padPerCol[size - FORMAT_NUM_FIRST_LAST_VALS + i]); })\n .join(', ') +\n ']'\n ];\n }\n return [\n '[' +\n Array.from(vals).map(function (x, i) { return valToString(x, padPerCol[i]); }).join(', ') +\n ']'\n ];\n }\n var subshape = shape.slice(1);\n var substrides = strides.slice(1);\n var stride = strides[0];\n var lines = [];\n if (size > FORMAT_LIMIT_NUM_VALS) {\n for (var i = 0; i < FORMAT_NUM_FIRST_LAST_VALS; i++) {\n var start = i * stride;\n var end = start + stride;\n lines.push.apply(lines, subTensorToString(vals.subarray(start, end), subshape, substrides, padPerCol, false));\n }\n lines.push('...');\n for (var i = size - FORMAT_NUM_FIRST_LAST_VALS; i < size; i++) {\n var start = i * stride;\n var end = start + stride;\n lines.push.apply(lines, subTensorToString(vals.subarray(start, end), subshape, substrides, padPerCol, i === size - 1));\n }\n }\n else {\n for (var i = 0; i < size; i++) {\n var start = i * stride;\n var end = start + stride;\n lines.push.apply(lines, subTensorToString(vals.subarray(start, end), subshape, substrides, padPerCol, i === size - 1));\n }\n }\n var sep = rank === 2 ? ',' : '';\n lines[0] = '[' + lines[0] + sep;\n for (var i = 1; i < lines.length - 1; i++) {\n lines[i] = ' ' + lines[i] + sep;\n }\n var newLineSep = ',\\n';\n for (var i = 2; i < rank; i++) {\n newLineSep += '\\n';\n }\n lines[lines.length - 1] =\n ' ' + lines[lines.length - 1] + ']' + (isLast ? '' : newLineSep);\n return lines;\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar util = require(\"../util\");\nfunction axesAreInnerMostDims(axes, rank) {\n for (var i = 0; i < axes.length; ++i) {\n if (axes[axes.length - i - 1] !== rank - 1 - i) {\n return false;\n }\n }\n return true;\n}\nexports.axesAreInnerMostDims = axesAreInnerMostDims;\nfunction combineLocations(outputLoc, reduceLoc, axes) {\n var rank = outputLoc.length + reduceLoc.length;\n var loc = [];\n var outIdx = 0;\n var reduceIdx = 0;\n for (var dim = 0; dim < rank; dim++) {\n if (axes.indexOf(dim) === -1) {\n loc.push(outputLoc[outIdx++]);\n }\n else {\n loc.push(reduceLoc[reduceIdx++]);\n }\n }\n return loc;\n}\nexports.combineLocations = combineLocations;\nfunction computeOutAndReduceShapes(aShape, axes) {\n var outShape = [];\n var rank = aShape.length;\n for (var dim = 0; dim < rank; dim++) {\n if (axes.indexOf(dim) === -1) {\n outShape.push(aShape[dim]);\n }\n }\n var reduceShape = axes.map(function (dim) { return aShape[dim]; });\n return [outShape, reduceShape];\n}\nexports.computeOutAndReduceShapes = computeOutAndReduceShapes;\nfunction expandShapeToKeepDim(shape, axes) {\n var reduceSubShape = axes.map(function (x) { return 1; });\n return combineLocations(shape, reduceSubShape, axes);\n}\nexports.expandShapeToKeepDim = expandShapeToKeepDim;\nfunction parseAxisParam(axis, shape) {\n var rank = shape.length;\n axis = axis == null ? shape.map(function (s, i) { return i; }) : [].concat(axis);\n util.assert(axis.every(function (ax) { return ax >= -rank && ax < rank; }), \"All values in axis param must be in range [-\" + rank + \", \" + rank + \") but \" +\n (\"got axis \" + axis));\n util.assert(axis.every(function (ax) { return util.isInt(ax); }), \"All values in axis param must be integers but \" +\n (\"got axis \" + axis));\n return axis.map(function (a) { return a < 0 ? rank + a : a; });\n}\nexports.parseAxisParam = parseAxisParam;\nfunction assertAxesAreInnerMostDims(msg, axes, rank) {\n util.assert(axesAreInnerMostDims(axes, rank), msg + \" supports only inner-most axes for now. \" +\n (\"Got axes \" + axes + \" and rank-\" + rank + \" input.\"));\n}\nexports.assertAxesAreInnerMostDims = assertAxesAreInnerMostDims;\nfunction getAxesPermutation(axes, rank) {\n if (axesAreInnerMostDims(axes, rank)) {\n return null;\n }\n var result = [];\n for (var i = 0; i < rank; ++i) {\n if (axes.indexOf(i) === -1) {\n result.push(i);\n }\n }\n axes.forEach(function (axis) { return result.push(axis); });\n return result;\n}\nexports.getAxesPermutation = getAxesPermutation;\nfunction getUndoAxesPermutation(axes) {\n return axes.map(function (axis, i) { return [i, axis]; })\n .sort(function (a, b) { return a[1] - b[1]; })\n .map(function (x) { return x[0]; });\n}\nexports.getUndoAxesPermutation = getUndoAxesPermutation;\nfunction getInnerMostAxes(numAxes, rank) {\n var res = [];\n for (var i = rank - numAxes; i < rank; ++i) {\n res.push(i);\n }\n return res;\n}\nexports.getInnerMostAxes = getInnerMostAxes;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar util = require(\"../util\");\nfunction assertParams(aShape, bShape, axis) {\n var aRank = aShape.length;\n var bRank = bShape.length;\n util.assert(aShape.length === bShape.length, \"Error in concat\" + aRank + \"D: rank of x1 (\" + aRank + \") and x2 (\" + bRank + \") \" +\n \"must be the same.\");\n util.assert(axis >= 0 && axis < aRank, \"Error in concat\" + aRank + \"D: axis must be \" +\n (\"between 0 and \" + (aRank - 1) + \".\"));\n for (var i = 0; i < aRank; i++) {\n util.assert((i === axis) || (aShape[i] === bShape[i]), \"Error in concat\" + aRank + \"D: Shape (\" + aShape + \") does not match \" +\n (\"(\" + bShape + \") along the non-concatenated axis \" + i + \".\"));\n }\n}\nexports.assertParams = assertParams;\nfunction computeOutShape1D(x1Shape, x2Shape) {\n util.assert(x1Shape.length === 1 && x2Shape.length === 1, 'x1 and x2 should be 1d array.');\n var outputShape = x1Shape.slice();\n outputShape[0] += x2Shape[0];\n return outputShape;\n}\nexports.computeOutShape1D = computeOutShape1D;\nfunction computeOutShape(x1Shape, x2Shape, axis) {\n util.assert(x1Shape.length === x2Shape.length, 'x1 and x2 should have the same rank.');\n var outputShape = x1Shape.slice();\n outputShape[axis] += x2Shape[axis];\n return outputShape;\n}\nexports.computeOutShape = computeOutShape;\nfunction computeGradientSliceShapes(aShape, bShape) {\n return {\n aBegin: [0, 0],\n aSize: aShape,\n bBegin: [0, aShape[1]],\n bSize: bShape\n };\n}\nexports.computeGradientSliceShapes = computeGradientSliceShapes;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar globals_1 = require(\"../globals\");\nfunction operation(target, name, descriptor) {\n var fn = descriptor.value;\n descriptor.value = function () {\n var args = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n args[_i] = arguments[_i];\n }\n return globals_1.tidy(name, function () { return fn.apply(void 0, args); });\n };\n return descriptor;\n}\nexports.operation = operation;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar axis_util_1 = require(\"./axis_util\");\nvar concat_util = require(\"./concat_util\");\nvar operation_1 = require(\"./operation\");\nvar ConcatOps = (function () {\n function ConcatOps() {\n }\n ConcatOps.concat1d = function (tensors) {\n return ConcatOps.concat(tensors, 0);\n };\n ConcatOps.concat2d = function (tensors, axis) {\n return ConcatOps.concat(tensors, axis);\n };\n ConcatOps.concat3d = function (tensors, axis) {\n return ConcatOps.concat(tensors, axis);\n };\n ConcatOps.concat4d = function (tensors, axis) {\n return ConcatOps.concat(tensors, axis);\n };\n ConcatOps.concat = function (tensors, axis) {\n if (axis === void 0) { axis = 0; }\n util.assert(tensors.length >= 1, 'Pass at least one tensor to concat');\n util.assertArgumentsAreTensors({ tensors: tensors }, 'concat');\n var result = tensors[0];\n if (tensors.length === 1) {\n return result;\n }\n var axes = axis_util_1.parseAxisParam(axis, result.shape);\n for (var i = 1; i < tensors.length; ++i) {\n result = concat2Tensors(result, tensors[i], axes[0]);\n }\n return result;\n };\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),\n operation_1.operation\n ], ConcatOps, \"concat\", null);\n return ConcatOps;\n}());\nexports.ConcatOps = ConcatOps;\nfunction concat2Tensors(a, b, axis) {\n concat_util.assertParams(a.shape, b.shape, axis);\n var outShape = concat_util.computeOutShape(a.shape, b.shape, axis);\n var a2D = a.as2D(-1, util.sizeFromShape(a.shape.slice(axis)));\n var b2D = b.as2D(-1, util.sizeFromShape(b.shape.slice(axis)));\n var _a = concat_util.computeGradientSliceShapes(a2D.shape, b2D.shape), aBegin = _a.aBegin, aSize = _a.aSize, bBegin = _a.bBegin, bSize = _a.bSize;\n var der = function (dy) {\n return { a: function () { return dy.slice(aBegin, aSize); }, b: function () { return dy.slice(bBegin, bSize); } };\n };\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.concat(a2D, b2D); }, { a: a2D, b: b2D }, der);\n return res.reshape(outShape);\n}\n","// A port of an algorithm by Johannes Baagøe <[email protected]>, 2010\n// http://baagoe.com/en/RandomMusings/javascript/\n// https://github.com/nquinlan/better-random-numbers-for-javascript-mirror\n// Original work is under MIT license -\n\n// Copyright (C) 2010 by Johannes Baagøe <[email protected]>\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n// \n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n// \n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\n\n\n(function(global, module, define) {\n\nfunction Alea(seed) {\n var me = this, mash = Mash();\n\n me.next = function() {\n var t = 2091639 * me.s0 + me.c * 2.3283064365386963e-10; // 2^-32\n me.s0 = me.s1;\n me.s1 = me.s2;\n return me.s2 = t - (me.c = t | 0);\n };\n\n // Apply the seeding algorithm from Baagoe.\n me.c = 1;\n me.s0 = mash(' ');\n me.s1 = mash(' ');\n me.s2 = mash(' ');\n me.s0 -= mash(seed);\n if (me.s0 < 0) { me.s0 += 1; }\n me.s1 -= mash(seed);\n if (me.s1 < 0) { me.s1 += 1; }\n me.s2 -= mash(seed);\n if (me.s2 < 0) { me.s2 += 1; }\n mash = null;\n}\n\nfunction copy(f, t) {\n t.c = f.c;\n t.s0 = f.s0;\n t.s1 = f.s1;\n t.s2 = f.s2;\n return t;\n}\n\nfunction impl(seed, opts) {\n var xg = new Alea(seed),\n state = opts && opts.state,\n prng = xg.next;\n prng.int32 = function() { return (xg.next() * 0x100000000) | 0; }\n prng.double = function() {\n return prng() + (prng() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53\n };\n prng.quick = prng;\n if (state) {\n if (typeof(state) == 'object') copy(state, xg);\n prng.state = function() { return copy(xg, {}); }\n }\n return prng;\n}\n\nfunction Mash() {\n var n = 0xefc8249d;\n\n var mash = function(data) {\n data = data.toString();\n for (var i = 0; i < data.length; i++) {\n n += data.charCodeAt(i);\n var h = 0.02519603282416938 * n;\n n = h >>> 0;\n h -= n;\n h *= n;\n n = h >>> 0;\n h -= n;\n n += h * 0x100000000; // 2^32\n }\n return (n >>> 0) * 2.3283064365386963e-10; // 2^-32\n };\n\n return mash;\n}\n\n\nif (module && module.exports) {\n module.exports = impl;\n} else if (define && define.amd) {\n define(function() { return impl; });\n} else {\n this.alea = impl;\n}\n\n})(\n this,\n (typeof module) == 'object' && module, // present in node.js\n (typeof define) == 'function' && define // present with an AMD loader\n);\n\n\n","// A Javascript implementaion of the \"xor128\" prng algorithm by\n// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper\n\n(function(global, module, define) {\n\nfunction XorGen(seed) {\n var me = this, strseed = '';\n\n me.x = 0;\n me.y = 0;\n me.z = 0;\n me.w = 0;\n\n // Set up generator function.\n me.next = function() {\n var t = me.x ^ (me.x << 11);\n me.x = me.y;\n me.y = me.z;\n me.z = me.w;\n return me.w ^= (me.w >>> 19) ^ t ^ (t >>> 8);\n };\n\n if (seed === (seed | 0)) {\n // Integer seed.\n me.x = seed;\n } else {\n // String seed.\n strseed += seed;\n }\n\n // Mix in string seed, then discard an initial batch of 64 values.\n for (var k = 0; k < strseed.length + 64; k++) {\n me.x ^= strseed.charCodeAt(k) | 0;\n me.next();\n }\n}\n\nfunction copy(f, t) {\n t.x = f.x;\n t.y = f.y;\n t.z = f.z;\n t.w = f.w;\n return t;\n}\n\nfunction impl(seed, opts) {\n var xg = new XorGen(seed),\n state = opts && opts.state,\n prng = function() { return (xg.next() >>> 0) / 0x100000000; };\n prng.double = function() {\n do {\n var top = xg.next() >>> 11,\n bot = (xg.next() >>> 0) / 0x100000000,\n result = (top + bot) / (1 << 21);\n } while (result === 0);\n return result;\n };\n prng.int32 = xg.next;\n prng.quick = prng;\n if (state) {\n if (typeof(state) == 'object') copy(state, xg);\n prng.state = function() { return copy(xg, {}); }\n }\n return prng;\n}\n\nif (module && module.exports) {\n module.exports = impl;\n} else if (define && define.amd) {\n define(function() { return impl; });\n} else {\n this.xor128 = impl;\n}\n\n})(\n this,\n (typeof module) == 'object' && module, // present in node.js\n (typeof define) == 'function' && define // present with an AMD loader\n);\n\n\n","// A Javascript implementaion of the \"xorwow\" prng algorithm by\n// George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper\n\n(function(global, module, define) {\n\nfunction XorGen(seed) {\n var me = this, strseed = '';\n\n // Set up generator function.\n me.next = function() {\n var t = (me.x ^ (me.x >>> 2));\n me.x = me.y; me.y = me.z; me.z = me.w; me.w = me.v;\n return (me.d = (me.d + 362437 | 0)) +\n (me.v = (me.v ^ (me.v << 4)) ^ (t ^ (t << 1))) | 0;\n };\n\n me.x = 0;\n me.y = 0;\n me.z = 0;\n me.w = 0;\n me.v = 0;\n\n if (seed === (seed | 0)) {\n // Integer seed.\n me.x = seed;\n } else {\n // String seed.\n strseed += seed;\n }\n\n // Mix in string seed, then discard an initial batch of 64 values.\n for (var k = 0; k < strseed.length + 64; k++) {\n me.x ^= strseed.charCodeAt(k) | 0;\n if (k == strseed.length) {\n me.d = me.x << 10 ^ me.x >>> 4;\n }\n me.next();\n }\n}\n\nfunction copy(f, t) {\n t.x = f.x;\n t.y = f.y;\n t.z = f.z;\n t.w = f.w;\n t.v = f.v;\n t.d = f.d;\n return t;\n}\n\nfunction impl(seed, opts) {\n var xg = new XorGen(seed),\n state = opts && opts.state,\n prng = function() { return (xg.next() >>> 0) / 0x100000000; };\n prng.double = function() {\n do {\n var top = xg.next() >>> 11,\n bot = (xg.next() >>> 0) / 0x100000000,\n result = (top + bot) / (1 << 21);\n } while (result === 0);\n return result;\n };\n prng.int32 = xg.next;\n prng.quick = prng;\n if (state) {\n if (typeof(state) == 'object') copy(state, xg);\n prng.state = function() { return copy(xg, {}); }\n }\n return prng;\n}\n\nif (module && module.exports) {\n module.exports = impl;\n} else if (define && define.amd) {\n define(function() { return impl; });\n} else {\n this.xorwow = impl;\n}\n\n})(\n this,\n (typeof module) == 'object' && module, // present in node.js\n (typeof define) == 'function' && define // present with an AMD loader\n);\n\n\n","// A Javascript implementaion of the \"xorshift7\" algorithm by\n// François Panneton and Pierre L'ecuyer:\n// \"On the Xorgshift Random Number Generators\"\n// http://saluc.engr.uconn.edu/refs/crypto/rng/panneton05onthexorshift.pdf\n\n(function(global, module, define) {\n\nfunction XorGen(seed) {\n var me = this;\n\n // Set up generator function.\n me.next = function() {\n // Update xor generator.\n var X = me.x, i = me.i, t, v, w;\n t = X[i]; t ^= (t >>> 7); v = t ^ (t << 24);\n t = X[(i + 1) & 7]; v ^= t ^ (t >>> 10);\n t = X[(i + 3) & 7]; v ^= t ^ (t >>> 3);\n t = X[(i + 4) & 7]; v ^= t ^ (t << 7);\n t = X[(i + 7) & 7]; t = t ^ (t << 13); v ^= t ^ (t << 9);\n X[i] = v;\n me.i = (i + 1) & 7;\n return v;\n };\n\n function init(me, seed) {\n var j, w, X = [];\n\n if (seed === (seed | 0)) {\n // Seed state array using a 32-bit integer.\n w = X[0] = seed;\n } else {\n // Seed state using a string.\n seed = '' + seed;\n for (j = 0; j < seed.length; ++j) {\n X[j & 7] = (X[j & 7] << 15) ^\n (seed.charCodeAt(j) + X[(j + 1) & 7] << 13);\n }\n }\n // Enforce an array length of 8, not all zeroes.\n while (X.length < 8) X.push(0);\n for (j = 0; j < 8 && X[j] === 0; ++j);\n if (j == 8) w = X[7] = -1; else w = X[j];\n\n me.x = X;\n me.i = 0;\n\n // Discard an initial 256 values.\n for (j = 256; j > 0; --j) {\n me.next();\n }\n }\n\n init(me, seed);\n}\n\nfunction copy(f, t) {\n t.x = f.x.slice();\n t.i = f.i;\n return t;\n}\n\nfunction impl(seed, opts) {\n if (seed == null) seed = +(new Date);\n var xg = new XorGen(seed),\n state = opts && opts.state,\n prng = function() { return (xg.next() >>> 0) / 0x100000000; };\n prng.double = function() {\n do {\n var top = xg.next() >>> 11,\n bot = (xg.next() >>> 0) / 0x100000000,\n result = (top + bot) / (1 << 21);\n } while (result === 0);\n return result;\n };\n prng.int32 = xg.next;\n prng.quick = prng;\n if (state) {\n if (state.x) copy(state, xg);\n prng.state = function() { return copy(xg, {}); }\n }\n return prng;\n}\n\nif (module && module.exports) {\n module.exports = impl;\n} else if (define && define.amd) {\n define(function() { return impl; });\n} else {\n this.xorshift7 = impl;\n}\n\n})(\n this,\n (typeof module) == 'object' && module, // present in node.js\n (typeof define) == 'function' && define // present with an AMD loader\n);\n\n","// A Javascript implementaion of Richard Brent's Xorgens xor4096 algorithm.\n//\n// This fast non-cryptographic random number generator is designed for\n// use in Monte-Carlo algorithms. It combines a long-period xorshift\n// generator with a Weyl generator, and it passes all common batteries\n// of stasticial tests for randomness while consuming only a few nanoseconds\n// for each prng generated. For background on the generator, see Brent's\n// paper: \"Some long-period random number generators using shifts and xors.\"\n// http://arxiv.org/pdf/1004.3115v1.pdf\n//\n// Usage:\n//\n// var xor4096 = require('xor4096');\n// random = xor4096(1); // Seed with int32 or string.\n// assert.equal(random(), 0.1520436450538547); // (0, 1) range, 53 bits.\n// assert.equal(random.int32(), 1806534897); // signed int32, 32 bits.\n//\n// For nonzero numeric keys, this impelementation provides a sequence\n// identical to that by Brent's xorgens 3 implementaion in C. This\n// implementation also provides for initalizing the generator with\n// string seeds, or for saving and restoring the state of the generator.\n//\n// On Chrome, this prng benchmarks about 2.1 times slower than\n// Javascript's built-in Math.random().\n\n(function(global, module, define) {\n\nfunction XorGen(seed) {\n var me = this;\n\n // Set up generator function.\n me.next = function() {\n var w = me.w,\n X = me.X, i = me.i, t, v;\n // Update Weyl generator.\n me.w = w = (w + 0x61c88647) | 0;\n // Update xor generator.\n v = X[(i + 34) & 127];\n t = X[i = ((i + 1) & 127)];\n v ^= v << 13;\n t ^= t << 17;\n v ^= v >>> 15;\n t ^= t >>> 12;\n // Update Xor generator array state.\n v = X[i] = v ^ t;\n me.i = i;\n // Result is the combination.\n return (v + (w ^ (w >>> 16))) | 0;\n };\n\n function init(me, seed) {\n var t, v, i, j, w, X = [], limit = 128;\n if (seed === (seed | 0)) {\n // Numeric seeds initialize v, which is used to generates X.\n v = seed;\n seed = null;\n } else {\n // String seeds are mixed into v and X one character at a time.\n seed = seed + '\\0';\n v = 0;\n limit = Math.max(limit, seed.length);\n }\n // Initialize circular array and weyl value.\n for (i = 0, j = -32; j < limit; ++j) {\n // Put the unicode characters into the array, and shuffle them.\n if (seed) v ^= seed.charCodeAt((j + 32) % seed.length);\n // After 32 shuffles, take v as the starting w value.\n if (j === 0) w = v;\n v ^= v << 10;\n v ^= v >>> 15;\n v ^= v << 4;\n v ^= v >>> 13;\n if (j >= 0) {\n w = (w + 0x61c88647) | 0; // Weyl.\n t = (X[j & 127] ^= (v + w)); // Combine xor and weyl to init array.\n i = (0 == t) ? i + 1 : 0; // Count zeroes.\n }\n }\n // We have detected all zeroes; make the key nonzero.\n if (i >= 128) {\n X[(seed && seed.length || 0) & 127] = -1;\n }\n // Run the generator 512 times to further mix the state before using it.\n // Factoring this as a function slows the main generator, so it is just\n // unrolled here. The weyl generator is not advanced while warming up.\n i = 127;\n for (j = 4 * 128; j > 0; --j) {\n v = X[(i + 34) & 127];\n t = X[i = ((i + 1) & 127)];\n v ^= v << 13;\n t ^= t << 17;\n v ^= v >>> 15;\n t ^= t >>> 12;\n X[i] = v ^ t;\n }\n // Storing state as object members is faster than using closure variables.\n me.w = w;\n me.X = X;\n me.i = i;\n }\n\n init(me, seed);\n}\n\nfunction copy(f, t) {\n t.i = f.i;\n t.w = f.w;\n t.X = f.X.slice();\n return t;\n};\n\nfunction impl(seed, opts) {\n if (seed == null) seed = +(new Date);\n var xg = new XorGen(seed),\n state = opts && opts.state,\n prng = function() { return (xg.next() >>> 0) / 0x100000000; };\n prng.double = function() {\n do {\n var top = xg.next() >>> 11,\n bot = (xg.next() >>> 0) / 0x100000000,\n result = (top + bot) / (1 << 21);\n } while (result === 0);\n return result;\n };\n prng.int32 = xg.next;\n prng.quick = prng;\n if (state) {\n if (state.X) copy(state, xg);\n prng.state = function() { return copy(xg, {}); }\n }\n return prng;\n}\n\nif (module && module.exports) {\n module.exports = impl;\n} else if (define && define.amd) {\n define(function() { return impl; });\n} else {\n this.xor4096 = impl;\n}\n\n})(\n this, // window object or global\n (typeof module) == 'object' && module, // present in node.js\n (typeof define) == 'function' && define // present with an AMD loader\n);\n","// A Javascript implementaion of the \"Tyche-i\" prng algorithm by\n// Samuel Neves and Filipe Araujo.\n// See https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf\n\n(function(global, module, define) {\n\nfunction XorGen(seed) {\n var me = this, strseed = '';\n\n // Set up generator function.\n me.next = function() {\n var b = me.b, c = me.c, d = me.d, a = me.a;\n b = (b << 25) ^ (b >>> 7) ^ c;\n c = (c - d) | 0;\n d = (d << 24) ^ (d >>> 8) ^ a;\n a = (a - b) | 0;\n me.b = b = (b << 20) ^ (b >>> 12) ^ c;\n me.c = c = (c - d) | 0;\n me.d = (d << 16) ^ (c >>> 16) ^ a;\n return me.a = (a - b) | 0;\n };\n\n /* The following is non-inverted tyche, which has better internal\n * bit diffusion, but which is about 25% slower than tyche-i in JS.\n me.next = function() {\n var a = me.a, b = me.b, c = me.c, d = me.d;\n a = (me.a + me.b | 0) >>> 0;\n d = me.d ^ a; d = d << 16 ^ d >>> 16;\n c = me.c + d | 0;\n b = me.b ^ c; b = b << 12 ^ d >>> 20;\n me.a = a = a + b | 0;\n d = d ^ a; me.d = d = d << 8 ^ d >>> 24;\n me.c = c = c + d | 0;\n b = b ^ c;\n return me.b = (b << 7 ^ b >>> 25);\n }\n */\n\n me.a = 0;\n me.b = 0;\n me.c = 2654435769 | 0;\n me.d = 1367130551;\n\n if (seed === Math.floor(seed)) {\n // Integer seed.\n me.a = (seed / 0x100000000) | 0;\n me.b = seed | 0;\n } else {\n // String seed.\n strseed += seed;\n }\n\n // Mix in string seed, then discard an initial batch of 64 values.\n for (var k = 0; k < strseed.length + 20; k++) {\n me.b ^= strseed.charCodeAt(k) | 0;\n me.next();\n }\n}\n\nfunction copy(f, t) {\n t.a = f.a;\n t.b = f.b;\n t.c = f.c;\n t.d = f.d;\n return t;\n};\n\nfunction impl(seed, opts) {\n var xg = new XorGen(seed),\n state = opts && opts.state,\n prng = function() { return (xg.next() >>> 0) / 0x100000000; };\n prng.double = function() {\n do {\n var top = xg.next() >>> 11,\n bot = (xg.next() >>> 0) / 0x100000000,\n result = (top + bot) / (1 << 21);\n } while (result === 0);\n return result;\n };\n prng.int32 = xg.next;\n prng.quick = prng;\n if (state) {\n if (typeof(state) == 'object') copy(state, xg);\n prng.state = function() { return copy(xg, {}); }\n }\n return prng;\n}\n\nif (module && module.exports) {\n module.exports = impl;\n} else if (define && define.amd) {\n define(function() { return impl; });\n} else {\n this.tychei = impl;\n}\n\n})(\n this,\n (typeof module) == 'object' && module, // present in node.js\n (typeof define) == 'function' && define // present with an AMD loader\n);\n\n\n","/*\nCopyright 2014 David Bau.\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n*/\n\n(function (pool, math) {\n//\n// The following constants are related to IEEE 754 limits.\n//\nvar global = this,\n width = 256, // each RC4 output is 0 <= x < 256\n chunks = 6, // at least six RC4 outputs for each double\n digits = 52, // there are 52 significant digits in a double\n rngname = 'random', // rngname: name for Math.random and Math.seedrandom\n startdenom = math.pow(width, chunks),\n significance = math.pow(2, digits),\n overflow = significance * 2,\n mask = width - 1,\n nodecrypto; // node.js crypto module, initialized at the bottom.\n\n//\n// seedrandom()\n// This is the seedrandom function described above.\n//\nfunction seedrandom(seed, options, callback) {\n var key = [];\n options = (options == true) ? { entropy: true } : (options || {});\n\n // Flatten the seed string or build one from local entropy if needed.\n var shortseed = mixkey(flatten(\n options.entropy ? [seed, tostring(pool)] :\n (seed == null) ? autoseed() : seed, 3), key);\n\n // Use the seed to initialize an ARC4 generator.\n var arc4 = new ARC4(key);\n\n // This function returns a random double in [0, 1) that contains\n // randomness in every bit of the mantissa of the IEEE 754 value.\n var prng = function() {\n var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48\n d = startdenom, // and denominator d = 2 ^ 48.\n x = 0; // and no 'extra last byte'.\n while (n < significance) { // Fill up all significant digits by\n n = (n + x) * width; // shifting numerator and\n d *= width; // denominator and generating a\n x = arc4.g(1); // new least-significant-byte.\n }\n while (n >= overflow) { // To avoid rounding up, before adding\n n /= 2; // last byte, shift everything\n d /= 2; // right using integer math until\n x >>>= 1; // we have exactly the desired bits.\n }\n return (n + x) / d; // Form the number within [0, 1).\n };\n\n prng.int32 = function() { return arc4.g(4) | 0; }\n prng.quick = function() { return arc4.g(4) / 0x100000000; }\n prng.double = prng;\n\n // Mix the randomness into accumulated entropy.\n mixkey(tostring(arc4.S), pool);\n\n // Calling convention: what to return as a function of prng, seed, is_math.\n return (options.pass || callback ||\n function(prng, seed, is_math_call, state) {\n if (state) {\n // Load the arc4 state from the given state if it has an S array.\n if (state.S) { copy(state, arc4); }\n // Only provide the .state method if requested via options.state.\n prng.state = function() { return copy(arc4, {}); }\n }\n\n // If called as a method of Math (Math.seedrandom()), mutate\n // Math.random because that is how seedrandom.js has worked since v1.0.\n if (is_math_call) { math[rngname] = prng; return seed; }\n\n // Otherwise, it is a newer calling convention, so return the\n // prng directly.\n else return prng;\n })(\n prng,\n shortseed,\n 'global' in options ? options.global : (this == math),\n options.state);\n}\nmath['seed' + rngname] = seedrandom;\n\n//\n// ARC4\n//\n// An ARC4 implementation. The constructor takes a key in the form of\n// an array of at most (width) integers that should be 0 <= x < (width).\n//\n// The g(count) method returns a pseudorandom integer that concatenates\n// the next (count) outputs from ARC4. Its return value is a number x\n// that is in the range 0 <= x < (width ^ count).\n//\nfunction ARC4(key) {\n var t, keylen = key.length,\n me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];\n\n // The empty key [] is treated as [0].\n if (!keylen) { key = [keylen++]; }\n\n // Set up S using the standard key scheduling algorithm.\n while (i < width) {\n s[i] = i++;\n }\n for (i = 0; i < width; i++) {\n s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];\n s[j] = t;\n }\n\n // The \"g\" method returns the next (count) outputs as one number.\n (me.g = function(count) {\n // Using instance members instead of closure state nearly doubles speed.\n var t, r = 0,\n i = me.i, j = me.j, s = me.S;\n while (count--) {\n t = s[i = mask & (i + 1)];\n r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];\n }\n me.i = i; me.j = j;\n return r;\n // For robust unpredictability, the function call below automatically\n // discards an initial batch of values. This is called RC4-drop[256].\n // See http://google.com/search?q=rsa+fluhrer+response&btnI\n })(width);\n}\n\n//\n// copy()\n// Copies internal state of ARC4 to or from a plain object.\n//\nfunction copy(f, t) {\n t.i = f.i;\n t.j = f.j;\n t.S = f.S.slice();\n return t;\n};\n\n//\n// flatten()\n// Converts an object tree to nested arrays of strings.\n//\nfunction flatten(obj, depth) {\n var result = [], typ = (typeof obj), prop;\n if (depth && typ == 'object') {\n for (prop in obj) {\n try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}\n }\n }\n return (result.length ? result : typ == 'string' ? obj : obj + '\\0');\n}\n\n//\n// mixkey()\n// Mixes a string seed into a key that is an array of integers, and\n// returns a shortened string seed that is equivalent to the result key.\n//\nfunction mixkey(seed, key) {\n var stringseed = seed + '', smear, j = 0;\n while (j < stringseed.length) {\n key[mask & j] =\n mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));\n }\n return tostring(key);\n}\n\n//\n// autoseed()\n// Returns an object for autoseeding, using window.crypto and Node crypto\n// module if available.\n//\nfunction autoseed() {\n try {\n var out;\n if (nodecrypto && (out = nodecrypto.randomBytes)) {\n // The use of 'out' to remember randomBytes makes tight minified code.\n out = out(width);\n } else {\n out = new Uint8Array(width);\n (global.crypto || global.msCrypto).getRandomValues(out);\n }\n return tostring(out);\n } catch (e) {\n var browser = global.navigator,\n plugins = browser && browser.plugins;\n return [+new Date, global, plugins, global.screen, tostring(pool)];\n }\n}\n\n//\n// tostring()\n// Converts an array of charcodes to a string\n//\nfunction tostring(a) {\n return String.fromCharCode.apply(0, a);\n}\n\n//\n// When seedrandom.js is loaded, we immediately mix a few bits\n// from the built-in RNG into the entropy pool. Because we do\n// not want to interfere with deterministic PRNG state later,\n// seedrandom will not call math.random on its own again after\n// initialization.\n//\nmixkey(math.random(), pool);\n\n//\n// Nodejs and AMD support: export the implementation as a module using\n// either convention.\n//\nif ((typeof module) == 'object' && module.exports) {\n module.exports = seedrandom;\n // When in node.js, try using crypto package for autoseeding.\n try {\n nodecrypto = require('crypto');\n } catch (ex) {}\n} else if ((typeof define) == 'function' && define.amd) {\n define(function() { return seedrandom; });\n}\n\n// End anonymous scope, and pass initial values.\n})(\n [], // pool: entropy pool starts empty\n Math // math: package containing random, pow, and seedrandom\n);\n","// A library of seedable RNGs implemented in Javascript.\n//\n// Usage:\n//\n// var seedrandom = require('seedrandom');\n// var random = seedrandom(1); // or any seed.\n// var x = random(); // 0 <= x < 1. Every bit is random.\n// var x = random.quick(); // 0 <= x < 1. 32 bits of randomness.\n\n// alea, a 53-bit multiply-with-carry generator by Johannes Baagøe.\n// Period: ~2^116\n// Reported to pass all BigCrush tests.\nvar alea = require('./lib/alea');\n\n// xor128, a pure xor-shift generator by George Marsaglia.\n// Period: 2^128-1.\n// Reported to fail: MatrixRank and LinearComp.\nvar xor128 = require('./lib/xor128');\n\n// xorwow, George Marsaglia's 160-bit xor-shift combined plus weyl.\n// Period: 2^192-2^32\n// Reported to fail: CollisionOver, SimpPoker, and LinearComp.\nvar xorwow = require('./lib/xorwow');\n\n// xorshift7, by François Panneton and Pierre L'ecuyer, takes\n// a different approach: it adds robustness by allowing more shifts\n// than Marsaglia's original three. It is a 7-shift generator\n// with 256 bits, that passes BigCrush with no systmatic failures.\n// Period 2^256-1.\n// No systematic BigCrush failures reported.\nvar xorshift7 = require('./lib/xorshift7');\n\n// xor4096, by Richard Brent, is a 4096-bit xor-shift with a\n// very long period that also adds a Weyl generator. It also passes\n// BigCrush with no systematic failures. Its long period may\n// be useful if you have many generators and need to avoid\n// collisions.\n// Period: 2^4128-2^32.\n// No systematic BigCrush failures reported.\nvar xor4096 = require('./lib/xor4096');\n\n// Tyche-i, by Samuel Neves and Filipe Araujo, is a bit-shifting random\n// number generator derived from ChaCha, a modern stream cipher.\n// https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf\n// Period: ~2^127\n// No systematic BigCrush failures reported.\nvar tychei = require('./lib/tychei');\n\n// The original ARC4-based prng included in this library.\n// Period: ~2^1600\nvar sr = require('./seedrandom');\n\nsr.alea = alea;\nsr.xor128 = xor128;\nsr.xorwow = xorwow;\nsr.xorshift7 = xorshift7;\nsr.xor4096 = xor4096;\nsr.tychei = tychei;\n\nmodule.exports = sr;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar seedrandom = require(\"seedrandom\");\nvar MPRandGauss = (function () {\n function MPRandGauss(mean, stdDeviation, dtype, truncated, seed) {\n this.mean = mean;\n this.stdDev = stdDeviation;\n this.dtype = dtype;\n this.nextVal = NaN;\n this.truncated = truncated;\n if (this.truncated) {\n this.upper = this.mean + this.stdDev * 2;\n this.lower = this.mean - this.stdDev * 2;\n }\n var seedValue = seed ? seed : Math.random();\n this.random = seedrandom.alea(seedValue.toString());\n }\n MPRandGauss.prototype.nextValue = function () {\n if (!isNaN(this.nextVal)) {\n var value = this.nextVal;\n this.nextVal = NaN;\n return value;\n }\n var resultX, resultY;\n var isValid = false;\n while (!isValid) {\n var v1 = void 0, v2 = void 0, s = void 0;\n do {\n v1 = 2 * this.random() - 1;\n v2 = 2 * this.random() - 1;\n s = v1 * v1 + v2 * v2;\n } while (s >= 1 || s === 0);\n var mul = Math.sqrt(-2.0 * Math.log(s) / s);\n resultX = this.mean + this.stdDev * v1 * mul;\n resultY = this.mean + this.stdDev * v2 * mul;\n if (!this.truncated || this.isValidTruncated(resultX)) {\n isValid = true;\n }\n }\n if (!this.truncated || this.isValidTruncated(resultY)) {\n this.nextVal = this.convertValue(resultY);\n }\n return this.convertValue(resultX);\n };\n MPRandGauss.prototype.convertValue = function (value) {\n if (this.dtype == null || this.dtype === 'float32') {\n return value;\n }\n return Math.round(value);\n };\n MPRandGauss.prototype.isValidTruncated = function (value) {\n return value <= this.upper && value >= this.lower;\n };\n return MPRandGauss;\n}());\nexports.MPRandGauss = MPRandGauss;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar globals_1 = require(\"../globals\");\nvar util = require(\"../util\");\nvar axis_util = require(\"./axis_util\");\nvar operation_1 = require(\"./operation\");\nvar ops = require(\"./ops\");\nvar ReductionOps = (function () {\n function ReductionOps() {\n }\n ReductionOps.logSumExp = function (x, axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n util.assertArgumentsAreTensors({ x: x }, 'logSumExp');\n var axes = axis_util.parseAxisParam(axis, x.shape);\n var xMax = x.max(axes, true);\n var a = x.sub(xMax);\n var b = a.exp();\n var c = b.sum(axes);\n var d = c.log();\n var res = xMax.reshape(d.shape).add(d);\n if (keepDims) {\n var newShape = axis_util.expandShapeToKeepDim(res.shape, axes);\n return res.reshape(newShape);\n }\n return res;\n };\n ReductionOps.sum = function (x, axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n util.assertArgumentsAreTensors({ x: x }, 'sum');\n if (x.dtype === 'bool') {\n x = x.toInt();\n }\n var axes = axis_util.parseAxisParam(axis, x.shape);\n var customOp = globals_1.customGrad(function (x) {\n var permutation = axis_util.getAxesPermutation(axes, x.rank);\n var reductionAxes = axes;\n var permutedX = x;\n if (permutation != null) {\n permutedX = x.transpose(permutation);\n reductionAxes =\n axis_util.getInnerMostAxes(reductionAxes.length, x.rank);\n }\n var value = environment_1.ENV.engine.runKernel(function (backend) { return backend.sum(permutedX, reductionAxes); }, { permutedX: permutedX });\n if (keepDims) {\n var newShape = axis_util.expandShapeToKeepDim(value.shape, axes);\n value = value.reshape(newShape);\n }\n var gradFunc = function (dy) {\n var expandedDyShape = x.shape.slice();\n axes.forEach(function (axis) {\n expandedDyShape[axis] = 1;\n });\n var expandedDy = dy.reshape(expandedDyShape);\n var derX = expandedDy.mul(ops.ones(x.shape, 'float32'));\n return derX;\n };\n return { value: value, gradFunc: gradFunc };\n });\n return customOp(x);\n };\n ReductionOps.mean = function (x, axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n util.assertArgumentsAreTensors({ x: x }, 'mean');\n var axes = axis_util.parseAxisParam(axis, x.shape);\n var shapes = axis_util.computeOutAndReduceShapes(x.shape, axes);\n var reduceShape = shapes[1];\n var reduceSize = util.sizeFromShape(reduceShape);\n var customOp = globals_1.customGrad(function (x) {\n var reduceSizeScalar = ops.scalar(reduceSize);\n var xReduce = reduceSizeScalar.dtype === x.dtype ?\n x :\n x.cast(reduceSizeScalar.dtype);\n var res = xReduce.div(reduceSizeScalar);\n var value = res.sum(axis, keepDims);\n var gradFunc = function (dy) {\n var expandedDyShape = x.shape.slice();\n axes.forEach(function (axis) {\n expandedDyShape[axis] = 1;\n });\n var expandedDy = dy.reshape(expandedDyShape);\n var derX = expandedDy.mul(ops.ones(x.shape, 'float32')).div(reduceSizeScalar);\n return derX;\n };\n return { value: value, gradFunc: gradFunc };\n });\n return customOp(x);\n };\n ReductionOps.min = function (x, axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n util.assertArgumentsAreTensors({ x: x }, 'min');\n var origAxes = axis_util.parseAxisParam(axis, x.shape);\n var axes = origAxes;\n var permutedAxes = axis_util.getAxesPermutation(axes, x.rank);\n if (permutedAxes != null) {\n x = x.transpose(permutedAxes);\n axes = axis_util.getInnerMostAxes(axes.length, x.rank);\n }\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.min(x, axes); }, { x: x });\n if (keepDims) {\n var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes);\n return res.reshape(newShape);\n }\n return res;\n };\n ReductionOps.max = function (x, axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n util.assertArgumentsAreTensors({ x: x }, 'max');\n var origAxes = axis_util.parseAxisParam(axis, x.shape);\n var axes = origAxes;\n var permutedAxes = axis_util.getAxesPermutation(axes, x.rank);\n if (permutedAxes != null) {\n x = x.transpose(permutedAxes);\n axes = axis_util.getInnerMostAxes(axes.length, x.rank);\n }\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.max(x, axes); }, { x: x });\n if (keepDims) {\n var newShape = axis_util.expandShapeToKeepDim(res.shape, origAxes);\n return res.reshape(newShape);\n }\n return res;\n };\n ReductionOps.argMin = function (x, axis) {\n if (axis === void 0) { axis = 0; }\n util.assertArgumentsAreTensors({ x: x }, 'argMin');\n if (axis == null) {\n axis = 0;\n }\n var axes = axis_util.parseAxisParam(axis, x.shape);\n var permutedAxes = axis_util.getAxesPermutation(axes, x.rank);\n if (permutedAxes != null) {\n x = x.transpose(permutedAxes);\n axes = axis_util.getInnerMostAxes(axes.length, x.rank);\n }\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.argMin(x, axes[0]); }, { x: x });\n };\n ReductionOps.argMax = function (x, axis) {\n if (axis === void 0) { axis = 0; }\n util.assertArgumentsAreTensors({ x: x }, 'argMax');\n if (axis == null) {\n axis = 0;\n }\n var axes = axis_util.parseAxisParam(axis, x.shape);\n var permutedAxes = axis_util.getAxesPermutation(axes, x.rank);\n if (permutedAxes != null) {\n x = x.transpose(permutedAxes);\n axes = axis_util.getInnerMostAxes(axes.length, x.rank);\n }\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.argMax(x, axes[0]); }, { x: x });\n };\n ReductionOps.moments = function (x, axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n util.assertArgumentsAreTensors({ x: x }, 'moments');\n var axes = axis_util.parseAxisParam(axis, x.shape);\n var mean = x.mean(axes, keepDims);\n var keepDimsShape = mean.shape;\n if (!keepDims) {\n keepDimsShape = axis_util.expandShapeToKeepDim(mean.shape, axes);\n }\n var devSquared = x.toFloat().sub(mean.reshape(keepDimsShape)).square();\n var variance = devSquared.mean(axes, keepDims);\n return { mean: mean, variance: variance };\n };\n ReductionOps.unsortedSegmentSum = function (x, segmentIds, numSegments, axis) {\n if (axis === void 0) { axis = 0; }\n util.assertArgumentsAreTensors({ x: x, segmentIds: segmentIds }, 'unsortedSegmentSum');\n util.assert(segmentIds.dtype === 'int32', 'Segment Ids must be of dtype `int32`');\n axis = axis_util.parseAxisParam(axis, x.shape)[0];\n var res = [];\n var dim = segmentIds.shape[0];\n var newShape = [];\n for (var i = 0; i < x.shape.length; i++) {\n if (i === axis) {\n newShape.push(dim);\n }\n else {\n newShape.push(1);\n }\n }\n var reshapedSegmentIds = ops.reshape(segmentIds, newShape);\n for (var i = 0; i < numSegments; i++) {\n var segmentId = ops.scalar(i, 'int32');\n var mask = ops.equal(segmentId, reshapedSegmentIds).asType('float32');\n var sum = mask.mul(x).sum(axis);\n res.push(sum);\n }\n return ops.stack(res, axis);\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),\n operation_1.operation\n ], ReductionOps, \"logSumExp\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),\n operation_1.operation\n ], ReductionOps, \"sum\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),\n operation_1.operation\n ], ReductionOps, \"mean\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),\n operation_1.operation\n ], ReductionOps, \"min\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),\n operation_1.operation\n ], ReductionOps, \"max\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),\n operation_1.operation\n ], ReductionOps, \"argMin\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),\n operation_1.operation\n ], ReductionOps, \"argMax\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }),\n operation_1.operation\n ], ReductionOps, \"moments\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Reduction' }),\n operation_1.operation\n ], ReductionOps, \"unsortedSegmentSum\", null);\n return ReductionOps;\n}());\nexports.ReductionOps = ReductionOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar tensor_1 = require(\"../tensor\");\nvar tensor_util = require(\"../tensor_util\");\nvar util = require(\"../util\");\nvar axis_util_1 = require(\"./axis_util\");\nvar concat_1 = require(\"./concat\");\nvar operation_1 = require(\"./operation\");\nvar rand_1 = require(\"./rand\");\nvar reduction_ops_1 = require(\"./reduction_ops\");\nvar ArrayOps = (function () {\n function ArrayOps() {\n }\n ArrayOps.tensor = function (values, shape, dtype) {\n if (dtype === void 0) { dtype = 'float32'; }\n var inferredShape = util.inferShape(values);\n if (shape != null && inferredShape.length !== 1) {\n util.assertShapesMatch(shape, inferredShape, \"Error creating a new Tensor. \" +\n (\"Inferred shape (\" + inferredShape + \") does not match the \") +\n (\"provided shape (\" + shape + \"). \"));\n }\n if (!util.isTypedArray(values) && !Array.isArray(values)) {\n values = [values];\n }\n shape = shape || inferredShape;\n return tensor_1.Tensor.make(shape, { values: toTypedArray(values, dtype) }, dtype);\n };\n ArrayOps.scalar = function (value, dtype) {\n if (dtype === void 0) { dtype = 'float32'; }\n if (util.isTypedArray(value) || Array.isArray(value)) {\n throw new Error('Error creating a new Scalar: value must be a primitive ' +\n '(number|boolean)');\n }\n return ArrayOps.tensor(value, [], dtype);\n };\n ArrayOps.tensor1d = function (values, dtype) {\n if (dtype === void 0) { dtype = 'float32'; }\n var inferredShape = util.inferShape(values);\n if (inferredShape.length !== 1) {\n throw new Error('tensor1d() requires values to be a flat/TypedArray');\n }\n return ArrayOps.tensor(values, inferredShape, dtype);\n };\n ArrayOps.tensor2d = function (values, shape, dtype) {\n if (dtype === void 0) { dtype = 'float32'; }\n if (shape != null && shape.length !== 2) {\n throw new Error('tensor2d() requires shape to have two numbers');\n }\n var inferredShape = util.inferShape(values);\n if (inferredShape.length !== 2 && inferredShape.length !== 1) {\n throw new Error('tensor2d() requires values to be number[][] or flat/TypedArray');\n }\n if (inferredShape.length === 1 && shape == null) {\n throw new Error('tensor2d() requires shape to be provided when `values` ' +\n 'are a flat/TypedArray');\n }\n shape = shape || inferredShape;\n return ArrayOps.tensor(values, shape, dtype);\n };\n ArrayOps.tensor3d = function (values, shape, dtype) {\n if (dtype === void 0) { dtype = 'float32'; }\n if (shape != null && shape.length !== 3) {\n throw new Error('tensor3d() requires shape to have three numbers');\n }\n var inferredShape = util.inferShape(values);\n if (inferredShape.length !== 3 && inferredShape.length !== 1) {\n throw new Error('tensor3d() requires values to be number[][][] or flat/TypedArray');\n }\n if (inferredShape.length === 1 && shape == null) {\n throw new Error('tensor3d() requires shape to be provided when `values` ' +\n 'are a flat array');\n }\n shape = shape || inferredShape;\n return ArrayOps.tensor(values, shape, dtype);\n };\n ArrayOps.tensor4d = function (values, shape, dtype) {\n if (dtype === void 0) { dtype = 'float32'; }\n if (shape != null && shape.length !== 4) {\n throw new Error('tensor4d() requires shape to have four numbers');\n }\n var inferredShape = util.inferShape(values);\n if (inferredShape.length !== 4 && inferredShape.length !== 1) {\n throw new Error('tensor4d() requires values to be number[][][][] or flat/TypedArray');\n }\n if (inferredShape.length === 1 && shape == null) {\n throw new Error('tensor4d() requires shape to be provided when `values` ' +\n 'are a flat array');\n }\n shape = shape || inferredShape;\n return ArrayOps.tensor(values, shape, dtype);\n };\n ArrayOps.ones = function (shape, dtype) {\n if (dtype === void 0) { dtype = 'float32'; }\n var values = makeOnesTypedArray(util.sizeFromShape(shape), dtype);\n return tensor_1.Tensor.make(shape, { values: values }, dtype);\n };\n ArrayOps.zeros = function (shape, dtype) {\n if (dtype === void 0) { dtype = 'float32'; }\n var values = makeZerosTypedArray(util.sizeFromShape(shape), dtype);\n return tensor_1.Tensor.make(shape, { values: values }, dtype);\n };\n ArrayOps.fill = function (shape, value, dtype) {\n if (dtype === void 0) { dtype = 'float32'; }\n var values = util.getTypedArrayFromDType(dtype, util.sizeFromShape(shape));\n values.fill(value);\n return tensor_1.Tensor.make(shape, { values: values }, dtype);\n };\n ArrayOps.onesLike = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'onesLike');\n return ArrayOps.ones(x.shape, x.dtype);\n };\n ArrayOps.zerosLike = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'zerosLike');\n return ArrayOps.zeros(x.shape, x.dtype);\n };\n ArrayOps.clone = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'clone');\n var der = function (dy) {\n return { x: function () { return dy.toFloat(); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) {\n return tensor_1.Tensor.make(x.shape, { dataId: x.dataId }, x.dtype);\n }, { x: x }, der);\n };\n ArrayOps.eye = function (numRows, numColumns, batchShape, dtype) {\n if (dtype === void 0) { dtype = 'float32'; }\n if (numColumns == null) {\n numColumns = numRows;\n }\n var buffer = ArrayOps.buffer([numRows, numColumns], dtype);\n var n = numRows <= numColumns ? numRows : numColumns;\n for (var i = 0; i < n; ++i) {\n buffer.set(1, i, i);\n }\n var out = buffer.toTensor().as2D(numRows, numColumns);\n if (batchShape == null) {\n return out;\n }\n else {\n if (batchShape.length === 1) {\n return ArrayOps.tile(ArrayOps.expandDims(out, 0), [batchShape[0], 1, 1]);\n }\n else if (batchShape.length === 2) {\n return ArrayOps.tile(ArrayOps.expandDims(ArrayOps.expandDims(out, 0), 0), [batchShape[0], batchShape[1], 1, 1]);\n }\n else {\n throw new Error(\"eye() currently supports only 1D and 2D \" +\n (\"batchShapes, but received \" + batchShape.length + \"D.\"));\n }\n }\n };\n ArrayOps.randomNormal = function (shape, mean, stdDev, dtype, seed) {\n if (mean === void 0) { mean = 0; }\n if (stdDev === void 0) { stdDev = 1; }\n if (dtype != null && dtype === 'bool') {\n throw new Error(\"Unsupported data type \" + dtype);\n }\n var randGauss = new rand_1.MPRandGauss(mean, stdDev, dtype, false, seed);\n var res = ArrayOps.buffer(shape, dtype);\n for (var i = 0; i < res.values.length; i++) {\n res.values[i] = randGauss.nextValue();\n }\n return res.toTensor();\n };\n ArrayOps.truncatedNormal = function (shape, mean, stdDev, dtype, seed) {\n if (mean === void 0) { mean = 0; }\n if (stdDev === void 0) { stdDev = 1; }\n if (dtype != null && dtype === 'bool') {\n throw new Error(\"Unsupported data type \" + dtype);\n }\n var randGauss = new rand_1.MPRandGauss(mean, stdDev, dtype, true, seed);\n var res = ArrayOps.buffer(shape, dtype);\n for (var i = 0; i < res.values.length; i++) {\n res.values[i] = randGauss.nextValue();\n }\n return res.toTensor();\n };\n ArrayOps.randomUniform = function (shape, minval, maxval, dtype) {\n if (minval === void 0) { minval = 0; }\n if (maxval === void 0) { maxval = 1; }\n if (dtype === void 0) { dtype = 'float32'; }\n var res = ArrayOps.buffer(shape, dtype);\n for (var i = 0; i < res.values.length; i++) {\n res.values[i] = util.randUniform(minval, maxval);\n }\n return res.toTensor();\n };\n ArrayOps.rand = function (shape, randFunction, dtype) {\n var size = util.sizeFromShape(shape);\n var values = null;\n if (dtype == null || dtype === 'float32') {\n values = new Float32Array(size);\n }\n else if (dtype === 'int32') {\n values = new Int32Array(size);\n }\n else if (dtype === 'bool') {\n values = new Uint8Array(size);\n }\n else {\n throw new Error(\"Unknown data type \" + dtype);\n }\n for (var i = 0; i < size; i++) {\n values[i] = randFunction();\n }\n return tensor_1.Tensor.make(shape, { values: values }, dtype);\n };\n ArrayOps.multinomial = function (logits, numSamples, seed, normalized) {\n if (normalized === void 0) { normalized = false; }\n util.assertArgumentsAreTensors({ logits: logits }, 'multinomial');\n var numOutcomes = logits.size;\n var origRank = logits.rank;\n if (numOutcomes < 2) {\n throw new Error(\"Error in multinomial: you need at least 2 outcomes, but got \" +\n (numOutcomes + \".\"));\n }\n if (origRank > 2) {\n throw new Error(\"Rank of probabilities must be 1 or 2, but is \" + origRank);\n }\n seed = seed || Math.random();\n var logits2D = origRank === 1 ? logits.as2D(1, -1) : logits;\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.multinomial(logits2D, normalized, numSamples, seed); }, { logits2D: logits2D });\n return origRank === 1 ? res.as1D() : res;\n };\n ArrayOps.oneHot = function (indices, depth, onValue, offValue) {\n if (onValue === void 0) { onValue = 1; }\n if (offValue === void 0) { offValue = 0; }\n util.assert(indices.dtype === 'int32', 'Indices must be of dtype `int32`');\n if (depth < 2) {\n throw new Error(\"Error in oneHot: depth must be >=2, but it is \" + depth);\n }\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.oneHot(indices, depth, onValue, offValue); }, { indices: indices });\n };\n ArrayOps.fromPixels = function (pixels, numChannels) {\n if (numChannels === void 0) { numChannels = 3; }\n if (numChannels > 4) {\n throw new Error('Cannot construct Tensor with more than 4 channels from pixels.');\n }\n return environment_1.ENV.engine.fromPixels(pixels, numChannels);\n };\n ArrayOps.toPixels = function (img, canvas) {\n return __awaiter(this, void 0, void 0, function () {\n var _a, height, width, depth, minTensor, maxTensor, min, max, data, multiplier, bytes, i, r, g, b, a, j, ctx, imageData;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n util.assertArgumentsAreTensors({ img: img }, 'toPixels');\n if (img.rank !== 2 && img.rank !== 3) {\n throw new Error(\"toPixels only supports rank 2 or 3 tensors, got rank \" + img.rank + \".\");\n }\n _a = img.shape.slice(0, 2), height = _a[0], width = _a[1];\n depth = img.rank === 2 ? 1 : img.shape[2];\n if (depth > 4 || depth === 2) {\n throw new Error(\"toPixels only supports depth of size \" +\n (\"1, 3 or 4 but got \" + depth));\n }\n minTensor = img.min();\n maxTensor = img.max();\n return [4, minTensor.data()];\n case 1:\n min = (_b.sent())[0];\n return [4, maxTensor.data()];\n case 2:\n max = (_b.sent())[0];\n minTensor.dispose();\n maxTensor.dispose();\n if (img.dtype === 'float32') {\n if (min < 0 || max > 1) {\n throw new Error(\"Tensor values for a float32 Tensor must be in the \" +\n (\"range [0 - 1] but got range [\" + min + \" - \" + max + \"].\"));\n }\n }\n else if (img.dtype === 'int32') {\n if (min < 0 || max > 255) {\n throw new Error(\"Tensor values for a int32 Tensor must be in the \" +\n (\"range [0 - 255] but got range [\" + min + \" - \" + max + \"].\"));\n }\n }\n else {\n throw new Error(\"Unsupported type for toPixels: \" + img.dtype + \".\" +\n \" Please use float32 or int32 tensors.\");\n }\n return [4, img.data()];\n case 3:\n data = _b.sent();\n multiplier = img.dtype === 'float32' ? 255 : 1;\n bytes = new Uint8ClampedArray(width * height * 4);\n for (i = 0; i < height * width; ++i) {\n r = void 0, g = void 0, b = void 0, a = void 0;\n if (depth === 1) {\n r = data[i] * multiplier;\n g = data[i] * multiplier;\n b = data[i] * multiplier;\n a = 255;\n }\n else if (depth === 3) {\n r = data[i * 3] * multiplier;\n g = data[i * 3 + 1] * multiplier;\n b = data[i * 3 + 2] * multiplier;\n a = 255;\n }\n else if (depth === 4) {\n r = data[i * 4] * multiplier;\n g = data[i * 4 + 1] * multiplier;\n b = data[i * 4 + 2] * multiplier;\n a = data[i * 4 + 3] * multiplier;\n }\n j = i * 4;\n bytes[j + 0] = Math.round(r);\n bytes[j + 1] = Math.round(g);\n bytes[j + 2] = Math.round(b);\n bytes[j + 3] = Math.round(a);\n }\n if (canvas != null) {\n canvas.width = width;\n canvas.height = height;\n ctx = canvas.getContext('2d');\n imageData = new ImageData(bytes, width, height);\n ctx.putImageData(imageData, 0, 0);\n }\n return [2, bytes];\n }\n });\n });\n };\n ArrayOps.reshape = function (x, shape) {\n util.assertArgumentsAreTensors({ x: x }, 'reshape');\n shape = util.inferFromImplicitShape(shape, x.size);\n util.assert(x.size === util.sizeFromShape(shape), 'new shape and old shape must have the same number of elements.');\n var grad = function (dy) {\n return { x: function () { return dy.reshape(x.shape); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.reshape(x, shape); }, { x: x }, grad);\n };\n ArrayOps.squeeze = function (x, axis) {\n util.assertArgumentsAreTensors({ x: x }, 'squeeze');\n return ArrayOps.reshape(x, util.squeezeShape(x.shape, axis).newShape);\n };\n ArrayOps.cast = function (x, dtype) {\n util.assertArgumentsAreTensors({ x: x }, 'cast');\n var grad = function (dy) {\n return { x: function () { return dy.clone(); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.cast(x, dtype); }, { x: x }, grad);\n };\n ArrayOps.tile = function (x, reps) {\n util.assertArgumentsAreTensors({ x: x }, 'tile');\n util.assert(x.rank === reps.length, \"Error in transpose: rank of input \" + x.rank + \" \" +\n (\"must match length of reps \" + reps + \".\"));\n var grad = function (dy) {\n var derX = function () {\n var xGrad = ArrayOps.zerosLike(x);\n if (x.rank === 1) {\n for (var i = 0; i < reps[0]; ++i) {\n xGrad = xGrad.add(dy.slice([i * x.shape[0]], [x.shape[0]]));\n }\n }\n else if (x.rank === 2) {\n for (var i = 0; i < reps[0]; ++i) {\n for (var j = 0; j < reps[1]; ++j) {\n xGrad = xGrad.add(dy.slice([i * x.shape[0], j * x.shape[1]], [x.shape[0], x.shape[1]]));\n }\n }\n }\n else if (x.rank === 3) {\n for (var i = 0; i < reps[0]; ++i) {\n for (var j = 0; j < reps[1]; ++j) {\n for (var k = 0; k < reps[2]; ++k) {\n xGrad = xGrad.add(dy.slice([i * x.shape[0], j * x.shape[1], k * x.shape[2]], [x.shape[0], x.shape[1], x.shape[2]]));\n }\n }\n }\n }\n else if (x.rank === 4) {\n for (var i = 0; i < reps[0]; ++i) {\n for (var j = 0; j < reps[1]; ++j) {\n for (var k = 0; k < reps[2]; ++k) {\n for (var l = 0; l < reps[3]; ++l) {\n xGrad = xGrad.add(dy.slice([\n i * x.shape[0], j * x.shape[1], k * x.shape[2],\n l * x.shape[3]\n ], [x.shape[0], x.shape[1], x.shape[2], x.shape[3]]));\n }\n }\n }\n }\n }\n else {\n throw new Error(\"Gradient for tile operation is not implemented for rank-\" +\n (x.rank + \" tensors yet.\"));\n }\n return xGrad;\n };\n return { x: derX };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.tile(x, reps); }, { x: x }, grad);\n };\n ArrayOps.gather = function (x, indices, axis) {\n if (axis === void 0) { axis = 0; }\n util.assertArgumentsAreTensors({ x: x, indices: indices }, 'gather');\n util.assert(indices.dtype === 'int32', 'Indices must be of dtype `int32`');\n axis = axis_util_1.parseAxisParam(axis, x.shape)[0];\n var grad = function (dy) {\n var derX = function () {\n return reduction_ops_1.ReductionOps.unsortedSegmentSum(dy, indices, x.shape[axis], axis);\n };\n return { x: derX };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.gather(x, indices, axis); }, { x: x }, grad);\n };\n ArrayOps.pad1d = function (x, paddings, constantValue) {\n if (constantValue === void 0) { constantValue = 0; }\n util.assert(paddings.length === 2, 'Invalid number of paddings. Must be length of 2.');\n return ArrayOps.pad(x, [paddings], constantValue);\n };\n ArrayOps.pad2d = function (x, paddings, constantValue) {\n if (constantValue === void 0) { constantValue = 0; }\n util.assert(paddings.length === 2 && paddings[0].length === 2 &&\n paddings[1].length === 2, 'Invalid number of paddings. Must be length of 2 each.');\n return ArrayOps.pad(x, paddings, constantValue);\n };\n ArrayOps.pad3d = function (x, paddings, constantValue) {\n if (constantValue === void 0) { constantValue = 0; }\n util.assert(paddings.length === 3 && paddings[0].length === 2 &&\n paddings[1].length === 2 && paddings[2].length === 2, 'Invalid number of paddings. Must be length of 2 each.');\n return ArrayOps.pad(x, paddings, constantValue);\n };\n ArrayOps.pad4d = function (x, paddings, constantValue) {\n if (constantValue === void 0) { constantValue = 0; }\n util.assert(paddings.length === 4 && paddings[0].length === 2 &&\n paddings[1].length === 2 && paddings[2].length === 2 &&\n paddings[3].length === 2, 'Invalid number of paddings. Must be length of 2 each.');\n return ArrayOps.pad(x, paddings, constantValue);\n };\n ArrayOps.pad = function (x, paddings, constantValue) {\n if (constantValue === void 0) { constantValue = 0; }\n util.assertArgumentsAreTensors({ x: x }, 'pad');\n if (x.rank === 0) {\n throw new Error('pad(scalar) is not defined. Pass non-scalar to pad');\n }\n var begin = paddings.map(function (p) { return p[0]; });\n var grad = function (dy) {\n return { x: function () { return dy.slice(begin, x.shape); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.pad(x, paddings, constantValue); }, { x: x }, grad);\n };\n ArrayOps.stack = function (tensors, axis) {\n if (axis === void 0) { axis = 0; }\n util.assertArgumentsAreTensors({ tensors: tensors }, 'stack');\n util.assert(tensors.length >= 1, 'Pass at least one tensor to tf.stack');\n if (tensors.length === 1) {\n return tensors[0].expandDims(axis);\n }\n var rank = tensors[0].rank;\n var shape = tensors[0].shape;\n var dtype = tensors[0].dtype;\n util.assert(axis <= rank, 'Axis must be <= rank of the tensor');\n tensors.forEach(function (t) {\n util.assertShapesMatch(shape, t.shape, 'All tensors passed to stack must have matching shapes');\n });\n tensors.forEach(function (t) {\n util.assert(dtype === t.dtype, 'All tensors passed to stack must have matching dtypes');\n });\n var expandedTensors = tensors.map(function (t) { return t.expandDims(axis); });\n return concat_1.ConcatOps.concat(expandedTensors, axis);\n };\n ArrayOps.split = function (x, numOrSizeSplits, axis) {\n if (axis === void 0) { axis = 0; }\n util.assertArgumentsAreTensors({ x: x }, 'split');\n axis = axis_util_1.parseAxisParam(axis, x.shape)[0];\n var splitSizes;\n if (typeof (numOrSizeSplits) === 'number') {\n util.assert(x.shape[axis] % numOrSizeSplits === 0, 'Number of splits must evenly divide the axis.');\n splitSizes = Array(numOrSizeSplits).fill(x.shape[axis] / numOrSizeSplits);\n }\n else {\n util.assert(x.shape[axis] === numOrSizeSplits.reduce(function (a, b) { return a + b; }), 'The sum of sizes must match the size of the axis dimension.');\n splitSizes = numOrSizeSplits;\n }\n var begin = Array(x.rank).fill(0);\n var size = x.shape.slice();\n return splitSizes.map(function (s) {\n size[axis] = s;\n var slice = x.slice(begin, size);\n begin[axis] += s;\n return slice;\n });\n };\n ArrayOps.expandDims = function (x, axis) {\n if (axis === void 0) { axis = 0; }\n util.assertArgumentsAreTensors({ x: x }, 'expandDims');\n util.assert(axis <= x.rank, 'Axis must be <= rank of the tensor');\n var newShape = x.shape.slice();\n newShape.splice(axis, 0, 1);\n return ArrayOps.reshape(x, newShape);\n };\n ArrayOps.linspace = function (start, stop, num) {\n if (num === 0) {\n throw new Error('Cannot request zero samples');\n }\n var step = (stop - start) / (num - 1);\n var values = makeZerosTypedArray(num, 'float32');\n values[0] = start;\n for (var i = 1; i < values.length; i++) {\n values[i] = values[i - 1] + step;\n }\n return ArrayOps.tensor1d(values, 'float32');\n };\n ArrayOps.range = function (start, stop, step, dtype) {\n if (step === void 0) { step = 1; }\n if (dtype === void 0) { dtype = 'float32'; }\n if (step === 0) {\n throw new Error('Cannot have a step of zero');\n }\n var sameStartStop = start === stop;\n var increasingRangeNegativeStep = start < stop && step < 0;\n var decreasingRangePositiveStep = stop < start && step > 1;\n if (sameStartStop || increasingRangeNegativeStep ||\n decreasingRangePositiveStep) {\n return ArrayOps.zeros([0], dtype);\n }\n var numElements = Math.abs(Math.ceil((stop - start) / step));\n var values = makeZerosTypedArray(numElements, dtype);\n if (stop < start && step === 1) {\n step = -1;\n }\n values[0] = start;\n for (var i = 1; i < values.length; i++) {\n values[i] = values[i - 1] + step;\n }\n return ArrayOps.tensor1d(values, dtype);\n };\n ArrayOps.buffer = function (shape, dtype, values) {\n if (dtype === void 0) { dtype = 'float32'; }\n return new tensor_1.TensorBuffer(shape, dtype, values);\n };\n ArrayOps.print = function (x, verbose) {\n if (verbose === void 0) { verbose = false; }\n console.log(tensor_util.tensorToString(x, verbose));\n };\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], ArrayOps, \"tensor\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], ArrayOps, \"scalar\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], ArrayOps, \"tensor1d\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], ArrayOps, \"tensor2d\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], ArrayOps, \"tensor3d\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], ArrayOps, \"tensor4d\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"ones\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"zeros\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"fill\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"onesLike\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"zerosLike\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"clone\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"eye\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"randomNormal\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"truncatedNormal\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"randomUniform\", null);\n __decorate([\n operation_1.operation\n ], ArrayOps, \"rand\", null);\n __decorate([\n operation_1.operation\n ], ArrayOps, \"multinomial\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"oneHot\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' }),\n operation_1.operation\n ], ArrayOps, \"fromPixels\", null);\n __decorate([\n doc_1.doc({ heading: 'Visualization' })\n ], ArrayOps, \"toPixels\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }),\n operation_1.operation\n ], ArrayOps, \"reshape\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' })\n ], ArrayOps, \"squeeze\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }),\n operation_1.operation\n ], ArrayOps, \"cast\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),\n operation_1.operation\n ], ArrayOps, \"tile\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),\n operation_1.operation\n ], ArrayOps, \"gather\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }),\n operation_1.operation\n ], ArrayOps, \"pad\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),\n operation_1.operation\n ], ArrayOps, \"stack\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),\n operation_1.operation\n ], ArrayOps, \"split\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Transformations' }),\n operation_1.operation\n ], ArrayOps, \"expandDims\", null);\n __decorate([\n operation_1.operation,\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], ArrayOps, \"linspace\", null);\n __decorate([\n operation_1.operation,\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], ArrayOps, \"range\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], ArrayOps, \"buffer\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], ArrayOps, \"print\", null);\n return ArrayOps;\n}());\nexports.ArrayOps = ArrayOps;\nfunction makeZerosTypedArray(size, dtype) {\n if (dtype == null || dtype === 'float32') {\n return new Float32Array(size);\n }\n else if (dtype === 'int32') {\n return new Int32Array(size);\n }\n else if (dtype === 'bool') {\n return new Uint8Array(size);\n }\n else {\n throw new Error(\"Unknown data type $ {dtype}\");\n }\n}\nfunction makeOnesTypedArray(size, dtype) {\n var array = makeZerosTypedArray(size, dtype);\n for (var i = 0; i < array.length; i++) {\n array[i] = 1;\n }\n return array;\n}\nfunction toTypedArray(a, dtype) {\n if (noConversionNeeded(a, dtype)) {\n return a;\n }\n if (Array.isArray(a)) {\n a = util.flatten(a);\n }\n return util.copyTypedArray(a, dtype);\n}\nfunction noConversionNeeded(a, dtype) {\n return (a instanceof Float32Array && dtype === 'float32') ||\n (a instanceof Int32Array && dtype === 'int32') ||\n (a instanceof Uint8Array && dtype === 'bool');\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nfunction getBroadcastDims(inShape, outShape) {\n var inRank = inShape.length;\n var dims = [];\n for (var i = 0; i < inRank; i++) {\n var dim = inRank - 1 - i;\n var a = inShape[dim] || 1;\n var b = outShape[outShape.length - 1 - i] || 1;\n if (b > 1 && a === 1) {\n dims.unshift(dim);\n }\n }\n return dims;\n}\nexports.getBroadcastDims = getBroadcastDims;\nfunction getReductionAxes(inShape, outShape) {\n var result = [];\n for (var i = 0; i < outShape.length; i++) {\n var inDim = inShape[inShape.length - i - 1];\n var outAxis = outShape.length - i - 1;\n var outDim = outShape[outAxis];\n if (inDim == null || (inDim === 1 && outDim > 1)) {\n result.unshift(outAxis);\n }\n }\n return result;\n}\nexports.getReductionAxes = getReductionAxes;\nfunction broadcastDimsAreOuter(dims) {\n for (var i = 0; i < dims.length; i++) {\n if (dims[i] !== i) {\n return false;\n }\n }\n return true;\n}\nexports.broadcastDimsAreOuter = broadcastDimsAreOuter;\nfunction assertAndGetBroadcastShape(shapeA, shapeB) {\n var result = [];\n var errMsg = \"Operands could not be broadcast together with shapes \" +\n (shapeA + \" and \" + shapeB + \".\");\n var l = Math.max(shapeA.length, shapeB.length);\n for (var i = 0; i < l; i++) {\n var a = shapeA[shapeA.length - i - 1] || 1;\n var b = shapeB[shapeB.length - i - 1] || 1;\n if (a > 1 && b > 1 && a !== b) {\n throw Error(errMsg);\n }\n result.unshift(Math.max(a, b));\n }\n return result;\n}\nexports.assertAndGetBroadcastShape = assertAndGetBroadcastShape;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar array_ops_1 = require(\"./array_ops\");\nvar broadcast_util_1 = require(\"./broadcast_util\");\nvar operation_1 = require(\"./operation\");\nvar ops_1 = require(\"./ops\");\nvar BatchNormOps = (function () {\n function BatchNormOps() {\n }\n BatchNormOps.batchNormalization2d = function (x, mean, variance, varianceEpsilon, scale, offset) {\n if (varianceEpsilon === void 0) { varianceEpsilon = .001; }\n util.assert(x.rank === 2, \"Error in batchNormalization3D: x must be rank 3 but got rank \" +\n (x.rank + \".\"));\n util.assert(mean.rank === 2 || mean.rank === 1, \"Error in batchNormalization2D: mean must be rank 2 or rank 1 but \" +\n (\"got rank \" + mean.rank + \".\"));\n util.assert(variance.rank === 2 || variance.rank === 1, \"Error in batchNormalization2D: variance must be rank 2 or rank 1 \" +\n (\"but got rank \" + variance.rank + \".\"));\n if (scale != null) {\n util.assert(scale.rank === 2 || scale.rank === 1, \"Error in batchNormalization2D: scale must be rank 2 or rank 1 \" +\n (\"but got rank \" + scale.rank + \".\"));\n }\n if (offset != null) {\n util.assert(offset.rank === 2 || offset.rank === 1, \"Error in batchNormalization2D: offset must be rank 2 or rank 1 \" +\n (\"but got rank \" + offset.rank + \".\"));\n }\n return BatchNormOps.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset);\n };\n BatchNormOps.batchNormalization3d = function (x, mean, variance, varianceEpsilon, scale, offset) {\n if (varianceEpsilon === void 0) { varianceEpsilon = .001; }\n util.assert(x.rank === 3, \"Error in batchNormalization3D: x must be rank 3 but got rank \" +\n (x.rank + \".\"));\n util.assert(mean.rank === 3 || mean.rank === 1, \"Error in batchNormalization3D: mean must be rank 3 or rank 1 but \" +\n (\"got rank \" + mean.rank + \".\"));\n util.assert(variance.rank === 3 || variance.rank === 1, \"Error in batchNormalization3D: variance must be rank 3 or rank 1 \" +\n (\"but got rank \" + variance.rank + \".\"));\n if (scale != null) {\n util.assert(scale.rank === 3 || scale.rank === 1, \"Error in batchNormalization3D: scale must be rank 3 or rank 1 \" +\n (\"but got rank \" + scale.rank + \".\"));\n }\n if (offset != null) {\n util.assert(offset.rank === 3 || offset.rank === 1, \"Error in batchNormalization3D: offset must be rank 3 or rank 1 \" +\n (\"but got rank \" + offset.rank + \".\"));\n }\n return BatchNormOps.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset);\n };\n BatchNormOps.batchNormalization4d = function (x, mean, variance, varianceEpsilon, scale, offset) {\n if (varianceEpsilon === void 0) { varianceEpsilon = .001; }\n util.assert(x.rank === 4, \"Error in batchNormalization4D: x must be rank 4 but got rank \" +\n (x.rank + \".\"));\n util.assert(mean.rank === 4 || mean.rank === 1, \"Error in batchNormalization4D: mean must be rank 4 or rank 1 but \" +\n (\"got rank \" + mean.rank + \".\"));\n util.assert(variance.rank === 4 || variance.rank === 1, \"Error in batchNormalization4D: variance must be rank 4 or rank 1 \" +\n (\"but got rank \" + variance.rank + \".\"));\n if (scale != null) {\n util.assert(scale.rank === 4 || scale.rank === 1, \"Error in batchNormalization4D: scale must be rank 4 or rank 1 \" +\n (\"but got rank \" + scale.rank + \".\"));\n }\n if (offset != null) {\n util.assert(offset.rank === 4 || offset.rank === 1, \"Error in batchNormalization4D: offset must be rank 4 or rank 1 \" +\n (\"but got rank \" + offset.rank + \".\"));\n }\n return BatchNormOps.batchNormalization(x, mean, variance, varianceEpsilon, scale, offset);\n };\n BatchNormOps.batchNormalization = function (x, mean, variance, varianceEpsilon, scale, offset) {\n if (varianceEpsilon === void 0) { varianceEpsilon = .001; }\n util.assertArgumentsAreTensors({ x: x, mean: mean, variance: variance }, 'batchNormalization');\n if (scale != null) {\n util.assertArgumentsAreTensors({ scale: scale }, 'batchNormalization');\n }\n if (offset != null) {\n util.assertArgumentsAreTensors({ offset: offset }, 'batchNormalization');\n }\n util.assert(mean.rank === variance.rank, 'Batch normalization gradient requires mean and variance to have ' +\n 'equal ranks.');\n util.assert(offset == null || mean.rank === offset.rank, 'Batch normalization gradient requires mean and offset to have ' +\n 'equal ranks.');\n util.assert(scale == null || mean.rank === scale.rank, 'Batch normalization gradient requires mean and scale to have ' +\n 'equal ranks.');\n var x4D;\n if (x.rank === 0 || x.rank === 1) {\n x4D = x.as4D(1, 1, 1, x.size);\n }\n else if (x.rank === 2) {\n x4D = x.as4D(1, 1, x.shape[0], x.shape[1]);\n }\n else if (x.rank === 3) {\n x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);\n }\n else {\n x4D = x;\n }\n var der = function (dy) {\n var scaleValue = scale == null ? array_ops_1.ArrayOps.scalar(1) : scale;\n var reductionAxes = broadcast_util_1.getReductionAxes(mean.shape, x4D.shape);\n var tileShape = [];\n if (mean.rank === 1) {\n for (var i = 0; i < x4D.shape.length - 1; ++i) {\n tileShape.push(x4D.shape[i]);\n }\n tileShape.push(1);\n }\n var xMinusMean = x.sub(mean);\n var dyTimesScaleValue = dy.mul(scaleValue);\n var oneOverSqrtVariance = ops_1.rsqrt(variance.add(array_ops_1.ArrayOps.scalar(varianceEpsilon)));\n var minusHalfRCube = oneOverSqrtVariance.mul(oneOverSqrtVariance)\n .mul(oneOverSqrtVariance)\n .mul(array_ops_1.ArrayOps.scalar(-0.5));\n var derX = function () {\n if (mean.rank === 1) {\n return dy\n .mul(array_ops_1.ArrayOps.tile(oneOverSqrtVariance.as4D(1, 1, 1, mean.shape[0]), tileShape))\n .mul(scaleValue)\n .reshape(x.shape);\n }\n else {\n return dy.mul(oneOverSqrtVariance).mul(scaleValue).reshape(x.shape);\n }\n };\n var derMean = function () {\n var meanDer = oneOverSqrtVariance.mul(array_ops_1.ArrayOps.scalar(-1)).mul(dyTimesScaleValue);\n if (mean.rank === 1) {\n meanDer = meanDer.sum(reductionAxes);\n }\n return meanDer.reshape(mean.shape);\n };\n var derVariance = function () {\n var varianceDer = minusHalfRCube.mul(xMinusMean).mul(dyTimesScaleValue);\n if (mean.rank === 1) {\n varianceDer = varianceDer.sum(reductionAxes);\n }\n return varianceDer.reshape(mean.shape);\n };\n var derScale = function () {\n var xMinusMean2TimesRsqrt = xMinusMean.mul(oneOverSqrtVariance);\n var scaleDer = dy.mul(xMinusMean2TimesRsqrt);\n if (mean.rank === 1) {\n scaleDer = scaleDer.sum(reductionAxes);\n }\n return scaleDer.reshape(mean.shape);\n };\n var derOffset = function () {\n var offsetDer = dy;\n if (mean.rank === 1) {\n offsetDer = offsetDer.sum(reductionAxes);\n }\n return offsetDer.reshape(mean.shape);\n };\n return {\n x: derX,\n mean: derMean,\n variance: derVariance,\n scale: derScale,\n offset: derOffset\n };\n };\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.batchNormalization(x4D, batchnormReshape4D(mean), batchnormReshape4D(variance), varianceEpsilon, batchnormReshape4D(scale), batchnormReshape4D(offset)); }, { x: x, mean: mean, variance: variance, scale: scale, offset: offset }, der);\n return res.reshape(x.shape);\n };\n __decorate([\n operation_1.operation\n ], BatchNormOps, \"batchNormalization2d\", null);\n __decorate([\n operation_1.operation\n ], BatchNormOps, \"batchNormalization3d\", null);\n __decorate([\n operation_1.operation\n ], BatchNormOps, \"batchNormalization4d\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Normalization' })\n ], BatchNormOps, \"batchNormalization\", null);\n return BatchNormOps;\n}());\nexports.BatchNormOps = BatchNormOps;\nfunction batchnormReshape4D(x) {\n if (x == null) {\n return null;\n }\n if (x.rank === 0) {\n return x.as1D();\n }\n else if (x.rank === 1) {\n return x;\n }\n else if (x.rank === 2) {\n return x.as4D(1, 1, x.shape[0], x.shape[1]);\n }\n else if (x.rank === 3) {\n return x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);\n }\n return x;\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar DType;\n(function (DType) {\n DType[\"float32\"] = \"float32\";\n DType[\"int32\"] = \"int32\";\n DType[\"bool\"] = \"bool\";\n})(DType = exports.DType || (exports.DType = {}));\nvar Rank;\n(function (Rank) {\n Rank[\"R0\"] = \"R0\";\n Rank[\"R1\"] = \"R1\";\n Rank[\"R2\"] = \"R2\";\n Rank[\"R3\"] = \"R3\";\n Rank[\"R4\"] = \"R4\";\n})(Rank = exports.Rank || (exports.Rank = {}));\nvar UpcastInt32AndMap;\n(function (UpcastInt32AndMap) {\n UpcastInt32AndMap[\"float32\"] = \"float32\";\n UpcastInt32AndMap[\"int32\"] = \"int32\";\n UpcastInt32AndMap[\"bool\"] = \"int32\";\n})(UpcastInt32AndMap || (UpcastInt32AndMap = {}));\nvar UpcastBoolAndMap;\n(function (UpcastBoolAndMap) {\n UpcastBoolAndMap[\"float32\"] = \"float32\";\n UpcastBoolAndMap[\"int32\"] = \"int32\";\n UpcastBoolAndMap[\"bool\"] = \"bool\";\n})(UpcastBoolAndMap || (UpcastBoolAndMap = {}));\nvar UpcastFloat32AndMap;\n(function (UpcastFloat32AndMap) {\n UpcastFloat32AndMap[\"float32\"] = \"float32\";\n UpcastFloat32AndMap[\"int32\"] = \"float32\";\n UpcastFloat32AndMap[\"bool\"] = \"float32\";\n})(UpcastFloat32AndMap || (UpcastFloat32AndMap = {}));\nvar upcastTypeMap = {\n float32: UpcastFloat32AndMap,\n int32: UpcastInt32AndMap,\n bool: UpcastBoolAndMap\n};\nfunction upcastType(typeA, typeB) {\n return upcastTypeMap[typeA][typeB];\n}\nexports.upcastType = upcastType;\nfunction sumOutType(type) {\n return upcastType(type, 'int32');\n}\nexports.sumOutType = sumOutType;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar types_1 = require(\"../types\");\nvar util = require(\"../util\");\nvar broadcast_util = require(\"./broadcast_util\");\nvar operation_1 = require(\"./operation\");\nvar ops_1 = require(\"./ops\");\nvar BinaryOps = (function () {\n function BinaryOps() {\n }\n BinaryOps.add = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'add');\n util.assertTypesMatch(a, b);\n var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n var der = function (dy) {\n var derA = function () {\n var res = dy;\n var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);\n if (reduceAxes.length > 0) {\n res = res.sum(reduceAxes);\n }\n return res.reshape(a.shape);\n };\n var derB = function () {\n var res = dy;\n var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);\n if (reduceAxes.length > 0) {\n res = res.sum(reduceAxes);\n }\n return res.reshape(b.shape);\n };\n return { a: derA, b: derB };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.add(a, b); }, { a: a, b: b }, der);\n };\n BinaryOps.addStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in addStrict: ');\n return a.add(b);\n };\n BinaryOps.sub = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'sub');\n util.assertTypesMatch(a, b);\n var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n var der = function (dy) {\n var derA = function () {\n var res = dy;\n var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);\n if (reduceAxes.length > 0) {\n res = res.sum(reduceAxes);\n }\n return res.reshape(a.shape);\n };\n var derB = function () {\n var res = dy;\n var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);\n if (reduceAxes.length > 0) {\n res = res.sum(reduceAxes);\n }\n return res.neg().reshape(b.shape);\n };\n return { a: derA, b: derB };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.subtract(a, b); }, { a: a, b: b }, der);\n };\n BinaryOps.subStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in subStrict: ');\n return a.sub(b);\n };\n BinaryOps.pow = function (base, exp) {\n util.assertArgumentsAreTensors({ base: base, exp: exp }, 'pow');\n var outShape = broadcast_util.assertAndGetBroadcastShape(base.shape, exp.shape);\n base = base.cast(types_1.upcastType(base.dtype, exp.dtype));\n exp = exp.cast(types_1.upcastType(base.dtype, exp.dtype));\n var grad = function (dy, saved) {\n var y = saved[0];\n var derBase = function () {\n var res = dy.mul(exp.toFloat().mul(y.div(base)));\n var reduceAxes = broadcast_util.getReductionAxes(base.shape, outShape);\n if (reduceAxes.length > 0) {\n res = res.sum(reduceAxes);\n }\n return res.reshape(base.shape);\n };\n var derExp = function () {\n var res = dy.mul(y.mul(base.log()).toFloat());\n var reduceAxes = broadcast_util.getReductionAxes(exp.shape, outShape);\n if (reduceAxes.length > 0) {\n res = res.sum(reduceAxes);\n }\n return res.reshape(exp.shape);\n };\n return { base: derBase, exp: derExp };\n };\n return environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.pow(base, exp)); }, { base: base, exp: exp }, grad);\n };\n BinaryOps.powStrict = function (base, exp) {\n util.assertShapesMatch(base.shape, exp.shape, 'Error in powStrict: ');\n return base.pow(exp);\n };\n BinaryOps.mul = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'mul');\n util.assertTypesMatch(a, b);\n var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n var der = function (dy) {\n var derA = function () {\n var res = dy.mul(b.toFloat());\n var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);\n if (reduceAxes.length > 0) {\n return res.sum(reduceAxes).reshape(a.shape);\n }\n return res;\n };\n var derB = function () {\n var res = dy.mul(a.toFloat());\n var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);\n if (reduceAxes.length > 0) {\n return res.sum(reduceAxes).reshape(b.shape);\n }\n return res;\n };\n return { a: derA, b: derB };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.multiply(a, b); }, { a: a, b: b }, der);\n };\n BinaryOps.mulStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in multiplyStrict: ');\n return a.mul(b);\n };\n BinaryOps.div = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'div');\n util.assertTypesMatch(a, b);\n var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n var der = function (dy) {\n var derA = function () {\n var res = dy.div(b.toFloat());\n var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);\n if (reduceAxes.length > 0) {\n return res.sum(reduceAxes).reshape(a.shape);\n }\n return res;\n };\n var derB = function () {\n var res = dy.mul(a.toFloat());\n var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);\n if (reduceAxes.length > 0) {\n res = res.sum(reduceAxes).reshape(b.shape);\n }\n var tmp = b.square();\n return res.div(tmp.toFloat()).neg();\n };\n return { a: derA, b: derB };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.divide(a, b); }, { a: a, b: b }, der);\n };\n BinaryOps.divStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in divideStrict: ');\n return a.div(b);\n };\n BinaryOps.mod = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'mod');\n util.assertTypesMatch(a, b);\n var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n var der = function (dy) {\n var derA = function () {\n var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);\n if (reduceAxes.length > 0) {\n return dy.sum(reduceAxes).reshape(a.shape);\n }\n return dy;\n };\n var derB = function () {\n var res = dy.mul(a.div(b).floor().neg());\n var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);\n if (reduceAxes.length > 0) {\n return res.sum(reduceAxes).reshape(b.shape);\n }\n return res;\n };\n return { a: derA, b: derB };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.mod(a, b); }, { a: a, b: b }, der);\n };\n BinaryOps.modStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in modStrict: ');\n return a.mod(b);\n };\n BinaryOps.minimum = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'minimum');\n util.assertTypesMatch(a, b);\n if (a.dtype === 'bool') {\n a = a.toInt();\n }\n if (b.dtype === 'bool') {\n b = b.toInt();\n }\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n var der = function (dy) {\n var derA = function () { return dy.mul(a.lessEqual(b).toFloat()); };\n var derB = function () { return dy.mul(a.greater(b).toFloat()); };\n return { a: derA, b: derB };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.minimum(a, b); }, { a: a, b: b }, der);\n };\n BinaryOps.minimumStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in minimumStrict: ');\n return a.minimum(b);\n };\n BinaryOps.maximum = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'maximum');\n util.assertTypesMatch(a, b);\n if (a.dtype === 'bool') {\n a = a.toInt();\n }\n if (b.dtype === 'bool') {\n b = b.toInt();\n }\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n var der = function (dy) {\n var derA = function () { return dy.mul(a.greaterEqual(b).toFloat()); };\n var derB = function () { return dy.mul(a.less(b).toFloat()); };\n return { a: derA, b: derB };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.maximum(a, b); }, { a: a, b: b }, der);\n };\n BinaryOps.maximumStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in minimumStrict: ');\n return a.maximum(b);\n };\n BinaryOps.squaredDifference = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'squaredDifference');\n util.assertTypesMatch(a, b);\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n var der = function (dy) {\n var two = ops_1.scalar(2);\n var derA = function () { return dy.mul(a.sub(b).mul(two)); };\n var derB = function () { return dy.mul(b.sub(a).mul(two)); };\n return { a: derA, b: derB };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.squaredDifference(a, b); }, { a: a, b: b }, der);\n };\n BinaryOps.squaredDifferenceStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in squaredDifferenceStrict: ');\n return a.squaredDifference(b);\n };\n BinaryOps.atan2 = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'atan2');\n util.assertTypesMatch(a, b);\n var outShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n var der = function (dy) {\n var derA = function () {\n var d = BinaryOps.add(ops_1.square(a), ops_1.square(b));\n var res = dy.mul(b.div(d));\n var reduceAxes = broadcast_util.getReductionAxes(a.shape, outShape);\n if (reduceAxes.length > 0) {\n res = res.sum(reduceAxes);\n }\n return res.reshape(a.shape);\n };\n var derB = function () {\n var d = BinaryOps.add(ops_1.square(a), ops_1.square(b));\n var res = ops_1.neg(dy.mul(a.div(d)));\n var reduceAxes = broadcast_util.getReductionAxes(b.shape, outShape);\n if (reduceAxes.length > 0) {\n res = res.sum(reduceAxes);\n }\n return res.reshape(b.shape);\n };\n return { a: derA, b: derB };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.atan2(a, b); }, { a: a, b: b }, der);\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),\n operation_1.operation\n ], BinaryOps, \"add\", null);\n __decorate([\n operation_1.operation\n ], BinaryOps, \"addStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),\n operation_1.operation\n ], BinaryOps, \"sub\", null);\n __decorate([\n operation_1.operation\n ], BinaryOps, \"subStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),\n operation_1.operation\n ], BinaryOps, \"pow\", null);\n __decorate([\n operation_1.operation\n ], BinaryOps, \"powStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),\n operation_1.operation\n ], BinaryOps, \"mul\", null);\n __decorate([\n operation_1.operation\n ], BinaryOps, \"mulStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),\n operation_1.operation\n ], BinaryOps, \"div\", null);\n __decorate([\n operation_1.operation\n ], BinaryOps, \"divStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),\n operation_1.operation\n ], BinaryOps, \"mod\", null);\n __decorate([\n operation_1.operation\n ], BinaryOps, \"modStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),\n operation_1.operation\n ], BinaryOps, \"minimum\", null);\n __decorate([\n operation_1.operation\n ], BinaryOps, \"minimumStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),\n operation_1.operation\n ], BinaryOps, \"maximum\", null);\n __decorate([\n operation_1.operation\n ], BinaryOps, \"maximumStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Arithmetic' }),\n operation_1.operation\n ], BinaryOps, \"squaredDifference\", null);\n __decorate([\n operation_1.operation\n ], BinaryOps, \"squaredDifferenceStrict\", null);\n __decorate([\n operation_1.operation\n ], BinaryOps, \"atan2\", null);\n return BinaryOps;\n}());\nexports.BinaryOps = BinaryOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar broadcast_util = require(\"./broadcast_util\");\nvar operation_1 = require(\"./operation\");\nvar CompareOps = (function () {\n function CompareOps() {\n }\n CompareOps.notEqual = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'notEqual');\n util.assertTypesMatch(a, b);\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.notEqual(a, b); }, { a: a, b: b });\n };\n CompareOps.notEqualStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in notEqualStrict: ');\n return a.notEqual(b);\n };\n CompareOps.less = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'less');\n util.assertTypesMatch(a, b);\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.less(a, b); }, { a: a, b: b });\n };\n CompareOps.lessStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in lessStrict: ');\n return a.less(b);\n };\n CompareOps.equal = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'equal');\n util.assertTypesMatch(a, b);\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.equal(a, b); }, { a: a, b: b });\n };\n CompareOps.equalStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in equalStrict: ');\n return a.equal(b);\n };\n CompareOps.lessEqual = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'lessEqual');\n util.assertTypesMatch(a, b);\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.lessEqual(a, b); }, { a: a, b: b });\n };\n CompareOps.lessEqualStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in lessEqualStrict: ');\n return a.lessEqual(b);\n };\n CompareOps.greater = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'greater');\n util.assertTypesMatch(a, b);\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.greater(a, b); }, { a: a, b: b });\n };\n CompareOps.greaterStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in greaterStrict: ');\n return a.greater(b);\n };\n CompareOps.greaterEqual = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'greaterEqual');\n util.assertTypesMatch(a, b);\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.greaterEqual(a, b); }, { a: a, b: b });\n };\n CompareOps.greaterEqualStrict = function (a, b) {\n util.assertShapesMatch(a.shape, b.shape, 'Error in greaterEqualStrict: ');\n return a.greaterEqual(b);\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], CompareOps, \"notEqual\", null);\n __decorate([\n operation_1.operation\n ], CompareOps, \"notEqualStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], CompareOps, \"less\", null);\n __decorate([\n operation_1.operation\n ], CompareOps, \"lessStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], CompareOps, \"equal\", null);\n __decorate([\n operation_1.operation\n ], CompareOps, \"equalStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], CompareOps, \"lessEqual\", null);\n __decorate([\n operation_1.operation\n ], CompareOps, \"lessEqualStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], CompareOps, \"greater\", null);\n __decorate([\n operation_1.operation\n ], CompareOps, \"greaterStrict\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], CompareOps, \"greaterEqual\", null);\n __decorate([\n operation_1.operation\n ], CompareOps, \"greaterEqualStrict\", null);\n return CompareOps;\n}());\nexports.CompareOps = CompareOps;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar util = require(\"../util\");\nfunction computePool2DInfo(inShape, filterSize, strides, pad, roundingMode, dataFormat) {\n if (dataFormat === void 0) { dataFormat = 'channelsLast'; }\n var _a = parseTupleParam(filterSize), filterHeight = _a[0], filterWidth = _a[1];\n var filterShape;\n if (dataFormat === 'channelsLast') {\n filterShape = [filterHeight, filterWidth, inShape[3], inShape[3]];\n }\n else if (dataFormat === 'channelsFirst') {\n filterShape = [filterHeight, filterWidth, inShape[1], inShape[1]];\n }\n else {\n throw new Error(\"Unknown dataFormat \" + dataFormat);\n }\n var dilations = 1;\n return computeConv2DInfo(inShape, filterShape, strides, dilations, pad, roundingMode, false, dataFormat);\n}\nexports.computePool2DInfo = computePool2DInfo;\nfunction computeConv2DInfo(inShape, filterShape, strides, dilations, pad, roundingMode, depthwise, dataFormat) {\n if (depthwise === void 0) { depthwise = false; }\n if (dataFormat === void 0) { dataFormat = 'channelsLast'; }\n var _a = [-1, -1, -1, -1], batchSize = _a[0], inHeight = _a[1], inWidth = _a[2], inChannels = _a[3];\n if (dataFormat === 'channelsLast') {\n batchSize = inShape[0], inHeight = inShape[1], inWidth = inShape[2], inChannels = inShape[3];\n }\n else if (dataFormat === 'channelsFirst') {\n batchSize = inShape[0], inChannels = inShape[1], inHeight = inShape[2], inWidth = inShape[3];\n }\n else {\n throw new Error(\"Unknown dataFormat \" + dataFormat);\n }\n var filterHeight = filterShape[0], filterWidth = filterShape[1], filterChannels = filterShape[3];\n var _b = parseTupleParam(strides), strideHeight = _b[0], strideWidth = _b[1];\n var _c = parseTupleParam(dilations), dilationHeight = _c[0], dilationWidth = _c[1];\n var effectiveFilterHeight = getEffectiveFilterSize(filterHeight, dilationHeight);\n var effectiveFilterWidth = getEffectiveFilterSize(filterWidth, dilationWidth);\n var _d = getPadAndOutInfo(pad, inHeight, inWidth, strideHeight, strideWidth, effectiveFilterHeight, effectiveFilterWidth, roundingMode), padInfo = _d.padInfo, outHeight = _d.outHeight, outWidth = _d.outWidth;\n var outChannels = depthwise ? filterChannels * inChannels : filterChannels;\n var outShape;\n if (dataFormat === 'channelsFirst') {\n outShape = [batchSize, outChannels, outHeight, outWidth];\n }\n else if (dataFormat === 'channelsLast') {\n outShape = [batchSize, outHeight, outWidth, outChannels];\n }\n return {\n batchSize: batchSize,\n dataFormat: dataFormat,\n inHeight: inHeight,\n inWidth: inWidth,\n inChannels: inChannels,\n outHeight: outHeight,\n outWidth: outWidth,\n outChannels: outChannels,\n padInfo: padInfo,\n strideHeight: strideHeight,\n strideWidth: strideWidth,\n filterHeight: filterHeight,\n filterWidth: filterWidth,\n dilationHeight: dilationHeight,\n dilationWidth: dilationWidth,\n inShape: inShape,\n outShape: outShape,\n filterShape: filterShape\n };\n}\nexports.computeConv2DInfo = computeConv2DInfo;\nfunction computeOutputShape3D(inShape, fieldSize, outDepth, stride, zeroPad, roundingMode) {\n if (zeroPad == null) {\n zeroPad = computeDefaultPad(inShape, fieldSize, stride);\n }\n var inputRows = inShape[0];\n var inputCols = inShape[1];\n var outputRows = conditionalRound((inputRows - fieldSize + 2 * zeroPad) / stride + 1, roundingMode);\n util.assert(util.isInt(outputRows), \"The output # of rows (\" + outputRows + \") must be an integer. Change the \" +\n \"stride and/or zero pad parameters\");\n var outputCols = conditionalRound((inputCols - fieldSize + 2 * zeroPad) / stride + 1, roundingMode);\n util.assert(util.isInt(outputCols), \"The output # of columns (\" + outputCols + \") must be an integer. Change \" +\n \"the stride and/or zero pad parameters\");\n return [outputRows, outputCols, outDepth];\n}\nfunction computeDefaultPad(inputShape, fieldSize, stride, dilation) {\n if (dilation === void 0) { dilation = 1; }\n var effectiveFieldSize = getEffectiveFilterSize(fieldSize, dilation);\n return Math.floor((inputShape[0] * (stride - 1) - stride + effectiveFieldSize) / 2);\n}\nexports.computeDefaultPad = computeDefaultPad;\nfunction parseTupleParam(param) {\n return typeof param === 'number' ? [param, param] : param;\n}\nfunction getEffectiveFilterSize(filterSize, dilation) {\n if (dilation <= 1) {\n return filterSize;\n }\n return filterSize + (filterSize - 1) * (dilation - 1);\n}\nfunction getPadAndOutInfo(pad, inHeight, inWidth, strideHeight, strideWidth, filterHeight, filterWidth, roundingMode) {\n var padInfo;\n var outHeight;\n var outWidth;\n if (typeof pad === 'number') {\n var padType = (pad === 0) ? 'VALID' : 'NUMBER';\n padInfo = { top: pad, bottom: pad, left: pad, right: pad, type: padType };\n var outShape = computeOutputShape3D([inHeight, inWidth, 1], filterHeight, 1, strideHeight, pad, roundingMode);\n outHeight = outShape[0];\n outWidth = outShape[1];\n }\n else if (pad === 'same') {\n outHeight = Math.ceil(inHeight / strideHeight);\n outWidth = Math.ceil(inWidth / strideWidth);\n var padAlongHeight = (outHeight - 1) * strideHeight + filterHeight - inHeight;\n var padAlongWidth = (outWidth - 1) * strideWidth + filterWidth - inWidth;\n var top_1 = Math.floor(padAlongHeight / 2);\n var bottom = padAlongHeight - top_1;\n var left = Math.floor(padAlongWidth / 2);\n var right = padAlongWidth - left;\n padInfo = { top: top_1, bottom: bottom, left: left, right: right, type: 'SAME' };\n }\n else if (pad === 'valid') {\n padInfo = { top: 0, bottom: 0, left: 0, right: 0, type: 'VALID' };\n outHeight = Math.ceil((inHeight - filterHeight + 1) / strideHeight);\n outWidth = Math.ceil((inWidth - filterWidth + 1) / strideWidth);\n }\n else {\n throw Error(\"Unknown padding parameter: \" + pad);\n }\n return { padInfo: padInfo, outHeight: outHeight, outWidth: outWidth };\n}\nfunction conditionalRound(value, roundingMode) {\n if (!roundingMode) {\n return value;\n }\n switch (roundingMode) {\n case 'round':\n return Math.round(value);\n case 'ceil':\n return Math.ceil(value);\n case 'floor':\n return Math.floor(value);\n default:\n throw new Error(\"Unknown roundingMode \" + roundingMode);\n }\n}\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar conv_util = require(\"./conv_util\");\nvar operation_1 = require(\"./operation\");\nvar ConvOps = (function () {\n function ConvOps() {\n }\n ConvOps.conv1d = function (x, filter, stride, pad, dataFormat, dilation, dimRoundingMode) {\n if (dataFormat === void 0) { dataFormat = 'NWC'; }\n if (dilation === void 0) { dilation = 1; }\n util.assertArgumentsAreTensors({ x: x, filter: filter }, 'conv1d');\n var x3D = x;\n var reshapedTo3D = false;\n if (x.rank === 2) {\n reshapedTo3D = true;\n x3D = x.as3D(1, x.shape[0], x.shape[1]);\n }\n util.assert(x3D.rank === 3, \"Error in conv1d: input must be rank 3, but got rank \" + x3D.rank + \".\");\n util.assert(filter.rank === 3, \"Error in conv1d: filter must be rank 3, but got rank \" +\n (filter.rank + \".\"));\n if (dimRoundingMode != null) {\n util.assert(util.isInt(pad), \"Error in conv1d: pad must be an integer when using, \" +\n (\"dimRoundingMode \" + dimRoundingMode + \" but got pad \" + pad + \".\"));\n }\n util.assert(x3D.shape[2] === filter.shape[1], \"Error in conv1d: depth of input (\" + x3D.shape[2] + \") must match \" +\n (\"input depth for filter \" + filter.shape[1] + \".\"));\n util.assert(eitherStridesOrDilationsAreOne(stride, dilation), 'Error in conv1D: Either stride or dilation must be 1.' +\n (\"Got stride \" + stride + \" and dilation '\" + dilation + \"'\"));\n util.assert(dataFormat === 'NWC', \"Error in conv1d: got dataFormat of \" + dataFormat + \" but only NWC is currently supported.\");\n var filter4D = filter.as4D(1, filter.shape[0], filter.shape[1], filter.shape[2]);\n var input4D = x3D.as4D(x3D.shape[0], 1, x3D.shape[1], x3D.shape[2]);\n var strides = [1, stride];\n var dilations = [1, dilation];\n var conv2dDataFormat = 'NHWC';\n var res = ConvOps.conv2d(input4D, filter4D, strides, pad, conv2dDataFormat, dilations, dimRoundingMode);\n if (reshapedTo3D) {\n return res.as2D(res.shape[2], res.shape[3]);\n }\n return res.as3D(res.shape[0], res.shape[2], res.shape[3]);\n };\n ConvOps.conv2d = function (x, filter, strides, pad, dataFormat, dilations, dimRoundingMode) {\n if (dataFormat === void 0) { dataFormat = 'NHWC'; }\n if (dilations === void 0) { dilations = [1, 1]; }\n util.assertArgumentsAreTensors({ x: x, filter: filter }, 'conv2d');\n var x4D = x;\n var reshapedTo4D = false;\n if (x.rank === 3) {\n reshapedTo4D = true;\n x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);\n }\n util.assert(x4D.rank === 4, \"Error in conv2d: input must be rank 4, but got rank \" + x4D.rank + \".\");\n util.assert(filter.rank === 4, \"Error in conv2d: filter must be rank 4, but got rank \" +\n (filter.rank + \".\"));\n if (dimRoundingMode != null) {\n util.assert(util.isInt(pad), \"Error in conv2d: pad must be an integer when using, \" +\n (\"dimRoundingMode \" + dimRoundingMode + \" but got pad \" + pad + \".\"));\n }\n util.assert(x4D.shape[3] === filter.shape[2], \"Error in conv2d: depth of input (\" + x4D.shape[3] + \") must match \" +\n (\"input depth for filter \" + filter.shape[2] + \".\"));\n util.assert(eitherStridesOrDilationsAreOne(strides, dilations), 'Error in conv2D: Either strides or dilations must be 1.' +\n (\"Got strides \" + strides + \" and dilations '\" + dilations + \"'\"));\n util.assert(dataFormat === 'NHWC', \"Error in conv2d: got dataFormat of \" + dataFormat + \" but only NHWC is currently supported.\");\n var convInfo = conv_util.computeConv2DInfo(x4D.shape, filter.shape, strides, dilations, pad, dimRoundingMode);\n var grad = function (dy) {\n util.assert(tupleValuesAreOne(dilations), 'Error in gradient of conv2D: dilation rates greater than 1 are not' +\n (\"yet supported in gradients. Got dilations '\" + dilations + \"'\"));\n return {\n x: function () { return ConvOps.conv2dDerInput(x4D.shape, dy, filter, strides, pad); },\n filter: function () {\n return ConvOps.conv2dDerFilter(x4D, dy, filter.shape, strides, pad);\n }\n };\n };\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.conv2d(x4D, filter, convInfo); }, { x: x4D, filter: filter }, grad);\n if (reshapedTo4D) {\n return res.as3D(res.shape[1], res.shape[2], res.shape[3]);\n }\n return res;\n };\n ConvOps.conv2dDerInput = function (xShape, dy, filter, strides, pad, dimRoundingMode) {\n util.assertArgumentsAreTensors({ dy: dy, filter: filter }, 'conv2dDerInput');\n util.assert(xShape.length === dy.rank, \"Length of inShape \" +\n (\"(\" + xShape.length + \") and rank of dy (\" + dy.rank + \") must match\"));\n var xShape4D = xShape;\n var dy4D = dy;\n var reshapedTo4D = false;\n if (dy.rank === 3) {\n reshapedTo4D = true;\n dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);\n xShape4D = [1, xShape[0], xShape[1], xShape[2]];\n }\n var inDepth = xShape4D[3];\n var outDepth = dy4D.shape[3];\n util.assert(xShape4D.length === 4, \"Error in conv2dDerInput: inShape must be length 4, but got length \" +\n (xShape4D.length + \".\"));\n util.assert(dy4D.rank === 4, \"Error in conv2dDerInput: dy must be rank 4, but got \" +\n (\"rank \" + dy4D.rank));\n util.assert(filter.rank === 4, \"Error in conv2dDerInput: filter must be rank 4, but got \" +\n (\"rank \" + filter.rank));\n util.assert(inDepth === filter.shape[2], \"Error in conv2dDerInput: depth of input (\" + inDepth + \") must \" +\n (\"match input depth for filter \" + filter.shape[2] + \".\"));\n util.assert(outDepth === filter.shape[3], \"Error in conv2dDerInput: depth of output (\" + outDepth + \") must\" +\n (\"match output depth for filter \" + filter.shape[3] + \".\"));\n if (dimRoundingMode != null) {\n util.assert(util.isInt(pad), \"Error in conv2dDerInput: pad must be an integer when using, \" +\n (\"dimRoundingMode \" + dimRoundingMode + \" but got pad \" + pad + \".\"));\n }\n var dilations = 1;\n var convInfo = conv_util.computeConv2DInfo(xShape4D, filter.shape, strides, dilations, pad, dimRoundingMode);\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.conv2dDerInput(dy4D, filter, convInfo); }, { dy4D: dy4D });\n if (reshapedTo4D) {\n return res.as3D(res.shape[1], res.shape[2], res.shape[3]);\n }\n return res;\n };\n ConvOps.conv2dDerFilter = function (x, dy, filterShape, strides, pad, dimRoundingMode) {\n util.assertArgumentsAreTensors({ x: x, dy: dy }, 'conv2dDerFilter');\n var x4D = x;\n if (x.rank === 3) {\n x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);\n }\n var dy4D = dy;\n if (dy4D.rank === 3) {\n dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);\n }\n util.assert(x4D.rank === 4, \"Error in conv2dDerFilter: input must be rank 4, but got shape \" +\n (x4D.shape + \".\"));\n util.assert(dy4D.rank === 4, \"Error in conv2dDerFilter: dy must be rank 4, but got shape \" +\n (dy4D.shape + \".\"));\n util.assert(filterShape.length === 4, \"Error in conv2dDerFilter: filterShape must be length 4, but got \" +\n (filterShape + \".\"));\n util.assert(x4D.shape[3] === filterShape[2], \"Error in conv2dDerFilter: depth of input \" + x4D.shape[3] + \") must \" +\n (\"match input depth in filter (\" + filterShape[2] + \".\"));\n util.assert(dy4D.shape[3] === filterShape[3], \"Error in conv2dDerFilter: depth of dy (\" + dy4D.shape[3] + \") must \" +\n (\"match output depth for filter (\" + filterShape[3] + \").\"));\n if (dimRoundingMode != null) {\n util.assert(util.isInt(pad), \"Error in conv2dDerFilter: pad must be an integer when using, \" +\n (\"dimRoundingMode \" + dimRoundingMode + \" but got pad \" + pad + \".\"));\n }\n var dilations = 1;\n var convInfo = conv_util.computeConv2DInfo(x4D.shape, filterShape, strides, dilations, pad, dimRoundingMode);\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.conv2dDerFilter(x4D, dy4D, convInfo); }, { x4D: x4D, dy4D: dy4D });\n };\n ConvOps.conv2dTranspose = function (x, filter, outputShape, strides, pad, dimRoundingMode) {\n util.assertArgumentsAreTensors({ x: x, filter: filter }, 'conv2dTranspose');\n return ConvOps.conv2dDerInput(outputShape, x, filter, strides, pad, dimRoundingMode);\n };\n ConvOps.depthwiseConv2d = function (x, filter, strides, pad, dataFormat, dilations, dimRoundingMode) {\n if (dataFormat === void 0) { dataFormat = 'NHWC'; }\n if (dilations === void 0) { dilations = [1, 1]; }\n util.assertArgumentsAreTensors({ x: x, filter: filter }, 'depthwiseConv2d');\n var x4D = x;\n var reshapedTo4D = false;\n if (x.rank === 3) {\n reshapedTo4D = true;\n x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);\n }\n util.assert(x4D.rank === 4, \"Error in depthwiseConv2D: input must be rank 4, but got \" +\n (\"rank \" + x4D.rank + \".\"));\n util.assert(filter.rank === 4, \"Error in depthwiseConv2D: filter must be rank 4, but got rank \" +\n (filter.rank + \".\"));\n util.assert(x4D.shape[3] === filter.shape[2], \"Error in depthwiseConv2D: number of input channels \" +\n (\"(\" + x4D.shape[3] + \") must match the inChannels dimension in \") +\n (\"filter \" + filter.shape[2] + \".\"));\n if (dilations == null) {\n dilations = [1, 1];\n }\n util.assert(eitherStridesOrDilationsAreOne(strides, dilations), 'Error in depthwiseConv2d: Either strides or dilations must be 1.' +\n (\"Got strides \" + strides + \" and dilations '\" + dilations + \"'\"));\n if (dimRoundingMode != null) {\n util.assert(util.isInt(pad), \"Error in depthwiseConv2D: pad must be an integer when using, \" +\n (\"dimRoundingMode \" + dimRoundingMode + \" but got pad \" + pad + \".\"));\n }\n var convInfo = conv_util.computeConv2DInfo(x4D.shape, filter.shape, strides, dilations, pad, dimRoundingMode, true);\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.depthwiseConv2D(x4D, filter, convInfo); }, { x4D: x4D, filter: filter });\n if (reshapedTo4D) {\n return res.as3D(res.shape[1], res.shape[2], res.shape[3]);\n }\n return res;\n };\n ConvOps.separableConv2d = function (x, depthwiseFilter, pointwiseFilter, strides, pad, dilation, dataFormat) {\n if (dilation === void 0) { dilation = [1, 1]; }\n if (dataFormat === void 0) { dataFormat = 'NHWC'; }\n util.assertArgumentsAreTensors({ x: x, depthwiseFilter: depthwiseFilter, pointwiseFilter: pointwiseFilter }, 'separableConv2d');\n var x4D = x;\n var reshapedTo4D = false;\n if (x.rank === 3) {\n reshapedTo4D = true;\n x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);\n }\n if (dataFormat === 'NCHW') {\n throw new Error('separableConv2d currently does not support dataFormat NCHW; only ' +\n 'NHWC is supported');\n }\n util.assert(x4D.rank === 4, \"Error in separableConv2d: input must be rank 4, but got \" +\n (\"rank \" + x4D.rank + \".\"));\n util.assert(depthwiseFilter.rank === 4, \"Error in separableConv2d: depthwise filter must be rank 4, but got \" +\n (\"rank \" + depthwiseFilter.rank + \".\"));\n util.assert(pointwiseFilter.rank === 4, \"Error in separableConv2d: pointwise filter must be rank 4, but got \" +\n (\"rank \" + depthwiseFilter.rank + \".\"));\n util.assert(pointwiseFilter.shape[0] === 1, \"Error in separableConv2d: the first dimension of pointwise filter \" +\n (\" must be 1, but got \" + pointwiseFilter.shape[0] + \".\"));\n util.assert(pointwiseFilter.shape[1] === 1, \"Error in separableConv2d: the second dimension of pointwise filter \" +\n (\" must be 1, but got \" + pointwiseFilter.shape[1] + \".\"));\n var inChannels = depthwiseFilter.shape[2];\n var channelMultiplier = depthwiseFilter.shape[3];\n util.assert(pointwiseFilter.shape[2] === inChannels * channelMultiplier, \"Error in separableConv2d: the third dimension of pointwise filter \" +\n (\"must be \" + inChannels * channelMultiplier + \", \") +\n (\"but got \" + pointwiseFilter.shape[2] + \".\"));\n var depthwise = ConvOps.depthwiseConv2d(x4D, depthwiseFilter, strides, pad, dataFormat, dilation);\n var pointwiseStride = 1;\n var res = ConvOps.conv2d(depthwise, pointwiseFilter, pointwiseStride, 'valid', dataFormat);\n if (reshapedTo4D) {\n return res.as3D(res.shape[1], res.shape[2], res.shape[3]);\n }\n return res;\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),\n operation_1.operation\n ], ConvOps, \"conv1d\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),\n operation_1.operation\n ], ConvOps, \"conv2d\", null);\n __decorate([\n operation_1.operation\n ], ConvOps, \"conv2dDerInput\", null);\n __decorate([\n operation_1.operation\n ], ConvOps, \"conv2dDerFilter\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),\n operation_1.operation\n ], ConvOps, \"conv2dTranspose\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),\n operation_1.operation\n ], ConvOps, \"depthwiseConv2d\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),\n operation_1.operation\n ], ConvOps, \"separableConv2d\", null);\n return ConvOps;\n}());\nexports.ConvOps = ConvOps;\nfunction parseTupleParam(param) {\n return typeof param === 'number' ? [param, param] : param;\n}\nfunction tupleValuesAreOne(param) {\n var _a = parseTupleParam(param), dimA = _a[0], dimB = _a[1];\n return dimA === 1 && dimB === 1;\n}\nfunction eitherStridesOrDilationsAreOne(strides, dilations) {\n return tupleValuesAreOne(strides) || tupleValuesAreOne(dilations);\n}\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar operation_1 = require(\"./operation\");\nvar ImageOps = (function () {\n function ImageOps() {\n }\n ImageOps.resizeBilinear = function (images, size, alignCorners) {\n if (alignCorners === void 0) { alignCorners = false; }\n util.assertArgumentsAreTensors({ images: images }, 'resizeBilinear');\n util.assert(images.rank === 3 || images.rank === 4, \"Error in resizeBilinear: x must be rank 3 or 4, but got \" +\n (\"rank \" + images.rank + \".\"));\n util.assert(size.length === 2, \"Error in resizeBilinear: new shape must 2D, but got shape \" +\n (size + \".\"));\n var batchImages = images;\n var reshapedTo4D = false;\n if (images.rank === 3) {\n reshapedTo4D = true;\n batchImages =\n images.as4D(1, images.shape[0], images.shape[1], images.shape[2]);\n }\n var newHeight = size[0], newWidth = size[1];\n var forward = function (backend, save) {\n return backend.resizeBilinear(batchImages, newHeight, newWidth, alignCorners);\n };\n var backward = function (dy, saved) {\n return {\n batchImages: function () { return environment_1.ENV.engine.runKernel(function (backend) {\n return backend.resizeBilinearBackprop(dy, batchImages, alignCorners);\n }, {}); }\n };\n };\n var res = environment_1.ENV.engine.runKernel(forward, { batchImages: batchImages }, backward);\n if (reshapedTo4D) {\n return res.as3D(res.shape[1], res.shape[2], res.shape[3]);\n }\n return res;\n };\n ImageOps.resizeNearestNeighbor = function (images, size, alignCorners) {\n if (alignCorners === void 0) { alignCorners = false; }\n util.assertArgumentsAreTensors({ images: images }, 'resizeNearestNeighbor');\n util.assert(images.rank === 3 || images.rank === 4, \"Error in resizeNearestNeighbor: x must be rank 3 or 4, but got \" +\n (\"rank \" + images.rank + \".\"));\n util.assert(size.length === 2, \"Error in resizeNearestNeighbor: new shape must 2D, but got shape \" +\n (size + \".\"));\n util.assert(images.dtype === 'float32' || images.dtype === 'int32', '`images` must have `int32` or `float32` as dtype');\n var batchImages = images;\n var reshapedTo4D = false;\n if (images.rank === 3) {\n reshapedTo4D = true;\n batchImages =\n images.as4D(1, images.shape[0], images.shape[1], images.shape[2]);\n }\n var newHeight = size[0], newWidth = size[1];\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.resizeNearestNeighbor(batchImages, newHeight, newWidth, alignCorners); }, { batchImages: batchImages });\n if (reshapedTo4D) {\n return res.as3D(res.shape[1], res.shape[2], res.shape[3]);\n }\n return res;\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Images', namespace: 'image' }),\n operation_1.operation\n ], ImageOps, \"resizeBilinear\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Images', namespace: 'image' }),\n operation_1.operation\n ], ImageOps, \"resizeNearestNeighbor\", null);\n return ImageOps;\n}());\nexports.ImageOps = ImageOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"./doc\");\nvar environment_1 = require(\"./environment\");\nvar util_1 = require(\"./util\");\nvar Tracking = (function () {\n function Tracking() {\n }\n Tracking.tidy = function (nameOrFn, fn, gradMode) {\n if (gradMode === void 0) { gradMode = false; }\n var name = null;\n if (fn == null) {\n if (typeof nameOrFn !== 'function') {\n throw new Error('Please provide a function to tidy()');\n }\n fn = nameOrFn;\n }\n else {\n if (typeof nameOrFn !== 'string' && !(nameOrFn instanceof String)) {\n throw new Error('When calling with two arguments, the first argument ' +\n 'to tidy() must be a string');\n }\n if (typeof fn !== 'function') {\n throw new Error('When calling with two arguments, the 2nd argument ' +\n 'to tidy() must be a function');\n }\n name = nameOrFn;\n }\n environment_1.ENV.engine.startScope(name, gradMode);\n var result = fn();\n if (result instanceof Promise) {\n console.error('Cannot return a Promise inside of tidy.');\n }\n environment_1.ENV.engine.endScope(result, gradMode);\n return result;\n };\n Tracking.dispose = function (container) {\n var tensors = util_1.extractTensorsFromAny(container);\n tensors.forEach(function (tensor) { return tensor.dispose(); });\n };\n Tracking.keep = function (result) {\n return environment_1.ENV.engine.keep(result);\n };\n Tracking.time = function (f) {\n return environment_1.ENV.engine.time(f);\n };\n __decorate([\n doc_1.doc({ heading: 'Performance', subheading: 'Memory' })\n ], Tracking, \"tidy\", null);\n __decorate([\n doc_1.doc({ heading: 'Performance', subheading: 'Memory' })\n ], Tracking, \"keep\", null);\n __decorate([\n doc_1.doc({ heading: 'Performance', subheading: 'Timing' })\n ], Tracking, \"time\", null);\n return Tracking;\n}());\nexports.Tracking = Tracking;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar tracking_1 = require(\"../tracking\");\nvar util_1 = require(\"../util\");\nvar operation_1 = require(\"./operation\");\nvar ops_1 = require(\"./ops\");\nvar LinalgOps = (function () {\n function LinalgOps() {\n }\n LinalgOps.gramSchmidt = function (xs) {\n var inputIsTensor2D;\n if (Array.isArray(xs)) {\n inputIsTensor2D = false;\n util_1.assert(xs != null && xs.length > 0, 'Gram-Schmidt process: input must not be null, undefined, or empty');\n var dim = xs[0].shape[0];\n for (var i = 1; i < xs.length; ++i) {\n util_1.assert(xs[i].shape[0] === dim, 'Gram-Schmidt: Non-unique lengths found in the input vectors: ' +\n (\"(\" + xs[i].shape[0] + \" vs. \" + dim + \")\"));\n }\n }\n else {\n inputIsTensor2D = true;\n xs = ops_1.split(xs, xs.shape[0], 0).map(function (x) { return ops_1.squeeze(x, [0]); });\n }\n util_1.assert(xs.length <= xs[0].shape[0], \"Gram-Schmidt: Number of vectors (\" + xs.length + \") exceeds \" +\n (\"number of dimensions (\" + xs[0].shape[0] + \").\"));\n var ys = [];\n var xs1d = xs;\n var _loop_1 = function (i) {\n ys.push(tracking_1.Tracking.tidy(function () {\n var x = xs1d[i];\n if (i > 0) {\n for (var j = 0; j < i; ++j) {\n var proj = ops_1.sum(ys[j].mulStrict(x)).mul(ys[j]);\n x = x.sub(proj);\n }\n }\n return x.div(ops_1.norm(x, 'euclidean'));\n }));\n };\n for (var i = 0; i < xs.length; ++i) {\n _loop_1(i);\n }\n if (inputIsTensor2D) {\n return ops_1.stack(ys, 0);\n }\n else {\n return ys;\n }\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Linear Algebra' }),\n operation_1.operation\n ], LinalgOps, \"gramSchmidt\", null);\n return LinalgOps;\n}());\nexports.LinalgOps = LinalgOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar types = require(\"../types\");\nvar util = require(\"../util\");\nvar broadcast_util = require(\"./broadcast_util\");\nvar operation_1 = require(\"./operation\");\nvar LogicalOps = (function () {\n function LogicalOps() {\n }\n LogicalOps.logicalNot = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'logicalNot');\n util.assert(x.dtype === 'bool', 'Error Array must be of type bool.');\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.logicalNot(x); }, { x: x });\n };\n LogicalOps.logicalAnd = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'logicalAnd');\n util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.');\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.logicalAnd(a, b); }, { a: a, b: b });\n };\n LogicalOps.logicalOr = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'logicalOr');\n util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.');\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.logicalOr(a, b); }, { a: a, b: b });\n };\n LogicalOps.logicalXor = function (a, b) {\n util.assertArgumentsAreTensors({ a: a, b: b }, 'logicalXor');\n util.assert(a.dtype === 'bool' && b.dtype === 'bool', 'Error Array must be of type bool.');\n broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n return LogicalOps.logicalOr(a, b).logicalAnd(LogicalOps.logicalAnd(a, b).logicalNot());\n };\n LogicalOps.where = function (condition, a, b) {\n util.assertArgumentsAreTensors({ condition: condition, a: a, b: b }, 'where');\n util.assert(condition.dtype === 'bool' || a.dtype === 'bool' || b.dtype === 'bool', 'Error Array must be of type bool.');\n util.assertShapesMatch(a.shape, b.shape, 'Error in where: ');\n if (condition.rank === 1) {\n util.assert(condition.shape[0] === a.shape[0], 'The first dimension of `a` must match the size of `condition`.');\n }\n else {\n util.assertShapesMatch(condition.shape, b.shape, 'Error in where: ');\n }\n var dtype = types.upcastType(a.dtype, b.dtype);\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.where(condition, a, b, dtype); }, { condition: condition, a: a, b: b });\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], LogicalOps, \"logicalNot\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], LogicalOps, \"logicalAnd\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], LogicalOps, \"logicalOr\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], LogicalOps, \"logicalXor\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Logical' }),\n operation_1.operation\n ], LogicalOps, \"where\", null);\n return LogicalOps;\n}());\nexports.LogicalOps = LogicalOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar util = require(\"../util\");\nvar operation_1 = require(\"./operation\");\nvar ops = require(\"./ops\");\nvar Reduction;\n(function (Reduction) {\n Reduction[Reduction[\"NONE\"] = 0] = \"NONE\";\n Reduction[Reduction[\"MEAN\"] = 1] = \"MEAN\";\n Reduction[Reduction[\"SUM\"] = 2] = \"SUM\";\n Reduction[Reduction[\"SUM_BY_NONZERO_WEIGHTS\"] = 3] = \"SUM_BY_NONZERO_WEIGHTS\";\n})(Reduction = exports.Reduction || (exports.Reduction = {}));\nvar LossOps = (function () {\n function LossOps() {\n }\n LossOps.computeWeightedLoss = function (losses, weights, reduction) {\n if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }\n util.assertArgumentsAreTensors({ losses: losses }, 'computeWeightedLoss');\n if (weights != null) {\n util.assertArgumentsAreTensors({ weights: weights }, 'computeWeightedLoss');\n }\n var weightedLoss = (weights == null) ? losses : losses.mul(weights);\n if (reduction === Reduction.NONE) {\n return weightedLoss;\n }\n if (reduction === Reduction.SUM) {\n return weightedLoss.sum();\n }\n if (reduction === Reduction.MEAN) {\n return (weights == null) ? weightedLoss.mean() :\n weightedLoss.sum().div(weights.sum());\n }\n if (reduction === Reduction.SUM_BY_NONZERO_WEIGHTS) {\n if (weights == null) {\n return weightedLoss.sum().div(ops.scalar(losses.size));\n }\n else {\n var numNonZeros = weights.notEqual(ops.scalar(0)).sum().toFloat();\n return weightedLoss.sum().div(numNonZeros);\n }\n }\n throw Error(\"Unknown reduction: \" + reduction);\n };\n LossOps.absoluteDifference = function (labels, predictions, weights, reduction) {\n if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }\n util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'absoluteDifference');\n if (weights != null) {\n util.assertArgumentsAreTensors({ weights: weights }, 'absoluteDifference');\n }\n util.assertShapesMatch(labels.shape, predictions.shape, 'Error in absoluteDifference: ');\n var losses = labels.sub(predictions).abs();\n return LossOps.computeWeightedLoss(losses, weights, reduction);\n };\n LossOps.meanSquaredError = function (labels, predictions, weights, reduction) {\n if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }\n util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'meanSquaredError');\n if (weights != null) {\n util.assertArgumentsAreTensors({ weights: weights }, 'meanSquaredError');\n }\n util.assertShapesMatch(labels.shape, predictions.shape, 'Error in meanSquaredError: ');\n var losses = labels.squaredDifference(predictions);\n return LossOps.computeWeightedLoss(losses, weights, reduction);\n };\n LossOps.cosineDistance = function (labels, predictions, axis, weights, reduction) {\n if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }\n util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'cosineDistance');\n if (weights != null) {\n util.assertArgumentsAreTensors({ weights: weights }, 'cosineDistance');\n }\n util.assertShapesMatch(labels.shape, predictions.shape, 'Error in cosineDistance: ');\n var one = ops.scalar(1);\n var losses = one.sub(labels.mul(predictions).sum(axis, true));\n return LossOps.computeWeightedLoss(losses, weights, reduction);\n };\n LossOps.hingeLoss = function (labels, predictions, weights, reduction) {\n if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }\n util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'hingeLoss');\n if (weights != null) {\n util.assertArgumentsAreTensors({ weights: weights }, 'hingeLoss');\n }\n util.assertShapesMatch(labels.shape, predictions.shape, 'Error in hingeLoss: ');\n var one = ops.scalar(1);\n labels = ops.scalar(2).mul(labels).sub(one);\n var losses = one.sub(labels.mul(predictions)).relu();\n return LossOps.computeWeightedLoss(losses, weights, reduction);\n };\n LossOps.logLoss = function (labels, predictions, weights, epsilon, reduction) {\n if (epsilon === void 0) { epsilon = 1e-7; }\n if (reduction === void 0) { reduction = Reduction.SUM_BY_NONZERO_WEIGHTS; }\n util.assertArgumentsAreTensors({ labels: labels, predictions: predictions }, 'logLoss');\n if (weights != null) {\n util.assertArgumentsAreTensors({ weights: weights }, 'logLoss');\n }\n util.assertShapesMatch(labels.shape, predictions.shape, 'Error in logLoss: ');\n var one = ops.scalar(1);\n var epsilonScalar = ops.scalar(epsilon);\n var losses = labels.mul(predictions.add(epsilonScalar).log())\n .neg()\n .sub(one.sub(labels).mul(one.sub(predictions).add(epsilonScalar).log()));\n return LossOps.computeWeightedLoss(losses, weights, reduction);\n };\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),\n operation_1.operation\n ], LossOps, \"computeWeightedLoss\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),\n operation_1.operation\n ], LossOps, \"absoluteDifference\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),\n operation_1.operation\n ], LossOps, \"meanSquaredError\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),\n operation_1.operation\n ], LossOps, \"cosineDistance\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),\n operation_1.operation\n ], LossOps, \"hingeLoss\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),\n operation_1.operation\n ], LossOps, \"logLoss\", null);\n return LossOps;\n}());\nexports.LossOps = LossOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar operation_1 = require(\"./operation\");\nvar LRNOps = (function () {\n function LRNOps() {\n }\n LRNOps.localResponseNormalization = function (x, radius, bias, alpha, beta) {\n if (radius === void 0) { radius = 5; }\n if (bias === void 0) { bias = 1; }\n if (alpha === void 0) { alpha = 1; }\n if (beta === void 0) { beta = 0.5; }\n util.assertArgumentsAreTensors({ x: x }, 'localResponseNormalization');\n util.assert(x.rank === 4 || x.rank === 3, \"Error in localResponseNormalization: x must be rank 3 or 4 but got\\n rank \" + x.rank + \".\");\n util.assert(util.isInt(radius), \"Error in localResponseNormalization3D: radius must be an integer\\n but got radius \" + radius + \".\");\n var x4D = x;\n var reshapedTo4D = false;\n if (x.rank === 3) {\n reshapedTo4D = true;\n x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);\n }\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.localResponseNormalization4D(x4D, radius, bias, alpha, beta); }, { x4D: x4D });\n if (reshapedTo4D) {\n return res.as3D(res.shape[1], res.shape[2], res.shape[3]);\n }\n else {\n return res;\n }\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }),\n operation_1.operation\n ], LRNOps, \"localResponseNormalization\", null);\n return LRNOps;\n}());\nexports.LRNOps = LRNOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar util = require(\"../util\");\nvar operation_1 = require(\"./operation\");\nvar LSTMOps = (function () {\n function LSTMOps() {\n }\n LSTMOps.multiRNNCell = function (lstmCells, data, c, h) {\n util.assertArgumentsAreTensors({ data: data, c: c, h: h }, 'multiRNNCell');\n var input = data;\n var newStates = [];\n for (var i = 0; i < lstmCells.length; i++) {\n var output = lstmCells[i](input, c[i], h[i]);\n newStates.push(output[0]);\n newStates.push(output[1]);\n input = output[1];\n }\n var newC = [];\n var newH = [];\n for (var i = 0; i < newStates.length; i += 2) {\n newC.push(newStates[i]);\n newH.push(newStates[i + 1]);\n }\n return [newC, newH];\n };\n LSTMOps.basicLSTMCell = function (forgetBias, lstmKernel, lstmBias, data, c, h) {\n util.assertArgumentsAreTensors({ forgetBias: forgetBias, lstmKernel: lstmKernel, lstmBias: lstmBias, data: data, c: c, h: h }, 'basicLSTMCell');\n var combined = data.concat(h, 1);\n var weighted = combined.matMul(lstmKernel);\n var res = weighted.add(lstmBias);\n var batchSize = res.shape[0];\n var sliceCols = res.shape[1] / 4;\n var sliceSize = [batchSize, sliceCols];\n var i = res.slice([0, 0], sliceSize);\n var j = res.slice([0, sliceCols], sliceSize);\n var f = res.slice([0, sliceCols * 2], sliceSize);\n var o = res.slice([0, sliceCols * 3], sliceSize);\n var newC = i.sigmoid().mulStrict(j.tanh()).addStrict(c.mulStrict(forgetBias.add(f).sigmoid()));\n var newH = newC.tanh().mulStrict(o.sigmoid());\n return [newC, newH];\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'RNN' }),\n operation_1.operation\n ], LSTMOps, \"multiRNNCell\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'RNN' }),\n operation_1.operation\n ], LSTMOps, \"basicLSTMCell\", null);\n return LSTMOps;\n}());\nexports.LSTMOps = LSTMOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar operation_1 = require(\"./operation\");\nvar MatmulOps = (function () {\n function MatmulOps() {\n }\n MatmulOps.matMul = function (a, b, transposeA, transposeB) {\n if (transposeA === void 0) { transposeA = false; }\n if (transposeB === void 0) { transposeB = false; }\n util.assertArgumentsAreTensors({ a: a, b: b }, 'matMul');\n var innerShapeA = transposeA ? a.shape[0] : a.shape[1];\n var innerShapeB = transposeB ? b.shape[1] : b.shape[0];\n util.assert(a.rank === 2 && b.rank === 2, \"Error in matMul: inputs must be rank 2, got ranks \" + a.rank +\n (\" and \" + b.rank + \".\"));\n util.assert(innerShapeA === innerShapeB, \"Error in matMul: inner shapes (\" + innerShapeA + \") and (\" +\n (innerShapeB + \") of Tensors with shapes \" + a.shape + \" and \") +\n (b.shape + \" and transposeA=\" + transposeA) +\n (\" and transposeB=\" + transposeB + \" must match.\"));\n var grad = function (dy) {\n if (!transposeA && !transposeB) {\n return {\n a: function () { return dy.matMul(b.toFloat(), false, true); },\n b: function () { return a.toFloat().matMul(dy, true, false); }\n };\n }\n else if (!transposeA && transposeB) {\n return {\n a: function () { return dy.matMul(b.toFloat(), false, false); },\n b: function () { return dy.matMul(a.toFloat(), true, false); }\n };\n }\n else if (transposeA && !transposeB) {\n return {\n a: function () { return b.toFloat().matMul(dy, false, true); },\n b: function () { return a.toFloat().matMul(dy, false, false); }\n };\n }\n else {\n return {\n a: function () { return b.toFloat().matMul(dy, true, true); },\n b: function () { return dy.matMul(a.toFloat(), true, true); }\n };\n }\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.matMul(a, b, transposeA, transposeB); }, { a: a, b: b }, grad);\n };\n MatmulOps.vectorTimesMatrix = function (v, matrix) {\n util.assert(v.rank === 1, \"Error in vectorTimesMatrix: first input must be rank 1, but got \" +\n (\"rank \" + v.rank + \".\"));\n util.assert(matrix.rank === 2, \"Error in vectorTimesMatrix: second input must be rank 2, but got \" +\n (\"rank \" + matrix.rank + \".\"));\n util.assert(v.size === matrix.shape[0], \"Error in vectorTimesMatrix: size of vector (\" + v.size + \") \" +\n (\"must match first dimension of matrix (\" + matrix.shape[0] + \")\"));\n return v.as2D(1, -1).matMul(matrix).as1D();\n };\n MatmulOps.matrixTimesVector = function (matrix, v) {\n util.assert(v.rank === 1, \"Error in matrixTimesVector: second input must rank 1, but got \" +\n (\"rank \" + v.rank + \".\"));\n util.assert(matrix.rank === 2, \"Error in matrixTimesVector: first input must be a rank 2, but got \" +\n (\"rank \" + matrix.rank + \".\"));\n util.assert(v.size === matrix.shape[1], \"Error in matrixTimesVector: size of first rank 1 input \" + v.size + \" \" +\n \"must match inner dimension of second rank 2 input, but got \" +\n (\"shape \" + matrix.shape + \".\"));\n return matrix.matMul(v.as2D(-1, 1)).as1D();\n };\n MatmulOps.dotProduct = function (v1, v2) {\n util.assert(v1.rank === 1 && v2.rank === 1, \"Error in dotProduct: inputs must be rank 1, but got ranks \" +\n (v1.rank + \" and \" + v2.rank + \".\"));\n util.assert(v1.size === v2.size, \"Error in dotProduct: size of inputs (\" + v1.size + \") and (\" +\n (v2.size + \") must match.\"));\n return v1.as2D(1, -1).matMul(v2.as2D(-1, 1)).asScalar();\n };\n MatmulOps.outerProduct = function (v1, v2) {\n util.assert(v1.rank === 1 && v2.rank === 1, \"Error in outerProduct: inputs must be rank 1, but got ranks \" +\n (v1.rank + \" and \" + v2.rank + \".\"));\n return v1.as2D(-1, 1).matMul(v2.as2D(1, -1));\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }),\n operation_1.operation\n ], MatmulOps, \"matMul\", null);\n __decorate([\n operation_1.operation\n ], MatmulOps, \"vectorTimesMatrix\", null);\n __decorate([\n operation_1.operation\n ], MatmulOps, \"matrixTimesVector\", null);\n __decorate([\n operation_1.operation\n ], MatmulOps, \"dotProduct\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }),\n operation_1.operation\n ], MatmulOps, \"outerProduct\", null);\n return MatmulOps;\n}());\nexports.MatmulOps = MatmulOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar util = require(\"../util\");\nvar array_ops_1 = require(\"./array_ops\");\nvar binary_ops_1 = require(\"./binary_ops\");\nvar operation_1 = require(\"./operation\");\nvar MovingAverageOps = (function () {\n function MovingAverageOps() {\n }\n MovingAverageOps.movingAverage = function (v, x, decay, step, zeroDebias) {\n if (zeroDebias === void 0) { zeroDebias = true; }\n util.assertArgumentsAreTensors({ v: v, x: x }, 'movingAverage');\n util.assertTypesMatch(v, x);\n util.assert(util.arraysEqual(v.shape, x.shape), 'Shape mismatch in v and x');\n var one = array_ops_1.ArrayOps.scalar(1);\n decay = typeof decay === 'number' ? array_ops_1.ArrayOps.scalar(decay) : decay;\n var oneMinusDecay = one.sub(decay);\n var update = x.sub(v).mul(oneMinusDecay);\n if (zeroDebias) {\n util.assert(step != null, 'When using zeroDebias: true, step is required.');\n step = typeof step === 'number' ? array_ops_1.ArrayOps.scalar(step) : step;\n update = update.div(one.sub(binary_ops_1.BinaryOps.pow(decay, step)));\n }\n return v.add(update);\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Moving Average' }),\n operation_1.operation\n ], MovingAverageOps, \"movingAverage\", null);\n return MovingAverageOps;\n}());\nexports.MovingAverageOps = MovingAverageOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar util = require(\"../util\");\nvar axis_util = require(\"./axis_util\");\nvar operation_1 = require(\"./operation\");\nvar ops = require(\"./ops\");\nvar NormOps = (function () {\n function NormOps() {\n }\n NormOps.norm = function (x, ord, axis, keepDims) {\n if (ord === void 0) { ord = 'euclidean'; }\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n util.assertArgumentsAreTensors({ x: x }, 'norm');\n var norm = normImpl(x, ord, axis);\n var keepDimsShape = norm.shape;\n if (keepDims) {\n var axes = axis_util.parseAxisParam(axis, x.shape);\n keepDimsShape = axis_util.expandShapeToKeepDim(norm.shape, axes);\n }\n return norm.reshape(keepDimsShape);\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }),\n operation_1.operation\n ], NormOps, \"norm\", null);\n return NormOps;\n}());\nexports.NormOps = NormOps;\nfunction normImpl(x, p, axis) {\n if (axis === void 0) { axis = null; }\n if (x.rank === 0) {\n return x.abs();\n }\n if (x.rank !== 1 && axis === null) {\n return normImpl(x.reshape([-1]), p, axis);\n }\n if (x.rank === 1 || typeof axis === 'number' ||\n axis instanceof Array && axis.length === 1) {\n if (p === 1) {\n return x.abs().sum(axis);\n }\n if (p === Infinity) {\n return x.abs().max(axis);\n }\n if (p === -Infinity) {\n return x.abs().min(axis);\n }\n if (p === 'euclidean' || p === 2) {\n return x.abs().pow(ops.scalar(2, 'int32')).sum(axis).sqrt();\n }\n throw new Error(\"Error in norm: invalid ord value: \" + p);\n }\n if (axis instanceof Array && axis.length === 2) {\n if (p === 1) {\n return x.abs().sum(axis[0]).max(axis[1] - 1);\n }\n if (p === Infinity) {\n return x.abs().sum(axis[1]).max(axis[0]);\n }\n if (p === -Infinity) {\n return x.abs().sum(axis[1]).min(axis[0]);\n }\n if (p === 'fro' || p === 'euclidean') {\n return x.square().sum(axis).sqrt();\n }\n throw new Error(\"Error in norm: invalid ord value: \" + p);\n }\n throw new Error(\"Error in norm: invalid axis: \" + axis);\n}\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar conv_util = require(\"./conv_util\");\nvar operation_1 = require(\"./operation\");\nvar PoolOps = (function () {\n function PoolOps() {\n }\n PoolOps.maxPool = function (x, filterSize, strides, pad, dimRoundingMode) {\n util.assertArgumentsAreTensors({ x: x }, 'maxPool');\n var x4D = x;\n var reshapedTo4D = false;\n if (x.rank === 3) {\n reshapedTo4D = true;\n x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);\n }\n util.assert(x4D.rank === 4, \"Error in maxPool: input must be rank 4 but got rank \" + x4D.rank + \".\");\n if (dimRoundingMode != null) {\n util.assert(util.isInt(pad), \"Error in maxPool: pad must be an integer when using, \" +\n (\"dimRoundingMode \" + dimRoundingMode + \" but got pad \" + pad + \".\"));\n }\n var convInfo = conv_util.computePool2DInfo(x4D.shape, filterSize, strides, pad, dimRoundingMode);\n var grad = function (dy, saved) {\n var y4D = saved[0];\n return {\n x: function () { return PoolOps.maxPoolBackprop(dy, x4D, y4D, filterSize, strides, pad); }\n };\n };\n var res = environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.maxPool(x4D, convInfo)); }, { x: x4D }, grad);\n if (reshapedTo4D) {\n return res.as3D(res.shape[1], res.shape[2], res.shape[3]);\n }\n return res;\n };\n PoolOps.maxPoolBackprop = function (dy, input, output, filterSize, strides, pad, dimRoundingMode) {\n util.assertArgumentsAreTensors({ dy: dy, input: input, output: output }, 'maxPoolBackprop');\n util.assert(input.rank === dy.rank, \"Rank of input (\" + input.rank + \") does not match rank of dy (\" + dy.rank + \")\");\n util.assert(dy.rank === 4, \"Error in maxPoolBackprop: dy must be rank 4 but got rank \" +\n (dy.rank + \".\"));\n util.assert(input.rank === 4, \"Error in maxPoolBackprop: input must be rank 4 but got rank \" +\n (input.rank + \".\"));\n if (dimRoundingMode != null) {\n util.assert(util.isInt(pad), \"Error in maxPoolBackprop: pad must be an integer when using, \" +\n (\"dimRoundingMode \" + dimRoundingMode + \" but got pad \" + pad + \".\"));\n }\n var convInfo = conv_util.computePool2DInfo(input.shape, filterSize, strides, pad, dimRoundingMode);\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.maxPoolBackprop(dy, input, output, convInfo); }, { dy: dy, input: input });\n return res;\n };\n PoolOps.avgPool = function (x, filterSize, strides, pad, dimRoundingMode) {\n util.assertArgumentsAreTensors({ x: x }, 'avgPool');\n util.assert(x.dtype === 'float32', 'The input dtype to avgPool must be float32');\n var x4D = x;\n var reshapedTo4D = false;\n if (x.rank === 3) {\n reshapedTo4D = true;\n x4D = x.as4D(1, x.shape[0], x.shape[1], x.shape[2]);\n }\n util.assert(x4D.rank === 4, \"Error in avgPool: x must be rank 4 but got rank \" + x4D.rank + \".\");\n if (dimRoundingMode != null) {\n util.assert(util.isInt(pad), \"Error in avgPool: pad must be an integer when using, \" +\n (\"dimRoundingMode \" + dimRoundingMode + \" but got pad \" + pad + \".\"));\n }\n var convInfo = conv_util.computePool2DInfo(x4D.shape, filterSize, strides, pad);\n var grad = function (dy) {\n return {\n x: function () { return PoolOps.avgPoolBackprop(dy, x4D, filterSize, strides, pad); }\n };\n };\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.avgPool(x4D, convInfo); }, { x: x4D }, grad);\n res = res.cast(x.dtype);\n if (reshapedTo4D) {\n return res.as3D(res.shape[1], res.shape[2], res.shape[3]);\n }\n return res;\n };\n PoolOps.avgPoolBackprop = function (dy, input, filterSize, strides, pad) {\n util.assertArgumentsAreTensors({ dy: dy, input: input }, 'avgPoolBackprop');\n util.assert(input.rank === dy.rank, \"Rank of input (\" + input.rank + \") does not match rank of dy (\" + dy.rank + \")\");\n var input4D = input;\n var dy4D = dy;\n var reshapedTo4D = false;\n if (input.rank === 3) {\n reshapedTo4D = true;\n input4D = input.as4D(1, input.shape[0], input.shape[1], input.shape[2]);\n dy4D = dy.as4D(1, dy.shape[0], dy.shape[1], dy.shape[2]);\n }\n util.assert(dy4D.rank === 4, \"Error in avgPoolBackprop: dy must be rank 4 but got rank \" +\n (dy4D.rank + \".\"));\n util.assert(input4D.rank === 4, \"Error in avgPoolBackprop: input must be rank 4 but got rank \" +\n (input4D.rank + \".\"));\n var convInfo = conv_util.computePool2DInfo(input4D.shape, filterSize, strides, pad);\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.avgPoolBackprop(dy4D, input4D, convInfo); }, { dy4D: dy4D, input4D: input4D });\n if (reshapedTo4D) {\n return res.as3D(res.shape[1], res.shape[2], res.shape[3]);\n }\n return res;\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),\n operation_1.operation\n ], PoolOps, \"maxPool\", null);\n __decorate([\n operation_1.operation\n ], PoolOps, \"maxPoolBackprop\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Convolution' }),\n operation_1.operation\n ], PoolOps, \"avgPool\", null);\n __decorate([\n operation_1.operation\n ], PoolOps, \"avgPoolBackprop\", null);\n return PoolOps;\n}());\nexports.PoolOps = PoolOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar axis_util_1 = require(\"./axis_util\");\nvar operation_1 = require(\"./operation\");\nvar ReverseOps = (function () {\n function ReverseOps() {\n }\n ReverseOps.reverse1d = function (x) {\n util.assert(x.rank === 1, \"Error in reverse1D: x must be rank 1 but got\\n rank \" + x.rank + \".\");\n return ReverseOps.reverse(x, 0);\n };\n ReverseOps.reverse2d = function (x, axis) {\n util.assert(x.rank === 2, \"Error in reverse2D: x must be rank 2 but got\\n rank \" + x.rank + \".\");\n return ReverseOps.reverse(x, axis);\n };\n ReverseOps.reverse3d = function (x, axis) {\n util.assert(x.rank === 3, \"Error in reverse3D: x must be rank 3 but got\\n rank \" + x.rank + \".\");\n return ReverseOps.reverse(x, axis);\n };\n ReverseOps.reverse4d = function (x, axis) {\n util.assert(x.rank === 4, \"Error in reverse4D: x must be rank 4 but got\\n rank \" + x.rank + \".\");\n return ReverseOps.reverse(x, axis);\n };\n ReverseOps.reverse = function (x, axis) {\n util.assertArgumentsAreTensors({ x: x }, 'reverse');\n if (x.rank === 0) {\n return x.clone();\n }\n var axes = axis_util_1.parseAxisParam(axis, x.shape);\n var grad = function (dy) {\n return { x: function () { return dy.reverse(axes); } };\n };\n var res = environment_1.ENV.engine.runKernel(function (backend) { return backend.reverse(x, axes); }, { x: x }, grad);\n return res.reshapeAs(x);\n };\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),\n operation_1.operation\n ], ReverseOps, \"reverse\", null);\n return ReverseOps;\n}());\nexports.ReverseOps = ReverseOps;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar util = require(\"../util\");\nfunction assertParamsValid(input, begin, size) {\n util.assert(input.rank === begin.length, \"Error in slice\" + input.rank + \"D: Length of begin \" + begin + \" must \" +\n (\"match the rank of the array (\" + input.rank + \").\"));\n util.assert(input.rank === size.length, \"Error in slice\" + input.rank + \"D: Length of size \" + size + \" must \" +\n (\"match the rank of the array (\" + input.rank + \").\"));\n for (var i = 0; i < input.rank; ++i) {\n util.assert(begin[i] + size[i] <= input.shape[i], \"Error in slice\" + input.rank + \"D: begin[\" + i + \"] + size[\" + i + \"] \" +\n (\"(\" + (begin[i] + size[i]) + \") would overflow input.shape[\" + i + \"] (\" + input.shape[i] + \")\"));\n }\n}\nexports.assertParamsValid = assertParamsValid;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar operation_1 = require(\"./operation\");\nvar slice_util = require(\"./slice_util\");\nvar SliceOps = (function () {\n function SliceOps() {\n }\n SliceOps.slice1d = function (x, begin, size) {\n util.assert(x.rank === 1, \"slice1d expects a rank-1 tensor, but got a rank-\" + x.rank + \" tensor\");\n return SliceOps.slice(x, [begin], [size]);\n };\n SliceOps.slice2d = function (x, begin, size) {\n util.assert(x.rank === 2, \"slice1d expects a rank-2 tensor, but got a rank-\" + x.rank + \" tensor\");\n return SliceOps.slice(x, begin, size);\n };\n SliceOps.slice3d = function (x, begin, size) {\n util.assert(x.rank === 3, \"slice1d expects a rank-3 tensor, but got a rank-\" + x.rank + \" tensor\");\n return SliceOps.slice(x, begin, size);\n };\n SliceOps.slice4d = function (x, begin, size) {\n util.assert(x.rank === 4, \"slice1d expects a rank-4 tensor, but got a rank-\" + x.rank + \" tensor\");\n return SliceOps.slice(x, begin, size);\n };\n SliceOps.slice = function (x, begin, size) {\n util.assertArgumentsAreTensors({ x: x }, 'slice');\n if (x.rank === 0) {\n throw new Error('Slicing scalar is not possible');\n }\n var begin_;\n if (typeof begin === 'number') {\n begin_ = [begin].concat(new Array(x.rank - 1).fill(0));\n }\n else if (begin.length < x.rank) {\n begin_ = begin.concat(new Array(x.rank - begin.length).fill(0));\n }\n else {\n begin_ = begin;\n }\n var size_;\n if (size == null) {\n size_ = new Array(x.rank).fill(-1);\n }\n else if (typeof size === 'number') {\n size_ = [size].concat(new Array(x.rank - 1).fill(-1));\n }\n else if (size.length < x.rank) {\n size_ = size.concat(new Array(x.rank - size.length).fill(-1));\n }\n else {\n size_ = size;\n }\n size_ = size_.map(function (d, i) {\n if (d >= 0) {\n return d;\n }\n else {\n util.assert(d === -1, 'Bad value in size');\n return x.shape[i] - begin_[i];\n }\n });\n slice_util.assertParamsValid(x, begin_, size_);\n var inputShape = x.shape;\n var grad = function (dy) {\n var paddings = [];\n for (var i = 0; i < dy.rank; i++) {\n paddings.push([begin_[i], inputShape[i] - begin_[i] - size_[i]]);\n }\n return { x: function () { return dy.pad(paddings); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.slice(x, begin_, size_); }, { x: x }, grad);\n };\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Slicing and Joining' }),\n operation_1.operation\n ], SliceOps, \"slice\", null);\n return SliceOps;\n}());\nexports.SliceOps = SliceOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar globals_1 = require(\"../globals\");\nvar util = require(\"../util\");\nvar axis_util = require(\"./axis_util\");\nvar operation_1 = require(\"./operation\");\nvar ops = require(\"./ops\");\nvar SoftmaxOps = (function () {\n function SoftmaxOps() {\n }\n SoftmaxOps.softmax = function (logits, dim) {\n if (dim === void 0) { dim = -1; }\n util.assertArgumentsAreTensors({ logits: logits }, 'softmax');\n if (dim === -1) {\n dim = logits.rank - 1;\n }\n if (dim !== logits.rank - 1) {\n throw Error('Softmax along a non-last dimension is not yet supported. ' +\n (\"Logits was rank \" + logits.rank + \" and dim was \" + dim));\n }\n var customOp = globals_1.customGrad(function (logits) {\n var keepDims = true;\n var lse = logits.logSumExp([dim], keepDims);\n var logResult = logits.toFloat().sub(lse);\n var y = logResult.exp();\n var gradFunc = function (dy) {\n var dyTimesY = dy.mul(y);\n var keepDims = true;\n return dyTimesY.sub(dyTimesY.sum([dim], keepDims).mul(y));\n };\n return { value: y, gradFunc: gradFunc };\n });\n return customOp(logits);\n };\n SoftmaxOps.softmaxCrossEntropy = function (labels, logits, dim) {\n if (dim === void 0) { dim = -1; }\n util.assertArgumentsAreTensors({ labels: labels, logits: logits }, 'softmaxCrossEntropy');\n util.assertShapesMatch(labels.shape, logits.shape, 'Error in softmaxCrossEntropy: ');\n if (dim === -1) {\n dim = logits.rank - 1;\n }\n if (dim !== logits.rank - 1) {\n throw Error(\"Softmax cross entropy along a non-last dimension is not yet \" +\n (\"supported. Labels / logits was rank \" + logits.rank + \" \") +\n (\"and dim was \" + dim));\n }\n var customOp = globals_1.customGrad(function (labels, logits) {\n var predictedProbs = logits.softmax(dim);\n var costVector = ops.scalar(1e-5).add(predictedProbs).log().mul(labels).neg();\n var value = costVector.sum([dim]);\n var gradFunc = function (dy) {\n var dyShape = axis_util.expandShapeToKeepDim(dy.shape, [dim]);\n return [\n dy.reshape(dyShape).mul(labels.toFloat().sub(predictedProbs)),\n dy.reshape(dyShape).mul(predictedProbs.sub(labels.toFloat())),\n ];\n };\n return { value: value, gradFunc: gradFunc };\n });\n return customOp(labels, logits);\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Normalization' }),\n operation_1.operation\n ], SoftmaxOps, \"softmax\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Losses', namespace: 'losses' }),\n operation_1.operation\n ], SoftmaxOps, \"softmaxCrossEntropy\", null);\n return SoftmaxOps;\n}());\nexports.SoftmaxOps = SoftmaxOps;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar axis_util = require(\"./axis_util\");\nvar operation_1 = require(\"./operation\");\nvar TransposeOps = (function () {\n function TransposeOps() {\n }\n TransposeOps.transpose = function (x, perm) {\n util.assertArgumentsAreTensors({ x: x }, 'transpose');\n if (perm == null) {\n perm = x.shape.map(function (s, i) { return i; }).reverse();\n }\n util.assert(x.rank === perm.length, \"Error in transpose: rank of input \" + x.rank + \" \" +\n (\"must match length of perm \" + perm + \".\"));\n perm.forEach(function (axis) {\n util.assert(axis >= 0 && axis < x.rank, \"All entries in 'perm' must be between 0 and \" + (x.rank - 1) +\n (\" but got \" + perm));\n });\n if (x.rank <= 1) {\n return x.clone();\n }\n var der = function (dy) {\n var undoPerm = axis_util.getUndoAxesPermutation(perm);\n return { x: function () { return dy.transpose(undoPerm); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.transpose(x, perm); }, { x: x }, der);\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Matrices' }),\n operation_1.operation\n ], TransposeOps, \"transpose\", null);\n return TransposeOps;\n}());\nexports.TransposeOps = TransposeOps;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.SELU_SCALEALPHA = 1.7580993408473768599402175208123;\nexports.SELU_SCALE = 1.0507009873554804934193349852946;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar environment_1 = require(\"../environment\");\nvar util = require(\"../util\");\nvar operation_1 = require(\"./operation\");\nvar ops = require(\"./ops\");\nvar ops_1 = require(\"./ops\");\nvar selu_util = require(\"./selu_util\");\nvar UnaryOps = (function () {\n function UnaryOps() {\n }\n UnaryOps.neg = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'neg');\n var grad = function (dy) {\n return { x: function () { return dy.neg(); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.neg(x); }, { x: x }, grad);\n };\n UnaryOps.ceil = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'ceil');\n var grad = function (dy) {\n return { x: function () { return ops.zerosLike(dy); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.ceil(x); }, { x: x }, grad);\n };\n UnaryOps.floor = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'floor');\n var grad = function (dy) {\n return { x: function () { return ops.zerosLike(dy); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.floor(x); }, { x: x }, grad);\n };\n UnaryOps.sign = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'sign');\n var grad = function (dy) {\n return { x: function () { return ops.zerosLike(dy); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.sign(x); }, { x: x }, grad);\n };\n UnaryOps.round = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'round');\n var grad = function (dy) {\n return { x: function () { return ops.zerosLike(dy); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.round(x); }, { x: x }, grad);\n };\n UnaryOps.exp = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'exp');\n var bck = function (dy, saved) {\n var y = saved[0];\n return { x: function () { return dy.mulStrict(y); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.exp(x)); }, { x: x }, bck);\n };\n UnaryOps.expm1 = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'expm1');\n var grad = function (dy) {\n return { x: function () { return dy.mulStrict(x.exp()); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.expm1(x); }, { x: x }, grad);\n };\n UnaryOps.log = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'log');\n var grad = function (dy) {\n return { x: function () { return dy.divStrict(x.toFloat()); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.log(x); }, { x: x }, grad);\n };\n UnaryOps.log1p = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'log1p');\n var grad = function (dy) {\n return { x: function () { return dy.divStrict(x.add(ops.scalar(1))); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.log1p(x); }, { x: x }, grad);\n };\n UnaryOps.sqrt = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'sqrt');\n var grad = function (dy) {\n return { x: function () { return dy.divStrict(x.toFloat().sqrt().mul(ops.scalar(2))); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.sqrt(x); }, { x: x }, grad);\n };\n UnaryOps.rsqrt = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'rsqrt');\n var grad = function (dy) {\n return {\n x: function () { return dy.divStrict(x.pow(ops.scalar(1.5)).mul(ops.scalar(2))).neg(); }\n };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.rsqrt(x); }, { x: x }, grad);\n };\n UnaryOps.square = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'square');\n var grad = function (dy) {\n return { x: function () { return dy.mulStrict(x.toFloat().mul(ops.scalar(2))); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.square(x); }, { x: x }, grad);\n };\n UnaryOps.reciprocal = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'reciprocal');\n var grad = function (dy) {\n return { x: function () { return dy.divStrict(x.square().neg()); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.reciprocal(x); }, { x: x }, grad);\n };\n UnaryOps.abs = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'abs');\n var grad = function (dy) {\n return { x: function () { return dy.mulStrict(x.toFloat().step(-1)); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.abs(x); }, { x: x }, grad);\n };\n UnaryOps.clipByValue = function (x, clipValueMin, clipValueMax) {\n util.assertArgumentsAreTensors({ x: x }, 'clipByValue');\n util.assert((clipValueMin <= clipValueMax), \"Error in clip: min (\" + clipValueMin + \") must be \" +\n (\"less than or equal to max (\" + clipValueMax + \").\"));\n var grad = function (dy) {\n return {\n x: function () { return dy.where(x.greater(ops.scalar(clipValueMin))\n .logicalAnd(x.less(ops.scalar(clipValueMax))), ops_1.zerosLike(dy)); },\n };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.clip(x, clipValueMin, clipValueMax); }, { x: x }, grad);\n };\n UnaryOps.relu = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'relu');\n if (x.dtype === 'bool') {\n return x.toInt();\n }\n var grad = function (dy) {\n var stepRes = x.step();\n return { x: function () { return dy.mulStrict(stepRes.toFloat()); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.relu(x); }, { x: x }, grad);\n };\n UnaryOps.elu = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'elu');\n var grad = function (dy, saved) {\n var y = saved[0];\n return {\n x: function () {\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.eluDer(dy, y); }, { dy: dy, y: y });\n }\n };\n };\n return environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.elu(x)); }, { x: x }, grad);\n };\n UnaryOps.selu = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'selu');\n var grad = function (dy) {\n return {\n x: function () {\n var mask = x.greater(ops.scalar(0));\n var scaleAlpha = ops.scalar(selu_util.SELU_SCALEALPHA);\n var scale = ops.scalar(selu_util.SELU_SCALE);\n var greaterThanZeroDer = dy.mul(scale);\n var lessEqualZeroDer = dy.mul(scaleAlpha).mul(x.toFloat().exp());\n return ops.where(mask, greaterThanZeroDer, lessEqualZeroDer);\n }\n };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.selu(x); }, { x: x }, grad);\n };\n UnaryOps.leakyRelu = function (x, alpha) {\n if (alpha === void 0) { alpha = 0.2; }\n util.assertArgumentsAreTensors({ x: x }, 'leakyRelu');\n return ops.maximum(ops.scalar(alpha).mul(x), x);\n };\n UnaryOps.prelu = function (x, alpha) {\n util.assertArgumentsAreTensors({ x: x, alpha: alpha }, 'prelu');\n var zero = ops.scalar(0);\n return ops.maximum(zero, x).add(alpha.mul(ops.minimum(zero, x)));\n };\n UnaryOps.sigmoid = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'sigmoid');\n var grad = function (dy, saved) {\n var y = saved[0];\n return { x: function () { return dy.mulStrict(y.mul(ops.scalar(1).sub(y))); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.sigmoid(x)); }, { x: x }, grad);\n };\n UnaryOps.logSigmoid = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'logSigmoid');\n var grad = function (dy) {\n return { x: function () { return dy.mulStrict(x.neg().sigmoid()); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.softplus(x.neg()).neg(); }, { x: x }, grad);\n };\n UnaryOps.softplus = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'softplus');\n var grad = function (dy) {\n return { x: function () { return dy.mulStrict(x.sigmoid()); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.softplus(x); }, { x: x }, grad);\n };\n UnaryOps.sin = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'sin');\n var grad = function (dy) {\n return { x: function () { return x.toFloat().cos().mulStrict(dy); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.sin(x); }, { x: x }, grad);\n };\n UnaryOps.cos = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'cos');\n var grad = function (dy) {\n return { x: function () { return x.toFloat().sin().neg().mulStrict(dy); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.cos(x); }, { x: x }, grad);\n };\n UnaryOps.tan = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'tan');\n var grad = function (dy) {\n return { x: function () { return dy.divStrict(x.cos().square()); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.tan(x); }, { x: x }, grad);\n };\n UnaryOps.asin = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'asin');\n var grad = function (dy) {\n return {\n x: function () {\n return dy.divStrict(UnaryOps.sqrt(ops.scalar(1).sub(x.toFloat().square())));\n }\n };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.asin(x); }, { x: x }, grad);\n };\n UnaryOps.acos = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'acos');\n var grad = function (dy) {\n return {\n x: function () {\n return dy.divStrict(UnaryOps.sqrt(ops.scalar(1).sub(x.toFloat().square())))\n .neg();\n }\n };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.acos(x); }, { x: x }, grad);\n };\n UnaryOps.atan = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'atan');\n var grad = function (dy) {\n return { x: function () { return dy.divStrict(ops.scalar(1).add(x.toFloat().square())); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.atan(x); }, { x: x }, grad);\n };\n UnaryOps.sinh = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'sinh');\n var grad = function (dy) {\n return { x: function () { return x.toFloat().cosh().mulStrict(dy); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.sinh(x); }, { x: x }, grad);\n };\n UnaryOps.cosh = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'cosh');\n var grad = function (dy) {\n return { x: function () { return x.toFloat().sinh().mulStrict(dy); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.cosh(x); }, { x: x }, grad);\n };\n UnaryOps.tanh = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'tanh');\n var grad = function (dy, saved) {\n var y = saved[0];\n return { x: function () { return ops.scalar(1).sub(y.square()).mulStrict(dy); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend, save) { return save(backend.tanh(x)); }, { x: x }, grad);\n };\n UnaryOps.asinh = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'asinh');\n var grad = function (dy) {\n return {\n x: function () {\n return dy.divStrict(UnaryOps.sqrt(ops.scalar(1).add(x.toFloat().square())));\n }\n };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.asinh(x); }, { x: x }, grad);\n };\n UnaryOps.acosh = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'acosh');\n var grad = function (dy) {\n return {\n x: function () {\n return dy.divStrict(UnaryOps.sqrt(x.toFloat().square().sub(ops.scalar(1))));\n }\n };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.acosh(x); }, { x: x }, grad);\n };\n UnaryOps.atanh = function (x) {\n util.assertArgumentsAreTensors({ x: x }, 'atanh');\n var grad = function (dy) {\n return { x: function () { return dy.divStrict(ops.scalar(1).sub(x.toFloat().square())); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.atanh(x); }, { x: x }, grad);\n };\n UnaryOps.erf = function (x) {\n util.assert(x.dtype === 'int32' || x.dtype === 'float32', 'Input dtype must be `int32` or `float32`.');\n if (x.dtype === 'int32') {\n x = x.toFloat();\n }\n var grad = function (dy) {\n return {\n x: function () {\n return dy.mulStrict(ops.scalar(2 / Math.sqrt(Math.PI))\n .mul(x.square().neg().exp()));\n }\n };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.erf(x); }, { x: x }, grad);\n };\n UnaryOps.step = function (x, alpha) {\n if (alpha === void 0) { alpha = 0.0; }\n util.assertArgumentsAreTensors({ x: x }, 'step');\n var grad = function (dy) {\n return { x: function () { return ops.zerosLike(dy); } };\n };\n return environment_1.ENV.engine.runKernel(function (backend) { return backend.step(x, alpha); }, { x: x }, grad);\n };\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"neg\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"ceil\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"floor\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"sign\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"round\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"exp\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"expm1\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"log\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"log1p\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"sqrt\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"rsqrt\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"square\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"reciprocal\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"abs\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"clipByValue\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"relu\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"elu\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"selu\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"leakyRelu\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"prelu\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"sigmoid\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"logSigmoid\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"softplus\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"sin\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"cos\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"tan\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"asin\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"acos\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"atan\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"sinh\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"cosh\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"tanh\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"asinh\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"acosh\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"atanh\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"erf\", null);\n __decorate([\n doc_1.doc({ heading: 'Operations', subheading: 'Basic math' }),\n operation_1.operation\n ], UnaryOps, \"step\", null);\n return UnaryOps;\n}());\nexports.UnaryOps = UnaryOps;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar array_ops_1 = require(\"./array_ops\");\nvar batchnorm_1 = require(\"./batchnorm\");\nvar binary_ops_1 = require(\"./binary_ops\");\nvar compare_1 = require(\"./compare\");\nvar concat_1 = require(\"./concat\");\nvar conv_1 = require(\"./conv\");\nvar image_ops_1 = require(\"./image_ops\");\nvar linalg_ops_1 = require(\"./linalg_ops\");\nvar logical_ops_1 = require(\"./logical_ops\");\nvar loss_ops_1 = require(\"./loss_ops\");\nvar lrn_1 = require(\"./lrn\");\nvar lstm_1 = require(\"./lstm\");\nvar matmul_1 = require(\"./matmul\");\nvar moving_average_1 = require(\"./moving_average\");\nvar norm_1 = require(\"./norm\");\nvar pool_1 = require(\"./pool\");\nvar reduction_ops_1 = require(\"./reduction_ops\");\nvar reverse_1 = require(\"./reverse\");\nvar slice_1 = require(\"./slice\");\nvar softmax_1 = require(\"./softmax\");\nvar transpose_1 = require(\"./transpose\");\nvar unary_ops_1 = require(\"./unary_ops\");\nexports.batchNormalization = batchnorm_1.BatchNormOps.batchNormalization;\nexports.batchNormalization2d = batchnorm_1.BatchNormOps.batchNormalization2d;\nexports.batchNormalization3d = batchnorm_1.BatchNormOps.batchNormalization3d;\nexports.batchNormalization4d = batchnorm_1.BatchNormOps.batchNormalization4d;\nexports.concat = concat_1.ConcatOps.concat;\nexports.concat1d = concat_1.ConcatOps.concat1d;\nexports.concat2d = concat_1.ConcatOps.concat2d;\nexports.concat3d = concat_1.ConcatOps.concat3d;\nexports.concat4d = concat_1.ConcatOps.concat4d;\nexports.conv1d = conv_1.ConvOps.conv1d;\nexports.conv2d = conv_1.ConvOps.conv2d;\nexports.conv2dTranspose = conv_1.ConvOps.conv2dTranspose;\nexports.depthwiseConv2d = conv_1.ConvOps.depthwiseConv2d;\nexports.separableConv2d = conv_1.ConvOps.separableConv2d;\nexports.matMul = matmul_1.MatmulOps.matMul;\nexports.matrixTimesVector = matmul_1.MatmulOps.matrixTimesVector;\nexports.outerProduct = matmul_1.MatmulOps.outerProduct;\nexports.vectorTimesMatrix = matmul_1.MatmulOps.vectorTimesMatrix;\nexports.avgPool = pool_1.PoolOps.avgPool;\nexports.maxPool = pool_1.PoolOps.maxPool;\nexports.transpose = transpose_1.TransposeOps.transpose;\nexports.reverse = reverse_1.ReverseOps.reverse;\nexports.reverse1d = reverse_1.ReverseOps.reverse1d;\nexports.reverse2d = reverse_1.ReverseOps.reverse2d;\nexports.reverse3d = reverse_1.ReverseOps.reverse3d;\nexports.reverse4d = reverse_1.ReverseOps.reverse4d;\nexports.slice = slice_1.SliceOps.slice;\nexports.slice1d = slice_1.SliceOps.slice1d;\nexports.slice2d = slice_1.SliceOps.slice2d;\nexports.slice3d = slice_1.SliceOps.slice3d;\nexports.slice4d = slice_1.SliceOps.slice4d;\nexports.argMax = reduction_ops_1.ReductionOps.argMax;\nexports.argMin = reduction_ops_1.ReductionOps.argMin;\nexports.logSumExp = reduction_ops_1.ReductionOps.logSumExp;\nexports.max = reduction_ops_1.ReductionOps.max;\nexports.mean = reduction_ops_1.ReductionOps.mean;\nexports.min = reduction_ops_1.ReductionOps.min;\nexports.moments = reduction_ops_1.ReductionOps.moments;\nexports.sum = reduction_ops_1.ReductionOps.sum;\nexports.unsortedSegmentSum = reduction_ops_1.ReductionOps.unsortedSegmentSum;\nexports.equal = compare_1.CompareOps.equal;\nexports.equalStrict = compare_1.CompareOps.equalStrict;\nexports.greater = compare_1.CompareOps.greater;\nexports.greaterStrict = compare_1.CompareOps.greaterStrict;\nexports.greaterEqual = compare_1.CompareOps.greaterEqual;\nexports.greaterEqualStrict = compare_1.CompareOps.greaterEqualStrict;\nexports.less = compare_1.CompareOps.less;\nexports.lessStrict = compare_1.CompareOps.lessStrict;\nexports.lessEqual = compare_1.CompareOps.lessEqual;\nexports.lessEqualStrict = compare_1.CompareOps.lessEqualStrict;\nexports.notEqual = compare_1.CompareOps.notEqual;\nexports.notEqualStrict = compare_1.CompareOps.notEqualStrict;\nexports.logicalNot = logical_ops_1.LogicalOps.logicalNot;\nexports.logicalAnd = logical_ops_1.LogicalOps.logicalAnd;\nexports.logicalOr = logical_ops_1.LogicalOps.logicalOr;\nexports.logicalXor = logical_ops_1.LogicalOps.logicalXor;\nexports.where = logical_ops_1.LogicalOps.where;\nexports.abs = unary_ops_1.UnaryOps.abs;\nexports.acos = unary_ops_1.UnaryOps.acos;\nexports.acosh = unary_ops_1.UnaryOps.acosh;\nexports.asin = unary_ops_1.UnaryOps.asin;\nexports.asinh = unary_ops_1.UnaryOps.asinh;\nexports.atan = unary_ops_1.UnaryOps.atan;\nexports.atanh = unary_ops_1.UnaryOps.atanh;\nexports.ceil = unary_ops_1.UnaryOps.ceil;\nexports.clipByValue = unary_ops_1.UnaryOps.clipByValue;\nexports.cos = unary_ops_1.UnaryOps.cos;\nexports.cosh = unary_ops_1.UnaryOps.cosh;\nexports.elu = unary_ops_1.UnaryOps.elu;\nexports.exp = unary_ops_1.UnaryOps.exp;\nexports.expm1 = unary_ops_1.UnaryOps.expm1;\nexports.floor = unary_ops_1.UnaryOps.floor;\nexports.sign = unary_ops_1.UnaryOps.sign;\nexports.leakyRelu = unary_ops_1.UnaryOps.leakyRelu;\nexports.log = unary_ops_1.UnaryOps.log;\nexports.log1p = unary_ops_1.UnaryOps.log1p;\nexports.logSigmoid = unary_ops_1.UnaryOps.logSigmoid;\nexports.neg = unary_ops_1.UnaryOps.neg;\nexports.prelu = unary_ops_1.UnaryOps.prelu;\nexports.relu = unary_ops_1.UnaryOps.relu;\nexports.reciprocal = unary_ops_1.UnaryOps.reciprocal;\nexports.round = unary_ops_1.UnaryOps.round;\nexports.selu = unary_ops_1.UnaryOps.selu;\nexports.sigmoid = unary_ops_1.UnaryOps.sigmoid;\nexports.sin = unary_ops_1.UnaryOps.sin;\nexports.sinh = unary_ops_1.UnaryOps.sinh;\nexports.softplus = unary_ops_1.UnaryOps.softplus;\nexports.sqrt = unary_ops_1.UnaryOps.sqrt;\nexports.rsqrt = unary_ops_1.UnaryOps.rsqrt;\nexports.square = unary_ops_1.UnaryOps.square;\nexports.step = unary_ops_1.UnaryOps.step;\nexports.tan = unary_ops_1.UnaryOps.tan;\nexports.tanh = unary_ops_1.UnaryOps.tanh;\nexports.erf = unary_ops_1.UnaryOps.erf;\nexports.add = binary_ops_1.BinaryOps.add;\nexports.addStrict = binary_ops_1.BinaryOps.addStrict;\nexports.atan2 = binary_ops_1.BinaryOps.atan2;\nexports.div = binary_ops_1.BinaryOps.div;\nexports.divStrict = binary_ops_1.BinaryOps.divStrict;\nexports.maximum = binary_ops_1.BinaryOps.maximum;\nexports.maximumStrict = binary_ops_1.BinaryOps.maximumStrict;\nexports.minimum = binary_ops_1.BinaryOps.minimum;\nexports.minimumStrict = binary_ops_1.BinaryOps.minimumStrict;\nexports.mod = binary_ops_1.BinaryOps.mod;\nexports.modStrict = binary_ops_1.BinaryOps.modStrict;\nexports.mul = binary_ops_1.BinaryOps.mul;\nexports.mulStrict = binary_ops_1.BinaryOps.mulStrict;\nexports.pow = binary_ops_1.BinaryOps.pow;\nexports.powStrict = binary_ops_1.BinaryOps.powStrict;\nexports.sub = binary_ops_1.BinaryOps.sub;\nexports.subStrict = binary_ops_1.BinaryOps.subStrict;\nexports.squaredDifference = binary_ops_1.BinaryOps.squaredDifference;\nexports.squaredDifferenceStrict = binary_ops_1.BinaryOps.squaredDifferenceStrict;\nexports.norm = norm_1.NormOps.norm;\nexports.cast = array_ops_1.ArrayOps.cast;\nexports.clone = array_ops_1.ArrayOps.clone;\nexports.fromPixels = array_ops_1.ArrayOps.fromPixels;\nexports.toPixels = array_ops_1.ArrayOps.toPixels;\nexports.ones = array_ops_1.ArrayOps.ones;\nexports.onesLike = array_ops_1.ArrayOps.onesLike;\nexports.zeros = array_ops_1.ArrayOps.zeros;\nexports.zerosLike = array_ops_1.ArrayOps.zerosLike;\nexports.eye = array_ops_1.ArrayOps.eye;\nexports.rand = array_ops_1.ArrayOps.rand;\nexports.randomNormal = array_ops_1.ArrayOps.randomNormal;\nexports.truncatedNormal = array_ops_1.ArrayOps.truncatedNormal;\nexports.randomUniform = array_ops_1.ArrayOps.randomUniform;\nexports.multinomial = array_ops_1.ArrayOps.multinomial;\nexports.reshape = array_ops_1.ArrayOps.reshape;\nexports.squeeze = array_ops_1.ArrayOps.squeeze;\nexports.tile = array_ops_1.ArrayOps.tile;\nexports.gather = array_ops_1.ArrayOps.gather;\nexports.oneHot = array_ops_1.ArrayOps.oneHot;\nexports.linspace = array_ops_1.ArrayOps.linspace;\nexports.range = array_ops_1.ArrayOps.range;\nexports.buffer = array_ops_1.ArrayOps.buffer;\nexports.fill = array_ops_1.ArrayOps.fill;\nexports.tensor = array_ops_1.ArrayOps.tensor;\nexports.scalar = array_ops_1.ArrayOps.scalar;\nexports.tensor1d = array_ops_1.ArrayOps.tensor1d;\nexports.tensor2d = array_ops_1.ArrayOps.tensor2d;\nexports.tensor3d = array_ops_1.ArrayOps.tensor3d;\nexports.tensor4d = array_ops_1.ArrayOps.tensor4d;\nexports.print = array_ops_1.ArrayOps.print;\nexports.expandDims = array_ops_1.ArrayOps.expandDims;\nexports.stack = array_ops_1.ArrayOps.stack;\nexports.split = array_ops_1.ArrayOps.split;\nexports.pad = array_ops_1.ArrayOps.pad;\nexports.pad1d = array_ops_1.ArrayOps.pad1d;\nexports.pad2d = array_ops_1.ArrayOps.pad2d;\nexports.pad3d = array_ops_1.ArrayOps.pad3d;\nexports.pad4d = array_ops_1.ArrayOps.pad4d;\nexports.movingAverage = moving_average_1.MovingAverageOps.movingAverage;\nexports.basicLSTMCell = lstm_1.LSTMOps.basicLSTMCell;\nexports.multiRNNCell = lstm_1.LSTMOps.multiRNNCell;\nexports.softmax = softmax_1.SoftmaxOps.softmax;\nexports.localResponseNormalization = lrn_1.LRNOps.localResponseNormalization;\nexports.linalg = linalg_ops_1.LinalgOps;\nvar operation_1 = require(\"./operation\");\nexports.operation = operation_1.operation;\nvar tensor_1 = require(\"../tensor\");\nvar types_1 = require(\"../types\");\n[tensor_1.Tensor, types_1.Rank];\n[loss_ops_1.Reduction];\nexports.losses = {\n absoluteDifference: loss_ops_1.LossOps.absoluteDifference,\n computeWeightedLoss: loss_ops_1.LossOps.computeWeightedLoss,\n cosineDistance: loss_ops_1.LossOps.cosineDistance,\n hingeLoss: loss_ops_1.LossOps.hingeLoss,\n logLoss: loss_ops_1.LossOps.logLoss,\n meanSquaredError: loss_ops_1.LossOps.meanSquaredError,\n softmaxCrossEntropy: softmax_1.SoftmaxOps.softmaxCrossEntropy\n};\nexports.image = {\n resizeBilinear: image_ops_1.ImageOps.resizeBilinear,\n resizeNearestNeighbor: image_ops_1.ImageOps.resizeNearestNeighbor,\n};\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"./doc\");\nvar environment_1 = require(\"./environment\");\nvar ops = require(\"./ops/ops\");\nvar tensor_util = require(\"./tensor_util\");\nvar util = require(\"./util\");\nvar TensorBuffer = (function () {\n function TensorBuffer(shape, dtype, values) {\n this.dtype = dtype;\n if (values != null) {\n var n = values.length;\n var size = util.sizeFromShape(shape);\n util.assert(n === size, \"Length of values '\" + n + \"' does not match the size \" +\n (\"inferred by the shape '\" + size + \"'\"));\n }\n this.shape = shape.slice();\n this.values =\n values || util.getTypedArrayFromDType(dtype, util.sizeFromShape(shape));\n this.strides = computeStrides(shape);\n this.size = util.sizeFromShape(shape);\n }\n TensorBuffer.prototype.set = function (value) {\n var locs = [];\n for (var _i = 1; _i < arguments.length; _i++) {\n locs[_i - 1] = arguments[_i];\n }\n if (locs.length === 0) {\n locs = [0];\n }\n util.assert(locs.length === this.rank, \"The number of provided coordinates (\" + locs.length + \") must \" +\n (\"match the rank (\" + this.rank + \")\"));\n var index = this.locToIndex(locs);\n this.values[index] = value;\n };\n TensorBuffer.prototype.get = function () {\n var locs = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n locs[_i] = arguments[_i];\n }\n if (locs.length === 0) {\n locs = [0];\n }\n var index = locs[locs.length - 1];\n for (var i = 0; i < locs.length - 1; ++i) {\n index += this.strides[i] * locs[i];\n }\n return this.values[index];\n };\n TensorBuffer.prototype.locToIndex = function (locs) {\n if (this.rank === 0) {\n return 0;\n }\n else if (this.rank === 1) {\n return locs[0];\n }\n var index = locs[locs.length - 1];\n for (var i = 0; i < locs.length - 1; ++i) {\n index += this.strides[i] * locs[i];\n }\n return index;\n };\n TensorBuffer.prototype.indexToLoc = function (index) {\n if (this.rank === 0) {\n return [];\n }\n else if (this.rank === 1) {\n return [index];\n }\n var locs = new Array(this.shape.length);\n for (var i = 0; i < locs.length - 1; ++i) {\n locs[i] = Math.floor(index / this.strides[i]);\n index -= locs[i] * this.strides[i];\n }\n locs[locs.length - 1] = index;\n return locs;\n };\n Object.defineProperty(TensorBuffer.prototype, \"rank\", {\n get: function () {\n return this.shape.length;\n },\n enumerable: true,\n configurable: true\n });\n TensorBuffer.prototype.toTensor = function () {\n return Tensor.make(this.shape, { values: this.values }, this.dtype);\n };\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], TensorBuffer.prototype, \"set\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], TensorBuffer.prototype, \"get\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], TensorBuffer.prototype, \"toTensor\", null);\n TensorBuffer = __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], TensorBuffer);\n return TensorBuffer;\n}());\nexports.TensorBuffer = TensorBuffer;\nvar Tensor = (function () {\n function Tensor(shape, dtype, values, dataId) {\n this.isDisposed = false;\n this.size = util.sizeFromShape(shape);\n if (values != null) {\n util.assert(this.size === values.length, \"Constructing tensor of shape (\" + this.size + \") should match the \" +\n (\"length of values (\" + values.length + \")\"));\n }\n this.shape = shape.slice();\n this.dtype = dtype || 'float32';\n this.strides = computeStrides(shape);\n this.dataId = dataId != null ? dataId : {};\n this.id = Tensor_1.nextId++;\n this.rankType = (this.rank < 5 ? this.rank.toString() : 'higher');\n environment_1.ENV.engine.registerTensor(this);\n if (values != null) {\n environment_1.ENV.engine.write(this.dataId, values);\n }\n }\n Tensor_1 = Tensor;\n Tensor.make = function (shape, data, dtype) {\n return new Tensor_1(shape, dtype, data.values, data.dataId);\n };\n Tensor.prototype.flatten = function () {\n this.throwIfDisposed();\n return this.as1D();\n };\n Tensor.prototype.asScalar = function () {\n this.throwIfDisposed();\n util.assert(this.size === 1, 'The array must have only 1 element.');\n return this.reshape([]);\n };\n Tensor.prototype.as1D = function () {\n this.throwIfDisposed();\n return this.reshape([this.size]);\n };\n Tensor.prototype.as2D = function (rows, columns) {\n this.throwIfDisposed();\n return this.reshape([rows, columns]);\n };\n Tensor.prototype.as3D = function (rows, columns, depth) {\n this.throwIfDisposed();\n return this.reshape([rows, columns, depth]);\n };\n Tensor.prototype.as4D = function (rows, columns, depth, depth2) {\n this.throwIfDisposed();\n return this.reshape([rows, columns, depth, depth2]);\n };\n Tensor.prototype.asType = function (dtype) {\n this.throwIfDisposed();\n return ops.cast(this, dtype);\n };\n Object.defineProperty(Tensor.prototype, \"rank\", {\n get: function () {\n return this.shape.length;\n },\n enumerable: true,\n configurable: true\n });\n Tensor.prototype.get = function () {\n var locs = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n locs[_i] = arguments[_i];\n }\n util.assert(locs.length === this.rank, 'Number of coordinates in get() must match the rank of the tensor');\n this.throwIfDisposed();\n if (locs.length === 0) {\n locs = [0];\n }\n var index = locs[locs.length - 1];\n for (var i = 0; i < locs.length - 1; ++i) {\n index += this.strides[i] * locs[i];\n }\n return this.dataSync()[index];\n };\n Tensor.prototype.buffer = function () {\n return ops.buffer(this.shape, this.dtype, this.dataSync());\n };\n Tensor.prototype.data = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n this.throwIfDisposed();\n return [2, environment_1.ENV.engine.read(this.dataId)];\n });\n });\n };\n Tensor.prototype.dataSync = function () {\n this.throwIfDisposed();\n return environment_1.ENV.engine.readSync(this.dataId);\n };\n Tensor.prototype.dispose = function () {\n if (this.isDisposed) {\n return;\n }\n this.isDisposed = true;\n environment_1.ENV.engine.disposeTensor(this);\n };\n Tensor.prototype.throwIfDisposed = function () {\n if (this.isDisposed) {\n throw new Error(\"Tensor is disposed.\");\n }\n };\n Tensor.prototype.toFloat = function () {\n return this.asType('float32');\n };\n Tensor.prototype.toInt = function () {\n return this.asType('int32');\n };\n Tensor.prototype.toBool = function () {\n return this.asType('bool');\n };\n Tensor.prototype.print = function (verbose) {\n if (verbose === void 0) { verbose = false; }\n return ops.print(this, verbose);\n };\n Tensor.prototype.reshape = function (newShape) {\n this.throwIfDisposed();\n return ops.reshape(this, newShape);\n };\n Tensor.prototype.reshapeAs = function (x) {\n this.throwIfDisposed();\n return this.reshape(x.shape);\n };\n Tensor.prototype.expandDims = function (axis) {\n if (axis === void 0) { axis = 0; }\n return ops.expandDims(this, axis);\n };\n Tensor.prototype.squeeze = function (axis) {\n this.throwIfDisposed();\n return ops.squeeze(this, axis);\n };\n Tensor.prototype.clone = function () {\n this.throwIfDisposed();\n return ops.clone(this);\n };\n Tensor.prototype.toString = function (verbose) {\n if (verbose === void 0) { verbose = false; }\n return tensor_util.tensorToString(this, verbose);\n };\n Tensor.prototype.tile = function (reps) {\n this.throwIfDisposed();\n return ops.tile(this, reps);\n };\n Tensor.prototype.gather = function (indices, axis) {\n if (axis === void 0) { axis = 0; }\n this.throwIfDisposed();\n return ops.gather(this, indices, axis);\n };\n Tensor.prototype.matMul = function (b, transposeA, transposeB) {\n if (transposeA === void 0) { transposeA = false; }\n if (transposeB === void 0) { transposeB = false; }\n this.throwIfDisposed();\n return ops.matMul(this, b, transposeA, transposeB);\n };\n Tensor.prototype.norm = function (ord, axis, keepDims) {\n if (ord === void 0) { ord = 'euclidean'; }\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n this.throwIfDisposed();\n return ops.norm(this, ord, axis, keepDims);\n };\n Tensor.prototype.slice = function (begin, size) {\n this.throwIfDisposed();\n return ops.slice(this, begin, size);\n };\n Tensor.prototype.reverse = function (axis) {\n this.throwIfDisposed();\n return ops.reverse(this, axis);\n };\n Tensor.prototype.concat = function (x, axis) {\n if (axis === void 0) { axis = 0; }\n this.throwIfDisposed();\n return ops.concat([this, x], axis);\n };\n Tensor.prototype.stack = function (x, axis) {\n if (axis === void 0) { axis = 0; }\n return ops.stack([this, x], axis);\n };\n Tensor.prototype.pad = function (paddings, constantValue) {\n if (constantValue === void 0) { constantValue = 0; }\n return ops.pad(this, paddings, constantValue);\n };\n Tensor.prototype.batchNormalization = function (mean, variance, varianceEpsilon, scale, offset) {\n if (varianceEpsilon === void 0) { varianceEpsilon = .001; }\n this.throwIfDisposed();\n return ops.batchNormalization(this, mean, variance, varianceEpsilon, scale, offset);\n };\n Tensor.prototype.logSumExp = function (axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n this.throwIfDisposed();\n return ops.logSumExp(this, axis, keepDims);\n };\n Tensor.prototype.sum = function (axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n this.throwIfDisposed();\n return ops.sum(this, axis, keepDims);\n };\n Tensor.prototype.mean = function (axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n this.throwIfDisposed();\n return ops.mean(this, axis, keepDims);\n };\n Tensor.prototype.min = function (axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n this.throwIfDisposed();\n return ops.min(this, axis, keepDims);\n };\n Tensor.prototype.max = function (axis, keepDims) {\n if (axis === void 0) { axis = null; }\n if (keepDims === void 0) { keepDims = false; }\n this.throwIfDisposed();\n return ops.max(this, axis, keepDims);\n };\n Tensor.prototype.argMin = function (axis) {\n if (axis === void 0) { axis = null; }\n this.throwIfDisposed();\n return ops.argMin(this, axis);\n };\n Tensor.prototype.argMax = function (axis) {\n if (axis === void 0) { axis = null; }\n this.throwIfDisposed();\n return ops.argMax(this, axis);\n };\n Tensor.prototype.cast = function (dtype) {\n this.throwIfDisposed();\n return ops.cast(this, dtype);\n };\n Tensor.prototype.add = function (x) {\n this.throwIfDisposed();\n return ops.add(this, x);\n };\n Tensor.prototype.addStrict = function (x) {\n this.throwIfDisposed();\n return ops.addStrict(this, x);\n };\n Tensor.prototype.sub = function (x) {\n this.throwIfDisposed();\n return ops.sub(this, x);\n };\n Tensor.prototype.subStrict = function (x) {\n this.throwIfDisposed();\n return ops.subStrict(this, x);\n };\n Tensor.prototype.pow = function (exp) {\n this.throwIfDisposed();\n return ops.pow(this, exp);\n };\n Tensor.prototype.powStrict = function (exp) {\n this.throwIfDisposed();\n return ops.powStrict(this, exp);\n };\n Tensor.prototype.mul = function (x) {\n this.throwIfDisposed();\n return ops.mul(this, x);\n };\n Tensor.prototype.mulStrict = function (x) {\n this.throwIfDisposed();\n return ops.mulStrict(this, x);\n };\n Tensor.prototype.div = function (x) {\n this.throwIfDisposed();\n return ops.div(this, x);\n };\n Tensor.prototype.divStrict = function (x) {\n this.throwIfDisposed();\n return ops.divStrict(this, x);\n };\n Tensor.prototype.minimum = function (x) {\n this.throwIfDisposed();\n return ops.minimum(this, x);\n };\n Tensor.prototype.minimumStrict = function (x) {\n this.throwIfDisposed();\n return ops.minimumStrict(this, x);\n };\n Tensor.prototype.maximum = function (x) {\n this.throwIfDisposed();\n return ops.maximum(this, x);\n };\n Tensor.prototype.maximumStrict = function (x) {\n this.throwIfDisposed();\n return ops.maximumStrict(this, x);\n };\n Tensor.prototype.mod = function (x) {\n this.throwIfDisposed();\n return ops.mod(this, x);\n };\n Tensor.prototype.modStrict = function (x) {\n this.throwIfDisposed();\n return ops.modStrict(this, x);\n };\n Tensor.prototype.squaredDifference = function (x) {\n this.throwIfDisposed();\n return ops.squaredDifference(this, x);\n };\n Tensor.prototype.squaredDifferenceStrict = function (x) {\n this.throwIfDisposed();\n return ops.squaredDifferenceStrict(this, x);\n };\n Tensor.prototype.transpose = function (perm) {\n this.throwIfDisposed();\n return ops.transpose(this, perm);\n };\n Tensor.prototype.notEqual = function (x) {\n this.throwIfDisposed();\n return ops.notEqual(this, x);\n };\n Tensor.prototype.notEqualStrict = function (x) {\n this.throwIfDisposed();\n return ops.notEqualStrict(this, x);\n };\n Tensor.prototype.less = function (x) {\n this.throwIfDisposed();\n return ops.less(this, x);\n };\n Tensor.prototype.lessStrict = function (x) {\n this.throwIfDisposed();\n return ops.lessStrict(this, x);\n };\n Tensor.prototype.equal = function (x) {\n this.throwIfDisposed();\n return ops.equal(this, x);\n };\n Tensor.prototype.equalStrict = function (x) {\n this.throwIfDisposed();\n return ops.equalStrict(this, x);\n };\n Tensor.prototype.lessEqual = function (x) {\n this.throwIfDisposed();\n return ops.lessEqual(this, x);\n };\n Tensor.prototype.lessEqualStrict = function (x) {\n this.throwIfDisposed();\n return ops.lessEqualStrict(this, x);\n };\n Tensor.prototype.greater = function (x) {\n this.throwIfDisposed();\n return ops.greater(this, x);\n };\n Tensor.prototype.greaterStrict = function (x) {\n this.throwIfDisposed();\n return ops.greaterStrict(this, x);\n };\n Tensor.prototype.greaterEqual = function (x) {\n this.throwIfDisposed();\n return ops.greaterEqual(this, x);\n };\n Tensor.prototype.greaterEqualStrict = function (x) {\n this.throwIfDisposed();\n return ops.greaterEqualStrict(this, x);\n };\n Tensor.prototype.logicalAnd = function (x) {\n this.throwIfDisposed();\n return ops.logicalAnd(this, x);\n };\n Tensor.prototype.logicalOr = function (x) {\n this.throwIfDisposed();\n return ops.logicalOr(this, x);\n };\n Tensor.prototype.logicalNot = function () {\n this.throwIfDisposed();\n return ops.logicalNot(this);\n };\n Tensor.prototype.logicalXor = function (x) {\n this.throwIfDisposed();\n return ops.logicalXor(this, x);\n };\n Tensor.prototype.where = function (condition, x) {\n this.throwIfDisposed();\n return ops.where(condition, this, x);\n };\n Tensor.prototype.neg = function () {\n this.throwIfDisposed();\n return ops.neg(this);\n };\n Tensor.prototype.ceil = function () {\n this.throwIfDisposed();\n return ops.ceil(this);\n };\n Tensor.prototype.floor = function () {\n this.throwIfDisposed();\n return ops.floor(this);\n };\n Tensor.prototype.sign = function () {\n this.throwIfDisposed();\n return ops.sign(this);\n };\n Tensor.prototype.exp = function () {\n this.throwIfDisposed();\n return ops.exp(this);\n };\n Tensor.prototype.expm1 = function () {\n this.throwIfDisposed();\n return ops.expm1(this);\n };\n Tensor.prototype.log = function () {\n this.throwIfDisposed();\n return ops.log(this);\n };\n Tensor.prototype.log1p = function () {\n this.throwIfDisposed();\n return ops.log1p(this);\n };\n Tensor.prototype.sqrt = function () {\n this.throwIfDisposed();\n return ops.sqrt(this);\n };\n Tensor.prototype.rsqrt = function () {\n this.throwIfDisposed();\n return ops.rsqrt(this);\n };\n Tensor.prototype.square = function () {\n this.throwIfDisposed();\n return ops.square(this);\n };\n Tensor.prototype.reciprocal = function () {\n this.throwIfDisposed();\n return ops.reciprocal(this);\n };\n Tensor.prototype.abs = function () {\n this.throwIfDisposed();\n return ops.abs(this);\n };\n Tensor.prototype.clipByValue = function (min, max) {\n this.throwIfDisposed();\n return ops.clipByValue(this, min, max);\n };\n Tensor.prototype.relu = function () {\n this.throwIfDisposed();\n return ops.relu(this);\n };\n Tensor.prototype.elu = function () {\n this.throwIfDisposed();\n return ops.elu(this);\n };\n Tensor.prototype.selu = function () {\n this.throwIfDisposed();\n return ops.selu(this);\n };\n Tensor.prototype.leakyRelu = function (alpha) {\n if (alpha === void 0) { alpha = 0.2; }\n this.throwIfDisposed();\n return ops.leakyRelu(this, alpha);\n };\n Tensor.prototype.prelu = function (alpha) {\n this.throwIfDisposed();\n return ops.prelu(this, alpha);\n };\n Tensor.prototype.sigmoid = function () {\n this.throwIfDisposed();\n return ops.sigmoid(this);\n };\n Tensor.prototype.logSigmoid = function () {\n this.throwIfDisposed();\n return ops.logSigmoid(this);\n };\n Tensor.prototype.softplus = function () {\n this.throwIfDisposed();\n return ops.softplus(this);\n };\n Tensor.prototype.sin = function () {\n this.throwIfDisposed();\n return ops.sin(this);\n };\n Tensor.prototype.cos = function () {\n this.throwIfDisposed();\n return ops.cos(this);\n };\n Tensor.prototype.tan = function () {\n this.throwIfDisposed();\n return ops.tan(this);\n };\n Tensor.prototype.asin = function () {\n this.throwIfDisposed();\n return ops.asin(this);\n };\n Tensor.prototype.acos = function () {\n this.throwIfDisposed();\n return ops.acos(this);\n };\n Tensor.prototype.atan = function () {\n this.throwIfDisposed();\n return ops.atan(this);\n };\n Tensor.prototype.sinh = function () {\n this.throwIfDisposed();\n return ops.sinh(this);\n };\n Tensor.prototype.cosh = function () {\n this.throwIfDisposed();\n return ops.cosh(this);\n };\n Tensor.prototype.tanh = function () {\n this.throwIfDisposed();\n return ops.tanh(this);\n };\n Tensor.prototype.asinh = function () {\n this.throwIfDisposed();\n return ops.asinh(this);\n };\n Tensor.prototype.acosh = function () {\n this.throwIfDisposed();\n return ops.acosh(this);\n };\n Tensor.prototype.atanh = function () {\n this.throwIfDisposed();\n return ops.atanh(this);\n };\n Tensor.prototype.erf = function () {\n this.throwIfDisposed();\n return ops.erf(this);\n };\n Tensor.prototype.round = function () {\n this.throwIfDisposed();\n return ops.round(this);\n };\n Tensor.prototype.step = function (alpha) {\n if (alpha === void 0) { alpha = 0.0; }\n this.throwIfDisposed();\n return ops.step(this, alpha);\n };\n Tensor.prototype.softmax = function (dim) {\n if (dim === void 0) { dim = -1; }\n this.throwIfDisposed();\n return ops.softmax(this, dim);\n };\n Tensor.prototype.resizeBilinear = function (newShape2D, alignCorners) {\n if (alignCorners === void 0) { alignCorners = false; }\n this.throwIfDisposed();\n return ops.image.resizeBilinear(this, newShape2D, alignCorners);\n };\n Tensor.prototype.resizeNearestNeighbor = function (newShape2D, alignCorners) {\n if (alignCorners === void 0) { alignCorners = false; }\n this.throwIfDisposed();\n return ops.image.resizeNearestNeighbor(this, newShape2D, alignCorners);\n };\n Tensor.prototype.conv1d = function (filter, stride, pad, dataFormat, dilation, dimRoundingMode) {\n if (dataFormat === void 0) { dataFormat = 'NWC'; }\n if (dilation === void 0) { dilation = 1; }\n this.throwIfDisposed();\n return ops.conv1d(this, filter, stride, pad, dataFormat, dilation, dimRoundingMode);\n };\n Tensor.prototype.conv2d = function (filter, strides, pad, dataFormat, dilations, dimRoundingMode) {\n if (dataFormat === void 0) { dataFormat = 'NHWC'; }\n if (dilations === void 0) { dilations = [1, 1]; }\n this.throwIfDisposed();\n return ops.conv2d(this, filter, strides, pad, dataFormat, dilations, dimRoundingMode);\n };\n Tensor.prototype.conv2dTranspose = function (filter, outputShape, strides, pad, dimRoundingMode) {\n this.throwIfDisposed();\n return ops.conv2dTranspose(this, filter, outputShape, strides, pad, dimRoundingMode);\n };\n Tensor.prototype.depthwiseConv2D = function (filter, strides, pad, dataFormat, dilations, dimRoundingMode) {\n if (dataFormat === void 0) { dataFormat = 'NHWC'; }\n if (dilations === void 0) { dilations = [1, 1]; }\n this.throwIfDisposed();\n return ops.depthwiseConv2d(this, filter, strides, pad, dataFormat, dilations, dimRoundingMode);\n };\n Tensor.prototype.avgPool = function (filterSize, strides, pad, dimRoundingMode) {\n this.throwIfDisposed();\n return ops.avgPool(this, filterSize, strides, pad, dimRoundingMode);\n };\n Tensor.prototype.maxPool = function (filterSize, strides, pad, dimRoundingMode) {\n this.throwIfDisposed();\n return ops.maxPool(this, filterSize, strides, pad, dimRoundingMode);\n };\n Tensor.prototype.localResponseNormalization = function (radius, bias, alpha, beta) {\n if (radius === void 0) { radius = 5; }\n if (bias === void 0) { bias = 1; }\n if (alpha === void 0) { alpha = 1; }\n if (beta === void 0) { beta = 0.5; }\n return ops.localResponseNormalization(this, radius, bias, alpha, beta);\n };\n Tensor.prototype.variable = function (trainable, name, dtype) {\n if (trainable === void 0) { trainable = true; }\n this.throwIfDisposed();\n return Variable.variable(this, trainable, name, dtype);\n };\n Tensor.prototype.unsortedSegmentSum = function (segmentIds, numSegments, axis) {\n if (axis === void 0) { axis = 0; }\n this.throwIfDisposed();\n return ops.unsortedSegmentSum(this, segmentIds, numSegments, axis);\n };\n Tensor.nextId = 0;\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"flatten\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"asScalar\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"as1D\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"as2D\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"as3D\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"as4D\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"asType\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"buffer\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"data\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"dataSync\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"dispose\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"toFloat\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"toInt\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"toBool\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"print\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"reshape\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"reshapeAs\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"expandDims\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"squeeze\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"clone\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor.prototype, \"toString\", null);\n Tensor = Tensor_1 = __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Tensor);\n return Tensor;\n var Tensor_1;\n}());\nexports.Tensor = Tensor;\nvar Variable = (function (_super) {\n __extends(Variable, _super);\n function Variable(initialValue, trainable, name) {\n if (trainable === void 0) { trainable = true; }\n var _this = _super.call(this, initialValue.shape, initialValue.dtype, null, initialValue.dataId) || this;\n _this.trainable = trainable;\n _this.name = name;\n if (_this.name == null) {\n _this.name = Variable_1.nextVarId.toString();\n Variable_1.nextVarId++;\n }\n environment_1.ENV.engine.registerVariable(_this);\n return _this;\n }\n Variable_1 = Variable;\n Variable.variable = function (initialValue, trainable, name, dtype) {\n if (trainable === void 0) { trainable = true; }\n if (dtype != null && dtype !== initialValue.dtype) {\n initialValue = initialValue.asType(dtype);\n }\n return new Variable_1(initialValue, trainable, name);\n };\n Variable.prototype.assign = function (newValue) {\n if (newValue.dtype !== this.dtype) {\n throw new Error(\"dtype of the new value (\" + newValue.dtype + \") and \" +\n (\"previous value (\" + this.dtype + \") must match\"));\n }\n if (!util.arraysEqual(newValue.shape, this.shape)) {\n throw new Error(\"shape of the new value (\" + newValue.shape + \") and \" +\n (\"previous value (\" + this.shape + \") must match\"));\n }\n environment_1.ENV.engine.disposeTensor(this);\n this.dataId = newValue.dataId;\n environment_1.ENV.engine.registerTensor(this);\n };\n Variable.nextVarId = 0;\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Variable.prototype, \"assign\", null);\n __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Creation' })\n ], Variable, \"variable\", null);\n Variable = Variable_1 = __decorate([\n doc_1.doc({ heading: 'Tensors', subheading: 'Classes' })\n ], Variable);\n return Variable;\n var Variable_1;\n}(Tensor));\nexports.Variable = Variable;\nvar variable = Variable.variable;\nexports.variable = variable;\nfunction computeStrides(shape) {\n var rank = shape.length;\n if (rank < 2) {\n return [];\n }\n var strides = new Array(rank - 1);\n strides[rank - 2] = shape[rank - 1];\n for (var i = rank - 3; i >= 0; --i) {\n strides[i] = strides[i + 1] * shape[i + 1];\n }\n return strides;\n}\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"./doc\");\nvar environment_1 = require(\"./environment\");\nvar globals_1 = require(\"./globals\");\nvar tensor_1 = require(\"./tensor\");\nvar util = require(\"./util\");\nvar Gradients = (function () {\n function Gradients() {\n }\n Gradients.gradScope = function (nameOrScopeFn, scopeFn) {\n return globals_1.tidy(nameOrScopeFn, scopeFn, true);\n };\n Gradients.grad = function (f) {\n util.assert(util.isFunction(f), 'The f passed in grad(f) must be a function');\n return function (x, dy) {\n util.assert(x instanceof tensor_1.Tensor, 'The x passed in grad(f)(x) must be a tensor');\n util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in grad(f)(x, dy) must be a tensor');\n return globals_1.tidy(function () {\n var _a = environment_1.ENV.engine.gradients(function () { return f(x); }, [x], dy), value = _a.value, grads = _a.grads;\n if (dy != null) {\n util.assertShapesMatch(value.shape, dy.shape, 'The shape of dy passed in grad(f)(x, dy) must match the shape ' +\n 'returned by f(x)');\n }\n checkGrads(grads);\n return grads[0];\n });\n };\n };\n Gradients.grads = function (f) {\n util.assert(util.isFunction(f), 'The f passed in grads(f) must be a function');\n return function (args, dy) {\n util.assert(Array.isArray(args) && args.every(function (arg) { return arg instanceof tensor_1.Tensor; }), 'The args passed in grads(f)(args) must be an array of tensors');\n util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in grads(f)(args, dy) must be a tensor');\n return globals_1.tidy(function () {\n var _a = environment_1.ENV.engine.gradients(function () { return f.apply(void 0, args); }, args, dy), value = _a.value, grads = _a.grads;\n if (dy != null) {\n util.assertShapesMatch(value.shape, dy.shape, 'The shape of dy passed in grads(f)([x1,...], dy) must ' +\n 'match the shape returned by f([x1,...])');\n }\n checkGrads(grads);\n return grads;\n });\n };\n };\n Gradients.valueAndGrad = function (f) {\n util.assert(util.isFunction(f), 'The f passed in valueAndGrad(f) must be a function');\n return function (x, dy) {\n util.assert(x instanceof tensor_1.Tensor, 'The x passed in valueAndGrad(f)(x) must be a tensor');\n util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in valueAndGrad(f)(x, dy) must be a tensor');\n var _a = environment_1.ENV.engine.gradients(function () { return f(x); }, [x], dy), grads = _a.grads, value = _a.value;\n checkGrads(grads);\n return { grad: grads[0], value: value };\n };\n };\n Gradients.valueAndGrads = function (f) {\n util.assert(util.isFunction(f), 'The f passed in valueAndGrads(f) must be a function');\n return function (args, dy) {\n util.assert(Array.isArray(args) && args.every(function (arg) { return arg instanceof tensor_1.Tensor; }), 'The args passed in valueAndGrads(f)(args) must be array of tensors');\n util.assert(dy == null || dy instanceof tensor_1.Tensor, 'The dy passed in valueAndGrads(f)(args, dy) must be a tensor');\n var res = environment_1.ENV.engine.gradients(function () { return f.apply(void 0, args); }, args, dy);\n if (dy != null) {\n util.assertShapesMatch(res.value.shape, dy.shape, 'The shape of dy passed in valueAndGrads(f)([x1,...], dy) must ' +\n 'match the shape returned by f([x1,...])');\n }\n checkGrads(res.grads);\n return res;\n };\n };\n Gradients.variableGrads = function (f, varList) {\n util.assert(util.isFunction(f), 'The f passed in variableGrads(f) must be a function');\n util.assert(varList == null ||\n Array.isArray(varList) && varList.every(function (v) { return v instanceof tensor_1.Variable; }), 'The varList passed in variableGrads(f, varList) must be an array ' +\n 'of variables');\n if (varList == null) {\n varList = [];\n for (var varName in environment_1.ENV.engine.registeredVariables) {\n varList.push(environment_1.ENV.engine.registeredVariables[varName]);\n }\n }\n var originalVarCount = varList.length;\n varList = varList.filter(function (variable) { return variable.trainable; });\n util.assert(varList.length > 0, \"variableGrads() expects at least one of the input variables to be \" +\n (\"trainable, but none of the \" + originalVarCount + \" variables is \") +\n \"trainable.\");\n var allowNoGradients = true;\n var _a = environment_1.ENV.engine.gradients(f, varList, null, allowNoGradients), value = _a.value, grads = _a.grads;\n util.assert(grads.some(function (g) { return g != null; }), 'Cannot find a connection between any variable and the result of the ' +\n 'loss function y=f(x). Please make sure the operations that use ' +\n 'variables are inside the function f passed to minimize().');\n util.assert(value.rank === 0, \"The f passed in variableGrads(f) must return a scalar, but it \" +\n (\"returned a rank-\" + value.rank + \" tensor\"));\n var namedGrads = {};\n varList.forEach(function (v, i) {\n if (grads[i] != null) {\n namedGrads[v.name] = grads[i];\n }\n });\n return { value: value, grads: namedGrads };\n };\n Gradients.customGrad = function (f) {\n return environment_1.ENV.engine.customGrad(f);\n };\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Gradients' })\n ], Gradients, \"grad\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Gradients' })\n ], Gradients, \"grads\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Gradients' })\n ], Gradients, \"valueAndGrad\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Gradients' })\n ], Gradients, \"valueAndGrads\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Gradients' })\n ], Gradients, \"variableGrads\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Gradients' })\n ], Gradients, \"customGrad\", null);\n return Gradients;\n}());\nexports.Gradients = Gradients;\nfunction checkGrads(grads) {\n var numNullGradients = grads.filter(function (g) { return g == null; }).length;\n if (numNullGradients > 0) {\n throw new Error(\"Cannot compute gradient of y=f(x) with respect to x. Make sure that\\n the f you passed encloses all operations that lead from x to y.\");\n }\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar gradients_1 = require(\"./gradients\");\nvar tracking_1 = require(\"./tracking\");\nexports.tidy = tracking_1.Tracking.tidy;\nexports.keep = tracking_1.Tracking.keep;\nexports.dispose = tracking_1.Tracking.dispose;\nexports.time = tracking_1.Tracking.time;\nexports.grad = gradients_1.Gradients.grad;\nexports.valueAndGrad = gradients_1.Gradients.valueAndGrad;\nexports.grads = gradients_1.Gradients.grads;\nexports.valueAndGrads = gradients_1.Gradients.valueAndGrads;\nexports.variableGrads = gradients_1.Gradients.variableGrads;\nexports.customGrad = gradients_1.Gradients.customGrad;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar util = require(\"./util\");\nvar Profiler = (function () {\n function Profiler(backendTimer, logger) {\n this.backendTimer = backendTimer;\n this.logger = logger;\n if (logger == null) {\n this.logger = new Logger();\n }\n }\n Profiler.prototype.profileKernel = function (name, f) {\n var _this = this;\n var result;\n var holdResultWrapperFn = function () {\n result = f();\n };\n var timer = this.backendTimer.time(holdResultWrapperFn);\n var vals = result.dataSync();\n util.checkForNaN(vals, result.dtype, name);\n timer.then(function (timing) {\n _this.logger.logKernelProfile(name, result, vals, timing.kernelMs);\n });\n return result;\n };\n return Profiler;\n}());\nexports.Profiler = Profiler;\nvar Logger = (function () {\n function Logger() {\n }\n Logger.prototype.logKernelProfile = function (name, result, vals, timeMs) {\n var time = util.rightPad(timeMs + \"ms\", 9);\n var paddedName = util.rightPad(name, 25);\n var rank = result.rank;\n var size = result.size;\n var shape = util.rightPad(result.shape.toString(), 14);\n console.log(\"%c\" + paddedName + \"\\t%c\" + time + \"\\t%c\" + rank + \"D \" + shape + \"\\t%c\" + size, 'font-weight:bold', 'color:red', 'color:blue', 'color: orange');\n };\n return Logger;\n}());\nexports.Logger = Logger;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar util = require(\"./util\");\nfunction getFilteredNodesXToY(tape, xs, y) {\n var tensorsFromX = {};\n var nodesFromX = {};\n for (var i = 0; i < xs.length; i++) {\n tensorsFromX[xs[i].id] = true;\n }\n for (var i = 0; i < tape.length; i++) {\n var node = tape[i];\n var nodeInputs = node.inputs;\n for (var inputName in nodeInputs) {\n var input = nodeInputs[inputName];\n var anyInputFromX = false;\n for (var j = 0; j < xs.length; j++) {\n if (tensorsFromX[input.id]) {\n tensorsFromX[node.output.id] = true;\n anyInputFromX = true;\n nodesFromX[node.id] = true;\n break;\n }\n }\n if (anyInputFromX) {\n break;\n }\n }\n }\n var tensorsLeadToY = {};\n tensorsLeadToY[y.id] = true;\n var nodesToY = {};\n for (var i = tape.length - 1; i >= 0; i--) {\n var node = tape[i];\n var nodeInputs = node.inputs;\n var outputs = [];\n outputs.push(node.output);\n for (var j = 0; j < outputs.length; j++) {\n if (tensorsLeadToY[outputs[j].id]) {\n for (var inputName in nodeInputs) {\n tensorsLeadToY[nodeInputs[inputName].id] = true;\n nodesToY[node.id] = true;\n }\n break;\n }\n }\n }\n var filteredTape = [];\n for (var i = 0; i < tape.length; i++) {\n var node = tape[i];\n if (nodesFromX[node.id] && nodesToY[node.id]) {\n var prunedInputs = {};\n for (var inputName in node.inputs) {\n var nodeInput = node.inputs[inputName];\n if (tensorsFromX[nodeInput.id]) {\n prunedInputs[inputName] = nodeInput;\n }\n }\n var prunedNode = Object.assign({}, node);\n prunedNode.inputs = prunedInputs;\n prunedNode.output = node.output;\n filteredTape.push(prunedNode);\n }\n }\n return filteredTape;\n}\nexports.getFilteredNodesXToY = getFilteredNodesXToY;\nfunction backpropagateGradients(tensorAccumulatedGradientMap, filteredTape) {\n for (var i = filteredTape.length - 1; i >= 0; i--) {\n var node = filteredTape[i];\n var dy = tensorAccumulatedGradientMap[node.output.id];\n if (node.gradient == null) {\n throw new Error(\"Cannot compute gradient: gradient function not found \" +\n (\"for \" + node.name + \".\"));\n }\n var inputGradients = node.gradient(dy);\n for (var inputName in node.inputs) {\n if (!(inputName in inputGradients)) {\n throw new Error(\"Cannot backprop through input \" + inputName + \". \" +\n (\"Available gradients found: \" + Object.keys(inputGradients) + \".\"));\n }\n var dx = inputGradients[inputName]();\n var x = node.inputs[inputName];\n if (!util.arraysEqual(dx.shape, x.shape)) {\n throw new Error(\"Error in gradient for op \" + node.name + \". The gradient of input \" +\n (\"'\" + inputName + \"' has shape '\" + dx.shape + \"', which does not match \") +\n (\"the shape of the input '\" + x.shape + \"'\"));\n }\n if (tensorAccumulatedGradientMap[x.id] == null) {\n tensorAccumulatedGradientMap[x.id] = dx;\n }\n else {\n var curGradient = tensorAccumulatedGradientMap[x.id];\n tensorAccumulatedGradientMap[x.id] = curGradient.add(dx);\n curGradient.dispose();\n }\n }\n }\n}\nexports.backpropagateGradients = backpropagateGradients;\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"./environment\");\nvar globals_1 = require(\"./globals\");\nvar ops = require(\"./ops/ops\");\nvar profiler_1 = require(\"./profiler\");\nvar tape_1 = require(\"./tape\");\nvar tensor_1 = require(\"./tensor\");\nvar util = require(\"./util\");\nvar Engine = (function () {\n function Engine(backend, safeMode) {\n this.backend = backend;\n this.safeMode = safeMode;\n this.registeredVariables = {};\n this.refCounter = new WeakMap();\n this.nextTapeNodeId = 0;\n this.numBytes = 0;\n this.numTensors = 0;\n this.numDataBuffers = 0;\n this.gradientScopeCount = 0;\n this.customGradientDepth = 0;\n this.activeScope = { keep: [], track: [] };\n this.scopeStack = [this.activeScope];\n this.profiler = new profiler_1.Profiler(backend);\n }\n Engine.prototype.runKernel = function (forwardFunc, inputs, backwardsFunc) {\n var _this = this;\n var result;\n var saved = [];\n var saveFunc = function (x) {\n saved.push(x);\n return x;\n };\n var scopeName = this.activeScope.name;\n this.customGradientDepth++;\n if (!environment_1.ENV.get('DEBUG')) {\n result = forwardFunc(this.backend, saveFunc);\n }\n else {\n result = this.profiler.profileKernel(scopeName, function () { return forwardFunc(_this.backend, saveFunc); });\n }\n this.customGradientDepth--;\n if (this.shouldRecord()) {\n var tapeNode = {\n id: this.nextTapeNodeId++,\n name: scopeName,\n inputs: inputs,\n output: result,\n };\n if (backwardsFunc != null) {\n tapeNode.gradient = function (dy) { return backwardsFunc(dy, saved); };\n }\n this.activeTape.push(tapeNode);\n }\n return result;\n };\n Engine.prototype.registerTensor = function (a) {\n var refCount = this.refCounter.has(a.dataId) ? this.refCounter.get(a.dataId) : 0;\n this.numTensors++;\n if (refCount === 0) {\n this.numDataBuffers++;\n this.numBytes +=\n util.sizeFromShape(a.shape) * util.bytesPerElement(a.dtype);\n this.backend.register(a.dataId, a.shape, a.dtype);\n }\n this.refCounter.set(a.dataId, refCount + 1);\n if (!(a instanceof tensor_1.Variable)) {\n this.track(a);\n }\n };\n Engine.prototype.registerVariable = function (v) {\n if (this.registeredVariables[v.name] != null) {\n throw new Error(\"Variable with name \" + v.name + \" was already registered\");\n }\n this.registeredVariables[v.name] = v;\n };\n Engine.prototype.disposeTensor = function (a) {\n if (!this.refCounter.has(a.dataId)) {\n return;\n }\n this.numTensors--;\n var refCount = this.refCounter.get(a.dataId);\n if (refCount <= 1) {\n this.refCounter.delete(a.dataId);\n this.backend.disposeData(a.dataId);\n this.numDataBuffers--;\n this.numBytes -=\n util.sizeFromShape(a.shape) * util.bytesPerElement(a.dtype);\n }\n else {\n this.refCounter.set(a.dataId, refCount - 1);\n }\n };\n Engine.prototype.disposeVariables = function () {\n for (var varName in this.registeredVariables) {\n var v = this.registeredVariables[varName];\n this.disposeTensor(v);\n delete this.registeredVariables[varName];\n }\n };\n Engine.prototype.memory = function () {\n var info = this.backend.memory();\n info.numTensors = this.numTensors;\n info.numDataBuffers = this.numDataBuffers;\n info.numBytes = this.numBytes;\n return info;\n };\n Engine.prototype.shouldRecord = function () {\n return this.activeTape != null && this.customGradientDepth === 0;\n };\n Engine.prototype.addTapeNode = function (inputs, result, gradientsFunc) {\n var inputsMap = {};\n inputs.forEach(function (input, idx) {\n inputsMap[idx] = input;\n });\n var gradient = function (dy) {\n var res = gradientsFunc(dy);\n var resMap = {};\n res.forEach(function (r, idx) {\n resMap[idx] = function () { return r; };\n });\n return resMap;\n };\n var tapeNode = {\n id: this.nextTapeNodeId++,\n name: this.activeScope.name,\n inputs: inputsMap,\n output: result,\n gradient: gradient\n };\n this.activeTape.push(tapeNode);\n };\n Engine.prototype.keep = function (result) {\n if (this.scopeStack.length === 1 && environment_1.ENV.engine.safeMode) {\n throw new Error('Safe mode is ON. Enclose all tensor operations inside tf.tidy(): ' +\n 'tf.tidy(() => {...}) to avoid memory leaks.');\n }\n this.activeScope.keep.push(result);\n return result;\n };\n Engine.prototype.startScope = function (name, gradientsMode) {\n if (gradientsMode === void 0) { gradientsMode = false; }\n if (gradientsMode && this.gradientScopeCount === 0) {\n this.activeTape = [];\n }\n if (gradientsMode) {\n this.gradientScopeCount++;\n }\n var scopeInfo = { keep: [], track: [] };\n if (name) {\n scopeInfo.name = name;\n }\n this.scopeStack.push(scopeInfo);\n this.activeScope = scopeInfo;\n };\n Engine.prototype.endScope = function (result, gradientsMode) {\n var _this = this;\n if (gradientsMode === void 0) { gradientsMode = false; }\n if (gradientsMode) {\n this.gradientScopeCount--;\n if (this.gradientScopeCount === 0) {\n this.activeTape = null;\n }\n }\n var tensorsToKeep = this.activeScope.keep;\n var tensorsToTrackInParent = util.extractTensorsFromContainer(result);\n tensorsToKeep = tensorsToKeep.concat(tensorsToTrackInParent);\n for (var i = 0; i < this.activeScope.track.length; i++) {\n var tensor = this.activeScope.track[i];\n if (util.isTensorInList(tensor, tensorsToKeep)) {\n continue;\n }\n if (this.activeTape != null) {\n tensorsToTrackInParent.push(tensor);\n }\n else {\n tensor.dispose();\n }\n }\n this.scopeStack.pop();\n this.activeScope = this.scopeStack.length === 0 ?\n { keep: [], track: [] } :\n this.scopeStack[this.scopeStack.length - 1];\n tensorsToTrackInParent.forEach(function (tensor) {\n if (!util.isTensorInList(tensor, _this.activeScope.keep)) {\n _this.track(tensor);\n }\n });\n };\n Engine.prototype.dispose = function () { };\n Engine.prototype.gradients = function (f, xs, dy, allowNoGradients) {\n var _this = this;\n if (allowNoGradients === void 0) { allowNoGradients = false; }\n util.assert(xs.length > 0, 'gradients() received an empty list of xs.');\n return globals_1.tidy('gradients', function () {\n var y = f();\n util.assert(y instanceof tensor_1.Tensor, 'The result y returned by f() must be a tensor.');\n var filteredTape = tape_1.getFilteredNodesXToY(_this.activeTape, xs, y);\n if (!allowNoGradients && filteredTape.length === 0 && xs.length > 0) {\n throw new Error('Cannot compute gradient of y=f(x) with respect to x. Make sure ' +\n 'that the f you passed encloses all operations that lead from x ' +\n 'to y.');\n }\n var accumulatedGradientMap = {};\n accumulatedGradientMap[y.id] = (dy == null) ? ops.ones(y.shape) : dy;\n tape_1.backpropagateGradients(accumulatedGradientMap, filteredTape);\n var grads = xs.map(function (x) { return accumulatedGradientMap[x.id]; });\n return { value: y, grads: grads };\n }, true);\n };\n Engine.prototype.customGrad = function (f) {\n var _this = this;\n util.assert(util.isFunction(f), 'The f passed in customGrad(f) must be a function.');\n return function () {\n var inputs = [];\n for (var _i = 0; _i < arguments.length; _i++) {\n inputs[_i] = arguments[_i];\n }\n util.assert(inputs.every(function (t) { return t instanceof tensor_1.Tensor; }), 'The args passed in customGrad(f)(x1, x2,...) must all be tensors');\n _this.customGradientDepth++;\n var gradientsFunc;\n var gradientsMode = true;\n var result = globals_1.tidy(f.name, function () {\n var _a = f.apply(void 0, inputs), value = _a.value, gradFunc = _a.gradFunc;\n util.assert(value instanceof tensor_1.Tensor, 'The function f passed in customGrad(f) must return an object ' +\n 'where `obj.value` is a tensor');\n util.assert(util.isFunction(gradFunc), 'The function f passed in customGrad(f) must return an object ' +\n 'where `obj.gradFunc` is a function.');\n gradientsFunc = gradFunc;\n return value;\n }, gradientsMode);\n _this.customGradientDepth--;\n if (_this.shouldRecord()) {\n var gradFunc = function (dy) {\n var res = gradientsFunc(dy);\n var grads = Array.isArray(res) ? res : [res];\n util.assert(grads.length === inputs.length, 'The function f passed in customGrad(f) must return an object ' +\n 'where `obj.gradFunc` is a function that returns the same ' +\n 'number of tensors as inputs passed to f(...).');\n util.assert(grads.every(function (t) { return t instanceof tensor_1.Tensor; }), 'The function f passed in customGrad(f) must return an object ' +\n 'where `obj.gradFunc` is a function that returns a list of ' +\n 'only tensors.');\n return grads;\n };\n _this.addTapeNode(inputs, result, gradFunc);\n }\n return result;\n };\n };\n Engine.prototype.write = function (dataId, values) {\n this.backend.write(dataId, values);\n };\n Engine.prototype.readSync = function (dataId) {\n return this.backend.readSync(dataId);\n };\n Engine.prototype.read = function (dataId) {\n return this.backend.read(dataId);\n };\n Engine.prototype.fromPixels = function (pixels, numChannels) {\n return this.backend.fromPixels(pixels, numChannels);\n };\n Engine.prototype.time = function (query) {\n return __awaiter(this, void 0, void 0, function () {\n var start, timingInfo;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n start = performance.now();\n return [4, this.backend.time(query)];\n case 1:\n timingInfo = _a.sent();\n timingInfo.wallMs = performance.now() - start;\n return [2, timingInfo];\n }\n });\n });\n };\n Engine.prototype.track = function (result) {\n if (this.scopeStack.length === 1 && this.safeMode) {\n throw new Error('Safe mode is ON. Enclose all tensor operations inside tf.tidy(): ' +\n 'tf.tidy(() => {op();...}); to avoid memory leaks.');\n }\n this.activeScope.track.push(result);\n return result;\n };\n return Engine;\n}());\nexports.Engine = Engine;\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar device_util = require(\"./device_util\");\nvar doc_1 = require(\"./doc\");\nvar engine_1 = require(\"./engine\");\nvar util = require(\"./util\");\nvar Type;\n(function (Type) {\n Type[Type[\"NUMBER\"] = 0] = \"NUMBER\";\n Type[Type[\"BOOLEAN\"] = 1] = \"BOOLEAN\";\n Type[Type[\"STRING\"] = 2] = \"STRING\";\n})(Type = exports.Type || (exports.Type = {}));\nexports.URL_PROPERTIES = [\n { name: 'DEBUG', type: Type.BOOLEAN }, { name: 'IS_BROWSER', type: Type.BOOLEAN },\n { name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION', type: Type.NUMBER },\n { name: 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE', type: Type.BOOLEAN },\n { name: 'WEBGL_VERSION', type: Type.NUMBER },\n { name: 'WEBGL_FLOAT_TEXTURE_ENABLED', type: Type.BOOLEAN }, {\n name: 'WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED',\n type: Type.BOOLEAN\n },\n { name: 'BACKEND', type: Type.STRING }\n];\nfunction hasExtension(gl, extensionName) {\n var ext = gl.getExtension(extensionName);\n return ext != null;\n}\nfunction getWebGLRenderingContext(webGLVersion) {\n if (webGLVersion === 0) {\n throw new Error('Cannot get WebGL rendering context, WebGL is disabled.');\n }\n var tempCanvas = document.createElement('canvas');\n if (webGLVersion === 1) {\n return (tempCanvas.getContext('webgl') ||\n tempCanvas.getContext('experimental-webgl'));\n }\n return tempCanvas.getContext('webgl2');\n}\nfunction loseContext(gl) {\n if (gl != null) {\n var loseContextExtension = gl.getExtension('WEBGL_lose_context');\n if (loseContextExtension == null) {\n throw new Error('Extension WEBGL_lose_context not supported on this browser.');\n }\n loseContextExtension.loseContext();\n }\n}\nfunction isWebGLVersionEnabled(webGLVersion) {\n var gl = getWebGLRenderingContext(webGLVersion);\n if (gl != null) {\n loseContext(gl);\n return true;\n }\n return false;\n}\nfunction getWebGLDisjointQueryTimerVersion(webGLVersion) {\n if (webGLVersion === 0) {\n return 0;\n }\n var queryTimerVersion;\n var gl = getWebGLRenderingContext(webGLVersion);\n if (hasExtension(gl, 'EXT_disjoint_timer_query_webgl2') &&\n webGLVersion === 2) {\n queryTimerVersion = 2;\n }\n else if (hasExtension(gl, 'EXT_disjoint_timer_query')) {\n queryTimerVersion = 1;\n }\n else {\n queryTimerVersion = 0;\n }\n if (gl != null) {\n loseContext(gl);\n }\n return queryTimerVersion;\n}\nfunction isFloatTextureReadPixelsEnabled(webGLVersion) {\n if (webGLVersion === 0) {\n return false;\n }\n var gl = getWebGLRenderingContext(webGLVersion);\n if (webGLVersion === 1) {\n if (!hasExtension(gl, 'OES_texture_float')) {\n return false;\n }\n }\n else {\n if (!hasExtension(gl, 'EXT_color_buffer_float')) {\n return false;\n }\n }\n var frameBuffer = gl.createFramebuffer();\n var texture = gl.createTexture();\n gl.bindTexture(gl.TEXTURE_2D, texture);\n var internalFormat = webGLVersion === 2 ? gl.RGBA32F : gl.RGBA;\n gl.texImage2D(gl.TEXTURE_2D, 0, internalFormat, 1, 1, 0, gl.RGBA, gl.FLOAT, null);\n gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);\n gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);\n var frameBufferComplete = (gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE);\n gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.FLOAT, new Float32Array(4));\n var readPixelsNoError = gl.getError() === gl.NO_ERROR;\n loseContext(gl);\n return frameBufferComplete && readPixelsNoError;\n}\nfunction isWebGLGetBufferSubDataAsyncExtensionEnabled(webGLVersion) {\n if (webGLVersion > 0) {\n return false;\n }\n if (webGLVersion !== 2) {\n return false;\n }\n var gl = getWebGLRenderingContext(webGLVersion);\n var isEnabled = hasExtension(gl, 'WEBGL_get_buffer_sub_data_async');\n loseContext(gl);\n return isEnabled;\n}\nvar Environment = (function () {\n function Environment(features) {\n this.features = {};\n this.registry = {};\n if (features != null) {\n this.features = features;\n }\n if (this.get('DEBUG')) {\n console.warn('Debugging mode is ON. The output of every math call will ' +\n 'be downloaded to CPU and checked for NaNs. ' +\n 'This significantly impacts performance.');\n }\n }\n Environment.setBackend = function (backendType, safeMode) {\n if (safeMode === void 0) { safeMode = false; }\n if (!(backendType in exports.ENV.registry)) {\n throw new Error(\"Backend type '\" + backendType + \"' not found in registry\");\n }\n exports.ENV.initBackend(backendType, safeMode);\n };\n Environment.getBackend = function () {\n exports.ENV.initDefaultBackend();\n return exports.ENV.currentBackend;\n };\n Environment.disposeVariables = function () {\n exports.ENV.engine.disposeVariables();\n };\n Environment.memory = function () {\n return exports.ENV.engine.memory();\n };\n Environment.prototype.get = function (feature) {\n if (feature in this.features) {\n return this.features[feature];\n }\n this.features[feature] = this.evaluateFeature(feature);\n return this.features[feature];\n };\n Environment.prototype.set = function (feature, value) {\n this.features[feature] = value;\n };\n Environment.prototype.getBestBackendType = function () {\n var _this = this;\n if (Object.keys(this.registry).length === 0) {\n throw new Error('No backend found in registry.');\n }\n var sortedBackends = Object.keys(this.registry)\n .map(function (name) {\n return { name: name, entry: _this.registry[name] };\n })\n .sort(function (a, b) {\n return b.entry.priority - a.entry.priority;\n });\n return sortedBackends[0].name;\n };\n Environment.prototype.evaluateFeature = function (feature) {\n if (feature === 'DEBUG') {\n return false;\n }\n else if (feature === 'IS_BROWSER') {\n return typeof window !== 'undefined';\n }\n else if (feature === 'BACKEND') {\n return this.getBestBackendType();\n }\n else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') {\n var webGLVersion = this.get('WEBGL_VERSION');\n if (webGLVersion === 0) {\n return 0;\n }\n return getWebGLDisjointQueryTimerVersion(webGLVersion);\n }\n else if (feature === 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_RELIABLE') {\n return this.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0 &&\n !device_util.isMobile();\n }\n else if (feature === 'WEBGL_VERSION') {\n if (isWebGLVersionEnabled(2)) {\n return 2;\n }\n else if (isWebGLVersionEnabled(1)) {\n return 1;\n }\n return 0;\n }\n else if (feature === 'WEBGL_FLOAT_TEXTURE_ENABLED') {\n return isFloatTextureReadPixelsEnabled(this.get('WEBGL_VERSION'));\n }\n else if (feature === 'WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED') {\n return isWebGLGetBufferSubDataAsyncExtensionEnabled(this.get('WEBGL_VERSION'));\n }\n throw new Error(\"Unknown feature \" + feature + \".\");\n };\n Environment.prototype.setFeatures = function (features) {\n this.features = features;\n };\n Environment.prototype.reset = function () {\n this.features = getFeaturesFromURL();\n if (this.globalEngine != null) {\n this.globalEngine.dispose();\n this.globalEngine = null;\n }\n };\n Environment.prototype.initBackend = function (backendType, safeMode) {\n if (safeMode === void 0) { safeMode = false; }\n this.currentBackend = backendType;\n if (this.globalEngine != null) {\n this.globalEngine.dispose();\n }\n var backend = exports.ENV.findBackend(backendType);\n this.globalEngine = new engine_1.Engine(backend, safeMode);\n };\n Environment.prototype.findBackend = function (name) {\n if (!(name in this.registry)) {\n return null;\n }\n return this.registry[name].backend;\n };\n Environment.prototype.registerBackend = function (name, factory, priority) {\n if (priority === void 0) { priority = 1; }\n if (name in this.registry) {\n console.warn(name + \" backend was already registered\");\n }\n try {\n var backend = factory();\n this.registry[name] = { backend: backend, priority: priority };\n return true;\n }\n catch (err) {\n console.warn(err.message);\n return false;\n }\n };\n Environment.prototype.removeBackend = function (name) {\n if (!(name in this.registry)) {\n throw new Error(name + \" backend not found in registry\");\n }\n this.registry[name].backend.dispose();\n delete this.registry[name];\n };\n Object.defineProperty(Environment.prototype, \"engine\", {\n get: function () {\n this.initDefaultBackend();\n return this.globalEngine;\n },\n enumerable: true,\n configurable: true\n });\n Environment.prototype.initDefaultBackend = function () {\n if (this.globalEngine == null) {\n this.initBackend(exports.ENV.get('BACKEND'), false);\n }\n };\n __decorate([\n doc_1.doc({ heading: 'Environment' })\n ], Environment, \"setBackend\", null);\n __decorate([\n doc_1.doc({ heading: 'Environment' })\n ], Environment, \"getBackend\", null);\n __decorate([\n doc_1.doc({ heading: 'Environment' })\n ], Environment, \"disposeVariables\", null);\n __decorate([\n doc_1.doc({ heading: 'Performance', subheading: 'Memory' })\n ], Environment, \"memory\", null);\n return Environment;\n}());\nexports.Environment = Environment;\nvar TENSORFLOWJS_FLAGS_PREFIX = 'tfjsflags';\nfunction getFeaturesFromURL() {\n var features = {};\n if (typeof window === 'undefined' || typeof window.location === 'undefined') {\n return features;\n }\n var urlParams = util.getQueryParams(window.location.search);\n if (TENSORFLOWJS_FLAGS_PREFIX in urlParams) {\n var urlFlags_1 = {};\n var keyValues = urlParams[TENSORFLOWJS_FLAGS_PREFIX].split(',');\n keyValues.forEach(function (keyValue) {\n var _a = keyValue.split(':'), key = _a[0], value = _a[1];\n urlFlags_1[key] = value;\n });\n exports.URL_PROPERTIES.forEach(function (urlProperty) {\n if (urlProperty.name in urlFlags_1) {\n console.log(\"Setting feature override from URL \" + urlProperty.name + \": \" +\n (\"\" + urlFlags_1[urlProperty.name]));\n if (urlProperty.type === Type.NUMBER) {\n features[urlProperty.name] = +urlFlags_1[urlProperty.name];\n }\n else if (urlProperty.type === Type.BOOLEAN) {\n features[urlProperty.name] = urlFlags_1[urlProperty.name] === 'true';\n }\n else if (urlProperty.type === Type.STRING) {\n features[urlProperty.name] = urlFlags_1[urlProperty.name];\n }\n else {\n console.warn(\"Unknown URL param: \" + urlProperty.name + \".\");\n }\n }\n });\n }\n return features;\n}\nfunction getGlobalNamespace() {\n var ns;\n if (typeof (window) !== 'undefined') {\n ns = window;\n }\n else if (typeof (global) !== 'undefined') {\n ns = global;\n }\n else {\n throw new Error('Could not find a global object');\n }\n return ns;\n}\nfunction getOrMakeEnvironment() {\n var ns = getGlobalNamespace();\n ns.ENV = ns.ENV || new Environment(getFeaturesFromURL());\n return ns.ENV;\n}\nexports.ENV = getOrMakeEnvironment();\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.PARALLELIZE_THRESHOLD = 30;\nfunction computeOptimalWindowSize(inSize) {\n if (inSize <= exports.PARALLELIZE_THRESHOLD) {\n return inSize;\n }\n return nearestDivisor(inSize, Math.floor(Math.sqrt(inSize)));\n}\nexports.computeOptimalWindowSize = computeOptimalWindowSize;\nfunction nearestDivisor(size, start) {\n for (var i = start; i < size; ++i) {\n if (size % i === 0) {\n return i;\n }\n }\n return size;\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar __1 = require(\"..\");\nvar array_ops_1 = require(\"../ops/array_ops\");\nfunction castTensor(x, dtype, backend) {\n if (!__1.util.hasEncodingLoss(x.dtype, dtype)) {\n return __1.Tensor.make(x.shape, { dataId: x.dataId }, dtype);\n }\n if (dtype === 'int32') {\n return backend.int(x);\n }\n else if (dtype === 'bool') {\n return backend.notEqual(x, array_ops_1.ArrayOps.scalar(0, x.dtype));\n }\n else {\n throw new Error(\"Error in Cast: unknown dtype argument (\" + dtype + \")\");\n }\n}\nexports.castTensor = castTensor;\nfunction reshapeTensor(x, shape) {\n return __1.Tensor.make(shape, { dataId: x.dataId }, x.dtype);\n}\nexports.reshapeTensor = reshapeTensor;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar ArgMinMaxProgram = (function () {\n function ArgMinMaxProgram(reduceInfo, op, firstPass) {\n this.variableNames = ['A'];\n var windowSize = reduceInfo.windowSize;\n var batchSize = reduceInfo.batchSize;\n var inSize = reduceInfo.inSize;\n var outSize = Math.ceil(inSize / windowSize);\n if (!firstPass) {\n this.variableNames.push('bestIndicesA');\n }\n this.outputShape = [batchSize, outSize];\n var compOp = (op === 'max') ? '>' : '<';\n var indexSnippet = firstPass ?\n 'inOffset + i;' :\n 'round(getBestIndicesA(batch, inOffset + i));';\n this.userCode = \"\\n void main() {\\n ivec2 coords = getOutputCoords();\\n int batch = coords[0];\\n int outIdx = coords[1];\\n int inOffset = outIdx * \" + windowSize + \";\\n\\n int bestIndex = 0;\\n float bestValue = getA(batch, inOffset);\\n\\n for (int i = 0; i < \" + windowSize + \"; i++) {\\n int inIdx = \" + indexSnippet + \";\\n float candidate = getA(batch, inIdx);\\n if (candidate \" + compOp + \" bestValue) {\\n bestValue = candidate;\\n bestIndex = inIdx;\\n }\\n }\\n setOutput(float(bestIndex));\\n }\\n \";\n }\n return ArgMinMaxProgram;\n}());\nexports.ArgMinMaxProgram = ArgMinMaxProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar AvgPool2DBackpropProgram = (function () {\n function AvgPool2DBackpropProgram(convInfo) {\n this.variableNames = ['dy'];\n this.outputShape = convInfo.inShape;\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var padTop = filterHeight - 1 - convInfo.padInfo.top;\n var padLeft = filterWidth - 1 - convInfo.padInfo.left;\n var avgMultiplier = 1 / (filterHeight * filterWidth);\n this.userCode = \"\\n const ivec2 pads = ivec2(\" + padTop + \", \" + padLeft + \");\\n const float avgMultiplier = float(\" + avgMultiplier + \");\\n\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int b = coords[0];\\n int d = coords[3];\\n\\n ivec2 dyRCCorner = coords.yz - pads;\\n int dyRCorner = dyRCCorner.x;\\n int dyCCorner = dyRCCorner.y;\\n\\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\\n // ? = to be determined. : = across all values in that axis.\\n float dotProd = 0.0;\\n for (int wR = 0; wR < \" + filterHeight + \"; wR++) {\\n float dyR = float(dyRCorner + wR) / \" + strideHeight + \".0;\\n\\n if (dyR < 0.0 || dyR >= \" + convInfo.outHeight + \".0 || fract(dyR) > 0.0) {\\n continue;\\n }\\n int idyR = int(dyR);\\n\\n for (int wC = 0; wC < \" + filterWidth + \"; wC++) {\\n float dyC = float(dyCCorner + wC) / \" + strideWidth + \".0;\\n\\n if (dyC < 0.0 || dyC >= \" + convInfo.outWidth + \".0 ||\\n fract(dyC) > 0.0) {\\n continue;\\n }\\n int idyC = int(dyC);\\n\\n float dyValue = getDy(b, idyR, idyC, d);\\n\\n dotProd += dyValue * avgMultiplier;\\n }\\n }\\n setOutput(dotProd);\\n }\\n \";\n }\n return AvgPool2DBackpropProgram;\n}());\nexports.AvgPool2DBackpropProgram = AvgPool2DBackpropProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar broadcast_util = require(\"../../ops/broadcast_util\");\nvar BatchNormProgram = (function () {\n function BatchNormProgram(xShape, meanShape, varianceShape, offsetShape, scaleShape, varianceEpsilon) {\n this.outputShape = [];\n this.supportsBroadcasting = true;\n this.variableNames = ['x', 'mean', 'variance'];\n broadcast_util.assertAndGetBroadcastShape(xShape, meanShape);\n broadcast_util.assertAndGetBroadcastShape(xShape, varianceShape);\n var offsetSnippet = '0.0';\n if (offsetShape != null) {\n broadcast_util.assertAndGetBroadcastShape(xShape, offsetShape);\n this.variableNames.push('offset');\n offsetSnippet = 'getOffsetAtOutCoords()';\n }\n var scaleSnippet = '1.0';\n if (scaleShape != null) {\n broadcast_util.assertAndGetBroadcastShape(xShape, scaleShape);\n this.variableNames.push('scale');\n scaleSnippet = 'getScaleAtOutCoords()';\n }\n this.outputShape = xShape;\n this.userCode = \"\\n void main() {\\n float x = getXAtOutCoords();\\n float mean = getMeanAtOutCoords();\\n float variance = getVarianceAtOutCoords();\\n float offset = \" + offsetSnippet + \";\\n float scale = \" + scaleSnippet + \";\\n float inv = scale * inversesqrt(variance + float(\" + varianceEpsilon + \"));\\n setOutput((x - mean) * inv + offset);\\n }\\n \";\n }\n return BatchNormProgram;\n}());\nexports.BatchNormProgram = BatchNormProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar broadcast_util = require(\"../../ops/broadcast_util\");\nvar CHECK_NAN_SNIPPET = \"\\n if (isNaN(a)) return a;\\n if (isNaN(b)) return b;\\n\";\nexports.ADD = 'return a + b;';\nexports.SUB = 'return a - b;';\nexports.MUL = 'return a * b;';\nexports.DIV = 'return a / b;';\nexports.INT_DIV = \"\\n float resultSign = sign(a) * sign(b);\\n int ia = round(a);\\n int ib = round(b);\\n int result = ia / ib;\\n int amodb = ia - ib * result;\\n\\n if (resultSign < 0.0 && amodb != 0) {\\n result -= 1;\\n }\\n return float(result);\\n\";\nexports.POW = \"\\n return (round(mod(b, 2.0)) == 0 || round(mod(b, 2.0)) == 2) ?\\n pow(abs(a), b) : sign(a) * pow(abs(a), b);\\n\";\nexports.SQUARED_DIFFERENCE = 'return (a - b) * (a - b);';\nexports.EQUAL = \"return float(a == b);\";\nexports.NOT_EQUAL = \"return float(a != b);\";\nexports.LESS = \"return float(a < b);\";\nexports.LESS_EQUAL = \"return float(a <= b);\";\nexports.GREATER = \"return float(a > b);\";\nexports.GREATER_EQUAL = \"return float(a >= b);\";\nexports.LOGICAL_AND = \"return float(a >= 1.0 && b >= 1.0);\";\nexports.LOGICAL_OR = \"return float(a >= 1.0 || b >= 1.0);\";\nexports.MAX = CHECK_NAN_SNIPPET + \"\\n return max(a, b);\\n\";\nexports.MIN = CHECK_NAN_SNIPPET + \"\\n return min(a, b);\\n\";\nexports.MOD = \"return mod(a, b);\";\nexports.ATAN2 = CHECK_NAN_SNIPPET + \"\\n return atan(a, b);\\n\";\nexports.ELU_DER = \"return (b >= 1.0) ? a : a * (b + 1.0);\";\nvar BinaryOpProgram = (function () {\n function BinaryOpProgram(op, aShape, bShape) {\n this.variableNames = ['A', 'B'];\n this.supportsBroadcasting = true;\n this.outputShape =\n broadcast_util.assertAndGetBroadcastShape(aShape, bShape);\n this.userCode = \"\\n float binaryOperation(float a, float b) {\\n \" + op + \"\\n }\\n\\n void main() {\\n float a = getAAtOutCoords();\\n float b = getBAtOutCoords();\\n setOutput(binaryOperation(a, b));\\n }\\n \";\n }\n return BinaryOpProgram;\n}());\nexports.BinaryOpProgram = BinaryOpProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar ClipProgram = (function () {\n function ClipProgram(aShape, min, max) {\n this.variableNames = ['A'];\n this.outputShape = aShape;\n var minFixed = min.toFixed(20);\n var maxFixed = max.toFixed(20);\n this.userCode = \"\\n void main() {\\n float value = getAAtOutCoords();\\n if (isNaN(value)) {\\n setOutput(value);\\n return;\\n }\\n\\n setOutput(clamp(value, \" + minFixed + \", \" + maxFixed + \"));\\n }\\n \";\n }\n return ClipProgram;\n}());\nexports.ClipProgram = ClipProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar concat_util = require(\"../../ops/concat_util\");\nvar ConcatProgram = (function () {\n function ConcatProgram(aShape, bShape) {\n this.variableNames = ['A', 'B'];\n this.outputShape = [];\n this.outputShape =\n concat_util.computeOutShape(aShape, bShape, 1);\n this.userCode = \"\\n void main() {\\n ivec2 coords = getOutputCoords();\\n int yR = coords.x;\\n int yC = coords.y;\\n\\n float value = 0.0;\\n if (yC < \" + aShape[1] + \") {\\n value = getA(yR, yC);\\n } else {\\n yC -= \" + aShape[1] + \";\\n value = getB(yR, yC);\\n }\\n\\n setOutput(value);\\n }\\n \";\n }\n return ConcatProgram;\n}());\nexports.ConcatProgram = ConcatProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar Conv2DDerFilterProgram = (function () {\n function Conv2DDerFilterProgram(convInfo) {\n this.variableNames = ['x', 'dy'];\n this.outputShape = convInfo.filterShape;\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var padTop = convInfo.padInfo.top;\n var padLeft = convInfo.padInfo.left;\n this.userCode = \"\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int wR = coords.x;\\n int wC = coords.y;\\n int d1 = coords.z;\\n int d2 = coords.w;\\n\\n // Convolve x(?, ?, d1) with dy(:, :, d2) to get dw(wR, wC, d1, d2).\\n // ? = to be determined. : = across all values in that axis.\\n float dotProd = 0.0;\\n\\n for (int b = 0; b < \" + convInfo.batchSize + \"; b++) {\\n for (int yR = 0; yR < \" + convInfo.outHeight + \"; yR++) {\\n int xR = wR + yR * \" + strideHeight + \" - \" + padTop + \";\\n\\n if (xR < 0 || xR >= \" + convInfo.inHeight + \") {\\n continue;\\n }\\n\\n for (int yC = 0; yC < \" + convInfo.outWidth + \"; yC++) {\\n int xC = wC + yC * \" + strideWidth + \" - \" + padLeft + \";\\n\\n if (xC < 0 || xC >= \" + convInfo.inWidth + \") {\\n continue;\\n }\\n\\n float dyValue = getDy(b, yR, yC, d2);\\n float xValue = getX(b, xR, xC, d1);\\n dotProd += (xValue * dyValue);\\n }\\n }\\n }\\n setOutput(dotProd);\\n }\\n \";\n }\n return Conv2DDerFilterProgram;\n}());\nexports.Conv2DDerFilterProgram = Conv2DDerFilterProgram;\nvar Conv2DDerInputProgram = (function () {\n function Conv2DDerInputProgram(convInfo) {\n this.variableNames = ['dy', 'W'];\n this.outputShape = convInfo.inShape;\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var padTop = filterHeight - 1 - convInfo.padInfo.top;\n var padLeft = filterWidth - 1 - convInfo.padInfo.left;\n this.userCode = \"\\n const ivec2 pads = ivec2(\" + padTop + \", \" + padLeft + \");\\n\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int batch = coords[0];\\n int d1 = coords[3];\\n\\n ivec2 dyCorner = coords.yz - pads;\\n int dyRCorner = dyCorner.x;\\n int dyCCorner = dyCorner.y;\\n\\n // Convolve dy(?, ?, d2) with w(:, :, d1, d2) to compute dx(xR, xC, d1).\\n // ? = to be determined. : = across all values in that axis.\\n float dotProd = 0.0;\\n for (int wR = 0; wR < \" + filterHeight + \"; wR++) {\\n float dyR = float(dyRCorner + wR) / \" + strideHeight + \".0;\\n\\n if (dyR < 0.0 || dyR >= \" + convInfo.outHeight + \".0 || fract(dyR) > 0.0) {\\n continue;\\n }\\n int idyR = int(dyR);\\n\\n int wRPerm = \" + filterHeight + \" - 1 - wR;\\n\\n for (int wC = 0; wC < \" + filterWidth + \"; wC++) {\\n float dyC = float(dyCCorner + wC) / \" + strideWidth + \".0;\\n\\n if (dyC < 0.0 || dyC >= \" + convInfo.outWidth + \".0 ||\\n fract(dyC) > 0.0) {\\n continue;\\n }\\n int idyC = int(dyC);\\n\\n int wCPerm = \" + filterWidth + \" - 1 - wC;\\n\\n for (int d2 = 0; d2 < \" + convInfo.outChannels + \"; d2++) {\\n float xValue = getDy(batch, idyR, idyC, d2);\\n float wValue = getW(wRPerm, wCPerm, d1, d2);\\n dotProd += xValue * wValue;\\n }\\n }\\n }\\n setOutput(dotProd);\\n }\\n \";\n }\n return Conv2DDerInputProgram;\n}());\nexports.Conv2DDerInputProgram = Conv2DDerInputProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar Conv2DProgram = (function () {\n function Conv2DProgram(convInfo) {\n this.variableNames = ['x', 'W'];\n this.outputShape = convInfo.outShape;\n var padTop = convInfo.padInfo.top;\n var padLeft = convInfo.padInfo.left;\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var dilationHeight = convInfo.dilationHeight;\n var dilationWidth = convInfo.dilationWidth;\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var inputDepthNearestVec4 = Math.floor(convInfo.inChannels / 4) * 4;\n var inputDepthVec4Remainder = convInfo.inChannels % 4;\n this.userCode = \"\\n const ivec2 strides = ivec2(\" + strideHeight + \", \" + strideWidth + \");\\n const ivec2 pads = ivec2(\" + padTop + \", \" + padLeft + \");\\n\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int batch = coords[0];\\n int d2 = coords[3];\\n\\n ivec2 xRCCorner = coords.yz * strides - pads;\\n int xRCorner = xRCCorner.x;\\n int xCCorner = xRCCorner.y;\\n\\n // Convolve x(?, ?, d1) with w(:, :, d1, d2) to get y(yR, yC, d2).\\n // ? = to be determined. : = across all values in that axis.\\n float dotProd = 0.0;\\n for (int wR = 0; wR < \" + filterHeight + \"; wR++) {\\n int xR = xRCorner + wR * \" + dilationHeight + \";\\n\\n if (xR < 0 || xR >= \" + convInfo.inHeight + \") {\\n continue;\\n }\\n\\n for (int wC = 0; wC < \" + filterWidth + \"; wC++) {\\n int xC = xCCorner + wC * \" + dilationWidth + \";\\n\\n if (xC < 0 || xC >= \" + convInfo.inWidth + \") {\\n continue;\\n }\\n\\n for (int d1 = 0; d1 < \" + inputDepthNearestVec4 + \"; d1 += 4) {\\n vec4 xValues = vec4(\\n getX(batch, xR, xC, d1),\\n getX(batch, xR, xC, d1 + 1),\\n getX(batch, xR, xC, d1 + 2),\\n getX(batch, xR, xC, d1 + 3)\\n );\\n vec4 wValues = vec4(\\n getW(wR, wC, d1, d2),\\n getW(wR, wC, d1 + 1, d2),\\n getW(wR, wC, d1 + 2, d2),\\n getW(wR, wC, d1 + 3, d2)\\n );\\n\\n dotProd += dot(xValues, wValues);\\n }\\n\\n if (\" + (inputDepthVec4Remainder === 1) + \") {\\n dotProd +=\\n getX(batch, xR, xC, \" + inputDepthNearestVec4 + \") *\\n getW(wR, wC, \" + inputDepthNearestVec4 + \", d2);\\n } else if (\" + (inputDepthVec4Remainder === 2) + \") {\\n vec2 xValues = vec2(\\n getX(batch, xR, xC, \" + inputDepthNearestVec4 + \"),\\n getX(batch, xR, xC, \" + inputDepthNearestVec4 + \" + 1)\\n );\\n vec2 wValues = vec2(\\n getW(wR, wC, \" + inputDepthNearestVec4 + \", d2),\\n getW(wR, wC, \" + inputDepthNearestVec4 + \" + 1, d2)\\n );\\n dotProd += dot(xValues, wValues);\\n } else if (\" + (inputDepthVec4Remainder === 3) + \") {\\n vec3 xValues = vec3(\\n getX(batch, xR, xC, \" + inputDepthNearestVec4 + \"),\\n getX(batch, xR, xC, \" + inputDepthNearestVec4 + \" + 1),\\n getX(batch, xR, xC, \" + inputDepthNearestVec4 + \" + 2)\\n );\\n vec3 wValues = vec3(\\n getW(wR, wC, \" + inputDepthNearestVec4 + \", d2),\\n getW(wR, wC, \" + inputDepthNearestVec4 + \" + 1, d2),\\n getW(wR, wC, \" + inputDepthNearestVec4 + \" + 2, d2)\\n );\\n dotProd += dot(xValues, wValues);\\n }\\n }\\n }\\n setOutput(dotProd);\\n }\\n \";\n }\n return Conv2DProgram;\n}());\nexports.Conv2DProgram = Conv2DProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar DepthwiseConv2DProgram = (function () {\n function DepthwiseConv2DProgram(convInfo) {\n this.variableNames = ['x', 'W'];\n this.outputShape = convInfo.outShape;\n var xNumRows = convInfo.inHeight;\n var xNumCols = convInfo.inWidth;\n var padTop = convInfo.padInfo.top;\n var padLeft = convInfo.padInfo.left;\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var dilationHeight = convInfo.dilationHeight;\n var dilationWidth = convInfo.dilationWidth;\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var channelMul = convInfo.outChannels / convInfo.inChannels;\n this.userCode = \"\\n const ivec2 strides = ivec2(\" + strideHeight + \", \" + strideWidth + \");\\n const ivec2 pads = ivec2(\" + padTop + \", \" + padLeft + \");\\n\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int batch = coords.x;\\n ivec2 xRCCorner = coords.yz * strides - pads;\\n int d2 = coords.w;\\n int d1 = d2 / \" + channelMul + \";\\n int q = d2 - d1 * \" + channelMul + \";\\n\\n int xRCorner = xRCCorner.x;\\n int xCCorner = xRCCorner.y;\\n\\n // Convolve x(?, ?, d1) with w(:, :, d1, q) to get y(yR, yC, d2).\\n // ? = to be determined. : = across all values in that axis.\\n float dotProd = 0.0;\\n // TODO(dsmilkov): Flatten the two for loops and vec4 the operations.\\n for (int wR = 0; wR < \" + filterHeight + \"; wR++) {\\n int xR = xRCorner + wR * \" + dilationHeight + \";\\n\\n if (xR < 0 || xR >= \" + xNumRows + \") {\\n continue;\\n }\\n\\n for (int wC = 0; wC < \" + filterWidth + \"; wC++) {\\n int xC = xCCorner + wC * \" + dilationWidth + \";\\n\\n if (xC < 0 || xC >= \" + xNumCols + \") {\\n continue;\\n }\\n\\n float xVal = getX(batch, xR, xC, d1);\\n float wVal = getW(wR, wC, d1, q);\\n dotProd += xVal * wVal;\\n }\\n }\\n setOutput(dotProd);\\n }\\n \";\n }\n return DepthwiseConv2DProgram;\n}());\nexports.DepthwiseConv2DProgram = DepthwiseConv2DProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar FromPixelsProgram = (function () {\n function FromPixelsProgram(outputShape) {\n this.variableNames = ['A'];\n var height = outputShape[0], width = outputShape[1];\n this.outputShape = outputShape;\n this.userCode = \"\\n void main() {\\n ivec3 coords = getOutputCoords();\\n int texR = coords[0];\\n int texC = coords[1];\\n int depth = coords[2];\\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(\" + width + \".0, \" + height + \".0);\\n\\n vec4 values = texture2D(A, uv);\\n float value;\\n if (depth == 0) {\\n value = values.r;\\n } else if (depth == 1) {\\n value = values.g;\\n } else if (depth == 2) {\\n value = values.b;\\n } else if (depth == 3) {\\n value = values.a;\\n }\\n\\n setOutput(floor(value * 255.0 + 0.5));\\n }\\n \";\n }\n return FromPixelsProgram;\n}());\nexports.FromPixelsProgram = FromPixelsProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar TextureType;\n(function (TextureType) {\n TextureType[TextureType[\"FLOAT\"] = 0] = \"FLOAT\";\n TextureType[TextureType[\"UNSIGNED_BYTE\"] = 1] = \"UNSIGNED_BYTE\";\n})(TextureType = exports.TextureType || (exports.TextureType = {}));\nfunction getUnpackedMatrixTextureShapeWidthHeight(rows, columns) {\n return [columns, rows];\n}\nexports.getUnpackedMatrixTextureShapeWidthHeight = getUnpackedMatrixTextureShapeWidthHeight;\nfunction getUnpackedArraySizeFromMatrixSize(matrixSize, channelsPerTexture) {\n return matrixSize * channelsPerTexture;\n}\nexports.getUnpackedArraySizeFromMatrixSize = getUnpackedArraySizeFromMatrixSize;\nfunction getColorMatrixTextureShapeWidthHeight(rows, columns) {\n return [columns * 4, rows];\n}\nexports.getColorMatrixTextureShapeWidthHeight = getColorMatrixTextureShapeWidthHeight;\nfunction getMatrixSizeFromUnpackedArraySize(unpackedSize, channelsPerTexture) {\n if (unpackedSize % channelsPerTexture !== 0) {\n throw new Error(\"unpackedSize (\" + unpackedSize + \") must be a multiple of \" +\n (\"\" + channelsPerTexture));\n }\n return unpackedSize / channelsPerTexture;\n}\nexports.getMatrixSizeFromUnpackedArraySize = getMatrixSizeFromUnpackedArraySize;\nfunction encodeMatrixToUnpackedArray(matrix, unpackedArray, channelsPerTexture) {\n var requiredSize = getUnpackedArraySizeFromMatrixSize(matrix.length, channelsPerTexture);\n if (unpackedArray.length < requiredSize) {\n throw new Error(\"unpackedArray length (\" + unpackedArray.length + \") must be >= \" +\n (\"\" + requiredSize));\n }\n var dst = 0;\n for (var src = 0; src < matrix.length; ++src) {\n unpackedArray[dst] = matrix[src];\n dst += channelsPerTexture;\n }\n}\nexports.encodeMatrixToUnpackedArray = encodeMatrixToUnpackedArray;\nexports.FLOAT_MAX = 20000;\nexports.FLOAT_MIN = -exports.FLOAT_MAX;\nvar FLOAT_RANGE = (exports.FLOAT_MAX - exports.FLOAT_MIN) / 255;\nvar FLOAT_DELTAS = [1, 1 / 255, 1 / (255 * 255), 1 / (255 * 255 * 255)];\nvar FLOAT_POWERS = [1, 255, 255 * 255];\nexports.BYTE_NAN_VALUE = 0;\nfunction encodeFloatArray(floatArray) {\n var uintArray = new Uint8Array(floatArray.length * 4);\n var _loop_1 = function (i) {\n var value = floatArray[i / 4];\n if (isNaN(value)) {\n uintArray[i] = exports.BYTE_NAN_VALUE;\n uintArray[i + 1] = exports.BYTE_NAN_VALUE;\n uintArray[i + 2] = exports.BYTE_NAN_VALUE;\n uintArray[i + 3] = exports.BYTE_NAN_VALUE;\n return \"continue\";\n }\n var normalizedValue = (value - exports.FLOAT_MIN) / FLOAT_RANGE;\n var enc = FLOAT_POWERS.map(function (pow) { return pow * normalizedValue; });\n var buckets = enc.map(function (value) { return Math.floor((value % 1) * 255); });\n uintArray[i] = Math.floor(normalizedValue);\n uintArray[i + 1] = buckets[0];\n uintArray[i + 2] = buckets[1];\n uintArray[i + 3] = buckets[2];\n };\n for (var i = 0; i < uintArray.length; i += 4) {\n _loop_1(i);\n }\n return uintArray;\n}\nexports.encodeFloatArray = encodeFloatArray;\nfunction decodeToFloatArray(uintArray) {\n var floatArray = new Float32Array(uintArray.length / 4);\n var _loop_2 = function (i) {\n if (uintArray[i] === exports.BYTE_NAN_VALUE &&\n uintArray[i + 1] === exports.BYTE_NAN_VALUE &&\n uintArray[i + 2] === exports.BYTE_NAN_VALUE &&\n uintArray[i + 3] === exports.BYTE_NAN_VALUE) {\n floatArray[i / 4] = NaN;\n return \"continue\";\n }\n var dot = 0;\n FLOAT_DELTAS.forEach(function (delta, j) {\n dot += delta * uintArray[i + j];\n });\n var value = dot * FLOAT_RANGE + exports.FLOAT_MIN;\n floatArray[i / 4] = value;\n };\n for (var i = 0; i < uintArray.length; i += 4) {\n _loop_2(i);\n }\n return floatArray;\n}\nexports.decodeToFloatArray = decodeToFloatArray;\nfunction decodeMatrixFromUnpackedArray(unpackedArray, matrix, channelsPerTexture) {\n var requiredSize = getMatrixSizeFromUnpackedArraySize(unpackedArray.length, channelsPerTexture);\n if (matrix.length < requiredSize) {\n throw new Error(\"matrix length (\" + matrix.length + \") must be >= \" + requiredSize);\n }\n var dst = 0;\n for (var src = 0; src < unpackedArray.length; src += channelsPerTexture) {\n matrix[dst++] = unpackedArray[src];\n }\n}\nexports.decodeMatrixFromUnpackedArray = decodeMatrixFromUnpackedArray;\nfunction decodeMatrixFromUnpackedColorRGBAArray(unpackedArray, matrix, channels) {\n var requiredSize = unpackedArray.length * channels / 4;\n if (matrix.length < requiredSize) {\n throw new Error(\"matrix length (\" + matrix.length + \") must be >= \" + requiredSize);\n }\n var dst = 0;\n for (var src = 0; src < unpackedArray.length; src += 4) {\n for (var c = 0; c < channels; c++) {\n matrix[dst++] = unpackedArray[src + c];\n }\n }\n}\nexports.decodeMatrixFromUnpackedColorRGBAArray = decodeMatrixFromUnpackedColorRGBAArray;\nfunction getPackedMatrixTextureShapeWidthHeight(rows, columns) {\n return [Math.ceil(columns / 2), Math.ceil(rows / 2)];\n}\nexports.getPackedMatrixTextureShapeWidthHeight = getPackedMatrixTextureShapeWidthHeight;\nfunction getPackedRGBAArraySizeFromMatrixShape(rows, columns) {\n var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];\n return w * h * 4;\n}\nexports.getPackedRGBAArraySizeFromMatrixShape = getPackedRGBAArraySizeFromMatrixShape;\nfunction encodeMatrixToPackedRGBA(matrix, rows, columns, packedRGBA) {\n var requiredSize = getPackedRGBAArraySizeFromMatrixShape(rows, columns);\n if (packedRGBA.length < requiredSize) {\n throw new Error(\"packedRGBA length (\" + packedRGBA.length + \") must be >= \" + requiredSize);\n }\n var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), textureWidth = _a[0], textureHeight = _a[1];\n var oddWidth = (columns % 2) === 1;\n var oddHeight = (rows % 2) === 1;\n var widthInFullBlocks = Math.floor(columns / 2);\n var heightInFullBlocks = Math.floor(rows / 2);\n {\n var dstStride = (oddWidth ? 4 : 0);\n var oneRow = columns;\n var dst = 0;\n for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) {\n var matrixSrcRow = (blockY * 2 * columns);\n for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) {\n var matrixSrcCol = blockX * 2;\n var src = matrixSrcRow + matrixSrcCol;\n packedRGBA[dst] = matrix[src];\n packedRGBA[dst + 1] = matrix[src + 1];\n packedRGBA[dst + 2] = matrix[src + oneRow];\n packedRGBA[dst + 3] = matrix[src + oneRow + 1];\n dst += 4;\n }\n dst += dstStride;\n }\n }\n if (oddWidth) {\n var src = columns - 1;\n var dst = (textureWidth - 1) * 4;\n var srcStride = 2 * columns;\n var dstStride = textureWidth * 4;\n for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) {\n packedRGBA[dst] = matrix[src];\n packedRGBA[dst + 2] = matrix[src + columns];\n src += srcStride;\n dst += dstStride;\n }\n }\n if (oddHeight) {\n var src = (rows - 1) * columns;\n var dst = (textureHeight - 1) * textureWidth * 4;\n for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) {\n packedRGBA[dst++] = matrix[src++];\n packedRGBA[dst++] = matrix[src++];\n dst += 2;\n }\n }\n if (oddWidth && oddHeight) {\n packedRGBA[packedRGBA.length - 4] = matrix[matrix.length - 1];\n }\n return packedRGBA;\n}\nexports.encodeMatrixToPackedRGBA = encodeMatrixToPackedRGBA;\nfunction decodeMatrixFromPackedRGBA(packedRGBA, rows, columns, matrix) {\n var requiredSize = rows * columns;\n if (requiredSize < matrix.length) {\n throw new Error(\"matrix length (\" + matrix.length + \") must be >= \" + requiredSize);\n }\n var oddWidth = (columns % 2) === 1;\n var oddHeight = (rows % 2) === 1;\n var widthInFullBlocks = Math.floor(columns / 2);\n var heightInFullBlocks = Math.floor(rows / 2);\n var _a = getPackedMatrixTextureShapeWidthHeight(rows, columns), textureWidth = _a[0], textureHeight = _a[1];\n {\n var srcStride = oddWidth ? 4 : 0;\n var dstStride = columns + (oddWidth ? 1 : 0);\n var src = 0;\n var dstRow1 = 0;\n var dstRow2 = columns;\n for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) {\n for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) {\n matrix[dstRow1++] = packedRGBA[src++];\n matrix[dstRow1++] = packedRGBA[src++];\n matrix[dstRow2++] = packedRGBA[src++];\n matrix[dstRow2++] = packedRGBA[src++];\n }\n src += srcStride;\n dstRow1 += dstStride;\n dstRow2 += dstStride;\n }\n }\n if (oddWidth) {\n var src = (textureWidth - 1) * 4;\n var dst = columns - 1;\n var srcStride = textureWidth * 4;\n var dstStride = 2 * columns;\n for (var blockY = 0; blockY < heightInFullBlocks; ++blockY) {\n matrix[dst] = packedRGBA[src];\n matrix[dst + columns] = packedRGBA[src + 2];\n src += srcStride;\n dst += dstStride;\n }\n }\n if (oddHeight) {\n var src = (textureHeight - 1) * textureWidth * 4;\n var dst = (rows - 1) * columns;\n for (var blockX = 0; blockX < widthInFullBlocks; ++blockX) {\n matrix[dst++] = packedRGBA[src++];\n matrix[dst++] = packedRGBA[src++];\n src += 2;\n }\n }\n if (oddWidth && oddHeight) {\n matrix[matrix.length - 1] = packedRGBA[packedRGBA.length - 4];\n }\n return matrix;\n}\nexports.decodeMatrixFromPackedRGBA = decodeMatrixFromPackedRGBA;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../../environment\");\nvar util = require(\"../../util\");\nvar broadcast_util = require(\"../../ops/broadcast_util\");\nvar tex_util = require(\"./tex_util\");\nfunction makeShader(inputsInfo, outputShape, userCode, broadcast) {\n var sampleSnippet = getSampleSnippet();\n var setOutputSnippet = getSetOutputSnippet();\n var inputPrefixSnippet = inputsInfo.map(function (x) { return \"uniform sampler2D \" + x.name + \";\"; }).join('\\n');\n var inputSamplingSnippet = inputsInfo.map(function (x) { return getInputSamplingSnippet(x, outputShape, broadcast); })\n .join('\\n');\n var outTexShape = outputShape.texShape;\n var outputSamplingSnippet = getOutputSamplingSnippet(outputShape.logicalShape, outTexShape);\n var source = [\n SHADER_PREFIX, sampleSnippet, setOutputSnippet, inputPrefixSnippet,\n outputSamplingSnippet, inputSamplingSnippet, userCode\n ].join('\\n');\n return source;\n}\nexports.makeShader = makeShader;\nfunction getSampleSnippet() {\n return environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED') ?\n FLOAT_TEXTURE_SAMPLE_SNIPPET :\n UNSIGNED_BYTE_TEXTURE_SAMPLE_SNIPPET;\n}\nfunction getSetOutputSnippet() {\n return environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED') ?\n FLOAT_TEXTURE_SETOUTPUT_SNIPPET :\n UNSIGNED_BYTE_TEXTURE_SETOUTPUT_SNIPPET;\n}\nfunction getSamplerFromInInfo(inInfo) {\n var shape = inInfo.shapeInfo.logicalShape;\n switch (shape.length) {\n case 0:\n return getSamplerScalar(inInfo);\n case 1:\n return getSampler1D(inInfo);\n case 2:\n return getSampler2D(inInfo);\n case 3:\n return getSampler3D(inInfo);\n case 4:\n return getSampler4D(inInfo);\n default:\n throw new Error(shape.length + \"-D input sampling\" +\n \" is not yet supported\");\n }\n}\nfunction getInputSamplingSnippet(inInfo, outShapeInfo, broadcast) {\n var res = getSamplerFlat(inInfo);\n res += getSamplerFromInInfo(inInfo);\n if (broadcast ||\n util.arraysEqual(inInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape)) {\n res += getSamplerAtOutputCoords(inInfo, outShapeInfo, broadcast);\n }\n return res;\n}\nfunction getOutputSamplingSnippet(outShape, outTexShape) {\n switch (outShape.length) {\n case 0:\n return getOutputScalarCoords();\n case 1:\n return getOutput1DCoords(outShape, outTexShape);\n case 2:\n return getOutput2DCoords(outShape, outTexShape);\n case 3:\n return getOutput3DCoords(outShape, outTexShape);\n case 4:\n return getOutput4DCoords(outShape, outTexShape);\n default:\n throw new Error(outShape.length + \"-D output sampling is not yet supported\");\n }\n}\nvar SAMPLE_1D_SNIPPET = \"\\nvec2 UVfrom1D(int texNumR, int texNumC, int index) {\\n int texR = index / texNumC;\\n int texC = index - texR * texNumC;\\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\\n}\\n\";\nvar SAMPLE_2D_SNIPPET = \"\\nvec2 UVfrom2D(int texNumR, int texNumC, int numC, int row, int col) {\\n int index = row * numC + col;\\n int texR = index / texNumC;\\n int texC = index - texR * texNumC;\\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\\n}\\n\";\nvar SAMPLE_3D_SNIPPET = \"\\nvec2 UVfrom3D(int texNumR, int texNumC, int stride0,\\n int stride1, int row, int col, int depth) {\\n // Explicitly use integer operations as dot() only works on floats.\\n int index = row * stride0 + col * stride1 + depth;\\n int texR = index / texNumC;\\n int texC = index - texR * texNumC;\\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\\n}\\n\";\nvar SAMPLE_4D_SNIPPET = \"\\nvec2 UVfrom4D(int texNumR, int texNumC, int stride0,\\n int stride1, int stride2, int row, int col, int depth,\\n int depth2) {\\n // Explicitly use integer operations as dot() only works on floats.\\n int index = row * stride0 + col * stride1 + depth * stride2 + depth2;\\n int texR = index / texNumC;\\n int texC = index - texR * texNumC;\\n return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);\\n}\\n\";\nvar UNSIGNED_BYTE_TEXTURE_SAMPLE_SNIPPET = \"\\n uniform float NaN;\\n\\n const vec4 floatDeltas = vec4(\\n 1.0,\\n 1.0 / 255.0,\\n 1.0 / (255.0 * 255.0),\\n 1.0 / (255.0 * 255.0 * 255.0)\\n );\\n const float minValue = \" + tex_util.FLOAT_MIN + \".0;\\n const float maxValue = \" + tex_util.FLOAT_MAX + \".0;\\n const float range = (maxValue - minValue) / 255.0;\\n const vec2 dotRange = vec2(1.0, range);\\n\\n float sampleTexture(sampler2D textureSampler, vec2 uv) {\\n vec4 sampleValue = texture2D(textureSampler, uv);\\n if (all(equal(sampleValue, vec4(\" + tex_util.BYTE_NAN_VALUE + \")))) {\\n return NaN;\\n }\\n\\n vec4 encValue = floor(sampleValue * 255.0 + 0.5);\\n float decodedValue = dot(encValue, floatDeltas);\\n return dot(vec2(minValue, decodedValue), dotRange);\\n }\\n\";\nvar UNSIGNED_BYTE_TEXTURE_SETOUTPUT_SNIPPET = \"\\n const vec4 floatPowers = vec4(\\n 1.0,\\n 255.0,\\n 255.0 * 255.0,\\n 255.0 * 255.0 * 255.0\\n );\\n const vec2 recipRange = vec2(1.0/range);\\n const vec2 recipRange255 = vec2(1.0/(maxValue - minValue));\\n\\n void setOutput(float decodedValue) {\\n if (isNaN(decodedValue)) {\\n gl_FragColor = vec4(\" + tex_util.BYTE_NAN_VALUE + \");\\n return;\\n }\\n\\n float a = dot(vec2(decodedValue, -minValue), recipRange);\\n float b = fract(a) * 255.0;\\n float c = fract(b) * 255.0;\\n float d = fract(c) * 255.0;\\n gl_FragColor = floor(vec4(a, b, c, d)) / 255.0;\\n\\n // TODO(dsmilkov): Version above gets better accuracy but probably slower\\n // than the version below. Benchmark to determine if the accuracy is worth\\n // the cost.\\n\\n // float normValue = dot(vec2(decodedValue, -minValue), recipRange255);\\n // vec4 f = normValue * floatPowers;\\n // gl_FragColor = floor(fract(f) * 255.0) / 255.0;\\n }\\n\";\nvar FLOAT_TEXTURE_SAMPLE_SNIPPET = \"\\n float sampleTexture(sampler2D textureSampler, vec2 uv) {\\n return texture2D(textureSampler, uv).r;\\n }\\n\";\nvar FLOAT_TEXTURE_SETOUTPUT_SNIPPET = \"\\n void setOutput(float val) {\\n gl_FragColor = vec4(val, 0, 0, 0);\\n }\\n\";\nvar SHADER_PREFIX = \"\\n precision highp float;\\n precision highp int;\\n varying vec2 resultUV;\\n const vec2 halfCR = vec2(0.5, 0.5);\\n\\n bool isNaN(float val) {\\n float v1 = val * val;\\n float v2 = val * val;\\n return v1 == v2 ? false : true;\\n }\\n\\n bool hasNaN(vec4 values) {\\n vec4 v1 = values * values;\\n vec4 v2 = values * values;\\n return any(notEqual(v1, v2));\\n }\\n\\n float getNaN(vec4 values) {\\n return dot(vec4(1), values);\\n }\\n\\n int round(float value) {\\n return int(floor(value + 0.5));\\n }\\n\\n int imod(int x, int y) {\\n return x - y * (x / y);\\n }\\n\\n //Based on the work of Dave Hoskins\\n //https://www.shadertoy.com/view/4djSRW\\n #define HASHSCALE1 443.8975\\n float random(float seed){\\n vec2 p = resultUV * seed;\\n vec3 p3 = fract(vec3(p.xyx) * HASHSCALE1);\\n p3 += dot(p3, p3.yzx + 19.19);\\n return fract((p3.x + p3.y) * p3.z);\\n }\\n\\n \" + SAMPLE_1D_SNIPPET + \"\\n \" + SAMPLE_2D_SNIPPET + \"\\n \" + SAMPLE_3D_SNIPPET + \"\\n \" + SAMPLE_4D_SNIPPET + \"\\n\";\nfunction getOutputScalarCoords() {\n return \"\\n int getOutputCoords() {\\n return 0;\\n }\\n \";\n}\nfunction getOutput1DCoords(shape, texShape) {\n if (texShape[0] === 1) {\n return \"\\n int getOutputCoords() {\\n return int(resultUV.x * \" + texShape[1] + \".0);\\n }\\n \";\n }\n if (texShape[1] === 1) {\n return \"\\n int getOutputCoords() {\\n return int(resultUV.y * \" + texShape[0] + \".0);\\n }\\n \";\n }\n return \"\\n int getOutputCoords() {\\n ivec2 resTexRC = ivec2(resultUV.yx *\\n vec2(\" + texShape[0] + \", \" + texShape[1] + \"));\\n return resTexRC.x * \" + texShape[1] + \" + resTexRC.y;\\n }\\n \";\n}\nfunction getOutput3DCoords(shape, texShape) {\n var stride0 = shape[1] * shape[2];\n var stride1 = shape[2];\n return \"\\n ivec3 getOutputCoords() {\\n ivec2 resTexRC = ivec2(resultUV.yx *\\n vec2(\" + texShape[0] + \", \" + texShape[1] + \"));\\n int index = resTexRC.x * \" + texShape[1] + \" + resTexRC.y;\\n int r = index / \" + stride0 + \";\\n index -= r * \" + stride0 + \";\\n int c = index / \" + stride1 + \";\\n int d = index - c * \" + stride1 + \";\\n return ivec3(r, c, d);\\n }\\n \";\n}\nfunction getOutput4DCoords(shape, texShape) {\n var stride2 = shape[3];\n var stride1 = shape[2] * stride2;\n var stride0 = shape[1] * stride1;\n return \"\\n ivec4 getOutputCoords() {\\n ivec2 resTexRC = ivec2(resultUV.yx *\\n vec2(\" + texShape[0] + \", \" + texShape[1] + \"));\\n int index = resTexRC.x * \" + texShape[1] + \" + resTexRC.y;\\n\\n int r = index / \" + stride0 + \";\\n index -= r * \" + stride0 + \";\\n\\n int c = index / \" + stride1 + \";\\n index -= c * \" + stride1 + \";\\n\\n int d = index / \" + stride2 + \";\\n int d2 = index - d * \" + stride2 + \";\\n\\n return ivec4(r, c, d, d2);\\n }\\n \";\n}\nfunction getOutput2DCoords(shape, texShape) {\n if (util.arraysEqual(shape, texShape)) {\n return \"\\n ivec2 getOutputCoords() {\\n return ivec2(resultUV.yx * vec2(\" + texShape[0] + \", \" + texShape[1] + \"));\\n }\\n \";\n }\n if (shape[1] === 1) {\n return \"\\n ivec2 getOutputCoords() {\\n ivec2 resTexRC = ivec2(resultUV.yx *\\n vec2(\" + texShape[0] + \", \" + texShape[1] + \"));\\n int index = resTexRC.x * \" + texShape[1] + \" + resTexRC.y;\\n return ivec2(index, 0);\\n }\\n \";\n }\n if (shape[0] === 1) {\n return \"\\n ivec2 getOutputCoords() {\\n ivec2 resTexRC = ivec2(resultUV.yx *\\n vec2(\" + texShape[0] + \", \" + texShape[1] + \"));\\n int index = resTexRC.x * \" + texShape[1] + \" + resTexRC.y;\\n return ivec2(0, index);\\n }\\n \";\n }\n return \"\\n ivec2 getOutputCoords() {\\n ivec2 resTexRC = ivec2(resultUV.yx *\\n vec2(\" + texShape[0] + \", \" + texShape[1] + \"));\\n int index = resTexRC.x * \" + texShape[1] + \" + resTexRC.y;\\n int r = index / \" + shape[1] + \";\\n int c = index - r * \" + shape[1] + \";\\n return ivec2(r, c);\\n }\\n \";\n}\nfunction getSamplerScalar(inputInfo) {\n var texName = inputInfo.name;\n var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);\n return \"\\n float \" + funcName + \"() {\\n return sampleTexture(\" + texName + \", halfCR);\\n }\\n \";\n}\nfunction getSampler1D(inputInfo) {\n var texName = inputInfo.name;\n var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);\n return \"\\n float \" + funcName + \"(int index) {\\n return \" + funcName + \"Flat(index);\\n }\\n \";\n}\nfunction getSampler2D(inputInfo) {\n var shape = inputInfo.shapeInfo.logicalShape;\n var texShape = inputInfo.shapeInfo.texShape;\n var texName = inputInfo.name;\n var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);\n var texNumR = texShape[0];\n var texNumC = texShape[1];\n if (util.arraysEqual(shape, texShape)) {\n return \"\\n float \" + funcName + \"(int row, int col) {\\n vec2 uv = (vec2(col, row) + halfCR) / vec2(\" + texNumC + \".0, \" + texNumR + \".0);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n }\n var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims;\n var squeezedShape = newShape;\n if (squeezedShape.length < shape.length) {\n var newInputInfo = squeezeInputInfo(inputInfo, squeezedShape);\n var params = ['row', 'col'];\n return \"\\n \" + getSamplerFromInInfo(newInputInfo) + \"\\n float \" + funcName + \"(int row, int col) {\\n return \" + funcName + \"(\" + getSqueezedParams(params, keptDims) + \");\\n }\\n \";\n }\n if (texNumC === 1) {\n return \"\\n float \" + funcName + \"(int row, int col) {\\n int index = row * \" + shape[1] + \" + col;\\n vec2 uv = vec2(0.5, (float(index) + 0.5) / \" + texNumR + \".0);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n }\n if (texNumR === 1) {\n return \"\\n float \" + funcName + \"(int row, int col) {\\n int index = row * \" + shape[1] + \" + col;\\n vec2 uv = vec2((float(index) + 0.5) / \" + texNumC + \".0, 0.5);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n }\n return \"\\n float \" + funcName + \"(int row, int col) {\\n vec2 uv = UVfrom2D(\" + texNumR + \", \" + texNumC + \", \" + shape[1] + \", row, col);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n\";\n}\nfunction getSampler3D(inputInfo) {\n var texShape = inputInfo.shapeInfo.texShape;\n var shape = inputInfo.shapeInfo.logicalShape;\n var texName = inputInfo.name;\n var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);\n var texNumR = texShape[0];\n var texNumC = texShape[1];\n var stride0 = shape[1] * shape[2];\n var stride1 = shape[2];\n var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims;\n var squeezedShape = newShape;\n if (squeezedShape.length < shape.length) {\n var newInputInfo = squeezeInputInfo(inputInfo, squeezedShape);\n var params = ['row', 'col', 'depth'];\n return \"\\n \" + getSamplerFromInInfo(newInputInfo) + \"\\n float \" + funcName + \"(int row, int col, int depth) {\\n return \" + funcName + \"(\" + getSqueezedParams(params, keptDims) + \");\\n }\\n \";\n }\n if (texNumC === stride0) {\n return \"\\n float \" + funcName + \"(int row, int col, int depth) {\\n int texR = row;\\n int texC = col * \" + stride1 + \" + depth;\\n vec2 uv = (vec2(texC, texR) + halfCR) /\\n vec2(\" + texNumC + \".0, \" + texNumR + \".0);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n }\n if (texNumC === stride1) {\n return \"\\n float \" + funcName + \"(int row, int col, int depth) {\\n int texR = row * \" + shape[1] + \" + col;\\n int texC = depth;\\n vec2 uv = (vec2(texC, texR) + halfCR) / vec2(\" + texNumC + \".0, \" + texNumR + \".0);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n }\n return \"\\n float \" + funcName + \"(int row, int col, int depth) {\\n vec2 uv = UVfrom3D(\\n \" + texNumR + \", \" + texNumC + \", \" + stride0 + \", \" + stride1 + \", row, col, depth);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n}\nfunction getSampler4D(inputInfo) {\n var shape = inputInfo.shapeInfo.logicalShape;\n var texShape = inputInfo.shapeInfo.texShape;\n var texName = inputInfo.name;\n var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1);\n var texNumR = texShape[0];\n var texNumC = texShape[1];\n var stride2 = shape[3];\n var stride1 = shape[2] * stride2;\n var stride0 = shape[1] * stride1;\n var _a = util.squeezeShape(shape), newShape = _a.newShape, keptDims = _a.keptDims;\n if (newShape.length < shape.length) {\n var newInputInfo = squeezeInputInfo(inputInfo, newShape);\n var params = ['row', 'col', 'depth', 'depth2'];\n return \"\\n \" + getSamplerFromInInfo(newInputInfo) + \"\\n float \" + funcName + \"(int row, int col, int depth, int depth2) {\\n return \" + funcName + \"(\" + getSqueezedParams(params, keptDims) + \");\\n }\\n \";\n }\n if (texNumC === stride0) {\n return \"\\n float \" + funcName + \"(int row, int col, int depth, int depth2) {\\n int texR = row;\\n int texC = col * \" + stride1 + \" + depth * \" + stride2 + \" + depth2;\\n vec2 uv = (vec2(texC, texR) + halfCR) /\\n vec2(\" + texNumC + \".0, \" + texNumR + \".0);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n }\n if (texNumC === stride2) {\n return \"\\n float \" + funcName + \"(int row, int col, int depth, int depth2) {\\n int texR = row * \" + shape[1] * shape[2] + \" + col * \" + shape[2] + \" + depth;\\n int texC = depth2;\\n vec2 uv = (vec2(texC, texR) + halfCR) /\\n vec2(\" + texNumC + \".0, \" + texNumR + \".0);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n }\n return \"\\n float \" + funcName + \"(int row, int col, int depth, int depth2) {\\n vec2 uv = UVfrom4D(\" + texNumR + \", \" + texNumC + \", \" + stride0 + \", \" + stride1 + \",\\n \" + stride2 + \", row, col, depth, depth2);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n}\nfunction getSamplerFlat(inputInfo) {\n var texName = inputInfo.name;\n var texShape = inputInfo.shapeInfo.texShape;\n var funcName = 'get' + texName.charAt(0).toUpperCase() + texName.slice(1) + 'Flat';\n var tNumR = texShape[0];\n var tNumC = texShape[1];\n if (tNumC === 1 && tNumR === 1) {\n return \"\\n float \" + funcName + \"(int index) {\\n return sampleTexture(\" + texName + \", halfCR);\\n }\\n \";\n }\n if (tNumC === 1) {\n return \"\\n float \" + funcName + \"(int index) {\\n vec2 uv = vec2(0.5, (float(index) + 0.5) / \" + tNumR + \".0);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n }\n if (tNumR === 1) {\n return \"\\n float \" + funcName + \"(int index) {\\n vec2 uv = vec2((float(index) + 0.5) / \" + tNumC + \".0, 0.5);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n }\n return \"\\n float \" + funcName + \"(int index) {\\n vec2 uv = UVfrom1D(\" + tNumR + \", \" + tNumC + \", index);\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n}\nfunction getBroadcastOutputCoordsSampler(inputInfo, outShapeInfo, texFuncSnippet, funcName) {\n var inRank = inputInfo.shapeInfo.logicalShape.length;\n var outRank = outShapeInfo.logicalShape.length;\n var type = 'int';\n if (outRank === 2) {\n type = 'ivec2';\n }\n else if (outRank === 3) {\n type = 'ivec3';\n }\n else if (outRank === 4) {\n type = 'ivec4';\n }\n var broadcastDims = broadcast_util.getBroadcastDims(inputInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape);\n var rankDiff = outRank - inRank;\n var coordsSnippet;\n if (inRank === 0) {\n coordsSnippet = '';\n }\n else if (outRank < 2 && broadcastDims.length >= 1) {\n coordsSnippet = 'coords = 0;';\n }\n else {\n coordsSnippet =\n broadcastDims.map(function (d) { return \"coords[\" + (d + rankDiff) + \"] = 0;\"; }).join('\\n');\n }\n var unpackedCoordsSnippet = '';\n if (outRank < 2 && inRank > 0) {\n unpackedCoordsSnippet = 'coords';\n }\n else {\n unpackedCoordsSnippet = inputInfo.shapeInfo.logicalShape\n .map(function (s, i) { return \"coords[\" + (i + rankDiff) + \"]\"; })\n .join(', ');\n }\n return \"\\n float \" + funcName + \"() {\\n \" + type + \" coords = getOutputCoords();\\n \" + coordsSnippet + \"\\n return get\" + texFuncSnippet + \"(\" + unpackedCoordsSnippet + \");\\n }\\n \";\n}\nfunction getSamplerAtOutputCoords(inputInfo, outShapeInfo, supportsBroadcasting) {\n var inTexShape = inputInfo.shapeInfo.texShape;\n var texName = inputInfo.name;\n var texFuncSnippet = texName.charAt(0).toUpperCase() + texName.slice(1);\n var funcName = 'get' + texFuncSnippet + 'AtOutCoords';\n var broadcastDims = broadcast_util.getBroadcastDims(inputInfo.shapeInfo.logicalShape, outShapeInfo.logicalShape);\n var inRank = inputInfo.shapeInfo.logicalShape.length;\n var outRank = outShapeInfo.logicalShape.length;\n var doBroadcast = supportsBroadcasting && ((outRank > inRank) || broadcastDims.length > 0);\n var broadcastOverOuter = broadcast_util.broadcastDimsAreOuter(broadcastDims);\n if (doBroadcast && !broadcastOverOuter) {\n return getBroadcastOutputCoordsSampler(inputInfo, outShapeInfo, texFuncSnippet, funcName);\n }\n var outTexShape = outShapeInfo.texShape;\n if (util.arraysEqual(inTexShape, outTexShape)) {\n return \"\\n float \" + funcName + \"() {\\n return sampleTexture(\" + texName + \", resultUV);\\n }\\n \";\n }\n var inSize = util.sizeFromShape(inTexShape);\n var broadcastSnippet = '';\n if (doBroadcast && broadcastOverOuter) {\n broadcastSnippet = \"\\n int mainPart = index / \" + inSize + \";\\n index -= mainPart * \" + inSize + \";\\n \";\n }\n return \"\\n float \" + funcName + \"() {\\n ivec2 resTexRC = ivec2(resultUV.yx *\\n vec2(\" + outTexShape[0] + \", \" + outTexShape[1] + \"));\\n int index = resTexRC.x * \" + outTexShape[1] + \" + resTexRC.y;\\n \" + broadcastSnippet + \"\\n int texR = index / \" + inTexShape[1] + \";\\n int texC = index - texR * \" + inTexShape[1] + \";\\n vec2 uv = (vec2(texC, texR) + halfCR) /\\n vec2(\" + inTexShape[1] + \".0, \" + inTexShape[0] + \".0);\\n\\n return sampleTexture(\" + texName + \", uv);\\n }\\n \";\n}\nfunction getCoordsDataType(rank) {\n if (rank <= 1) {\n return 'int';\n }\n else if (rank === 2) {\n return 'ivec2';\n }\n else if (rank === 3) {\n return 'ivec3';\n }\n else if (rank === 4) {\n return 'ivec4';\n }\n else {\n throw Error(\"GPU for rank \" + rank + \" is not yet supported\");\n }\n}\nexports.getCoordsDataType = getCoordsDataType;\nfunction squeezeInputInfo(inInfo, squeezedShape) {\n var newInputInfo = JSON.parse(JSON.stringify(inInfo));\n newInputInfo.shapeInfo.logicalShape = squeezedShape;\n return newInputInfo;\n}\nfunction getSqueezedParams(params, keptDims) {\n return keptDims.map(function (d) { return params[d]; }).join(', ');\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar shader_compiler_1 = require(\"./shader_compiler\");\nvar GatherProgram = (function () {\n function GatherProgram(aShape, indicesLength, axis) {\n this.variableNames = ['A', 'indices'];\n var outputShape = aShape.slice();\n outputShape[axis] = indicesLength;\n this.outputShape = outputShape;\n this.rank = outputShape.length;\n var dtype = shader_compiler_1.getCoordsDataType(this.rank);\n var sourceCoords = getSourceCoords(aShape, axis);\n this.userCode = \"\\n void main() {\\n \" + dtype + \" resRC = getOutputCoords();\\n setOutput(getA(\" + sourceCoords + \"));\\n }\\n \";\n }\n return GatherProgram;\n}());\nexports.GatherProgram = GatherProgram;\nfunction getSourceCoords(aShape, axis) {\n var rank = aShape.length;\n if (rank > 4) {\n throw Error(\"Gather for rank \" + rank + \" is not yet supported\");\n }\n if (rank === 1) {\n return \"int(getIndices(resRC))\";\n }\n var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w'];\n var sourceCoords = [];\n for (var i = 0; i < aShape.length; i++) {\n if (i === axis) {\n sourceCoords.push(\"int(getIndices(\" + currentCoords[i] + \"))\");\n }\n else {\n sourceCoords.push(\"\" + currentCoords[i]);\n }\n }\n return sourceCoords.join();\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar MAX_TEXTURE_SIZE = null;\nvar util = require(\"../../util\");\nvar environment_1 = require(\"../../environment\");\nfunction createWebGLRenderingContext(attributes) {\n var canvas = document.createElement('canvas');\n canvas.width = 1;\n canvas.height = 1;\n return createWebGLRenderingContextFromCanvas(canvas, attributes);\n}\nexports.createWebGLRenderingContext = createWebGLRenderingContext;\nfunction createWebGLRenderingContextFromCanvas(canvas, attributes) {\n var gl;\n var webglVersion = environment_1.ENV.get('WEBGL_VERSION');\n if (webglVersion === 2) {\n gl = canvas.getContext('webgl2', attributes);\n }\n else if (webglVersion === 1) {\n gl = (canvas.getContext('webgl', attributes) ||\n canvas.getContext('experimental-webgl', attributes));\n }\n if (webglVersion === 0 || gl == null) {\n throw new Error('This browser does not support WebGL.');\n }\n return gl;\n}\nexports.createWebGLRenderingContextFromCanvas = createWebGLRenderingContextFromCanvas;\nfunction callAndCheck(gl, func) {\n var returnValue = func();\n checkWebGLError(gl);\n return returnValue;\n}\nexports.callAndCheck = callAndCheck;\nvar webGLDebugErrorCheckingEnabled = false;\nfunction enableDebugWebGLErrorChecking(enabled) {\n webGLDebugErrorCheckingEnabled = enabled;\n}\nexports.enableDebugWebGLErrorChecking = enableDebugWebGLErrorChecking;\nfunction checkWebGLError(gl) {\n if (webGLDebugErrorCheckingEnabled) {\n var error = gl.getError();\n if (error !== gl.NO_ERROR) {\n throw new Error('WebGL Error: ' + getWebGLErrorMessage(gl, error));\n }\n }\n}\nexports.checkWebGLError = checkWebGLError;\nfunction getWebGLErrorMessage(gl, status) {\n switch (status) {\n case gl.NO_ERROR:\n return 'NO_ERROR';\n case gl.INVALID_ENUM:\n return 'INVALID_ENUM';\n case gl.INVALID_VALUE:\n return 'INVALID_VALUE';\n case gl.INVALID_OPERATION:\n return 'INVALID_OPERATION';\n case gl.INVALID_FRAMEBUFFER_OPERATION:\n return 'INVALID_FRAMEBUFFER_OPERATION';\n case gl.OUT_OF_MEMORY:\n return 'OUT_OF_MEMORY';\n case gl.CONTEXT_LOST_WEBGL:\n return 'CONTEXT_LOST_WEBGL';\n default:\n return \"Unknown error code \" + status;\n }\n}\nexports.getWebGLErrorMessage = getWebGLErrorMessage;\nfunction getExtensionOrThrow(gl, extensionName) {\n return throwIfNull(gl, function () { return gl.getExtension(extensionName); }, 'Extension \"' + extensionName + '\" not supported on this browser.');\n}\nexports.getExtensionOrThrow = getExtensionOrThrow;\nfunction createVertexShader(gl, vertexShaderSource) {\n var vertexShader = throwIfNull(gl, function () { return gl.createShader(gl.VERTEX_SHADER); }, 'Unable to create vertex WebGLShader.');\n callAndCheck(gl, function () { return gl.shaderSource(vertexShader, vertexShaderSource); });\n callAndCheck(gl, function () { return gl.compileShader(vertexShader); });\n if (gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS) === false) {\n console.log(gl.getShaderInfoLog(vertexShader));\n throw new Error('Failed to compile vertex shader.');\n }\n return vertexShader;\n}\nexports.createVertexShader = createVertexShader;\nfunction createFragmentShader(gl, fragmentShaderSource) {\n var fragmentShader = throwIfNull(gl, function () { return gl.createShader(gl.FRAGMENT_SHADER); }, 'Unable to create fragment WebGLShader.');\n callAndCheck(gl, function () { return gl.shaderSource(fragmentShader, fragmentShaderSource); });\n callAndCheck(gl, function () { return gl.compileShader(fragmentShader); });\n if (gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS) === false) {\n logShaderSourceAndInfoLog(fragmentShaderSource, gl.getShaderInfoLog(fragmentShader));\n throw new Error('Failed to compile fragment shader.');\n }\n return fragmentShader;\n}\nexports.createFragmentShader = createFragmentShader;\nvar lineNumberRegex = /ERROR: [0-9]+:([0-9]+):/g;\nfunction logShaderSourceAndInfoLog(shaderSource, shaderInfoLog) {\n var lineNumberRegexResult = lineNumberRegex.exec(shaderInfoLog);\n if (lineNumberRegexResult == null) {\n console.log(\"Couldn't parse line number in error: \" + shaderInfoLog);\n console.log(shaderSource);\n return;\n }\n var lineNumber = +lineNumberRegexResult[1];\n var shaderLines = shaderSource.split('\\n');\n var pad = shaderLines.length.toString().length + 2;\n var linesWithLineNumbers = shaderLines.map(function (line, lineNumber) {\n return util.rightPad((lineNumber + 1).toString(), pad) + line;\n });\n var maxLineLength = 0;\n for (var i = 0; i < linesWithLineNumbers.length; i++) {\n maxLineLength = Math.max(linesWithLineNumbers[i].length, maxLineLength);\n }\n var beforeErrorLines = linesWithLineNumbers.slice(0, lineNumber - 1);\n var errorLine = linesWithLineNumbers.slice(lineNumber - 1, lineNumber);\n var afterErrorLines = linesWithLineNumbers.slice(lineNumber);\n console.log(beforeErrorLines.join('\\n'));\n console.log(shaderInfoLog.split('\\n')[0]);\n console.log(\"%c \" + util.rightPad(errorLine[0], maxLineLength), 'border:1px solid red; background-color:#e3d2d2; color:#a61717');\n console.log(afterErrorLines.join('\\n'));\n}\nfunction createProgram(gl) {\n return throwIfNull(gl, function () { return gl.createProgram(); }, 'Unable to create WebGLProgram.');\n}\nexports.createProgram = createProgram;\nfunction linkProgram(gl, program) {\n callAndCheck(gl, function () { return gl.linkProgram(program); });\n if (gl.getProgramParameter(program, gl.LINK_STATUS) === false) {\n console.log(gl.getProgramInfoLog(program));\n throw new Error('Failed to link vertex and fragment shaders.');\n }\n}\nexports.linkProgram = linkProgram;\nfunction validateProgram(gl, program) {\n callAndCheck(gl, function () { return gl.validateProgram(program); });\n if (gl.getProgramParameter(program, gl.VALIDATE_STATUS) === false) {\n console.log(gl.getProgramInfoLog(program));\n throw new Error('Shader program validation failed.');\n }\n}\nexports.validateProgram = validateProgram;\nfunction createStaticVertexBuffer(gl, data) {\n var buffer = throwIfNull(gl, function () { return gl.createBuffer(); }, 'Unable to create WebGLBuffer');\n callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, buffer); });\n callAndCheck(gl, function () { return gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW); });\n return buffer;\n}\nexports.createStaticVertexBuffer = createStaticVertexBuffer;\nfunction createStaticIndexBuffer(gl, data) {\n var buffer = throwIfNull(gl, function () { return gl.createBuffer(); }, 'Unable to create WebGLBuffer');\n callAndCheck(gl, function () { return gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer); });\n callAndCheck(gl, function () { return gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data, gl.STATIC_DRAW); });\n return buffer;\n}\nexports.createStaticIndexBuffer = createStaticIndexBuffer;\nfunction queryMaxTextureSize(gl) {\n if (MAX_TEXTURE_SIZE != null) {\n return MAX_TEXTURE_SIZE;\n }\n MAX_TEXTURE_SIZE =\n callAndCheck(gl, function () { return gl.getParameter(gl.MAX_TEXTURE_SIZE); });\n return MAX_TEXTURE_SIZE;\n}\nexports.queryMaxTextureSize = queryMaxTextureSize;\nfunction getChannelsPerTexture() {\n if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) {\n return 4;\n }\n if (environment_1.ENV.get('WEBGL_VERSION') === 2) {\n return 1;\n }\n return 4;\n}\nexports.getChannelsPerTexture = getChannelsPerTexture;\nfunction createTexture(gl) {\n return throwIfNull(gl, function () { return gl.createTexture(); }, 'Unable to create WebGLTexture.');\n}\nexports.createTexture = createTexture;\nfunction validateTextureSize(gl, width, height) {\n var maxTextureSize = queryMaxTextureSize(gl);\n if ((width <= 0) || (height <= 0)) {\n var requested = \"[\" + width + \"x\" + height + \"]\";\n throw new Error('Requested texture size ' + requested + ' is invalid.');\n }\n if ((width > maxTextureSize) || (height > maxTextureSize)) {\n var requested = \"[\" + width + \"x\" + height + \"]\";\n var max = \"[\" + maxTextureSize + \"x\" + maxTextureSize + \"]\";\n throw new Error('Requested texture size ' + requested +\n ' greater than WebGL maximum on this browser / GPU ' + max + '.');\n }\n}\nexports.validateTextureSize = validateTextureSize;\nfunction createFramebuffer(gl) {\n return throwIfNull(gl, function () { return gl.createFramebuffer(); }, 'Unable to create WebGLFramebuffer.');\n}\nexports.createFramebuffer = createFramebuffer;\nfunction bindVertexBufferToProgramAttribute(gl, program, attribute, buffer, arrayEntriesPerItem, itemStrideInBytes, itemOffsetInBytes) {\n var loc = gl.getAttribLocation(program, attribute);\n if (loc === -1) {\n return false;\n }\n callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, buffer); });\n callAndCheck(gl, function () { return gl.vertexAttribPointer(loc, arrayEntriesPerItem, gl.FLOAT, false, itemStrideInBytes, itemOffsetInBytes); });\n callAndCheck(gl, function () { return gl.enableVertexAttribArray(loc); });\n return true;\n}\nexports.bindVertexBufferToProgramAttribute = bindVertexBufferToProgramAttribute;\nfunction bindTextureUnit(gl, texture, textureUnit) {\n validateTextureUnit(gl, textureUnit);\n callAndCheck(gl, function () { return gl.activeTexture(gl.TEXTURE0 + textureUnit); });\n callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); });\n}\nexports.bindTextureUnit = bindTextureUnit;\nfunction unbindTextureUnit(gl, textureUnit) {\n validateTextureUnit(gl, textureUnit);\n callAndCheck(gl, function () { return gl.activeTexture(gl.TEXTURE0 + textureUnit); });\n callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });\n}\nexports.unbindTextureUnit = unbindTextureUnit;\nfunction getProgramUniformLocationOrThrow(gl, program, uniformName) {\n return throwIfNull(gl, function () { return gl.getUniformLocation(program, uniformName); }, 'uniform \"' + uniformName + '\" not present in program.');\n}\nexports.getProgramUniformLocationOrThrow = getProgramUniformLocationOrThrow;\nfunction getProgramUniformLocation(gl, program, uniformName) {\n return gl.getUniformLocation(program, uniformName);\n}\nexports.getProgramUniformLocation = getProgramUniformLocation;\nfunction bindTextureToProgramUniformSampler(gl, program, texture, uniformSamplerLocation, textureUnit) {\n callAndCheck(gl, function () { return bindTextureUnit(gl, texture, textureUnit); });\n callAndCheck(gl, function () { return gl.uniform1i(uniformSamplerLocation, textureUnit); });\n}\nexports.bindTextureToProgramUniformSampler = bindTextureToProgramUniformSampler;\nfunction bindCanvasToFramebuffer(gl) {\n callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, null); });\n callAndCheck(gl, function () { return gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); });\n callAndCheck(gl, function () { return gl.scissor(0, 0, gl.canvas.width, gl.canvas.height); });\n}\nexports.bindCanvasToFramebuffer = bindCanvasToFramebuffer;\nfunction bindColorTextureToFramebuffer(gl, texture, framebuffer) {\n callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); });\n callAndCheck(gl, function () { return gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); });\n}\nexports.bindColorTextureToFramebuffer = bindColorTextureToFramebuffer;\nfunction unbindColorTextureFromFramebuffer(gl, framebuffer) {\n callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); });\n callAndCheck(gl, function () { return gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, null, 0); });\n}\nexports.unbindColorTextureFromFramebuffer = unbindColorTextureFromFramebuffer;\nfunction validateFramebuffer(gl) {\n var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);\n if (status !== gl.FRAMEBUFFER_COMPLETE) {\n throw new Error('Error binding framebuffer: ' + getFramebufferErrorMessage(gl, status));\n }\n}\nexports.validateFramebuffer = validateFramebuffer;\nfunction getFramebufferErrorMessage(gl, status) {\n switch (status) {\n case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:\n return 'FRAMEBUFFER_INCOMPLETE_ATTACHMENT';\n case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:\n return 'FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT';\n case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:\n return 'FRAMEBUFFER_INCOMPLETE_DIMENSIONS';\n case gl.FRAMEBUFFER_UNSUPPORTED:\n return 'FRAMEBUFFER_UNSUPPORTED';\n default:\n return \"unknown error \" + status;\n }\n}\nexports.getFramebufferErrorMessage = getFramebufferErrorMessage;\nfunction throwIfNull(gl, returnTOrNull, failureMessage) {\n var tOrNull = callAndCheck(gl, function () { return returnTOrNull(); });\n if (tOrNull == null) {\n throw new Error(failureMessage);\n }\n return tOrNull;\n}\nfunction validateTextureUnit(gl, textureUnit) {\n var maxTextureUnit = gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS - 1;\n var glTextureUnit = textureUnit + gl.TEXTURE0;\n if (glTextureUnit < gl.TEXTURE0 || glTextureUnit > maxTextureUnit) {\n var textureUnitRange = \"[gl.TEXTURE0, gl.TEXTURE\" + maxTextureUnit + \"]\";\n throw new Error(\"textureUnit must be in \" + textureUnitRange + \".\");\n }\n}\nfunction getTextureShapeFromLogicalShape(gl, logShape) {\n if (logShape.length !== 2) {\n var squeezeResult = util.squeezeShape(logShape);\n logShape = squeezeResult.newShape;\n }\n var maxTexSize = queryMaxTextureSize(gl);\n var size = util.sizeFromShape(logShape);\n if (logShape.length <= 1 && size <= maxTexSize) {\n return [size, 1];\n }\n else if (logShape.length === 2 && logShape[0] <= maxTexSize &&\n logShape[1] <= maxTexSize) {\n return logShape;\n }\n else if (logShape.length === 3 && logShape[0] <= maxTexSize &&\n logShape[1] * logShape[2] <= maxTexSize) {\n return [logShape[0], logShape[1] * logShape[2]];\n }\n else if (logShape.length === 4 && logShape[0] <= maxTexSize &&\n logShape[1] * logShape[2] * logShape[3] <= maxTexSize) {\n return [logShape[0], logShape[1] * logShape[2] * logShape[3]];\n }\n else {\n return util.sizeToSquarishShape(size);\n }\n}\nexports.getTextureShapeFromLogicalShape = getTextureShapeFromLogicalShape;\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../../environment\");\nvar tex_util = require(\"./tex_util\");\nvar webgl_util = require(\"./webgl_util\");\nfunction getWebGLContextAttributes() {\n return {\n alpha: false,\n antialias: false,\n premultipliedAlpha: false,\n preserveDrawingBuffer: false,\n depth: false,\n stencil: false,\n failIfMajorPerformanceCaveat: true\n };\n}\nexports.getWebGLContextAttributes = getWebGLContextAttributes;\nfunction createWebGLContext(canvas) {\n var attributes = getWebGLContextAttributes();\n var gl;\n if (canvas != null) {\n gl = webgl_util.createWebGLRenderingContextFromCanvas(canvas, attributes);\n }\n else {\n gl = webgl_util.createWebGLRenderingContext(attributes);\n }\n webgl_util.callAndCheck(gl, function () { return gl.disable(gl.DEPTH_TEST); });\n webgl_util.callAndCheck(gl, function () { return gl.disable(gl.STENCIL_TEST); });\n webgl_util.callAndCheck(gl, function () { return gl.disable(gl.BLEND); });\n webgl_util.callAndCheck(gl, function () { return gl.disable(gl.DITHER); });\n webgl_util.callAndCheck(gl, function () { return gl.disable(gl.POLYGON_OFFSET_FILL); });\n webgl_util.callAndCheck(gl, function () { return gl.disable(gl.SAMPLE_COVERAGE); });\n webgl_util.callAndCheck(gl, function () { return gl.enable(gl.SCISSOR_TEST); });\n webgl_util.callAndCheck(gl, function () { return gl.enable(gl.CULL_FACE); });\n webgl_util.callAndCheck(gl, function () { return gl.cullFace(gl.BACK); });\n return gl;\n}\nexports.createWebGLContext = createWebGLContext;\nfunction createVertexShader(gl) {\n var vertexShaderSource = \"\\n precision highp float;\\n attribute vec3 clipSpacePos;\\n attribute vec2 uv;\\n varying vec2 resultUV;\\n\\n void main() {\\n gl_Position = vec4(clipSpacePos, 1);\\n resultUV = uv;\\n }\";\n return webgl_util.createVertexShader(gl, vertexShaderSource);\n}\nexports.createVertexShader = createVertexShader;\nfunction createVertexBuffer(gl) {\n var vertexArray = new Float32Array([-1, 1, 0, 0, 1, -1, -1, 0, 0, 0, 1, 1, 0, 1, 1, 1, -1, 0, 1, 0]);\n return webgl_util.createStaticVertexBuffer(gl, vertexArray);\n}\nexports.createVertexBuffer = createVertexBuffer;\nfunction createIndexBuffer(gl) {\n var triangleVertexIndices = new Uint16Array([0, 1, 2, 2, 1, 3]);\n return webgl_util.createStaticIndexBuffer(gl, triangleVertexIndices);\n}\nexports.createIndexBuffer = createIndexBuffer;\nfunction getTextureInternalFormat(gl, numChannels) {\n if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) {\n return gl.RGBA;\n }\n if (environment_1.ENV.get('WEBGL_VERSION') === 2) {\n if (numChannels === 4) {\n return gl.RGBA32F;\n }\n return gl.R32F;\n }\n return gl.RGBA;\n}\nfunction getTextureFormat(gl, numChannels) {\n if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) {\n return gl.RGBA;\n }\n if (environment_1.ENV.get('WEBGL_VERSION') === 2) {\n if (numChannels === 4) {\n return gl.RGBA;\n }\n return gl.RED;\n }\n return gl.RGBA;\n}\nfunction getTextureType(gl) {\n if (!environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) {\n return gl.UNSIGNED_BYTE;\n }\n return gl.FLOAT;\n}\nfunction createAndConfigureTexture(gl, width, height, numChannels) {\n webgl_util.validateTextureSize(gl, width, height);\n var texture = webgl_util.createTexture(gl);\n var tex2d = gl.TEXTURE_2D;\n var internalFormat = getTextureInternalFormat(gl, numChannels);\n var format = getTextureFormat(gl, numChannels);\n webgl_util.callAndCheck(gl, function () { return gl.bindTexture(tex2d, texture); });\n webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); });\n webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); });\n webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MIN_FILTER, gl.NEAREST); });\n webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MAG_FILTER, gl.NEAREST); });\n webgl_util.callAndCheck(gl, function () { return gl.texImage2D(tex2d, 0, internalFormat, width, height, 0, format, getTextureType(gl), null); });\n webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });\n return texture;\n}\nfunction createMatrixTexture(gl, rows, columns) {\n var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1];\n var numChannels = 1;\n return createAndConfigureTexture(gl, width, height, numChannels);\n}\nexports.createMatrixTexture = createMatrixTexture;\nfunction createColorMatrixTexture(gl, rows, columns) {\n var _a = tex_util.getColorMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1];\n var numChannels = 4;\n return createAndConfigureTexture(gl, width, height, numChannels);\n}\nexports.createColorMatrixTexture = createColorMatrixTexture;\nfunction createPackedMatrixTexture(gl, rows, columns) {\n var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1];\n var numChannels = 4;\n return createAndConfigureTexture(gl, width, height, numChannels);\n}\nexports.createPackedMatrixTexture = createPackedMatrixTexture;\nfunction bindVertexProgramAttributeStreams(gl, program, vertexBuffer) {\n var posOffset = 0;\n var uvOffset = 3 * 4;\n var stride = (3 * 4) + (2 * 4);\n webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer); });\n var success = webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'clipSpacePos', vertexBuffer, 3, stride, posOffset);\n return success &&\n webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'uv', vertexBuffer, 2, stride, uvOffset);\n}\nexports.bindVertexProgramAttributeStreams = bindVertexProgramAttributeStreams;\nfunction uploadPixelDataToTexture(gl, texture, pixels) {\n webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); });\n webgl_util.callAndCheck(gl, function () { return gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, pixels); });\n webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });\n}\nexports.uploadPixelDataToTexture = uploadPixelDataToTexture;\nfunction uploadDataToTexture(gl, texture, width, height, data, numChannels) {\n var textureFormat = getTextureFormat(gl, numChannels);\n webgl_util.validateTextureSize(gl, width, height);\n webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, texture); });\n webgl_util.callAndCheck(gl, function () { return gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, width, height, textureFormat, getTextureType(gl), data); });\n webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });\n}\nfunction uploadMatrixToTexture(gl, texture, rows, columns, matrix, numChannels) {\n var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];\n var unpackedArray;\n if (environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED')) {\n var channelsPerTexture = numChannels === 1 ? webgl_util.getChannelsPerTexture() : numChannels;\n if (channelsPerTexture === 1) {\n unpackedArray = matrix;\n }\n else {\n unpackedArray =\n new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(matrix.length, channelsPerTexture));\n tex_util.encodeMatrixToUnpackedArray(matrix, unpackedArray, channelsPerTexture);\n }\n }\n else {\n unpackedArray = tex_util.encodeFloatArray(matrix);\n }\n uploadDataToTexture(gl, texture, w, h, unpackedArray, numChannels);\n}\nexports.uploadMatrixToTexture = uploadMatrixToTexture;\nfunction uploadMatrixToPackedTexture(gl, texture, rows, columns, matrix) {\n var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];\n var packedRGBA = new Float32Array(tex_util.getPackedRGBAArraySizeFromMatrixShape(rows, columns));\n tex_util.encodeMatrixToPackedRGBA(matrix, rows, columns, packedRGBA);\n var numChannels = 4;\n uploadDataToTexture(gl, texture, w, h, packedRGBA, numChannels);\n}\nexports.uploadMatrixToPackedTexture = uploadMatrixToPackedTexture;\nfunction getDownloadTargetArrayBuffer(rows, columns, channelsPerTexture) {\n var isFloatTexture = environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED');\n var downloadTarget;\n if (isFloatTexture) {\n downloadTarget =\n new Float32Array(tex_util.getUnpackedArraySizeFromMatrixSize(rows * columns, channelsPerTexture));\n }\n else {\n downloadTarget = new Uint8Array(rows * columns * channelsPerTexture);\n }\n return downloadTarget;\n}\nfunction decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel) {\n var isFloatTexture = environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED');\n if (isFloatTexture) {\n var matrix = new Float32Array(rows * columns);\n tex_util.decodeMatrixFromUnpackedArray(downloadTarget, matrix, channelsPerPixel);\n return matrix;\n }\n else {\n return tex_util.decodeToFloatArray(downloadTarget);\n }\n}\nfunction downloadMatrixFromOutputTextureAsync(gl, getBufferSubDataAsyncExtension, rows, columns) {\n return __awaiter(this, void 0, void 0, function () {\n var gl2, channelsPerPixel, downloadTarget, bufferSizeBytes, buffer;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n gl2 = gl;\n channelsPerPixel = 4;\n downloadTarget = getDownloadTargetArrayBuffer(rows, columns, channelsPerPixel);\n bufferSizeBytes = downloadTarget instanceof Float32Array ?\n downloadTarget.length * 4 :\n downloadTarget;\n buffer = gl.createBuffer();\n webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl2.PIXEL_PACK_BUFFER, buffer); });\n webgl_util.callAndCheck(gl, function () { return gl.bufferData(gl2.PIXEL_PACK_BUFFER, bufferSizeBytes, gl.STATIC_DRAW); });\n webgl_util.callAndCheck(gl, function () {\n return gl2.readPixels(0, 0, columns, rows, gl.RGBA, getTextureType(gl), 0);\n });\n return [4, getBufferSubDataAsyncExtension.getBufferSubDataAsync(gl2.PIXEL_PACK_BUFFER, 0, downloadTarget)];\n case 1:\n _a.sent();\n return [2, decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel)];\n }\n });\n });\n}\nexports.downloadMatrixFromOutputTextureAsync = downloadMatrixFromOutputTextureAsync;\nfunction downloadMatrixFromOutputTexture(gl, rows, columns) {\n var _a = tex_util.getUnpackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];\n var channelsPerPixel = 4;\n var downloadTarget = getDownloadTargetArrayBuffer(rows, columns, channelsPerPixel);\n webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, gl.RGBA, getTextureType(gl), downloadTarget); });\n return decodeDownloadTargetArrayBuffer(downloadTarget, rows, columns, channelsPerPixel);\n}\nexports.downloadMatrixFromOutputTexture = downloadMatrixFromOutputTexture;\nfunction downloadMatrixFromRGBAColorTexture(gl, rows, columns, channels) {\n var size = rows * columns * 4;\n var downloadTarget = new Uint8Array(size);\n webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, columns, rows, gl.RGBA, gl.UNSIGNED_BYTE, downloadTarget); });\n var packedRGBA = new Float32Array(size);\n for (var i = 0; i < downloadTarget.length; i++) {\n packedRGBA[i] = downloadTarget[i];\n }\n var matrix = new Float32Array(rows * columns * channels);\n tex_util.decodeMatrixFromUnpackedColorRGBAArray(packedRGBA, matrix, channels);\n return matrix;\n}\nexports.downloadMatrixFromRGBAColorTexture = downloadMatrixFromRGBAColorTexture;\nfunction downloadMatrixFromPackedOutputTexture(gl, rows, columns) {\n var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), w = _a[0], h = _a[1];\n var packedRGBA = new Float32Array(tex_util.getPackedRGBAArraySizeFromMatrixShape(rows, columns));\n webgl_util.callAndCheck(gl, function () { return gl.readPixels(0, 0, w, h, gl.RGBA, getTextureType(gl), packedRGBA); });\n var matrix = new Float32Array(rows * columns);\n return tex_util.decodeMatrixFromPackedRGBA(packedRGBA, rows, columns, matrix);\n}\nexports.downloadMatrixFromPackedOutputTexture = downloadMatrixFromPackedOutputTexture;\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../../environment\");\nvar util = require(\"../../util\");\nvar gpgpu_util = require(\"./gpgpu_util\");\nvar tex_util = require(\"./tex_util\");\nvar webgl_util = require(\"./webgl_util\");\nvar GPGPUContext = (function () {\n function GPGPUContext(gl) {\n this.outputTexture = null;\n this.program = null;\n this.disposed = false;\n this.autoDebugValidate = false;\n this.vertexAttrsAreBound = false;\n if (gl != null) {\n this.gl = gl;\n }\n else {\n this.gl = gpgpu_util.createWebGLContext();\n }\n if (environment_1.ENV.get('WEBGL_VERSION') === 1) {\n this.textureFloatExtension =\n webgl_util.getExtensionOrThrow(this.gl, 'OES_texture_float');\n this.colorBufferFloatExtension =\n this.gl.getExtension('WEBGL_color_buffer_float');\n }\n else {\n this.colorBufferFloatExtension =\n webgl_util.getExtensionOrThrow(this.gl, 'EXT_color_buffer_float');\n }\n this.loseContextExtension =\n webgl_util.getExtensionOrThrow(this.gl, 'WEBGL_lose_context');\n if (environment_1.ENV.get('WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED')) {\n this.getBufferSubDataAsyncExtension =\n this.gl.getExtension('WEBGL_get_buffer_sub_data_async');\n }\n this.vertexBuffer = gpgpu_util.createVertexBuffer(this.gl);\n this.indexBuffer = gpgpu_util.createIndexBuffer(this.gl);\n this.framebuffer = webgl_util.createFramebuffer(this.gl);\n }\n GPGPUContext.prototype.dispose = function () {\n var _this = this;\n if (this.disposed) {\n return;\n }\n if (this.program != null) {\n console.warn('Disposing a GPGPUContext that still has a bound WebGLProgram.' +\n ' This is probably a resource leak, delete the program with ' +\n 'GPGPUContext.deleteProgram before disposing.');\n }\n if (this.outputTexture != null) {\n console.warn('Disposing a GPGPUContext that still has a bound output matrix ' +\n 'texture. This is probably a resource leak, delete the output ' +\n 'matrix texture with GPGPUContext.deleteMatrixTexture before ' +\n 'disposing.');\n }\n var gl = this.gl;\n webgl_util.callAndCheck(gl, function () { return gl.finish(); });\n webgl_util.callAndCheck(gl, function () { return gl.bindFramebuffer(gl.FRAMEBUFFER, null); });\n webgl_util.callAndCheck(gl, function () { return gl.deleteFramebuffer(_this.framebuffer); });\n webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, null); });\n webgl_util.callAndCheck(gl, function () { return gl.deleteBuffer(_this.vertexBuffer); });\n webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null); });\n webgl_util.callAndCheck(gl, function () { return gl.deleteBuffer(_this.indexBuffer); });\n this.loseContextExtension.loseContext();\n this.disposed = true;\n };\n GPGPUContext.prototype.enableAutomaticDebugValidation = function (enabled) {\n this.autoDebugValidate = enabled;\n webgl_util.enableDebugWebGLErrorChecking(enabled);\n };\n GPGPUContext.prototype.createMatrixTexture = function (rows, columns) {\n this.throwIfDisposed();\n return gpgpu_util.createMatrixTexture(this.gl, rows, columns);\n };\n GPGPUContext.prototype.uploadPixelDataToTexture = function (texture, pixels) {\n this.throwIfDisposed();\n gpgpu_util.uploadPixelDataToTexture(this.gl, texture, pixels);\n };\n GPGPUContext.prototype.createPackedMatrixTexture = function (rows, columns) {\n this.throwIfDisposed();\n return gpgpu_util.createPackedMatrixTexture(this.gl, rows, columns);\n };\n GPGPUContext.prototype.deleteMatrixTexture = function (texture) {\n var _this = this;\n this.throwIfDisposed();\n if (this.outputTexture === texture) {\n webgl_util.unbindColorTextureFromFramebuffer(this.gl, this.framebuffer);\n this.outputTexture = null;\n }\n webgl_util.callAndCheck(this.gl, function () { return _this.gl.deleteTexture(texture); });\n };\n GPGPUContext.prototype.uploadMatrixToTexture = function (texture, rows, columns, matrix) {\n this.throwIfDisposed();\n var numChannels = 1;\n return gpgpu_util.uploadMatrixToTexture(this.gl, texture, rows, columns, matrix, numChannels);\n };\n GPGPUContext.prototype.uploadMatrixToPackedTexture = function (texture, rows, columns, matrix) {\n this.throwIfDisposed();\n return gpgpu_util.uploadMatrixToPackedTexture(this.gl, texture, rows, columns, matrix);\n };\n GPGPUContext.prototype.downloadMatrixFromTexture = function (texture, rows, columns) {\n var _this = this;\n return this.downloadMatrixDriver(texture, function () {\n return gpgpu_util.downloadMatrixFromOutputTexture(_this.gl, rows, columns);\n });\n };\n GPGPUContext.prototype.downloadMatrixFromTextureAsync = function (texture, rows, columns) {\n return __awaiter(this, void 0, void 0, function () {\n var _this = this;\n return __generator(this, function (_a) {\n if (this.getBufferSubDataAsyncExtension == null) {\n throw new Error(\"Cannot download matrix from output texture asynchronously, \" +\n \"WEBGL_get_buffer_sub_data_async is not enabled.\");\n }\n return [2, this.downloadMatrixDriverAsync(texture, function () { return gpgpu_util.downloadMatrixFromOutputTextureAsync(_this.gl, _this.getBufferSubDataAsyncExtension, rows, columns); })];\n });\n });\n };\n GPGPUContext.prototype.downloadMatrixFromRGBAColorTexture = function (texture, rows, columns, channels) {\n var _this = this;\n return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadMatrixFromRGBAColorTexture(_this.gl, rows, columns, channels); });\n };\n GPGPUContext.prototype.downloadMatrixFromPackedTexture = function (texture, rows, columns) {\n var _this = this;\n return this.downloadMatrixDriver(texture, function () { return gpgpu_util.downloadMatrixFromPackedOutputTexture(_this.gl, rows, columns); });\n };\n GPGPUContext.prototype.createProgram = function (fragmentShaderSource) {\n this.throwIfDisposed();\n var gl = this.gl;\n var fragmentShader = webgl_util.createFragmentShader(gl, fragmentShaderSource);\n var vertexShader = gpgpu_util.createVertexShader(gl);\n var program = webgl_util.createProgram(gl);\n webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, vertexShader); });\n webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, fragmentShader); });\n webgl_util.linkProgram(gl, program);\n if (this.autoDebugValidate) {\n webgl_util.validateProgram(gl, program);\n }\n if (!this.vertexAttrsAreBound) {\n this.setProgram(program);\n this.vertexAttrsAreBound = gpgpu_util.bindVertexProgramAttributeStreams(gl, this.program, this.vertexBuffer);\n }\n return program;\n };\n GPGPUContext.prototype.deleteProgram = function (program) {\n var _this = this;\n this.throwIfDisposed();\n if (program === this.program) {\n this.program = null;\n }\n if (program != null) {\n webgl_util.callAndCheck(this.gl, function () { return _this.gl.deleteProgram(program); });\n }\n };\n GPGPUContext.prototype.setProgram = function (program) {\n var _this = this;\n this.throwIfDisposed();\n this.program = program;\n if ((this.program != null) && this.autoDebugValidate) {\n webgl_util.validateProgram(this.gl, this.program);\n }\n webgl_util.callAndCheck(this.gl, function () { return _this.gl.useProgram(program); });\n };\n GPGPUContext.prototype.getUniformLocation = function (program, uniformName, shouldThrow) {\n if (shouldThrow === void 0) { shouldThrow = true; }\n this.throwIfDisposed();\n if (shouldThrow) {\n return webgl_util.getProgramUniformLocationOrThrow(this.gl, program, uniformName);\n }\n else {\n return webgl_util.getProgramUniformLocation(this.gl, program, uniformName);\n }\n };\n GPGPUContext.prototype.getAttributeLocation = function (program, attribute) {\n var _this = this;\n this.throwIfDisposed();\n return webgl_util.callAndCheck(this.gl, function () { return _this.gl.getAttribLocation(program, attribute); });\n };\n GPGPUContext.prototype.getUniformLocationNoThrow = function (program, uniformName) {\n this.throwIfDisposed();\n return this.gl.getUniformLocation(program, uniformName);\n };\n GPGPUContext.prototype.setInputMatrixTexture = function (inputMatrixTexture, uniformLocation, textureUnit) {\n this.throwIfDisposed();\n this.throwIfNoProgram();\n webgl_util.bindTextureToProgramUniformSampler(this.gl, this.program, inputMatrixTexture, uniformLocation, textureUnit);\n };\n GPGPUContext.prototype.setOutputMatrixTexture = function (outputMatrixTexture, rows, columns) {\n this.setOutputMatrixTextureDriver(outputMatrixTexture, columns, rows);\n };\n GPGPUContext.prototype.setOutputPackedMatrixTexture = function (outputPackedMatrixTexture, rows, columns) {\n this.throwIfDisposed();\n var _a = tex_util.getPackedMatrixTextureShapeWidthHeight(rows, columns), width = _a[0], height = _a[1];\n this.setOutputMatrixTextureDriver(outputPackedMatrixTexture, width, height);\n };\n GPGPUContext.prototype.setOutputMatrixWriteRegion = function (startRow, numRows, startColumn, numColumns) {\n this.setOutputMatrixWriteRegionDriver(startColumn, startRow, numColumns, numRows);\n };\n GPGPUContext.prototype.setOutputPackedMatrixWriteRegion = function (startRow, numRows, startColumn, numColumns) {\n throw new Error('setOutputPackedMatrixWriteRegion not implemented.');\n };\n GPGPUContext.prototype.debugValidate = function () {\n if (this.program != null) {\n webgl_util.validateProgram(this.gl, this.program);\n }\n webgl_util.validateFramebuffer(this.gl);\n };\n GPGPUContext.prototype.executeProgram = function () {\n this.throwIfDisposed();\n this.throwIfNoProgram();\n var gl = this.gl;\n if (this.autoDebugValidate) {\n this.debugValidate();\n }\n webgl_util.callAndCheck(gl, function () { return gl.drawElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0); });\n };\n GPGPUContext.prototype.blockUntilAllProgramsCompleted = function () {\n var _this = this;\n this.throwIfDisposed();\n webgl_util.callAndCheck(this.gl, function () { return _this.gl.finish(); });\n };\n GPGPUContext.prototype.getQueryTimerExtension = function () {\n if (this.disjointQueryTimerExtension == null) {\n this.disjointQueryTimerExtension =\n webgl_util.getExtensionOrThrow(this.gl, environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2 ?\n 'EXT_disjoint_timer_query_webgl2' :\n 'EXT_disjoint_timer_query');\n }\n return this.disjointQueryTimerExtension;\n };\n GPGPUContext.prototype.getQueryTimerExtensionWebGL2 = function () {\n return this.getQueryTimerExtension();\n };\n GPGPUContext.prototype.getQueryTimerExtensionWebGL1 = function () {\n return this.getQueryTimerExtension();\n };\n GPGPUContext.prototype.runQuery = function (queryFn) {\n var query = this.beginQuery();\n queryFn();\n this.endQuery();\n return this.pollQueryTime(query);\n };\n GPGPUContext.prototype.beginQuery = function () {\n if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2) {\n var gl2 = this.gl;\n var ext_1 = this.getQueryTimerExtensionWebGL2();\n var query_1 = gl2.createQuery();\n gl2.beginQuery(ext_1.TIME_ELAPSED_EXT, query_1);\n return query_1;\n }\n var ext = this.getQueryTimerExtensionWebGL1();\n var query = ext.createQueryEXT();\n ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, query);\n return query;\n };\n GPGPUContext.prototype.endQuery = function () {\n if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 2) {\n var gl2 = this.gl;\n var ext_2 = this.getQueryTimerExtensionWebGL2();\n gl2.endQuery(ext_2.TIME_ELAPSED_EXT);\n return;\n }\n var ext = this.getQueryTimerExtensionWebGL1();\n ext.endQueryEXT(ext.TIME_ELAPSED_EXT);\n };\n GPGPUContext.prototype.isQueryAvailable = function (query, queryTimerVersion) {\n if (queryTimerVersion === 0) {\n return true;\n }\n if (queryTimerVersion === 2) {\n var gl2 = this.gl;\n var ext = this.getQueryTimerExtensionWebGL2();\n var available = gl2.getQueryParameter(query, gl2.QUERY_RESULT_AVAILABLE);\n var disjoint = this.gl.getParameter(ext.GPU_DISJOINT_EXT);\n return available && !disjoint;\n }\n else {\n var ext = this.getQueryTimerExtensionWebGL1();\n var available = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_AVAILABLE_EXT);\n var disjoint = this.gl.getParameter(ext.GPU_DISJOINT_EXT);\n return available && !disjoint;\n }\n };\n GPGPUContext.prototype.pollQueryTime = function (query) {\n var _this = this;\n return new Promise(function (resolve, reject) {\n var resolveWithWarning = function () {\n console.warn('Disjoint query timer never available.');\n resolve(-1);\n };\n var queryTimerVersion = environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION');\n util.repeatedTry(function () { return _this.isQueryAvailable(query, queryTimerVersion); })\n .then(function () { return resolve(_this.getQueryTime(query, queryTimerVersion)); })\n .catch(resolveWithWarning);\n });\n };\n GPGPUContext.prototype.getQueryTime = function (query, queryTimerVersion) {\n if (queryTimerVersion === 0) {\n return null;\n }\n if (queryTimerVersion === 2) {\n var gl2 = this.gl;\n var timeElapsedNanos = gl2.getQueryParameter(query, gl2.QUERY_RESULT);\n return timeElapsedNanos / 1000000;\n }\n else {\n var ext = this.getQueryTimerExtensionWebGL1();\n var timeElapsedNanos = ext.getQueryObjectEXT(query, ext.QUERY_RESULT_EXT);\n return timeElapsedNanos / 1000000;\n }\n };\n GPGPUContext.prototype.downloadMatrixDriverSetup = function (texture) {\n this.throwIfDisposed();\n webgl_util.bindColorTextureToFramebuffer(this.gl, texture, this.framebuffer);\n if (this.autoDebugValidate) {\n webgl_util.validateFramebuffer(this.gl);\n }\n };\n GPGPUContext.prototype.downloadMatrixDriverTeardown = function () {\n if (this.outputTexture != null) {\n webgl_util.bindColorTextureToFramebuffer(this.gl, this.outputTexture, this.framebuffer);\n if (this.autoDebugValidate) {\n webgl_util.validateFramebuffer(this.gl);\n }\n }\n else {\n webgl_util.unbindColorTextureFromFramebuffer(this.gl, this.framebuffer);\n }\n };\n GPGPUContext.prototype.downloadMatrixDriver = function (texture, downloadAndDecode) {\n this.downloadMatrixDriverSetup(texture);\n var result = downloadAndDecode();\n this.downloadMatrixDriverTeardown();\n return result;\n };\n GPGPUContext.prototype.downloadMatrixDriverAsync = function (texture, downloadAndDecode) {\n return __awaiter(this, void 0, void 0, function () {\n var result;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n this.downloadMatrixDriverSetup(texture);\n return [4, downloadAndDecode()];\n case 1:\n result = _a.sent();\n this.downloadMatrixDriverTeardown();\n return [2, result];\n }\n });\n });\n };\n GPGPUContext.prototype.setOutputMatrixTextureDriver = function (outputMatrixTextureMaybePacked, width, height) {\n this.throwIfDisposed();\n var gl = this.gl;\n webgl_util.bindColorTextureToFramebuffer(gl, outputMatrixTextureMaybePacked, this.framebuffer);\n if (this.autoDebugValidate) {\n webgl_util.validateFramebuffer(gl);\n }\n this.outputTexture = outputMatrixTextureMaybePacked;\n webgl_util.callAndCheck(gl, function () { return gl.viewport(0, 0, width, height); });\n webgl_util.callAndCheck(gl, function () { return gl.scissor(0, 0, width, height); });\n };\n GPGPUContext.prototype.setOutputMatrixWriteRegionDriver = function (x, y, width, height) {\n var _this = this;\n this.throwIfDisposed();\n webgl_util.callAndCheck(this.gl, function () { return _this.gl.scissor(x, y, width, height); });\n };\n GPGPUContext.prototype.throwIfDisposed = function () {\n if (this.disposed) {\n throw new Error('Attempted to use disposed GPGPUContext.');\n }\n };\n GPGPUContext.prototype.throwIfNoProgram = function () {\n if (this.program == null) {\n throw new Error('No GPU program is currently set.');\n }\n };\n return GPGPUContext;\n}());\nexports.GPGPUContext = GPGPUContext;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../../environment\");\nvar util = require(\"../../util\");\nvar shader_compiler = require(\"./shader_compiler\");\nvar NAN_UNIFORM_NAME = 'NaN';\nfunction shouldUploadNaNUniform() {\n return !environment_1.ENV.get('WEBGL_FLOAT_TEXTURE_ENABLED');\n}\nfunction compileProgram(gpgpu, program, inputs, output) {\n var userCode = program.userCode;\n var inputInfos = inputs.map(function (input, i) {\n var shapeInfo = {\n logicalShape: input.tensor.shape,\n texShape: input.texData.texShape\n };\n return { name: program.variableNames[i], shapeInfo: shapeInfo };\n });\n var inShapeInfos = inputInfos.map(function (x) { return x.shapeInfo; });\n var outShapeInfo = {\n logicalShape: output.tensor.shape,\n texShape: output.texData.texShape\n };\n var source = shader_compiler.makeShader(inputInfos, outShapeInfo, userCode, program.supportsBroadcasting === true);\n var webGLProgram = gpgpu.createProgram(source);\n var uniformLocations = {};\n for (var i = 0; i < program.variableNames.length; i++) {\n var uniformName = program.variableNames[i];\n uniformLocations[uniformName] =\n gpgpu.getUniformLocation(webGLProgram, uniformName);\n }\n if (shouldUploadNaNUniform()) {\n var throwIfNaNUniformIsNotUsed = false;\n uniformLocations[NAN_UNIFORM_NAME] = gpgpu.getUniformLocation(webGLProgram, NAN_UNIFORM_NAME, throwIfNaNUniformIsNotUsed);\n }\n return {\n program: program,\n source: source,\n webGLProgram: webGLProgram,\n uniformLocations: uniformLocations,\n gpgpu: gpgpu,\n inShapeInfos: inShapeInfos,\n outShapeInfo: outShapeInfo\n };\n}\nexports.compileProgram = compileProgram;\nfunction validateBinaryAndProgram(shapeInfos, inputs) {\n if (shapeInfos.length !== inputs.length) {\n throw Error(\"Binary was compiled with \" + shapeInfos.length + \" inputs, but \" +\n (\"was executed with \" + inputs.length + \" inputs\"));\n }\n shapeInfos.forEach(function (s, i) {\n var shapeA = s.logicalShape;\n var texShapeA = s.texShape;\n var shapeB = inputs[i].tensor.shape;\n var texShapeB = inputs[i].texData.texShape;\n if (!util.arraysEqual(shapeA, shapeB)) {\n throw Error(\"Binary was compiled with different shapes than \" +\n (\"the current args. Shapes \" + shapeA + \" and \" + shapeB + \" must match\"));\n }\n if (!util.arraysEqual(texShapeA, texShapeB)) {\n throw Error(\"Binary was compiled with different texture shapes than the\" +\n (\" current args. Shape \" + texShapeA + \" and \" + texShapeB + \" must match\"));\n }\n });\n}\nfunction runProgram(binary, inputs, output, customSetup) {\n validateBinaryAndProgram(binary.inShapeInfos, inputs);\n validateBinaryAndProgram([binary.outShapeInfo], [output]);\n var outTex = output.texData.texture;\n var outTexShape = output.texData.texShape;\n var gpgpu = binary.gpgpu;\n gpgpu.setOutputMatrixTexture(outTex, outTexShape[0], outTexShape[1]);\n gpgpu.setProgram(binary.webGLProgram);\n inputs.forEach(function (input, i) {\n var tex = input.texData.texture;\n var variableName = binary.program.variableNames[i];\n var variableUniformLocation = binary.uniformLocations[variableName];\n gpgpu.setInputMatrixTexture(tex, variableUniformLocation, i);\n });\n if (shouldUploadNaNUniform()) {\n gpgpu.gl.uniform1f(binary.uniformLocations[NAN_UNIFORM_NAME], NaN);\n }\n if (customSetup != null) {\n customSetup(gpgpu, binary.webGLProgram);\n }\n gpgpu.executeProgram();\n}\nexports.runProgram = runProgram;\nfunction makeShaderKey(program, inputs, output) {\n var keyInputs = '';\n inputs.concat(output).forEach(function (x) {\n keyInputs += x.tensor.shape + \"_\" + x.texData.texShape;\n });\n var keyUserCode = program.userCode;\n var keyBroadcast = (program.supportsBroadcasting === true).toString();\n var key = program.constructor.name;\n key += '_' + keyBroadcast + '_' + keyInputs + '_' + keyUserCode;\n return key;\n}\nexports.makeShaderKey = makeShaderKey;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar shader_compiler_1 = require(\"./shader_compiler\");\nvar WhereProgram = (function () {\n function WhereProgram(cRank, shape, rank) {\n this.variableNames = ['c', 'a', 'b'];\n this.outputShape = shape;\n var cCoords;\n var abCoords;\n if (rank > 4) {\n throw Error(\"Where for rank \" + rank + \" is not yet supported\");\n }\n if (rank === 1) {\n abCoords = \"resRC\";\n cCoords = \"resRC\";\n }\n else {\n var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w'];\n var cCoordVars = [];\n var abCoordVars = [];\n for (var i = 0; i < shape.length; i++) {\n abCoordVars.push(\"\" + currentCoords[i]);\n if (i < cRank) {\n cCoordVars.push(\"\" + currentCoords[i]);\n }\n }\n cCoords = cCoordVars.join();\n abCoords = abCoordVars.join();\n }\n var dtype = shader_compiler_1.getCoordsDataType(rank);\n this.userCode = \"\\n void main() {\\n \" + dtype + \" resRC = getOutputCoords();\\n float cVal = getC(\" + cCoords + \");\\n if (cVal >= 1.0) {\\n setOutput(getA(\" + abCoords + \"));\\n } else {\\n setOutput(getB(\" + abCoords + \"));\\n }\\n }\\n \";\n }\n return WhereProgram;\n}());\nexports.WhereProgram = WhereProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar LRNProgram = (function () {\n function LRNProgram(xShape, radius, bias, alpha, beta) {\n this.variableNames = ['x'];\n this.outputShape = [];\n var rad = radius;\n var maxD = xShape[3] - 1;\n this.outputShape = xShape;\n var powOperator;\n var basis = \"float(\" + bias + \") + float(\" + alpha + \") * sum\";\n if (beta === 0.5) {\n powOperator = \"inversesqrt(\" + basis + \")\";\n }\n else if (beta === 1.0) {\n powOperator = \"1.0/(\" + basis + \")\";\n }\n else {\n powOperator = \"exp(log(\" + basis + \") * float(-\" + beta + \"));\";\n }\n this.userCode = \"\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int b = coords[0];\\n int r = coords[1];\\n int c = coords[2];\\n int d = coords[3];\\n float x = getX(b, r, c, d);\\n float sum = 0.0;\\n for (int j = -\" + rad + \"; j <= \" + rad + \"; j++) {\\n int idx = d + j;\\n if (idx >= 0 && idx <= \" + maxD + \") {\\n float z = getX(b, r, c, idx);\\n sum += z * z;\\n }\\n }\\n float val = x * \" + powOperator + \";\\n setOutput(val);\\n }\\n \";\n }\n return LRNProgram;\n}());\nexports.LRNProgram = LRNProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar MaxPool2DBackpropProgram = (function () {\n function MaxPool2DBackpropProgram(convInfo) {\n this.variableNames = ['dy', 'maxPos'];\n this.outputShape = convInfo.inShape;\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var padTop = filterHeight - 1 - convInfo.padInfo.top;\n var padLeft = filterWidth - 1 - convInfo.padInfo.left;\n var lastIndex = filterHeight * filterWidth - 1;\n this.userCode = \"\\n const ivec2 pads = ivec2(\" + padTop + \", \" + padLeft + \");\\n\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int b = coords[0];\\n int d = coords[3];\\n\\n ivec2 dyRCCorner = coords.yz - pads;\\n int dyRCorner = dyRCCorner.x;\\n int dyCCorner = dyRCCorner.y;\\n\\n // Convolve dy(?, ?, d) with pos mask(:, :, d) to get dx(xR, xC, d).\\n // ? = to be determined. : = across all values in that axis.\\n float dotProd = 0.0;\\n for (int wR = 0; wR < \" + filterHeight + \"; wR++) {\\n float dyR = float(dyRCorner + wR) / \" + strideHeight + \".0;\\n\\n if (dyR < 0.0 || dyR >= \" + convInfo.outHeight + \".0 || fract(dyR) > 0.0) {\\n continue;\\n }\\n int idyR = int(dyR);\\n\\n for (int wC = 0; wC < \" + filterWidth + \"; wC++) {\\n float dyC = float(dyCCorner + wC) / \" + strideWidth + \".0;\\n\\n if (dyC < 0.0 || dyC >= \" + convInfo.outWidth + \".0 ||\\n fract(dyC) > 0.0) {\\n continue;\\n }\\n int idyC = int(dyC);\\n\\n float dyValue = getDy(b, idyR, idyC, d);\\n int maxPosValue = \" + lastIndex + \" - int(getMaxPos(b, idyR, idyC, d));\\n\\n // Get the current value, check it against the value from the\\n // position matrix.\\n int curPosValue = wR * \" + filterWidth + \" + wC;\\n float mask = float(maxPosValue == curPosValue ? 1.0 : 0.0);\\n\\n dotProd += dyValue * mask;\\n }\\n }\\n setOutput(dotProd);\\n }\\n \";\n }\n return MaxPool2DBackpropProgram;\n}());\nexports.MaxPool2DBackpropProgram = MaxPool2DBackpropProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar MatMulProgram = (function () {\n function MatMulProgram(aShape, bShape, transposeA, transposeB) {\n if (transposeA === void 0) { transposeA = false; }\n if (transposeB === void 0) { transposeB = false; }\n this.variableNames = ['matrixA', 'matrixB'];\n var outerShapeA = transposeA ? aShape[1] : aShape[0];\n var outerShapeB = transposeB ? bShape[0] : bShape[1];\n var sharedDim = transposeA ? aShape[0] : aShape[1];\n this.outputShape = [outerShapeA, outerShapeB];\n var aSnippetFromOffset = function (vec4Offset, indexVar) {\n return transposeA ? indexVar + \" + \" + vec4Offset + \", aRow\" :\n \"aRow, \" + indexVar + \" + \" + vec4Offset;\n };\n var bSnippetFromOffset = function (vec4Offset, indexVar) {\n return transposeB ? \"bCol, \" + indexVar + \" + \" + vec4Offset :\n indexVar + \" + \" + vec4Offset + \", bCol\";\n };\n var sharedDimNearestVec4 = Math.floor(sharedDim / 4) * 4;\n var sharedDimVec4Remainder = sharedDim % 4;\n this.userCode = \" float dotARowBCol(int aRow, int bCol) {\\n float result = 0.0;\\n for (int i = 0; i < \" + sharedDimNearestVec4 + \"; i += 4) {\\n vec4 a = vec4(\\n getMatrixA(\" + aSnippetFromOffset(0, 'i') + \"),\\n getMatrixA(\" + aSnippetFromOffset(1, 'i') + \"),\\n getMatrixA(\" + aSnippetFromOffset(2, 'i') + \"),\\n getMatrixA(\" + aSnippetFromOffset(3, 'i') + \")\\n );\\n vec4 b = vec4(\\n getMatrixB(\" + bSnippetFromOffset(0, 'i') + \"),\\n getMatrixB(\" + bSnippetFromOffset(1, 'i') + \"),\\n getMatrixB(\" + bSnippetFromOffset(2, 'i') + \"),\\n getMatrixB(\" + bSnippetFromOffset(3, 'i') + \")\\n );\\n\\n result += dot(a, b);\\n }\\n\\n if (\" + (sharedDimVec4Remainder === 1) + \") {\\n result += getMatrixA(\" + aSnippetFromOffset(0, sharedDimNearestVec4) + \") *\\n getMatrixB(\" + bSnippetFromOffset(0, sharedDimNearestVec4) + \");\\n } else if (\" + (sharedDimVec4Remainder === 2) + \") {\\n vec2 a = vec2(\\n getMatrixA(\" + aSnippetFromOffset(0, sharedDimNearestVec4) + \"),\\n getMatrixA(\" + aSnippetFromOffset(1, sharedDimNearestVec4) + \")\\n );\\n vec2 b = vec2(\\n getMatrixB(\" + bSnippetFromOffset(0, sharedDimNearestVec4) + \"),\\n getMatrixB(\" + bSnippetFromOffset(1, sharedDimNearestVec4) + \")\\n );\\n result += dot(a, b);\\n } else if (\" + (sharedDimVec4Remainder === 3) + \") {\\n vec3 a = vec3(\\n getMatrixA(\" + aSnippetFromOffset(0, sharedDimNearestVec4) + \"),\\n getMatrixA(\" + aSnippetFromOffset(1, sharedDimNearestVec4) + \"),\\n getMatrixA(\" + aSnippetFromOffset(2, sharedDimNearestVec4) + \")\\n );\\n vec3 b = vec3(\\n getMatrixB(\" + bSnippetFromOffset(0, sharedDimNearestVec4) + \"),\\n getMatrixB(\" + bSnippetFromOffset(1, sharedDimNearestVec4) + \"),\\n getMatrixB(\" + bSnippetFromOffset(2, sharedDimNearestVec4) + \")\\n );\\n result += dot(a, b);\\n }\\n\\n return result;\\n }\\n\\n void main() {\\n ivec2 resRC = getOutputCoords();\\n setOutput(dotARowBCol(resRC.x, resRC.y));\\n }\\n \";\n }\n return MatMulProgram;\n}());\nexports.MatMulProgram = MatMulProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar MultinomialProgram = (function () {\n function MultinomialProgram(batchSize, numOutcomes, numSamples) {\n this.variableNames = ['probs'];\n this.outputShape = [batchSize, numSamples];\n this.userCode = \"\\n uniform float seed;\\n\\n void main() {\\n ivec2 coords = getOutputCoords();\\n int batch = coords[0];\\n\\n float r = random(seed);\\n float cdf = 0.0;\\n\\n for (int i = 0; i < \" + (numOutcomes - 1) + \"; i++) {\\n cdf += getProbs(batch, i);\\n\\n if (r < cdf) {\\n setOutput(float(i));\\n return;\\n }\\n }\\n\\n // If no other event happened, last event happened.\\n setOutput(float(\" + (numOutcomes - 1) + \"));\\n }\\n \";\n }\n MultinomialProgram.prototype.getCustomSetupFunc = function (seed) {\n var _this = this;\n return function (gpgpu, webGLProgram) {\n if (_this.seedLoc == null) {\n _this.seedLoc = gpgpu.getUniformLocation(webGLProgram, 'seed');\n }\n gpgpu.gl.uniform1f(_this.seedLoc, seed);\n };\n };\n return MultinomialProgram;\n}());\nexports.MultinomialProgram = MultinomialProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar OneHotProgram = (function () {\n function OneHotProgram(numIndices, depth, onValue, offValue) {\n this.variableNames = ['indices'];\n this.outputShape = [numIndices, depth];\n this.userCode = \"\\n void main() {\\n ivec2 coords = getOutputCoords();\\n int index = round(getIndices(coords.x));\\n setOutput(mix(float(\" + offValue + \"), float(\" + onValue + \"),\\n float(index == coords.y)));\\n }\\n \";\n }\n return OneHotProgram;\n}());\nexports.OneHotProgram = OneHotProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar shader_compiler_1 = require(\"./shader_compiler\");\nvar PadProgram = (function () {\n function PadProgram(xShape, paddings, constantValue) {\n this.variableNames = ['x'];\n this.outputShape = paddings.map(function (p, i) { return p[0] + xShape[i] + p[1]; });\n var rank = xShape.length;\n var type = shader_compiler_1.getCoordsDataType(rank);\n var start = paddings.map(function (p) { return p[0]; }).join(',');\n var end = paddings.map(function (p, i) { return p[0] + xShape[i]; }).join(',');\n var unpackedCoords = ['coords[0]', 'coords[1]', 'coords[2]', 'coords[3]'].slice(0, rank);\n if (rank === 1) {\n this.userCode = \"\\n int start = \" + start + \";\\n int end = \" + end + \";\\n\\n void main() {\\n int outC = getOutputCoords();\\n if (outC < start || outC >= end) {\\n setOutput(float(\" + constantValue + \"));\\n } else {\\n setOutput(getX(outC - start));\\n }\\n }\\n \";\n return;\n }\n this.userCode = \"\\n \" + type + \" start = \" + type + \"(\" + start + \");\\n \" + type + \" end = \" + type + \"(\" + end + \");\\n\\n void main() {\\n \" + type + \" outC = getOutputCoords();\\n if (any(lessThan(outC, start)) || any(greaterThanEqual(outC, end))) {\\n setOutput(float(\" + constantValue + \"));\\n } else {\\n \" + type + \" coords = outC - start;\\n setOutput(getX(\" + unpackedCoords + \"));\\n }\\n }\\n \";\n }\n return PadProgram;\n}());\nexports.PadProgram = PadProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar Pool2DProgram = (function () {\n function Pool2DProgram(convInfo, poolType, computePositions) {\n this.variableNames = ['x'];\n if (poolType === 'avg' && computePositions) {\n throw new Error('Cannot compute positions for average pool.');\n }\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var padTop = convInfo.padInfo.top;\n var padLeft = convInfo.padInfo.left;\n this.outputShape = convInfo.outShape;\n var isAvgPool = poolType === 'avg';\n var initializationValue = '0.0';\n if (!isAvgPool) {\n initializationValue = '-1.0 / 0.0';\n }\n if (computePositions) {\n var compareOp_1 = '>=';\n this.userCode = \"\\n const ivec2 strides = ivec2(\" + strideHeight + \", \" + strideWidth + \");\\n const ivec2 pads = ivec2(\" + padTop + \", \" + padLeft + \");\\n\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int batch = coords[0];\\n int d = coords[3];\\n\\n ivec2 xRCCorner = coords.yz * strides - pads;\\n int xRCorner = xRCCorner.x;\\n int xCCorner = xRCCorner.y;\\n\\n // max/min x(?, ?, d) to get y(yR, yC, d).\\n // ? = to be determined\\n float minMaxValue = 0.0;\\n float minMaxValueFound = 0.0;\\n int minMaxPosition = 0;\\n float avgValue = 0.0;\\n\\n for (int wR = 0; wR < \" + filterHeight + \"; wR++) {\\n int xR = xRCorner + wR;\\n\\n if (xR < 0 || xR >= \" + convInfo.inHeight + \") {\\n continue;\\n }\\n\\n for (int wC = 0; wC < \" + filterWidth + \"; wC++) {\\n int xC = xCCorner + wC;\\n\\n if (xC < 0 || xC >= \" + convInfo.inWidth + \") {\\n continue;\\n }\\n\\n float value = getX(batch, xR, xC, d);\\n\\n // If a min / max value has already been found, use it. If not,\\n // use the current value.\\n float currMinMaxValue = mix(\\n value, minMaxValue, minMaxValueFound);\\n if (value \" + compareOp_1 + \" currMinMaxValue) {\\n minMaxValue = value;\\n minMaxValueFound = 1.0;\\n minMaxPosition = wR * \" + filterWidth + \" + wC;\\n }\\n }\\n }\\n setOutput(float(minMaxPosition));\\n }\\n \";\n return;\n }\n var compareOp = 'max';\n var returnValue = poolType + \"(\" + poolType + \"(\" + poolType + \"(\" +\n 'minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])';\n if (poolType === 'avg') {\n returnValue = \"avgValue / count\";\n }\n var filterWidthNearestVec4 = Math.floor(filterWidth / 4) * 4;\n var filterWidthVec4Remainder = filterWidth % 4;\n var updateSnippet = \"\\n if (\" + isAvgPool + \") {\\n avgValue += dot(values, ones);\\n } else {\\n minMaxValue = \" + compareOp + \"(values, minMaxValue);\\n }\\n \";\n this.userCode = \"\\n const ivec2 strides = ivec2(\" + strideHeight + \", \" + strideWidth + \");\\n const ivec2 pads = ivec2(\" + padTop + \", \" + padLeft + \");\\n const float initializationValue = \" + initializationValue + \";\\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\\n\\n float count = 0.0;\\n\\n float getValue(int batch, int xR, int xC, int d) {\\n if (xC < 0 || xC >= \" + convInfo.inWidth + \") {\\n return initializationValue;\\n }\\n count += 1.0;\\n return getX(batch, xR, xC, d);\\n }\\n\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int batch = coords[0];\\n int d = coords[3];\\n\\n ivec2 xRCCorner = coords.yz * strides - pads;\\n int xRCorner = xRCCorner.x;\\n int xCCorner = xRCCorner.y;\\n\\n // max/min x(?, ?, d) to get y(yR, yC, d).\\n // ? = to be determined\\n vec4 minMaxValue = vec4(\" + initializationValue + \");\\n float avgValue = 0.0;\\n count = 0.0;\\n\\n for (int wR = 0; wR < \" + filterHeight + \"; wR++) {\\n int xR = xRCorner + wR;\\n\\n if (xR < 0 || xR >= \" + convInfo.inHeight + \") {\\n continue;\\n }\\n\\n for (int wC = 0; wC < \" + filterWidthNearestVec4 + \"; wC += 4) {\\n int xC = xCCorner + wC;\\n\\n vec4 values = vec4(\\n getValue(batch, xR, xC, d),\\n getValue(batch, xR, xC + 1, d),\\n getValue(batch, xR, xC + 2, d),\\n getValue(batch, xR, xC + 3, d)\\n );\\n\\n \" + updateSnippet + \"\\n }\\n\\n int xC = xCCorner + \" + filterWidthNearestVec4 + \";\\n if (\" + (filterWidthVec4Remainder === 1) + \") {\\n vec4 values = vec4(\\n getValue(batch, xR, xC, d),\\n initializationValue,\\n initializationValue,\\n initializationValue\\n );\\n\\n \" + updateSnippet + \"\\n } else if (\" + (filterWidthVec4Remainder === 2) + \") {\\n vec4 values = vec4(\\n getValue(batch, xR, xC, d),\\n getValue(batch, xR, xC + 1, d),\\n initializationValue,\\n initializationValue\\n );\\n\\n \" + updateSnippet + \"\\n } else if (\" + (filterWidthVec4Remainder === 3) + \") {\\n vec4 values = vec4(\\n getValue(batch, xR, xC, d),\\n getValue(batch, xR, xC + 1, d),\\n getValue(batch, xR, xC + 2, d),\\n initializationValue\\n );\\n\\n \" + updateSnippet + \"\\n }\\n }\\n setOutput(\" + returnValue + \");\\n }\\n \";\n }\n return Pool2DProgram;\n}());\nexports.Pool2DProgram = Pool2DProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar ReduceProgram = (function () {\n function ReduceProgram(reduceInfo, reduceType) {\n this.variableNames = ['x'];\n var windowSize = reduceInfo.windowSize;\n var batchSize = reduceInfo.batchSize;\n var inSize = reduceInfo.inSize;\n var outSize = Math.ceil(inSize / windowSize);\n this.outputShape = [batchSize, outSize];\n var isReduceSum = reduceType === 'sum';\n var initializationValue = '0.0';\n if (!isReduceSum) {\n if (reduceType === 'min') {\n initializationValue = '1.0 / 0.0';\n }\n else {\n initializationValue = '-1.0 / 0.0';\n }\n }\n var compareOp = reduceType === 'min' ? 'min' : 'max';\n var returnValue = reduceType + \"(\" + reduceType + \"(\" + reduceType + \"(\" +\n 'minMaxValue[0], minMaxValue[1]), minMaxValue[2]), minMaxValue[3])';\n if (reduceType === 'sum') {\n returnValue = \"sumValue\";\n }\n var windowSizeNearestVec4 = Math.floor(windowSize / 4) * 4;\n var windowSizeVec4Remainder = windowSize % 4;\n var updateSnippet = \"\\n if (\" + isReduceSum + \") {\\n sumValue += dot(values, ones);\\n } else {\\n minMaxValue = \" + compareOp + \"(values, minMaxValue);\\n }\\n \";\n var checkOutOfBounds = '';\n if (inSize % windowSize > 0) {\n checkOutOfBounds = \"\\n if (inIdx < 0 || inIdx >= \" + inSize + \") {\\n return initializationValue;\\n }\\n \";\n }\n this.userCode = \"\\n const float initializationValue = \" + initializationValue + \";\\n const vec4 ones = vec4(1.0, 1.0, 1.0, 1.0);\\n\\n float getValue(int batch, int inIdx) {\\n \" + checkOutOfBounds + \"\\n return getX(batch, inIdx);\\n }\\n\\n void main() {\\n ivec2 coords = getOutputCoords();\\n int batch = coords[0];\\n int outIdx = coords[1];\\n int inOffset = outIdx * \" + windowSize + \";\\n\\n vec4 minMaxValue = vec4(\" + initializationValue + \");\\n float sumValue = 0.0;\\n\\n for (int i = 0; i < \" + windowSizeNearestVec4 + \"; i += 4) {\\n int inIdx = inOffset + i;\\n vec4 values = vec4(\\n getValue(batch, inIdx),\\n getValue(batch, inIdx + 1),\\n getValue(batch, inIdx + 2),\\n getValue(batch, inIdx + 3)\\n );\\n\\n \" + updateSnippet + \"\\n }\\n\\n int inIdx = inOffset + \" + windowSizeNearestVec4 + \";\\n if (\" + (windowSizeVec4Remainder === 1) + \") {\\n vec4 values = vec4(\\n getValue(batch, inIdx),\\n initializationValue,\\n initializationValue,\\n initializationValue\\n );\\n \" + updateSnippet + \"\\n } else if (\" + (windowSizeVec4Remainder === 2) + \") {\\n vec4 values = vec4(\\n getValue(batch, inIdx),\\n getValue(batch, inIdx + 1),\\n initializationValue,\\n initializationValue\\n );\\n \" + updateSnippet + \"\\n } else if (\" + (windowSizeVec4Remainder === 3) + \") {\\n vec4 values = vec4(\\n getValue(batch, inIdx),\\n getValue(batch, inIdx + 1),\\n getValue(batch, inIdx + 2),\\n initializationValue\\n );\\n \" + updateSnippet + \"\\n }\\n setOutput(\" + returnValue + \");\\n }\\n \";\n }\n return ReduceProgram;\n}());\nexports.ReduceProgram = ReduceProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar ResizeBilinearBackpropProgram = (function () {\n function ResizeBilinearBackpropProgram(dy, x, alignCorners) {\n this.variableNames = ['dy'];\n this.outputShape = [];\n this.outputShape = x.shape;\n var _a = x.shape, xHeight = _a[1], xWidth = _a[2];\n var _b = dy.shape, yHeight = _b[1], yWidth = _b[2];\n var effectiveXSize = [\n (alignCorners && yHeight > 1) ? xHeight - 1 : xHeight,\n (alignCorners && yWidth > 1) ? xWidth - 1 : xWidth\n ];\n var effectiveYSize = [\n (alignCorners && yHeight > 1) ? yHeight - 1 : yHeight,\n (alignCorners && yWidth > 1) ? yWidth - 1 : yWidth\n ];\n var heightScale = effectiveXSize[0] / effectiveYSize[0];\n var widthScale = effectiveXSize[1] / effectiveYSize[1];\n var invHeightScale = 1 / heightScale;\n var invWidthScale = 1 / widthScale;\n var winHeight = (Math.ceil(invHeightScale) * 2) + 2;\n var winWidth = (Math.ceil(invWidthScale) * 2) + 2;\n this.userCode = \"\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int b = coords[0];\\n int d = coords[3];\\n int r = coords[1];\\n int c = coords[2];\\n\\n float accumulator = 0.0;\\n\\n const float heightScale = float(\" + heightScale + \");\\n const float widthScale = float(\" + widthScale + \");\\n\\n const float invHeightScale = float(\" + invHeightScale + \");\\n const float invWidthScale = float(\" + invWidthScale + \");\\n\\n const int winHeight = int(\" + winHeight + \");\\n const int winWidth = int(\" + winWidth + \");\\n\\n // Compute bounds for where in dy we will look\\n float startRLerp = floor(float(r) * invHeightScale);\\n int startDyR = int(startRLerp - float(winHeight / 2));\\n\\n float startCLerp = floor(float(c) * invWidthScale);\\n int startDyC = int(startCLerp - float(winWidth / 2));\\n\\n // Loop over dy\\n for (int dyROffset = 0; dyROffset < winHeight; dyROffset++) {\\n int dyR = dyROffset + startDyR;\\n\\n // Guard against the window exceeding the bounds of dy\\n if (dyR < 0 || dyR >= \" + yHeight + \") {\\n continue;\\n }\\n\\n for (int dyCOffset = 0; dyCOffset < winWidth; dyCOffset++) {\\n int dyC = dyCOffset + startDyC;\\n\\n // Guard against the window exceeding the bounds of dy\\n if (dyC < 0 || dyC >= \" + yWidth + \") {\\n continue;\\n }\\n\\n float dxR = float(dyR) * heightScale;\\n int topDxRIndex = int(floor(dxR));\\n int bottomDxRIndex = int(min(ceil(dxR), \" + (xHeight - 1) + \".0));\\n float dxRLerp = dxR - float(topDxRIndex);\\n float inverseDxRLerp = 1.0 - dxRLerp;\\n\\n float dxC = float(dyC) * widthScale;\\n int leftDxCIndex = int(floor(dxC));\\n int rightDxCIndex = int(min(ceil(dxC), \" + (xWidth - 1) + \".0));\\n float dxCLerp = dxC - float(leftDxCIndex);\\n float inverseDxCLerp = 1.0 - dxCLerp;\\n\\n if (r == topDxRIndex && c == leftDxCIndex) {\\n // topLeft\\n accumulator +=\\n getDy(b, dyR, dyC, d) * inverseDxRLerp * inverseDxCLerp;\\n }\\n\\n if (r == topDxRIndex && c == rightDxCIndex) {\\n // topRight\\n accumulator += getDy(b, dyR, dyC, d) * inverseDxRLerp * dxCLerp;\\n }\\n\\n if (r == bottomDxRIndex && c == leftDxCIndex) {\\n // bottomLeft\\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * inverseDxCLerp;\\n }\\n\\n if (r == bottomDxRIndex && c == rightDxCIndex) {\\n // bottomRight\\n accumulator += getDy(b, dyR, dyC, d) * dxRLerp * dxCLerp;\\n }\\n }\\n }\\n // End loop over dy\\n\\n setOutput(accumulator);\\n }\\n \";\n }\n return ResizeBilinearBackpropProgram;\n}());\nexports.ResizeBilinearBackpropProgram = ResizeBilinearBackpropProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar ResizeBilinearProgram = (function () {\n function ResizeBilinearProgram(inputShape, newHeight, newWidth, alignCorners) {\n this.variableNames = ['A'];\n this.outputShape = [];\n var batch = inputShape[0], oldHeight = inputShape[1], oldWidth = inputShape[2], depth = inputShape[3];\n this.outputShape = [batch, newHeight, newWidth, depth];\n var effectiveInSize = [\n (alignCorners && newHeight > 1) ? oldHeight - 1 : oldHeight,\n (alignCorners && newWidth > 1) ? oldWidth - 1 : oldWidth\n ];\n var effectiveOutSize = [\n (alignCorners && newHeight > 1) ? newHeight - 1 : newHeight,\n (alignCorners && newWidth > 1) ? newWidth - 1 : newWidth\n ];\n this.userCode = \"\\n const vec2 effectiveInputOverOutputRatioRC = vec2(\\n \" + effectiveInSize[0] / effectiveOutSize[0] + \",\\n \" + effectiveInSize[1] / effectiveOutSize[1] + \");\\n const vec2 inputShapeRC = vec2(\" + oldHeight + \".0, \" + oldWidth + \".0);\\n\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int b = coords[0];\\n int d = coords[3];\\n ivec2 yRC = coords.yz;\\n\\n // Fractional source index.\\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\\n\\n // Compute the four integer indices.\\n ivec2 sourceFloorRC = ivec2(sourceFracIndexRC);\\n ivec2 sourceCeilRC = ivec2(\\n min(inputShapeRC - 1.0, ceil(sourceFracIndexRC)));\\n\\n float topLeft = getA(b, sourceFloorRC.x, sourceFloorRC.y, d);\\n float bottomLeft = getA(b, sourceCeilRC.x, sourceFloorRC.y, d);\\n float topRight = getA(b, sourceFloorRC.x, sourceCeilRC.y, d);\\n float bottomRight = getA(b, sourceCeilRC.x, sourceCeilRC.y, d);\\n\\n vec2 fracRC = sourceFracIndexRC - vec2(sourceFloorRC);\\n\\n float top = topLeft + (topRight - topLeft) * fracRC.y;\\n float bottom = bottomLeft + (bottomRight - bottomLeft) * fracRC.y;\\n float newValue = top + (bottom - top) * fracRC.x;\\n\\n setOutput(newValue);\\n }\\n \";\n }\n return ResizeBilinearProgram;\n}());\nexports.ResizeBilinearProgram = ResizeBilinearProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar ResizeNearestNeighborProgram = (function () {\n function ResizeNearestNeighborProgram(inputShape, newHeight, newWidth, alignCorners) {\n this.variableNames = ['A'];\n this.outputShape = [];\n var batch = inputShape[0], oldHeight = inputShape[1], oldWidth = inputShape[2], depth = inputShape[3];\n this.outputShape = [batch, newHeight, newWidth, depth];\n var effectiveInSize = alignCorners ? [oldHeight - 1, oldWidth - 1] : [oldHeight, oldWidth];\n var effectiveOutSize = alignCorners ? [newHeight - 1, newWidth - 1] : [newHeight, newWidth];\n var roundBase = alignCorners ? '0.5' : '0.0';\n this.userCode = \"\\n const vec2 effectiveInputOverOutputRatioRC = vec2(\\n \" + effectiveInSize[0] / effectiveOutSize[0] + \",\\n \" + effectiveInSize[1] / effectiveOutSize[1] + \");\\n const vec2 inputShapeRC = vec2(\" + oldHeight + \".0, \" + oldWidth + \".0);\\n\\n void main() {\\n ivec4 coords = getOutputCoords();\\n int b = coords[0];\\n int d = coords[3];\\n ivec2 yRC = coords.yz;\\n\\n // Fractional source index.\\n vec2 sourceFracIndexRC = vec2(yRC) * effectiveInputOverOutputRatioRC;\\n\\n // Compute the coordinators of nearest neighbor point.\\n ivec2 sourceNearestRC = ivec2(\\n min(inputShapeRC - 1.0, floor(sourceFracIndexRC + \" + roundBase + \")));\\n\\n float newValue = getA(b, sourceNearestRC.x, sourceNearestRC.y, d);\\n\\n setOutput(newValue);\\n }\\n \";\n }\n return ResizeNearestNeighborProgram;\n}());\nexports.ResizeNearestNeighborProgram = ResizeNearestNeighborProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar shader_compiler_1 = require(\"./shader_compiler\");\nvar ReverseProgram = (function () {\n function ReverseProgram(xShape, axis) {\n this.variableNames = ['x'];\n var rank = xShape.length;\n if (rank > 4) {\n throw new Error(\"WebGL backend: Reverse of rank-\" + rank + \" tensor is not yet supported\");\n }\n this.outputShape = xShape;\n if (rank === 1) {\n this.userCode = \"\\n void main() {\\n int coord = getOutputCoords();\\n setOutput(getX(\" + xShape[0] + \" - coord - 1));\\n }\\n \";\n return;\n }\n var getInCoord = function (i) {\n if (axis.indexOf(i) !== -1 && xShape[i] !== 1) {\n return xShape[i] + \" - coords[\" + i + \"] - 1\";\n }\n return \"coords[\" + i + \"]\";\n };\n var inCoords = xShape.map(function (_, i) { return getInCoord(i); }).join(',');\n var type = shader_compiler_1.getCoordsDataType(rank);\n this.userCode = \"\\n void main() {\\n \" + type + \" coords = getOutputCoords();\\n setOutput(getX(\" + inCoords + \"));\\n }\\n \";\n }\n return ReverseProgram;\n}());\nexports.ReverseProgram = ReverseProgram;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar shader_compiler_1 = require(\"./shader_compiler\");\nvar SliceProgram = (function () {\n function SliceProgram(destSize) {\n this.variableNames = ['source'];\n this.outputShape = destSize;\n this.rank = destSize.length;\n var dtype = shader_compiler_1.getCoordsDataType(this.rank);\n var sourceCoords = getCoords(this.rank);\n this.userCode = \"\\n uniform \" + dtype + \" start;\\n\\n void main() {\\n \" + dtype + \" sourceLoc = start + getOutputCoords();\\n setOutput(getSource(\" + sourceCoords + \"));\\n }\\n \";\n }\n SliceProgram.prototype.getCustomSetupFunc = function (start) {\n var _this = this;\n if (start.length !== this.rank) {\n throw Error(\"The rank (\" + this.rank + \") of the program must match the \" +\n (\"length of start (\" + start.length + \")\"));\n }\n return function (gpgpu, webGLProgram) {\n if (_this.startLoc == null) {\n _this.startLoc = gpgpu.getUniformLocationNoThrow(webGLProgram, 'start');\n if (_this.startLoc == null) {\n return;\n }\n }\n if (_this.rank === 1) {\n gpgpu.gl.uniform1i(_this.startLoc, start[0]);\n }\n else if (_this.rank === 2) {\n gpgpu.gl.uniform2i(_this.startLoc, start[0], start[1]);\n }\n else if (_this.rank === 3) {\n gpgpu.gl.uniform3i(_this.startLoc, start[0], start[1], start[2]);\n }\n else if (_this.rank === 4) {\n gpgpu.gl.uniform4i(_this.startLoc, start[0], start[1], start[2], start[3]);\n }\n else {\n throw Error(\"Slicing for rank \" + _this.rank + \" is not yet supported\");\n }\n };\n };\n return SliceProgram;\n}());\nexports.SliceProgram = SliceProgram;\nfunction getCoords(rank) {\n if (rank === 1) {\n return 'sourceLoc';\n }\n else if (rank === 2) {\n return 'sourceLoc.x, sourceLoc.y';\n }\n else if (rank === 3) {\n return 'sourceLoc.x, sourceLoc.y, sourceLoc.z';\n }\n else if (rank === 4) {\n return 'sourceLoc.x, sourceLoc.y, sourceLoc.z, sourceLoc.w';\n }\n else {\n throw Error(\"Slicing for rank \" + rank + \" is not yet supported\");\n }\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tex_util_1 = require(\"./tex_util\");\nvar TextureManager = (function () {\n function TextureManager(gpgpu) {\n this.gpgpu = gpgpu;\n this.numUsedTextures = 0;\n this.numFreeTextures = 0;\n this.freeTextures = {};\n this.logEnabled = false;\n this.allocatedTextures = [];\n this.usedTextureCount = {};\n }\n TextureManager.prototype.acquireTexture = function (shapeRC, texType) {\n if (texType === void 0) { texType = tex_util_1.TextureType.FLOAT; }\n var shapeKey = getKeyFromTextureShape(shapeRC, texType);\n if (!(shapeKey in this.freeTextures)) {\n this.freeTextures[shapeKey] = [];\n }\n if (!(shapeKey in this.usedTextureCount)) {\n this.usedTextureCount[shapeKey] = 0;\n }\n this.usedTextureCount[shapeKey]++;\n if (this.freeTextures[shapeKey].length > 0) {\n this.numFreeTextures--;\n this.numUsedTextures++;\n this.log();\n return this.freeTextures[shapeKey].shift();\n }\n this.numUsedTextures++;\n this.log();\n var newTexture = this.gpgpu.createMatrixTexture(shapeRC[0], shapeRC[1]);\n this.allocatedTextures.push(newTexture);\n return newTexture;\n };\n TextureManager.prototype.releaseTexture = function (texture, shape, texType) {\n if (texType === void 0) { texType = tex_util_1.TextureType.FLOAT; }\n var shapeKey = getKeyFromTextureShape(shape, texType);\n if (!(shapeKey in this.freeTextures)) {\n this.freeTextures[shapeKey] = [];\n }\n this.freeTextures[shapeKey].push(texture);\n this.numFreeTextures++;\n this.numUsedTextures--;\n this.usedTextureCount[shapeKey]--;\n this.log();\n };\n TextureManager.prototype.log = function () {\n if (!this.logEnabled) {\n return;\n }\n var total = this.numFreeTextures + this.numUsedTextures;\n console.log('Free/Used', this.numFreeTextures + \" / \" + this.numUsedTextures, \"(\" + total + \")\");\n };\n TextureManager.prototype.getNumUsedTextures = function () {\n return this.numUsedTextures;\n };\n TextureManager.prototype.getNumFreeTextures = function () {\n return this.numFreeTextures;\n };\n TextureManager.prototype.dispose = function () {\n var _this = this;\n if (this.allocatedTextures == null) {\n return;\n }\n this.allocatedTextures.forEach(function (texture) {\n _this.gpgpu.deleteMatrixTexture(texture);\n });\n this.freeTextures = null;\n this.allocatedTextures = null;\n this.usedTextureCount = null;\n this.numUsedTextures = 0;\n this.numFreeTextures = 0;\n };\n return TextureManager;\n}());\nexports.TextureManager = TextureManager;\nfunction getKeyFromTextureShape(shapeRowsCol, texType) {\n return shapeRowsCol[0] + \"_\" + shapeRowsCol[1] + \"_\" + texType;\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar shader_compiler_1 = require(\"./shader_compiler\");\nvar TileProgram = (function () {\n function TileProgram(aShape, reps) {\n this.variableNames = ['A'];\n var outputShape = new Array(aShape.length);\n for (var i = 0; i < outputShape.length; i++) {\n outputShape[i] = aShape[i] * reps[i];\n }\n this.outputShape = outputShape;\n this.rank = outputShape.length;\n var dtype = shader_compiler_1.getCoordsDataType(this.rank);\n var sourceCoords = getSourceCoords(aShape);\n this.userCode = \"\\n void main() {\\n \" + dtype + \" resRC = getOutputCoords();\\n setOutput(getA(\" + sourceCoords + \"));\\n }\\n \";\n }\n return TileProgram;\n}());\nexports.TileProgram = TileProgram;\nfunction getSourceCoords(aShape) {\n var rank = aShape.length;\n if (rank > 4) {\n throw Error(\"Tile for rank \" + rank + \" is not yet supported\");\n }\n if (rank === 1) {\n return \"imod(resRC, \" + aShape[0] + \")\";\n }\n var currentCoords = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w'];\n var sourceCoords = [];\n for (var i = 0; i < aShape.length; i++) {\n sourceCoords.push(\"imod(\" + currentCoords[i] + \", \" + aShape[i] + \")\");\n }\n return sourceCoords.join();\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar shader_compiler_1 = require(\"./shader_compiler\");\nvar TransposeProgram = (function () {\n function TransposeProgram(aShape, newDim) {\n this.variableNames = ['A'];\n var outputShape = new Array(aShape.length);\n for (var i = 0; i < outputShape.length; i++) {\n outputShape[i] = aShape[newDim[i]];\n }\n this.outputShape = outputShape;\n this.rank = outputShape.length;\n var dtype = shader_compiler_1.getCoordsDataType(this.rank);\n var switched = getSwitchedCoords(newDim);\n this.userCode = \"\\n void main() {\\n \" + dtype + \" resRC = getOutputCoords();\\n setOutput(getA(\" + switched + \"));\\n }\\n \";\n }\n return TransposeProgram;\n}());\nexports.TransposeProgram = TransposeProgram;\nfunction getSwitchedCoords(newDim) {\n var rank = newDim.length;\n if (rank > 4) {\n throw Error(\"Transpose for rank \" + rank + \" is not yet supported\");\n }\n var originalOrder = ['resRC.x', 'resRC.y', 'resRC.z', 'resRC.w'];\n var switchedCoords = new Array(rank);\n for (var i = 0; i < newDim.length; i++) {\n switchedCoords[newDim[i]] = originalOrder[i];\n }\n return switchedCoords.join();\n}\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ERF_P = 0.3275911;\nexports.ERF_A1 = 0.254829592;\nexports.ERF_A2 = -0.284496736;\nexports.ERF_A3 = 1.421413741;\nexports.ERF_A4 = -1.453152027;\nexports.ERF_A5 = 1.061405429;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar erf_util = require(\"../../ops/erf_util\");\nvar selu_util = require(\"../../ops/selu_util\");\nvar UnaryOpProgram = (function () {\n function UnaryOpProgram(aShape, opSnippet) {\n this.variableNames = ['A'];\n this.outputShape = aShape;\n this.userCode = \"\\n float unaryOperation(float x) {\\n \" + opSnippet + \"\\n }\\n\\n void main() {\\n float x = getAAtOutCoords();\\n float y = unaryOperation(x);\\n\\n setOutput(y);\\n }\\n \";\n }\n return UnaryOpProgram;\n}());\nexports.UnaryOpProgram = UnaryOpProgram;\nvar CHECK_NAN_SNIPPET = \"if (isNaN(x)) return x;\";\nexports.ABS = \"return abs(x);\";\nexports.RELU = CHECK_NAN_SNIPPET + \"\\n return (x < 0.0) ? 0.0 : x;\\n\";\nexports.ELU = \"return (x >= 0.0) ? x : (exp(x) - 1.0);\";\nexports.SELU = \"\\n // Stable and Attracting Fixed Point (0, 1) for Normalized Weights.\\n // see: https://arxiv.org/abs/1706.02515\\n float scaleAlpha = \" + selu_util.SELU_SCALEALPHA + \";\\n float scale = \" + selu_util.SELU_SCALE + \";\\n return (x >= 0.0) ? scale * x : scaleAlpha * (exp(x) - 1.0);\\n\";\nfunction STEP(alpha) {\n if (alpha === void 0) { alpha = 0.0; }\n return CHECK_NAN_SNIPPET + (\"\\n return x > 0.0 ? 1.0 : float(\" + alpha + \");\\n \");\n}\nexports.STEP = STEP;\nexports.NEG = \"return -x;\";\nexports.CEIL = \"return ceil(x);\";\nexports.FLOOR = \"return floor(x);\";\nexports.SIGN = \"\\n if (isNaN(x)) { return 0.0; }\\n return sign(x);\\n\";\nexports.ROUND = \"\\n // OpenGL ES does not support round function.\\n // The algorithm is based on banker's rounding.\\n float base = floor(x);\\n if ((x - base) < 0.5) {\\n return floor(x);\\n } else if ((x - base) > 0.5) {\\n return ceil(x);\\n } else {\\n if (mod(base, 2.0) == 0.0) {\\n return base;\\n } else {\\n return base + 1.0;\\n }\\n }\\n\";\nexports.EXP = \"return exp(x);\";\nexports.EXPM1 = \"return exp(x) - 1.0;\";\nexports.LOG = \"return log(x);\";\nexports.LOG1P = \"return log(1.0 + x);\";\nexports.SQRT = \"return sqrt(x);\";\nexports.RSQRT = \"return inversesqrt(x);\";\nexports.SIGMOID = \"return 1.0 / (1.0 + exp(-1.0 * x));\";\nexports.SOFTPLUS = \"\\n float epsilon = 1.1920928955078125e-7;\\n float threshold = log(epsilon) + 2.0;\\n\\n bool too_large = x > -threshold;\\n bool too_small = x < threshold;\\n\\n float result;\\n float exp_x = exp(x);\\n\\n if (too_large){\\n result = x;\\n }\\n else if (too_small){\\n result = exp_x;\\n }\\n else{\\n result = log(exp_x + 1.0);\\n }\\n return result;\\n\";\nexports.SIN = \"return sin(x);\";\nexports.COS = \"return cos(x);\";\nexports.TAN = \"return tan(x);\";\nexports.ASIN = \"return asin(x);\";\nexports.ACOS = \"return acos(x);\";\nexports.ATAN = CHECK_NAN_SNIPPET + \"\\n return atan(x);\\n\";\nexports.SINH = \"\\n float e2x = exp(x);\\n return (e2x - 1.0 / e2x) / 2.0;\\n\";\nexports.COSH = \"\\n float e2x = exp(-x);\\n return (e2x + 1.0 / e2x) / 2.0;\\n\";\nexports.TANH = \"\\n float e2x = exp(-2.0 * abs(x));\\n return sign(x) * (1.0 - e2x) / (1.0 + e2x);\\n\";\nexports.ASINH = \"return log(x + sqrt(x * x + 1.0));\";\nexports.ACOSH = \"return log(x + sqrt(x * x - 1.0));\";\nexports.ATANH = \"return (log(1.0 + x) - log(1.0 - x)) / 2.0;\";\nexports.ERF = \"\\n // Error function is calculated approximately with elementary function.\\n // See \\\"Handbook of Mathematical Functions with Formulas,\\n // Graphs, and Mathematical Tables\\\", Abramowitz and Stegun.\\n float p = \" + erf_util.ERF_P + \";\\n float a1 = \" + erf_util.ERF_A1 + \";\\n float a2 = \" + erf_util.ERF_A2 + \";\\n float a3 = \" + erf_util.ERF_A3 + \";\\n float a4 = \" + erf_util.ERF_A4 + \";\\n float a5 = \" + erf_util.ERF_A5 + \";\\n\\n float t = 1.0 / (1.0 + p * x);\\n return 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*exp(-x*x);\\n\";\nexports.SQUARE = \"return x * x;\";\nexports.RECIPROCAL = \"return 1.0 / x;\";\nexports.LOGICAL_NOT = \"return float(!(x >= 1.0));\";\nexports.TO_INT = \"return float(int(x));\";\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar axis_util = require(\"../ops/axis_util\");\nvar ops = require(\"../ops/ops\");\nvar reduce_util = require(\"../ops/reduce_util\");\nvar tensor_1 = require(\"../tensor\");\nvar types = require(\"../types\");\nvar util = require(\"../util\");\nvar backend_util = require(\"./backend_util\");\nvar argminmax_gpu_1 = require(\"./webgl/argminmax_gpu\");\nvar avg_pool_backprop_gpu_1 = require(\"./webgl/avg_pool_backprop_gpu\");\nvar batchnorm_gpu_1 = require(\"./webgl/batchnorm_gpu\");\nvar binaryop_gpu = require(\"./webgl/binaryop_gpu\");\nvar binaryop_gpu_1 = require(\"./webgl/binaryop_gpu\");\nvar clip_gpu_1 = require(\"./webgl/clip_gpu\");\nvar concat_gpu_1 = require(\"./webgl/concat_gpu\");\nvar conv_backprop_gpu_1 = require(\"./webgl/conv_backprop_gpu\");\nvar conv_gpu_1 = require(\"./webgl/conv_gpu\");\nvar conv_gpu_depthwise_1 = require(\"./webgl/conv_gpu_depthwise\");\nvar from_pixels_gpu_1 = require(\"./webgl/from_pixels_gpu\");\nvar gather_gpu_1 = require(\"./webgl/gather_gpu\");\nvar gpgpu_context_1 = require(\"./webgl/gpgpu_context\");\nvar gpgpu_math = require(\"./webgl/gpgpu_math\");\nvar gpgpu_util = require(\"./webgl/gpgpu_util\");\nvar logical_gpu_1 = require(\"./webgl/logical_gpu\");\nvar lrn_gpu_1 = require(\"./webgl/lrn_gpu\");\nvar max_pool_backprop_gpu_1 = require(\"./webgl/max_pool_backprop_gpu\");\nvar mulmat_gpu_1 = require(\"./webgl/mulmat_gpu\");\nvar multinomial_gpu_1 = require(\"./webgl/multinomial_gpu\");\nvar onehot_gpu_1 = require(\"./webgl/onehot_gpu\");\nvar pad_gpu_1 = require(\"./webgl/pad_gpu\");\nvar pool_gpu_1 = require(\"./webgl/pool_gpu\");\nvar reduce_gpu_1 = require(\"./webgl/reduce_gpu\");\nvar resize_bilinear_backprop_gpu_1 = require(\"./webgl/resize_bilinear_backprop_gpu\");\nvar resize_bilinear_gpu_1 = require(\"./webgl/resize_bilinear_gpu\");\nvar resize_nearest_neighbor_gpu_1 = require(\"./webgl/resize_nearest_neighbor_gpu\");\nvar reverse_gpu_1 = require(\"./webgl/reverse_gpu\");\nvar slice_gpu_1 = require(\"./webgl/slice_gpu\");\nvar tex_util_1 = require(\"./webgl/tex_util\");\nvar texture_manager_1 = require(\"./webgl/texture_manager\");\nvar tile_gpu_1 = require(\"./webgl/tile_gpu\");\nvar transpose_gpu_1 = require(\"./webgl/transpose_gpu\");\nvar unary_op = require(\"./webgl/unaryop_gpu\");\nvar unaryop_gpu_1 = require(\"./webgl/unaryop_gpu\");\nvar webgl_util = require(\"./webgl/webgl_util\");\nvar MathBackendWebGL = (function () {\n function MathBackendWebGL(gpgpu, delayedStorage) {\n if (delayedStorage === void 0) { delayedStorage = true; }\n this.gpgpu = gpgpu;\n this.delayedStorage = delayedStorage;\n this.texData = new WeakMap();\n this.uploadWaitMs = 0;\n this.downloadWaitMs = 0;\n this.binaryCache = {};\n this.disposed = false;\n if (environment_1.ENV.get('WEBGL_VERSION') < 1) {\n throw new Error('WebGL is not supported on this device');\n }\n if (typeof document !== 'undefined') {\n this.canvas = document.createElement('canvas');\n }\n if (gpgpu == null) {\n this.gpgpu = new gpgpu_context_1.GPGPUContext(gpgpu_util.createWebGLContext(this.canvas));\n this.gpgpuCreatedLocally = true;\n }\n else {\n this.gpgpuCreatedLocally = false;\n }\n this.textureManager = new texture_manager_1.TextureManager(this.gpgpu);\n }\n MathBackendWebGL.prototype.register = function (dataId, shape, dtype) {\n if (this.texData.has(dataId)) {\n throw new Error('Data buffer is already registered');\n }\n this.texData.set(dataId, {\n shape: shape,\n dtype: dtype,\n values: null,\n texture: null,\n texShape: null,\n texType: tex_util_1.TextureType.FLOAT\n });\n };\n MathBackendWebGL.prototype.fromPixels = function (pixels, numChannels) {\n if (pixels == null) {\n throw new Error('MathBackendWebGL.writePixels(): pixels can not be null');\n }\n var texShape = [pixels.height, pixels.width];\n var outShape = [pixels.height, pixels.width, numChannels];\n if (pixels instanceof HTMLVideoElement) {\n if (this.canvas == null) {\n throw new Error('Can\\'t read pixels from HTMLImageElement outside ' +\n 'the browser.');\n }\n this.canvas.width = pixels.width;\n this.canvas.height = pixels.height;\n this.canvas.getContext('2d').drawImage(pixels, 0, 0, pixels.width, pixels.height);\n pixels = this.canvas;\n }\n var tempPixelArray = tensor_1.Tensor.make(texShape, {}, 'int32');\n this.texData.get(tempPixelArray.dataId).texType = tex_util_1.TextureType.UNSIGNED_BYTE;\n this.gpgpu.uploadPixelDataToTexture(this.getTexture(tempPixelArray.dataId), pixels);\n var program = new from_pixels_gpu_1.FromPixelsProgram(outShape);\n var res = this.compileAndRun(program, [tempPixelArray]);\n tempPixelArray.dispose();\n return res;\n };\n MathBackendWebGL.prototype.write = function (dataId, values) {\n if (values == null) {\n throw new Error('MathBackendWebGL.write(): values can not be null');\n }\n this.throwIfNoData(dataId);\n var texData = this.texData.get(dataId);\n var texture = texData.texture, texShape = texData.texShape, texType = texData.texType;\n if (texture != null) {\n this.textureManager.releaseTexture(texture, texShape, texType);\n texData.texture = null;\n texData.texShape = null;\n }\n texData.values = values;\n if (!this.delayedStorage) {\n this.uploadToGPU(dataId);\n }\n };\n MathBackendWebGL.prototype.readSync = function (dataId) {\n this.throwIfNoData(dataId);\n var texData = this.texData.get(dataId);\n var texture = texData.texture, values = texData.values, texShape = texData.texShape;\n if (values != null) {\n this.cacheOnCPU(dataId);\n return values;\n }\n var shouldTimeProgram = this.activeTimers != null;\n var start;\n if (shouldTimeProgram) {\n start = performance.now();\n }\n var float32Values = this.gpgpu.downloadMatrixFromTexture(texture, texShape[0], texShape[1]);\n if (shouldTimeProgram) {\n this.downloadWaitMs += performance.now() - start;\n }\n this.cacheOnCPU(dataId, float32Values);\n return texData.values;\n };\n MathBackendWebGL.prototype.read = function (dataId) {\n return __awaiter(this, void 0, void 0, function () {\n var texData, texture, values, texShape, float32Values;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n this.throwIfNoData(dataId);\n texData = this.texData.get(dataId);\n texture = texData.texture, values = texData.values, texShape = texData.texShape;\n if (values != null) {\n this.cacheOnCPU(dataId);\n return [2, values];\n }\n if (!environment_1.ENV.get('WEBGL_GET_BUFFER_SUB_DATA_ASYNC_EXTENSION_ENABLED')) return [3, 2];\n return [4, this.gpgpu.downloadMatrixFromTextureAsync(texture, texShape[0], texShape[1])];\n case 1:\n float32Values = _a.sent();\n this.cacheOnCPU(dataId, float32Values);\n return [2, texData.values];\n case 2:\n if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') === 0) {\n return [2, this.readSync(dataId)];\n }\n return [4, this.gpgpu.runQuery(function () { })];\n case 3:\n _a.sent();\n return [2, this.readSync(dataId)];\n }\n });\n });\n };\n MathBackendWebGL.prototype.time = function (f) {\n return __awaiter(this, void 0, void 0, function () {\n var oldActiveTimers, newActiveTimers, outerMostTime, flattenedActiveTimers, kernelMs, res;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n oldActiveTimers = this.activeTimers;\n newActiveTimers = [];\n outerMostTime = false;\n if (this.programTimersStack == null) {\n this.programTimersStack = newActiveTimers;\n outerMostTime = true;\n }\n else {\n this.activeTimers.push(newActiveTimers);\n }\n this.activeTimers = newActiveTimers;\n f();\n flattenedActiveTimers = util.flatten(this.activeTimers);\n this.activeTimers = oldActiveTimers;\n if (outerMostTime) {\n this.programTimersStack = null;\n }\n return [4, Promise.all(flattenedActiveTimers).then(function (results) {\n var sum = 0;\n results.forEach(function (result) { return sum += result; });\n return sum;\n })];\n case 1:\n kernelMs = _a.sent();\n res = {\n uploadWaitMs: this.uploadWaitMs,\n downloadWaitMs: this.downloadWaitMs,\n kernelMs: kernelMs,\n wallMs: null\n };\n this.uploadWaitMs = 0;\n this.downloadWaitMs = 0;\n return [2, res];\n }\n });\n });\n };\n MathBackendWebGL.prototype.memory = function () {\n return { unreliable: false };\n };\n MathBackendWebGL.prototype.startTimer = function () {\n if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) {\n return this.gpgpu.beginQuery();\n }\n return { startMs: performance.now(), endMs: null };\n };\n MathBackendWebGL.prototype.endTimer = function (query) {\n if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) {\n this.gpgpu.endQuery();\n return query;\n }\n query.endMs = performance.now();\n return query;\n };\n MathBackendWebGL.prototype.getQueryTime = function (query) {\n return __awaiter(this, void 0, void 0, function () {\n var timerQuery;\n return __generator(this, function (_a) {\n if (environment_1.ENV.get('WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION') > 0) {\n return [2, this.gpgpu.pollQueryTime(query)];\n }\n timerQuery = query;\n return [2, timerQuery.endMs - timerQuery.startMs];\n });\n });\n };\n MathBackendWebGL.prototype.disposeData = function (dataId) {\n if (this.texData.has(dataId)) {\n var _a = this.texData.get(dataId), texture = _a.texture, texShape = _a.texShape, texType = _a.texType;\n if (texture != null) {\n this.textureManager.releaseTexture(texture, texShape, texType);\n }\n this.texData.delete(dataId);\n }\n };\n MathBackendWebGL.prototype.getTexture = function (dataId) {\n this.uploadToGPU(dataId);\n return this.texData.get(dataId).texture;\n };\n MathBackendWebGL.prototype.getTextureData = function (dataId) {\n this.uploadToGPU(dataId);\n return this.texData.get(dataId);\n };\n MathBackendWebGL.prototype.getGPGPUContext = function () {\n return this.gpgpu;\n };\n MathBackendWebGL.prototype.getCanvas = function () {\n return this.canvas;\n };\n MathBackendWebGL.prototype.slice = function (x, begin, size) {\n var program = new slice_gpu_1.SliceProgram(size);\n var customSetup = program.getCustomSetupFunc(begin);\n return this.compileAndRun(program, [x], null, customSetup);\n };\n MathBackendWebGL.prototype.reverse = function (x, axis) {\n var program = new reverse_gpu_1.ReverseProgram(x.shape, axis);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.concat = function (a, b) {\n var program = new concat_gpu_1.ConcatProgram(a.shape, b.shape);\n return this.compileAndRun(program, [a, b]);\n };\n MathBackendWebGL.prototype.neg = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.NEG);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.matMul = function (a, b, transposeA, transposeB) {\n var program = new mulmat_gpu_1.MatMulProgram(a.shape, b.shape, transposeA, transposeB);\n return this.compileAndRun(program, [a, b]);\n };\n MathBackendWebGL.prototype.multiply = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MUL, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype));\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.batchNormalization = function (x, mean, variance, varianceEpsilon, scale, offset) {\n var inputs = [x, mean, variance];\n var offsetShape = null;\n if (offset != null) {\n offsetShape = offset.shape;\n inputs.push(offset);\n }\n var scaleShape = null;\n if (scale != null) {\n scaleShape = scale.shape;\n inputs.push(scale);\n }\n var program = new batchnorm_gpu_1.BatchNormProgram(x.shape, mean.shape, variance.shape, offsetShape, scaleShape, varianceEpsilon);\n return this.compileAndRun(program, inputs);\n };\n MathBackendWebGL.prototype.localResponseNormalization4D = function (x, radius, bias, alpha, beta) {\n var program = new lrn_gpu_1.LRNProgram(x.shape, radius, bias, alpha, beta);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.tile = function (x, reps) {\n var program = new tile_gpu_1.TileProgram(x.shape, reps);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.pad = function (x, paddings, constantValue) {\n var program = new pad_gpu_1.PadProgram(x.shape, paddings, constantValue);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.transpose = function (x, perm) {\n var program = new transpose_gpu_1.TransposeProgram(x.shape, perm);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.gather = function (x, indices, axis) {\n var program = new gather_gpu_1.GatherProgram(x.shape, indices.size, axis);\n return this.compileAndRun(program, [x, indices]);\n };\n MathBackendWebGL.prototype.reduce = function (x, reduceType, dtype) {\n var batchSize = x.shape[0];\n var inSize = x.shape[1];\n var windowSize = reduce_util.computeOptimalWindowSize(inSize);\n var reduceInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize };\n var program = new reduce_gpu_1.ReduceProgram(reduceInfo, reduceType);\n var _a = program.outputShape, rows = _a[0], cols = _a[1];\n var output = this.makeOutputArray([rows, cols], dtype);\n this.compileAndRun(program, [x], output);\n if (output.shape[1] === 1) {\n return output;\n }\n return this.reduce(output, reduceType, dtype);\n };\n MathBackendWebGL.prototype.argReduce = function (x, reduceType, bestIndicesA) {\n if (bestIndicesA === void 0) { bestIndicesA = null; }\n var batchSize = x.shape[0];\n var inSize = x.shape[1];\n if (bestIndicesA != null) {\n batchSize = bestIndicesA.shape[0];\n inSize = bestIndicesA.shape[1];\n }\n var windowSize = reduce_util.computeOptimalWindowSize(inSize);\n var reduceInfo = { windowSize: windowSize, inSize: inSize, batchSize: batchSize };\n var program = new argminmax_gpu_1.ArgMinMaxProgram(reduceInfo, reduceType, bestIndicesA == null);\n var _a = program.outputShape, rows = _a[0], cols = _a[1];\n var output = this.makeOutputArray([rows, cols], 'int32');\n var inputs = [x];\n if (bestIndicesA != null) {\n inputs.push(bestIndicesA);\n }\n this.compileAndRun(program, inputs, output);\n if (output.shape[1] === 1) {\n return output;\n }\n return this.argReduce(x, reduceType, output);\n };\n MathBackendWebGL.prototype.sum = function (x, axes) {\n axis_util.assertAxesAreInnerMostDims('sum', axes, x.rank);\n var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];\n var inSize = util.sizeFromShape(reduceShape);\n var a2D = x.as2D(-1, inSize);\n var outputDType = types.sumOutType(x.dtype);\n return this.reduce(a2D, 'sum', outputDType).reshape(outShape);\n };\n MathBackendWebGL.prototype.argMin = function (x, axis) {\n var axes = [axis];\n axis_util.assertAxesAreInnerMostDims('argMin', axes, x.rank);\n var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];\n var inSize = util.sizeFromShape(reduceShape);\n var a2D = x.as2D(-1, inSize);\n return this.argReduce(a2D, 'min').reshape(outShape);\n };\n MathBackendWebGL.prototype.argMax = function (x, axis) {\n var axes = [axis];\n axis_util.assertAxesAreInnerMostDims('argMax', axes, x.rank);\n var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];\n var inSize = util.sizeFromShape(reduceShape);\n var a2D = x.as2D(-1, inSize);\n return this.argReduce(a2D, 'max').reshape(outShape);\n };\n MathBackendWebGL.prototype.equal = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.EQUAL, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, 'bool');\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.notEqual = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.NOT_EQUAL, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, 'bool');\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.less = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LESS, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, 'bool');\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.lessEqual = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LESS_EQUAL, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, 'bool');\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.greater = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.GREATER, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, 'bool');\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.greaterEqual = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.GREATER_EQUAL, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, 'bool');\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.logicalNot = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOGICAL_NOT);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.logicalAnd = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_AND, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, 'bool');\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.logicalOr = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.LOGICAL_OR, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, 'bool');\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.where = function (condition, a, b, dtype) {\n var program = new logical_gpu_1.WhereProgram(condition.rank, a.shape, a.rank);\n var output = this.makeOutputArray(program.outputShape, dtype);\n return this.compileAndRun(program, [condition, a, b], output);\n };\n MathBackendWebGL.prototype.topKValues = function (x, k) {\n throw new Error('topKValues GPU not yet implemented!');\n };\n MathBackendWebGL.prototype.topKIndices = function (x, k) {\n throw new Error('topKIndices GPU not yet implemented!');\n };\n MathBackendWebGL.prototype.min = function (x, axes) {\n axis_util.assertAxesAreInnerMostDims('min', axes, x.rank);\n var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];\n var inSize = util.sizeFromShape(reduceShape);\n var a2D = x.as2D(-1, inSize);\n return this.reduce(a2D, 'min', a2D.dtype).reshape(outShape);\n };\n MathBackendWebGL.prototype.minimum = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MIN, a.shape, b.shape);\n return this.compileAndRun(program, [a, b]);\n };\n MathBackendWebGL.prototype.mod = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MOD, a.shape, b.shape);\n return this.compileAndRun(program, [a, b]);\n };\n MathBackendWebGL.prototype.max = function (x, axes) {\n axis_util.assertAxesAreInnerMostDims('max', axes, x.rank);\n var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];\n var inSize = util.sizeFromShape(reduceShape);\n var a2D = x.as2D(-1, inSize);\n return this.reduce(a2D, 'max', a2D.dtype).reshape(outShape);\n };\n MathBackendWebGL.prototype.maximum = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.MAX, a.shape, b.shape);\n return this.compileAndRun(program, [a, b]);\n };\n MathBackendWebGL.prototype.squaredDifference = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.SQUARED_DIFFERENCE, a.shape, b.shape);\n return this.compileAndRun(program, [a, b]);\n };\n MathBackendWebGL.prototype.divide = function (a, b) {\n var op;\n var outputDtype;\n if (a.dtype === 'int32' && b.dtype === 'int32') {\n op = binaryop_gpu.INT_DIV;\n outputDtype = 'int32';\n }\n else {\n op = binaryop_gpu.DIV;\n outputDtype = 'float32';\n }\n var program = new binaryop_gpu_1.BinaryOpProgram(op, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, outputDtype);\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.add = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.ADD, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype));\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.subtract = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.SUB, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype));\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.pow = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.POW, a.shape, b.shape);\n var output = this.makeOutputArray(program.outputShape, types.upcastType(a.dtype, b.dtype));\n return this.compileAndRun(program, [a, b], output);\n };\n MathBackendWebGL.prototype.ceil = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.CEIL);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.floor = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.FLOOR);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.sign = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIGN);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.round = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ROUND);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.exp = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.EXP);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.expm1 = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.EXPM1);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.log = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOG);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.log1p = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.LOG1P);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.sqrt = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SQRT);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.rsqrt = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.RSQRT);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.square = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SQUARE);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.reciprocal = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.RECIPROCAL);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.relu = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.RELU);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.elu = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ELU);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.eluDer = function (dy, y) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.ELU_DER, dy.shape, y.shape);\n return this.compileAndRun(program, [dy, y]);\n };\n MathBackendWebGL.prototype.selu = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SELU);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.int = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TO_INT);\n var output = this.makeOutputArray(program.outputShape, 'int32');\n return this.compileAndRun(program, [x], output);\n };\n MathBackendWebGL.prototype.clip = function (x, min, max) {\n var program = new clip_gpu_1.ClipProgram(x.shape, min, max);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.abs = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ABS);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.sigmoid = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIGMOID);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.softplus = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SOFTPLUS);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.sin = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SIN);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.cos = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.COS);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.tan = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TAN);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.asin = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ASIN);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.acos = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ACOS);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.atan = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ATAN);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.atan2 = function (a, b) {\n var program = new binaryop_gpu_1.BinaryOpProgram(binaryop_gpu.ATAN2, a.shape, b.shape);\n return this.compileAndRun(program, [a, b]);\n };\n MathBackendWebGL.prototype.sinh = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.SINH);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.cosh = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.COSH);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.tanh = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.TANH);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.asinh = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ASINH);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.acosh = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ACOSH);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.atanh = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ATANH);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.erf = function (x) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.ERF);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.step = function (x, alpha) {\n var program = new unaryop_gpu_1.UnaryOpProgram(x.shape, unary_op.STEP(alpha));\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.conv2d = function (x, filter, convInfo) {\n var program = new conv_gpu_1.Conv2DProgram(convInfo);\n return this.compileAndRun(program, [x, filter]);\n };\n MathBackendWebGL.prototype.conv2dDerInput = function (dy, filter, convInfo) {\n var program = new conv_backprop_gpu_1.Conv2DDerInputProgram(convInfo);\n return this.compileAndRun(program, [dy, filter]);\n };\n MathBackendWebGL.prototype.conv2dDerFilter = function (x, dy, convInfo) {\n var program = new conv_backprop_gpu_1.Conv2DDerFilterProgram(convInfo);\n return this.compileAndRun(program, [x, dy]);\n };\n MathBackendWebGL.prototype.depthwiseConv2D = function (x, filter, convInfo) {\n var program = new conv_gpu_depthwise_1.DepthwiseConv2DProgram(convInfo);\n return this.compileAndRun(program, [x, filter]);\n };\n MathBackendWebGL.prototype.maxPool = function (x, convInfo) {\n var program = new pool_gpu_1.Pool2DProgram(convInfo, 'max', false);\n var output = this.makeOutputArray(program.outputShape, x.dtype);\n return this.compileAndRun(program, [x], output);\n };\n MathBackendWebGL.prototype.avgPool = function (x, convInfo) {\n var program = new pool_gpu_1.Pool2DProgram(convInfo, 'avg', false);\n var output = this.makeOutputArray(program.outputShape, 'float32');\n return this.compileAndRun(program, [x], output);\n };\n MathBackendWebGL.prototype.maxPoolBackprop = function (dy, x, y, convInfo) {\n var getPositions = true;\n var maxPoolPositionsProgram = new pool_gpu_1.Pool2DProgram(convInfo, 'max', getPositions);\n var maxPoolPositions = this.compileAndRun(maxPoolPositionsProgram, [x]);\n var maxPoolBackPropProgram = new max_pool_backprop_gpu_1.MaxPool2DBackpropProgram(convInfo);\n var output = this.makeOutputArray(maxPoolBackPropProgram.outputShape, x.dtype);\n var result = this.compileAndRun(maxPoolBackPropProgram, [dy, maxPoolPositions], output);\n maxPoolPositions.dispose();\n return result;\n };\n MathBackendWebGL.prototype.avgPoolBackprop = function (dy, x, convInfo) {\n var avgPoolBackpropProgram = new avg_pool_backprop_gpu_1.AvgPool2DBackpropProgram(convInfo);\n var output = this.makeOutputArray(avgPoolBackpropProgram.outputShape, x.dtype);\n return this.compileAndRun(avgPoolBackpropProgram, [dy], output);\n };\n MathBackendWebGL.prototype.cast = function (x, dtype) {\n return backend_util.castTensor(x, dtype, this);\n };\n MathBackendWebGL.prototype.reshape = function (x, shape) {\n return backend_util.reshapeTensor(x, shape);\n };\n MathBackendWebGL.prototype.resizeBilinear = function (x, newHeight, newWidth, alignCorners) {\n var program = new resize_bilinear_gpu_1.ResizeBilinearProgram(x.shape, newHeight, newWidth, alignCorners);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.resizeBilinearBackprop = function (dy, x, alignCorners) {\n var program = new resize_bilinear_backprop_gpu_1.ResizeBilinearBackpropProgram(dy, x, alignCorners);\n return this.compileAndRun(program, [dy]);\n };\n MathBackendWebGL.prototype.resizeNearestNeighbor = function (x, newHeight, newWidth, alignCorners) {\n var program = new resize_nearest_neighbor_gpu_1.ResizeNearestNeighborProgram(x.shape, newHeight, newWidth, alignCorners);\n return this.compileAndRun(program, [x]);\n };\n MathBackendWebGL.prototype.multinomial = function (logits, normalized, numSamples, seed) {\n var probs = normalized ? logits : ops.softmax(logits);\n var batchSize = probs.shape[0];\n var numOutcomes = probs.shape[1];\n var program = new multinomial_gpu_1.MultinomialProgram(batchSize, numOutcomes, numSamples);\n var output = this.makeOutputArray(program.outputShape, 'int32');\n var customSetup = program.getCustomSetupFunc(seed);\n return this.compileAndRun(program, [probs], output, customSetup);\n };\n MathBackendWebGL.prototype.oneHot = function (indices, depth, onValue, offValue) {\n var program = new onehot_gpu_1.OneHotProgram(indices.size, depth, onValue, offValue);\n return this.compileAndRun(program, [indices]);\n };\n MathBackendWebGL.prototype.makeOutputArray = function (shape, dtype) {\n return tensor_1.Tensor.make(shape, {}, dtype);\n };\n MathBackendWebGL.prototype.compileAndRun = function (program, inputs, output, customSetup) {\n var _this = this;\n if (output == null) {\n output = this.makeOutputArray(program.outputShape, inputs[0].dtype);\n }\n var inputsData = inputs.map(function (input) {\n _this.uploadToGPU(input.dataId);\n return { tensor: input, texData: _this.texData.get(input.dataId) };\n });\n this.uploadToGPU(output.dataId);\n var outputData = {\n tensor: output,\n texData: this.texData.get(output.dataId)\n };\n var key = gpgpu_math.makeShaderKey(program, inputsData, outputData);\n var binary = this.getAndSaveBinary(key, function () {\n return gpgpu_math.compileProgram(_this.gpgpu, program, inputsData, outputData);\n });\n var shouldTimeProgram = this.activeTimers != null;\n var query;\n if (shouldTimeProgram) {\n query = this.startTimer();\n }\n gpgpu_math.runProgram(binary, inputsData, outputData, customSetup);\n if (shouldTimeProgram) {\n query = this.endTimer(query);\n this.activeTimers.push(this.getQueryTime(query));\n }\n return output;\n };\n MathBackendWebGL.prototype.getAndSaveBinary = function (key, getBinary) {\n if (!(key in this.binaryCache)) {\n this.binaryCache[key] = getBinary();\n }\n return this.binaryCache[key];\n };\n MathBackendWebGL.prototype.getTextureManager = function () {\n return this.textureManager;\n };\n MathBackendWebGL.prototype.dispose = function () {\n if (this.disposed) {\n return;\n }\n for (var key in this.binaryCache) {\n this.gpgpu.deleteProgram(this.binaryCache[key].webGLProgram);\n }\n this.textureManager.dispose();\n this.canvas.remove();\n if (this.gpgpuCreatedLocally) {\n this.gpgpu.dispose();\n }\n this.disposed = true;\n };\n MathBackendWebGL.prototype.throwIfNoData = function (dataId) {\n if (!this.texData.has(dataId)) {\n throw new Error(\"WebGL backend: No data found for this tensor. \" +\n \"Did you change your backend in the middle of the program? \" +\n \"New backends can't use Tensors created with previous backends\");\n }\n };\n MathBackendWebGL.prototype.uploadToGPU = function (dataId) {\n this.throwIfNoData(dataId);\n var texData = this.texData.get(dataId);\n var shape = texData.shape, values = texData.values, texture = texData.texture, dtype = texData.dtype, texType = texData.texType;\n if (texture != null) {\n return;\n }\n var shouldTimeProgram = this.activeTimers != null;\n var start;\n if (shouldTimeProgram) {\n start = performance.now();\n }\n var texShape = webgl_util.getTextureShapeFromLogicalShape(this.gpgpu.gl, shape);\n texData.texShape = texShape;\n var newTexture = this.textureManager.acquireTexture(texShape, texType);\n texData.texture = newTexture;\n if (values != null) {\n this.gpgpu.uploadMatrixToTexture(newTexture, texShape[0], texShape[1], typedArrayToFloat32(values, dtype));\n texData.values = null;\n if (shouldTimeProgram) {\n this.uploadWaitMs += performance.now() - start;\n }\n }\n };\n MathBackendWebGL.prototype.cacheOnCPU = function (dataId, float32Values) {\n var dontKeepCopyOnGPU = this.delayedStorage;\n var texData = this.texData.get(dataId);\n var texture = texData.texture, texShape = texData.texShape, dtype = texData.dtype, texType = texData.texType;\n if (dontKeepCopyOnGPU && texture != null) {\n this.textureManager.releaseTexture(texture, texShape, texType);\n texData.texture = null;\n texData.texShape = null;\n }\n if (float32Values != null) {\n texData.values = float32ToTypedArray(float32Values, dtype);\n }\n };\n return MathBackendWebGL;\n}());\nexports.MathBackendWebGL = MathBackendWebGL;\nenvironment_1.ENV.registerBackend('webgl', function () { return new MathBackendWebGL(); }, 2);\nfunction float32ToTypedArray(a, dtype) {\n if (dtype === 'float32') {\n return a;\n }\n else if (dtype === 'int32' || dtype === 'bool') {\n var result = (dtype === 'int32') ? new Int32Array(a.length) :\n new Uint8Array(a.length);\n for (var i = 0; i < result.length; ++i) {\n result[i] = Math.round(a[i]);\n }\n return result;\n }\n else {\n throw new Error(\"Unknown dtype \" + dtype);\n }\n}\nfunction typedArrayToFloat32(a, dtype) {\n return (a instanceof Float32Array) ? a : new Float32Array(a);\n}\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar seedrandom = require(\"seedrandom\");\nvar environment_1 = require(\"../environment\");\nvar axis_util = require(\"../ops/axis_util\");\nvar broadcast_util = require(\"../ops/broadcast_util\");\nvar concat_util = require(\"../ops/concat_util\");\nvar erf_util = require(\"../ops/erf_util\");\nvar ops = require(\"../ops/ops\");\nvar ops_1 = require(\"../ops/ops\");\nvar selu_util = require(\"../ops/selu_util\");\nvar tensor_1 = require(\"../tensor\");\nvar types = require(\"../types\");\nvar util = require(\"../util\");\nvar backend_util = require(\"./backend_util\");\nvar MathBackendCPU = (function () {\n function MathBackendCPU() {\n this.data = new WeakMap();\n if (typeof document !== 'undefined') {\n this.canvas = document.createElement('canvas');\n }\n }\n MathBackendCPU.prototype.register = function (dataId, shape, dtype) {\n if (this.data.has(dataId)) {\n throw new Error(\"Data buffer is already registered\");\n }\n this.data.set(dataId, null);\n };\n MathBackendCPU.prototype.write = function (dataId, values) {\n if (values == null) {\n throw new Error('MathBackendCPU.write(): values can not be null');\n }\n this.throwIfNoData(dataId);\n this.data.set(dataId, values);\n };\n MathBackendCPU.prototype.fromPixels = function (pixels, numChannels) {\n if (pixels == null) {\n throw new Error('MathBackendCPU.writePixels(): pixels can not be null');\n }\n var vals;\n if (pixels instanceof ImageData) {\n vals = pixels.data;\n }\n else if (pixels instanceof HTMLCanvasElement) {\n vals = pixels.getContext('2d')\n .getImageData(0, 0, pixels.width, pixels.height)\n .data;\n }\n else if (pixels instanceof HTMLImageElement ||\n pixels instanceof HTMLVideoElement) {\n if (this.canvas == null) {\n throw new Error('Can\\'t read pixels from HTMLImageElement outside ' +\n 'the browser.');\n }\n this.canvas.width = pixels.width;\n this.canvas.height = pixels.height;\n this.canvas.getContext('2d').drawImage(pixels, 0, 0, pixels.width, pixels.height);\n vals = this.canvas.getContext('2d')\n .getImageData(0, 0, pixels.width, pixels.height)\n .data;\n }\n else {\n throw new Error(\"pixels is of unknown type: \" + pixels.constructor.name);\n }\n var values;\n if (numChannels === 4) {\n values = new Int32Array(vals);\n }\n else {\n var numPixels = pixels.width * pixels.height;\n values = new Int32Array(numPixels * numChannels);\n for (var i = 0; i < numPixels; i++) {\n for (var channel = 0; channel < numChannels; ++channel) {\n values[i * numChannels + channel] = vals[i * 4 + channel];\n }\n }\n }\n var outShape = [pixels.height, pixels.width, numChannels];\n return ops_1.tensor3d(values, outShape, 'int32');\n };\n MathBackendCPU.prototype.read = function (dataId) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2, this.readSync(dataId)];\n });\n });\n };\n MathBackendCPU.prototype.readSync = function (dataId) {\n this.throwIfNoData(dataId);\n return this.data.get(dataId);\n };\n MathBackendCPU.prototype.disposeData = function (dataId) {\n if (this.data.has(dataId)) {\n this.data.delete(dataId);\n }\n };\n MathBackendCPU.prototype.time = function (f) {\n return __awaiter(this, void 0, void 0, function () {\n var start, kernelMs;\n return __generator(this, function (_a) {\n start = performance.now();\n f();\n kernelMs = performance.now() - start;\n return [2, { kernelMs: kernelMs }];\n });\n });\n };\n MathBackendCPU.prototype.memory = function () {\n return {\n unreliable: true\n };\n };\n MathBackendCPU.prototype.throwIfNoData = function (dataId) {\n if (!this.data.has(dataId)) {\n throw new Error(\"CPU backend: No data found for this tensor. \" +\n \"Did you change your backend in the middle of the program? \" +\n \"New backends can't use Tensors created with previous backends\");\n }\n };\n MathBackendCPU.prototype.slice = function (x, begin, size) {\n var buffer = ops.buffer(size, x.dtype);\n for (var i = 0; i < buffer.size; ++i) {\n var loc = buffer.indexToLoc(i);\n var xLoc = loc.map(function (idx, j) { return idx + begin[j]; });\n buffer.set.apply(buffer, [x.get.apply(x, xLoc)].concat(loc));\n }\n return buffer.toTensor();\n };\n MathBackendCPU.prototype.reverse = function (x, axis) {\n var buffer = ops.buffer(x.shape, x.dtype);\n var xBuffer = x.buffer();\n var _loop_1 = function (i) {\n var outLoc = buffer.indexToLoc(i);\n var inLoc = outLoc.slice();\n axis.forEach(function (ax) { return inLoc[ax] = x.shape[ax] - 1 - inLoc[ax]; });\n buffer.set.apply(buffer, [xBuffer.get.apply(xBuffer, inLoc)].concat(outLoc));\n };\n for (var i = 0; i < buffer.size; i++) {\n _loop_1(i);\n }\n return buffer.toTensor();\n };\n MathBackendCPU.prototype.concat = function (a, b) {\n var outShape = concat_util.computeOutShape(a.shape, b.shape, 1);\n var buffer = ops.buffer(outShape, a.dtype);\n if (a.shape[0] === 1 && b.shape[0] === 1) {\n var aVals = a.dataSync();\n var bVals = b.dataSync();\n var vals = buffer.values;\n vals.set(aVals, 0);\n vals.set(bVals, a.size);\n return buffer.toTensor();\n }\n for (var i = 0; i < outShape[0]; ++i) {\n for (var j = 0; j < a.shape[1]; ++j) {\n buffer.set(a.get(i, j), i, j);\n }\n for (var j = 0; j < b.shape[1]; ++j) {\n buffer.set(b.get(i, j), i, j + a.shape[1]);\n }\n }\n return buffer.toTensor();\n };\n MathBackendCPU.prototype.neg = function (x) {\n return this.multiply(ops.scalar(-1), x);\n };\n MathBackendCPU.prototype.add = function (a, b) {\n return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue + bValue; });\n };\n MathBackendCPU.prototype.subtract = function (a, b) {\n return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue - bValue; });\n };\n MathBackendCPU.prototype.pow = function (a, b) {\n return this.broadcastedBinaryOp(a, b, a.dtype, function (aValue, bValue) { return Math.pow(aValue, bValue); });\n };\n MathBackendCPU.prototype.matMul = function (a, b, transposeA, transposeB) {\n var sharedDim = transposeA ? a.shape[0] : a.shape[1];\n var leftDim = transposeA ? a.shape[1] : a.shape[0];\n var rightDim = transposeB ? b.shape[0] : b.shape[1];\n var aValues = a.dataSync();\n var bValues = b.dataSync();\n var _a = transposeA ? [1, a.strides[0]] : [a.strides[0], 1], aOuterStep = _a[0], aInnerStep = _a[1];\n var _b = transposeB ? [b.strides[0], 1] : [1, b.strides[0]], bOuterStep = _b[0], bInnerStep = _b[1];\n var aOuterEnd = leftDim * aOuterStep;\n var bOuterEnd = rightDim * bOuterStep;\n var result = new Float32Array(leftDim * rightDim);\n var resultIndex = 0;\n for (var aOuter = 0; aOuter < aOuterEnd; aOuter += aOuterStep) {\n for (var bOuter = 0; bOuter < bOuterEnd; bOuter += bOuterStep) {\n var aInner = aOuter;\n var bInner = bOuter;\n var sum = 0;\n for (var k = 0; k < sharedDim; ++k) {\n sum += aValues[aInner] * bValues[bInner];\n aInner += aInnerStep;\n bInner += bInnerStep;\n }\n result[resultIndex++] = sum;\n }\n }\n return ops.tensor2d(result, [leftDim, rightDim]);\n };\n MathBackendCPU.prototype.multiply = function (a, b) {\n return this.broadcastedBinaryOp(a, b, types.upcastType(a.dtype, b.dtype), function (aValue, bValue) { return aValue * bValue; });\n };\n MathBackendCPU.prototype.divide = function (a, b) {\n var op;\n var outputDtype;\n if (a.dtype === 'int32' && b.dtype === 'int32') {\n outputDtype = 'int32';\n op = function (a, b) { return Math.floor(a / b); };\n }\n else {\n outputDtype = 'float32';\n op = function (a, b) { return a / b; };\n }\n return this.broadcastedBinaryOp(a, b, outputDtype, op);\n };\n MathBackendCPU.prototype.sum = function (x, axes) {\n axis_util.assertAxesAreInnerMostDims('sum', axes, x.rank);\n var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];\n var resultDtype = types.upcastType(x.dtype, 'int32');\n var result = ops.zeros(outShape, resultDtype);\n var reduceSize = util.sizeFromShape(reduceShape);\n var vals = result.dataSync();\n var aVals = x.dataSync();\n for (var i = 0; i < vals.length; ++i) {\n var offset = i * reduceSize;\n var sum = 0;\n for (var j = 0; j < reduceSize; ++j) {\n sum += aVals[offset + j];\n }\n vals[i] = sum;\n }\n return result;\n };\n MathBackendCPU.prototype.argMin = function (x, axis) {\n var axes = [axis];\n axis_util.assertAxesAreInnerMostDims('argMin', axes, x.rank);\n var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];\n var result = ops.zeros(outShape, 'int32');\n var reduceSize = util.sizeFromShape(reduceShape);\n var vals = result.dataSync();\n var aVals = x.dataSync();\n for (var i = 0; i < vals.length; ++i) {\n var offset = i * reduceSize;\n var min = aVals[offset];\n var minIndex = 0;\n for (var j = 0; j < reduceSize; ++j) {\n var value = aVals[offset + j];\n if (value < min) {\n min = value;\n minIndex = j;\n }\n }\n vals[i] = minIndex;\n }\n return result;\n };\n MathBackendCPU.prototype.argMax = function (x, axis) {\n var axes = [axis];\n axis_util.assertAxesAreInnerMostDims('argMax', axes, x.rank);\n var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];\n var result = ops.zeros(outShape, 'int32');\n var reduceSize = util.sizeFromShape(reduceShape);\n var vals = result.dataSync();\n var aVals = x.dataSync();\n for (var i = 0; i < vals.length; ++i) {\n var offset = i * reduceSize;\n var max = aVals[offset];\n var maxIndex = 0;\n for (var j = 0; j < reduceSize; ++j) {\n var value = aVals[offset + j];\n if (value > max) {\n max = value;\n maxIndex = j;\n }\n }\n vals[i] = maxIndex;\n }\n return result;\n };\n MathBackendCPU.prototype.equal = function (a, b) {\n return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {\n return (aVal === bVal) ? 1 : 0;\n });\n };\n MathBackendCPU.prototype.notEqual = function (a, b) {\n return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {\n return (aVal !== bVal) ? 1 : 0;\n });\n };\n MathBackendCPU.prototype.less = function (a, b) {\n return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {\n return (aVal < bVal) ? 1 : 0;\n });\n };\n MathBackendCPU.prototype.lessEqual = function (a, b) {\n return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {\n return (aVal <= bVal) ? 1 : 0;\n });\n };\n MathBackendCPU.prototype.greater = function (a, b) {\n return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {\n return (aVal > bVal) ? 1 : 0;\n });\n };\n MathBackendCPU.prototype.greaterEqual = function (a, b) {\n return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {\n return (aVal >= bVal) ? 1 : 0;\n });\n };\n MathBackendCPU.prototype.logicalNot = function (x) {\n var values = x.dataSync();\n var newValues = new Int32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n newValues[i] = values[i] ? 0 : 1;\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues }, 'bool');\n };\n MathBackendCPU.prototype.logicalAnd = function (a, b) {\n return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {\n return aVal && bVal;\n });\n };\n MathBackendCPU.prototype.logicalOr = function (a, b) {\n return this.broadcastedBinaryOp(a, b, 'bool', function (aVal, bVal) {\n return aVal || bVal;\n });\n };\n MathBackendCPU.prototype.where = function (condition, a, b, dtype) {\n var values = condition.dataSync();\n var aValues = a.dataSync();\n var bValues = b.dataSync();\n var result = ops.zeros(a.shape, dtype);\n var newValues = result.dataSync();\n var index = 0;\n var offset = condition.rank === 0 || condition.rank > 1 || a.rank === 1 ?\n 1 :\n a.shape[1];\n for (var i = 0; i < values.length; i++) {\n for (var j = 0; j < offset; j++) {\n if (values[i] === 1) {\n newValues[index++] = aValues[i];\n }\n else {\n newValues[index++] = bValues[i];\n }\n }\n }\n return result;\n };\n MathBackendCPU.prototype.topKValues = function (x, k) {\n return this.topK(x, k).values;\n };\n MathBackendCPU.prototype.topKIndices = function (x, k) {\n return this.topK(x, k).indices;\n };\n MathBackendCPU.prototype.topK = function (x, k) {\n var values = x.dataSync();\n var valuesAndIndices = [];\n for (var i = 0; i < values.length; i++) {\n valuesAndIndices.push({ value: values[i], index: i });\n }\n valuesAndIndices.sort(function (a, b) {\n return b.value - a.value;\n });\n var topkValues = util.getTypedArrayFromDType(x.dtype, k);\n var topkIndices = new Int32Array(k);\n for (var i = 0; i < k; i++) {\n topkValues[i] = valuesAndIndices[i].value;\n topkIndices[i] = valuesAndIndices[i].index;\n }\n return {\n values: ops.tensor1d(topkValues, x.dtype),\n indices: ops.tensor1d(topkIndices, 'int32')\n };\n };\n MathBackendCPU.prototype.min = function (x, axes) {\n axis_util.assertAxesAreInnerMostDims('min', axes, x.rank);\n var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];\n var result = ops.zeros(outShape, x.dtype);\n var reduceSize = util.sizeFromShape(reduceShape);\n var vals = result.dataSync();\n var aVals = x.dataSync();\n for (var i = 0; i < vals.length; ++i) {\n var offset = i * reduceSize;\n var min = aVals[0];\n for (var j = 0; j < reduceSize; ++j) {\n var value = aVals[offset + j];\n if (value < min) {\n min = value;\n }\n }\n vals[i] = min;\n }\n return result;\n };\n MathBackendCPU.prototype.minimum = function (a, b) {\n return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) { return Math.min(aVal, bVal); });\n };\n MathBackendCPU.prototype.mod = function (a, b) {\n return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) {\n var rem = aVal % bVal;\n if ((aVal < 0 && bVal < 0) || (aVal >= 0 && bVal >= 0)) {\n return rem;\n }\n else {\n return (rem + bVal) % bVal;\n }\n });\n };\n MathBackendCPU.prototype.max = function (x, axes) {\n axis_util.assertAxesAreInnerMostDims('max', axes, x.rank);\n var _a = axis_util.computeOutAndReduceShapes(x.shape, axes), outShape = _a[0], reduceShape = _a[1];\n var result = ops.zeros(outShape, x.dtype);\n var reduceSize = util.sizeFromShape(reduceShape);\n var vals = result.dataSync();\n var aVals = x.dataSync();\n for (var i = 0; i < vals.length; ++i) {\n var offset = i * reduceSize;\n var max = aVals[offset];\n for (var j = 0; j < reduceSize; ++j) {\n var value = aVals[offset + j];\n if (value > max) {\n max = value;\n }\n }\n vals[i] = max;\n }\n return result;\n };\n MathBackendCPU.prototype.maximum = function (a, b) {\n return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) { return Math.max(aVal, bVal); });\n };\n MathBackendCPU.prototype.squaredDifference = function (a, b) {\n return this.broadcastedBinaryOp(a, b, a.dtype, function (aVal, bVal) {\n var diff = aVal - bVal;\n return diff * diff;\n });\n };\n MathBackendCPU.prototype.ceil = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n newValues[i] = Math.ceil(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.floor = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n newValues[i] = Math.floor(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.sign = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n if (values[i] < 0) {\n newValues[i] = -1;\n }\n else if (values[i] > 0) {\n newValues[i] = 1;\n }\n else {\n newValues[i] = 0;\n }\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.round = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n var base = Math.floor(values[i]);\n if (values[i] - base < 0.5) {\n newValues[i] = Math.floor(values[i]);\n }\n else if (values[i] - base > 0.5) {\n newValues[i] = Math.ceil(values[i]);\n }\n else {\n if (base % 2.0 === 0.0) {\n newValues[i] = base;\n }\n else {\n newValues[i] = base + 1.0;\n }\n }\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.exp = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n newValues[i] = Math.exp(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.expm1 = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n newValues[i] = Math.expm1(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.log = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n var value = values[i];\n newValues[i] = Math.log(value);\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.log1p = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n var value = values[i];\n newValues[i] = Math.log1p(value);\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.sqrt = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n var value = values[i];\n newValues[i] = Math.sqrt(value);\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.rsqrt = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n var value = values[i];\n newValues[i] = 1 / Math.sqrt(value);\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.square = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n var value = values[i];\n newValues[i] = value * value;\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.reciprocal = function (x) {\n var values = x.dataSync();\n var newValues = new Float32Array(values.length);\n for (var i = 0; i < values.length; ++i) {\n newValues[i] = 1 / values[i];\n }\n return tensor_1.Tensor.make(x.shape, { values: newValues });\n };\n MathBackendCPU.prototype.relu = function (x) {\n var res = ops.zeros(x.shape, x.dtype);\n var resVals = res.dataSync();\n var inVals = x.dataSync();\n for (var i = 0; i < inVals.length; ++i) {\n resVals[i] = Math.max(0, inVals[i]);\n }\n return res;\n };\n MathBackendCPU.prototype.elu = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n var v = values[i];\n if (v >= 0) {\n resultValues[i] = v;\n }\n else {\n resultValues[i] = (Math.exp(v) - 1);\n }\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.eluDer = function (dy, y) {\n var resultValues = new Float32Array(y.size);\n var values = y.dataSync();\n var dyValues = dy.dataSync();\n for (var i = 0; i < values.length; ++i) {\n var v = values[i];\n if (v >= 1) {\n resultValues[i] = dyValues[i];\n }\n else {\n resultValues[i] = dyValues[i] * (v + 1);\n }\n }\n return tensor_1.Tensor.make(y.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.selu = function (x) {\n var scaleAlpha = selu_util.SELU_SCALEALPHA;\n var scale = selu_util.SELU_SCALE;\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n var v = values[i];\n if (v >= 0) {\n resultValues[i] = scale * v;\n }\n else {\n resultValues[i] = scaleAlpha * (Math.exp(v) - 1);\n }\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.clip = function (x, min, max) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.min(max, Math.max(min, values[i]));\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.abs = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.abs(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.int = function (x) {\n var resultValues = new Int32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = values[i];\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues }, 'int32');\n };\n MathBackendCPU.prototype.sigmoid = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = 1 / (1 + Math.exp(-values[i]));\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.softplus = function (x) {\n var epsilon = 1.1920928955078125e-7;\n var threshold = Math.log(epsilon) + 2.0;\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n var tooLarge = values[i] > -threshold;\n var tooSmall = values[i] < threshold;\n var expX = Math.exp(values[i]);\n var result = void 0;\n if (tooSmall) {\n result = expX;\n }\n else if (tooLarge) {\n result = values[i];\n }\n else {\n result = Math.log(1.0 + expX);\n }\n resultValues[i] = result;\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.sin = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.sin(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.cos = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.cos(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.tan = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.tan(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.asin = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.asin(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.acos = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.acos(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.atan = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.atan(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.atan2 = function (a, b) {\n return this.broadcastedBinaryOp(a, b, a.dtype, function (aValue, bValue) { return Math.atan2(aValue, bValue); });\n };\n MathBackendCPU.prototype.sinh = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.sinh(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.cosh = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.cosh(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.tanh = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = util.tanh(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.asinh = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.asinh(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.acosh = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.acosh(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.atanh = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n resultValues[i] = Math.atanh(values[i]);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.erf = function (x) {\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n var p = erf_util.ERF_P;\n var a1 = erf_util.ERF_A1;\n var a2 = erf_util.ERF_A2;\n var a3 = erf_util.ERF_A3;\n var a4 = erf_util.ERF_A4;\n var a5 = erf_util.ERF_A5;\n for (var i = 0; i < values.length; ++i) {\n var v = values[i];\n var t = 1.0 / (1.0 + p * v);\n resultValues[i] = 1.0 -\n (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1) * t *\n Math.exp(-v * v);\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.step = function (x, alpha) {\n if (alpha === void 0) { alpha = 0; }\n var resultValues = new Float32Array(x.size);\n var values = x.dataSync();\n for (var i = 0; i < values.length; ++i) {\n var value = values[i];\n if (isNaN(value)) {\n resultValues[i] = NaN;\n }\n else {\n resultValues[i] = value > 0 ? 1 : alpha;\n }\n }\n return tensor_1.Tensor.make(x.shape, { values: resultValues });\n };\n MathBackendCPU.prototype.conv2d = function (x, filter, convInfo) {\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var dilationHeight = convInfo.dilationHeight;\n var dilationWidth = convInfo.dilationWidth;\n var padLeft = convInfo.padInfo.left;\n var padTop = convInfo.padInfo.top;\n var y = ops.buffer(convInfo.outShape, x.dtype);\n for (var b = 0; b < convInfo.batchSize; ++b) {\n for (var d2 = 0; d2 < convInfo.outChannels; ++d2) {\n for (var yR = 0; yR < convInfo.outHeight; ++yR) {\n var xRCorner = yR * convInfo.strideHeight - padLeft;\n for (var yC = 0; yC < convInfo.outWidth; ++yC) {\n var xCCorner = yC * convInfo.strideWidth - padTop;\n var dotProd = 0;\n for (var wR = 0; wR < filterHeight; wR++) {\n var xR = xRCorner + wR * dilationHeight;\n if (xR < 0 || xR >= convInfo.inHeight) {\n continue;\n }\n for (var wC = 0; wC < filterWidth; wC++) {\n var xC = xCCorner + wC * dilationWidth;\n if (xC < 0 || xC >= convInfo.inWidth) {\n continue;\n }\n for (var d1 = 0; d1 < convInfo.inChannels; ++d1) {\n var pixel = x.get(b, xR, xC, d1);\n var weight = filter.get(wR, wC, d1, d2);\n dotProd += pixel * weight;\n }\n }\n }\n y.set(dotProd, b, yR, yC, d2);\n }\n }\n }\n }\n return y.toTensor();\n };\n MathBackendCPU.prototype.conv2dDerInput = function (dy, filter, convInfo) {\n var dx = ops.buffer(convInfo.inShape, 'float32');\n var dxValues = dx.values;\n var _a = dx.strides, dxS0 = _a[0], dxS1 = _a[1], dxS2 = _a[2];\n var dyValues = dy.dataSync();\n var _b = dy.strides, dyS0 = _b[0], dyS1 = _b[1], dyS2 = _b[2];\n var fltValues = filter.dataSync();\n var _c = filter.strides, fltS0 = _c[0], fltS1 = _c[1], fltS2 = _c[2];\n var batchSize = convInfo.batchSize, filterHeight = convInfo.filterHeight, filterWidth = convInfo.filterWidth, inChannels = convInfo.inChannels, inHeight = convInfo.inHeight, inWidth = convInfo.inWidth, outChannels = convInfo.outChannels, outHeight = convInfo.outHeight, outWidth = convInfo.outWidth, strideHeight = convInfo.strideHeight, strideWidth = convInfo.strideWidth;\n var topPad = filterHeight - 1 - convInfo.padInfo.top;\n var leftPad = filterWidth - 1 - convInfo.padInfo.left;\n for (var b = 0; b < batchSize; ++b) {\n for (var d1 = 0; d1 < inChannels; ++d1) {\n for (var xR = 0; xR < inHeight; ++xR) {\n var xRCorner = xR - topPad;\n var xRMin = Math.max(0, Math.ceil(xRCorner / strideHeight));\n var yRMax = Math.min(outHeight, (filterHeight + xRCorner) / strideHeight);\n for (var xC = 0; xC < inWidth; ++xC) {\n var xCCorner = xC - leftPad;\n var xCMin = Math.max(0, Math.ceil(xCCorner / strideWidth));\n var yCMax = Math.min(outWidth, (filterWidth + xCCorner) / strideWidth);\n var dotProd = 0;\n for (var yR = xRMin; yR < yRMax; ++yR) {\n var wR = yR * strideHeight - xRCorner;\n for (var yC = xCMin; yC < yCMax; ++yC) {\n var wC = yC * strideWidth - xCCorner;\n var dyOffset = dyS0 * b + dyS1 * yR + dyS2 * yC;\n var fltOffset = fltS0 * (filterHeight - 1 - wR) +\n fltS1 * (filterWidth - 1 - wC) + fltS2 * d1;\n for (var d2 = 0; d2 < outChannels; ++d2) {\n var pixel = dyValues[dyOffset + d2];\n var weight = fltValues[fltOffset + d2];\n dotProd += pixel * weight;\n }\n }\n }\n dxValues[dxS0 * b + dxS1 * xR + dxS2 * xC + d1] = dotProd;\n }\n }\n }\n }\n return dx.toTensor();\n };\n MathBackendCPU.prototype.conv2dDerFilter = function (x, dy, convInfo) {\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var dW = ops.buffer(convInfo.filterShape, 'float32');\n var leftPad = convInfo.padInfo.left;\n var topPad = convInfo.padInfo.top;\n for (var wR = 0; wR < filterHeight; ++wR) {\n var yRMin = Math.max(0, Math.ceil((topPad - wR) / strideHeight));\n var yRMax = Math.min(convInfo.outHeight, (convInfo.inHeight + topPad - wR) / strideHeight);\n for (var wC = 0; wC < filterWidth; ++wC) {\n var yCMin = Math.max(0, Math.ceil((leftPad - wC) / strideWidth));\n var yCMax = Math.min(convInfo.outWidth, (convInfo.inWidth + leftPad - wC) / strideWidth);\n for (var d1 = 0; d1 < convInfo.inChannels; ++d1) {\n for (var d2 = 0; d2 < convInfo.outChannels; ++d2) {\n var dotProd = 0;\n for (var b = 0; b < convInfo.batchSize; ++b) {\n for (var yR = yRMin; yR < yRMax; ++yR) {\n var xR = wR + yR * strideHeight - topPad;\n for (var yC = yCMin; yC < yCMax; ++yC) {\n var xC = wC + yC * strideWidth - leftPad;\n dotProd += x.get(b, xR, xC, d1) * dy.get(b, yR, yC, d2);\n }\n }\n }\n dW.set(dotProd, wR, wC, d1, d2);\n }\n }\n }\n }\n return dW.toTensor();\n };\n MathBackendCPU.prototype.depthwiseConv2D = function (x, filter, convInfo) {\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var dilationHeight = convInfo.dilationHeight;\n var dilationWidth = convInfo.dilationWidth;\n var padLeft = convInfo.padInfo.left;\n var padTop = convInfo.padInfo.top;\n var chMul = convInfo.outChannels / convInfo.inChannels;\n var y = ops.buffer(convInfo.outShape, x.dtype);\n for (var b = 0; b < convInfo.batchSize; ++b) {\n for (var d1 = 0; d1 < convInfo.inChannels; ++d1) {\n for (var yR = 0; yR < convInfo.outHeight; ++yR) {\n var xRCorner = yR * convInfo.strideHeight - padLeft;\n for (var yC = 0; yC < convInfo.outWidth; ++yC) {\n var xCCorner = yC * convInfo.strideWidth - padTop;\n for (var q = 0; q < chMul; ++q) {\n var dotProd = 0;\n for (var wR = 0; wR < filterHeight; ++wR) {\n var xR = xRCorner + wR * dilationHeight;\n if (xR < 0 || xR >= convInfo.inHeight) {\n continue;\n }\n for (var wC = 0; wC < filterWidth; ++wC) {\n var xC = xCCorner + wC * dilationWidth;\n if (xC < 0 || xC >= convInfo.inWidth) {\n continue;\n }\n var pixel = x.get(b, xR, xC, d1);\n var weight = filter.get(wR, wC, d1, q);\n dotProd += pixel * weight;\n }\n }\n y.set(dotProd, b, yR, yC, d1 * chMul + q);\n }\n }\n }\n }\n }\n return y.toTensor();\n };\n MathBackendCPU.prototype.tile = function (x, reps) {\n var newShape = new Array(x.rank);\n for (var i = 0; i < newShape.length; i++) {\n newShape[i] = x.shape[i] * reps[i];\n }\n var result = ops.buffer(newShape, x.dtype);\n var xBuf = x.buffer();\n for (var i = 0; i < result.values.length; ++i) {\n var newLoc = result.indexToLoc(i);\n var originalLoc = new Array(x.rank);\n for (var i_1 = 0; i_1 < originalLoc.length; i_1++) {\n originalLoc[i_1] = newLoc[i_1] % x.shape[i_1];\n }\n var originalIndex = xBuf.locToIndex(originalLoc);\n result.values[i] = xBuf.values[originalIndex];\n }\n return result.toTensor();\n };\n MathBackendCPU.prototype.pad = function (x, paddings, constantValue) {\n var outShape = paddings.map(function (p, i) { return p[0] + x.shape[i] + p[1]; });\n var start = paddings.map(function (p) { return p[0]; });\n var xBuffer = x.buffer();\n var buffer = ops.buffer(outShape, x.dtype);\n if (constantValue !== 0) {\n buffer.values.fill(constantValue);\n }\n for (var i = 0; i < x.size; i++) {\n var coords = xBuffer.indexToLoc(i);\n var outCoords = coords.map(function (c, i) { return c + start[i]; });\n buffer.set.apply(buffer, [x.get.apply(x, coords)].concat(outCoords));\n }\n return buffer.toTensor();\n };\n MathBackendCPU.prototype.transpose = function (x, perm) {\n var newShape = new Array(x.rank);\n for (var i = 0; i < newShape.length; i++) {\n newShape[i] = x.shape[perm[i]];\n }\n var values = x.dataSync();\n var result = ops_1.buffer(newShape, x.dtype);\n var xBuf = x.buffer();\n for (var i = 0; i < x.size; ++i) {\n var loc = xBuf.indexToLoc(i);\n var newLoc = new Array(loc.length);\n for (var i_2 = 0; i_2 < newLoc.length; i_2++) {\n newLoc[i_2] = loc[perm[i_2]];\n }\n var newIndex = result.locToIndex(newLoc);\n result.values[newIndex] = values[i];\n }\n return result.toTensor();\n };\n MathBackendCPU.prototype.gather = function (x, indices, axis) {\n var newShape = x.shape.slice();\n var indicesValues = indices.dataSync();\n newShape[axis] = indicesValues.length;\n var result = ops_1.buffer(newShape, x.dtype);\n var xBuf = x.buffer();\n for (var i = 0; i < result.size; ++i) {\n var newLoc = result.indexToLoc(i);\n var originalLoc = newLoc.slice();\n originalLoc[axis] = indicesValues[newLoc[axis]];\n var originalIndex = xBuf.locToIndex(originalLoc);\n result.values[i] = xBuf.values[originalIndex];\n }\n return result.toTensor();\n };\n MathBackendCPU.prototype.pool = function (x, convInfo, poolType) {\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var y = ops.buffer(convInfo.outShape, 'float32');\n var padTop = convInfo.padInfo.top;\n var padLeft = convInfo.padInfo.left;\n for (var b = 0; b < convInfo.batchSize; ++b) {\n for (var d = 0; d < convInfo.inChannels; ++d) {\n for (var yR = 0; yR < convInfo.outHeight; ++yR) {\n var xRCorner = yR * strideHeight - padTop;\n var xRMin = Math.max(0, xRCorner);\n var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner);\n for (var yC = 0; yC < convInfo.outWidth; ++yC) {\n var xCCorner = yC * strideWidth - padLeft;\n var xCMin = Math.max(0, xCCorner);\n var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner);\n var minMaxValue = (poolType === 'max' ? Number.NEGATIVE_INFINITY :\n Number.POSITIVE_INFINITY);\n var avgValue = 0;\n var count = 0;\n for (var xR = xRMin; xR < xRMax; ++xR) {\n for (var xC = xCMin; xC < xCMax; ++xC) {\n var pixel = x.get(b, xR, xC, d);\n if ((poolType === 'max' && pixel > minMaxValue)) {\n minMaxValue = pixel;\n }\n else if (poolType === 'avg') {\n avgValue += pixel;\n count++;\n }\n }\n if (isNaN(minMaxValue)) {\n break;\n }\n }\n y.set(poolType === 'avg' ? avgValue / count : minMaxValue, b, yR, yC, d);\n }\n }\n }\n }\n return y.toTensor();\n };\n MathBackendCPU.prototype.maxPool = function (x, convInfo) {\n return this.pool(x, convInfo, 'max');\n };\n MathBackendCPU.prototype.maxPoolPositions = function (x, convInfo) {\n var maxPositions = ops.buffer(convInfo.outShape, 'int32');\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var padTop = convInfo.padInfo.top;\n var padLeft = convInfo.padInfo.left;\n for (var b = 0; b < convInfo.batchSize; ++b) {\n for (var d = 0; d < convInfo.inChannels; ++d) {\n for (var yR = 0; yR < convInfo.outHeight; ++yR) {\n var xRCorner = yR * strideHeight - padTop;\n var xRMin = Math.max(0, xRCorner);\n var xRMax = Math.min(convInfo.inHeight, filterHeight + xRCorner);\n for (var yC = 0; yC < convInfo.outWidth; ++yC) {\n var xCCorner = yC * strideWidth - padLeft;\n var xCMin = Math.max(0, xCCorner);\n var xCMax = Math.min(convInfo.inWidth, filterWidth + xCCorner);\n var maxValue = Number.NEGATIVE_INFINITY;\n var maxPosition = -1;\n for (var xR = xRMin; xR < xRMax; ++xR) {\n var wR = xR - xRCorner;\n for (var xC = xCMin; xC < xCMax; ++xC) {\n var wC = xC - xCCorner;\n var pixel = x.get(b, xR, xC, d);\n if (pixel > maxValue) {\n maxValue = pixel;\n maxPosition = wR * filterWidth + wC;\n }\n }\n }\n maxPositions.set(maxPosition, b, yR, yC, d);\n }\n }\n }\n }\n return maxPositions.toTensor();\n };\n MathBackendCPU.prototype.maxPoolBackprop = function (dy, x, y, convInfo) {\n var maxPositions = this.maxPoolPositions(x, convInfo);\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var padLeft = filterWidth - 1 - convInfo.padInfo.left;\n var padTop = filterHeight - 1 - convInfo.padInfo.top;\n var dx = ops.buffer(x.shape, 'float32');\n for (var b = 0; b < convInfo.batchSize; ++b) {\n for (var d = 0; d < convInfo.inChannels; ++d) {\n for (var dxR = 0; dxR < convInfo.inHeight; ++dxR) {\n for (var dxC = 0; dxC < convInfo.inWidth; ++dxC) {\n var dyRCorner = dxR - padTop;\n var dyCCorner = dxC - padLeft;\n var dotProd = 0;\n for (var wR = 0; wR < filterHeight; ++wR) {\n var dyR = (dyRCorner + wR) / strideHeight;\n if (dyR < 0 || dyR >= convInfo.outHeight ||\n Math.floor(dyR) !== dyR) {\n continue;\n }\n for (var wC = 0; wC < filterWidth; ++wC) {\n var dyC = (dyCCorner + wC) / strideWidth;\n if (dyC < 0 || dyC >= convInfo.outWidth ||\n Math.floor(dyC) !== dyC) {\n continue;\n }\n var maxPos = filterHeight * filterWidth - 1 -\n maxPositions.get(b, dyR, dyC, d);\n var curPos = wR * filterWidth + wC;\n var mask = maxPos === curPos ? 1 : 0;\n if (mask === 0) {\n continue;\n }\n var pixel = dy.get(b, dyR, dyC, d);\n dotProd += pixel * mask;\n }\n }\n dx.set(dotProd, b, dxR, dxC, d);\n }\n }\n }\n }\n return dx.toTensor();\n };\n MathBackendCPU.prototype.avgPoolBackprop = function (dy, x, convInfo) {\n var strideHeight = convInfo.strideHeight;\n var strideWidth = convInfo.strideWidth;\n var filterHeight = convInfo.filterHeight;\n var filterWidth = convInfo.filterWidth;\n var padLeft = filterWidth - 1 - convInfo.padInfo.left;\n var padTop = filterHeight - 1 - convInfo.padInfo.top;\n var dx = ops.buffer(x.shape, 'float32');\n var avgMultiplier = 1 / (filterHeight * filterWidth);\n for (var b = 0; b < convInfo.batchSize; ++b) {\n for (var d = 0; d < convInfo.inChannels; ++d) {\n for (var dxR = 0; dxR < convInfo.inHeight; ++dxR) {\n for (var dxC = 0; dxC < convInfo.inWidth; ++dxC) {\n var dyRCorner = dxR - padTop;\n var dyCCorner = dxC - padLeft;\n var dotProd = 0;\n for (var wR = 0; wR < filterHeight; ++wR) {\n var dyR = (dyRCorner + wR) / strideHeight;\n if (dyR < 0 || dyR >= convInfo.outHeight ||\n Math.floor(dyR) !== dyR) {\n continue;\n }\n for (var wC = 0; wC < filterWidth; ++wC) {\n var dyC = (dyCCorner + wC) / strideWidth;\n if (dyC < 0 || dyC >= convInfo.outWidth ||\n Math.floor(dyC) !== dyC) {\n continue;\n }\n var pixel = dy.get(b, dyR, dyC, d);\n dotProd += pixel;\n }\n }\n dx.set(dotProd * avgMultiplier, b, dxR, dxC, d);\n }\n }\n }\n }\n return dx.toTensor();\n };\n MathBackendCPU.prototype.cast = function (x, dtype) {\n return backend_util.castTensor(x, dtype, this);\n };\n MathBackendCPU.prototype.reshape = function (x, shape) {\n return backend_util.reshapeTensor(x, shape);\n };\n MathBackendCPU.prototype.avgPool = function (x, convInfo) {\n return this.pool(x, convInfo, 'avg').toFloat();\n };\n MathBackendCPU.prototype.resizeBilinear = function (x, newHeight, newWidth, alignCorners) {\n var _a = x.shape, batch = _a[0], oldHeight = _a[1], oldWidth = _a[2], numChannels = _a[3];\n var output = ops.buffer([batch, newHeight, newWidth, numChannels], x.dtype);\n var effectiveInputSize = [\n (alignCorners && newHeight > 1) ? oldHeight - 1 : oldHeight,\n (alignCorners && newWidth > 1) ? oldWidth - 1 : oldWidth\n ];\n var effectiveOutputSize = [\n (alignCorners && newHeight > 1) ? newHeight - 1 : newHeight,\n (alignCorners && newWidth > 1) ? newWidth - 1 : newWidth\n ];\n for (var b = 0; b < batch; b++) {\n for (var r = 0; r < newHeight; r++) {\n for (var c = 0; c < newWidth; c++) {\n for (var d = 0; d < numChannels; d++) {\n var sourceFracRow = (effectiveInputSize[0]) * r / (effectiveOutputSize[0]);\n var sourceFracCol = (effectiveInputSize[1]) * c / (effectiveOutputSize[1]);\n var sourceRowFloor = Math.floor(sourceFracRow);\n var sourceRowCeil = Math.min(oldHeight - 1, Math.ceil(sourceFracRow));\n var sourceColFloor = Math.floor(sourceFracCol);\n var sourceColCeil = Math.min(oldWidth - 1, Math.ceil(sourceFracCol));\n var topLeft = x.get(b, sourceRowFloor, sourceColFloor, d);\n var bottomLeft = x.get(b, sourceRowCeil, sourceColFloor, d);\n var topRight = x.get(b, sourceRowFloor, sourceColCeil, d);\n var bottomRight = x.get(b, sourceRowCeil, sourceColCeil, d);\n var rowFrac = sourceFracRow - sourceRowFloor;\n var colFrac = sourceFracCol - sourceColFloor;\n var top_1 = topLeft + (topRight - topLeft) * colFrac;\n var bottom = bottomLeft + (bottomRight - bottomLeft) * colFrac;\n var newValue = top_1 + (bottom - top_1) * rowFrac;\n output.set(newValue, b, r, c, d);\n }\n }\n }\n }\n return output.toTensor();\n };\n MathBackendCPU.prototype.resizeBilinearBackprop = function (dy, x, alignCorners) {\n var _a = x.shape, batch = _a[0], xHeight = _a[1], xWidth = _a[2], depth = _a[3];\n var _b = dy.shape, yHeight = _b[1], yWidth = _b[2];\n var output = ops.buffer([batch, xHeight, xWidth, depth], x.dtype);\n var effectiveXSize = [\n (alignCorners && yHeight > 1) ? xHeight - 1 : xHeight,\n (alignCorners && yWidth > 1) ? xWidth - 1 : xWidth\n ];\n var effectiveYSize = [\n (alignCorners && yHeight > 1) ? yHeight - 1 : yHeight,\n (alignCorners && yWidth > 1) ? yWidth - 1 : yWidth\n ];\n var heightScale = effectiveXSize[0] / effectiveYSize[0];\n var widthScale = effectiveXSize[1] / effectiveYSize[1];\n for (var b = 0; b < batch; b++) {\n for (var r = 0; r < yHeight; r++) {\n var dxR = r * heightScale;\n var topDxRIndex = Math.floor(dxR);\n var bottomDxRIndex = Math.min(Math.ceil(dxR), xHeight - 1);\n var dxRLerp = dxR - topDxRIndex;\n var inverseDxRLerp = 1.0 - dxRLerp;\n for (var c = 0; c < yWidth; c++) {\n var dxC = c * widthScale;\n var leftDxCIndex = Math.floor(dxC);\n var rightDxCIndex = Math.min(Math.ceil(dxC), xWidth - 1);\n var dxCLerp = dxC - leftDxCIndex;\n var inverseDxCLerp = 1.0 - dxCLerp;\n for (var d = 0; d < depth; d++) {\n var dyVal = dy.get(b, r, c, d);\n var topLeft = output.get(b, topDxRIndex, leftDxCIndex, d);\n topLeft += dyVal * inverseDxRLerp * inverseDxCLerp;\n output.set(topLeft, b, topDxRIndex, leftDxCIndex, d);\n var topRight = output.get(b, topDxRIndex, rightDxCIndex, d);\n topRight += dyVal * inverseDxRLerp * dxCLerp;\n output.set(topRight, b, topDxRIndex, rightDxCIndex, d);\n var bottomLeft = output.get(b, bottomDxRIndex, leftDxCIndex, d);\n bottomLeft += dyVal * dxRLerp * inverseDxCLerp;\n output.set(bottomLeft, b, bottomDxRIndex, leftDxCIndex, d);\n var bottomRight = output.get(b, bottomDxRIndex, rightDxCIndex, d);\n bottomRight += dyVal * dxRLerp * dxCLerp;\n output.set(bottomRight, b, bottomDxRIndex, rightDxCIndex, d);\n }\n }\n }\n }\n return output.toTensor();\n };\n MathBackendCPU.prototype.resizeNearestNeighbor = function (x, newHeight, newWidth, alignCorners) {\n var _a = x.shape, batch = _a[0], oldHeight = _a[1], oldWidth = _a[2], numChannels = _a[3];\n var output = ops.buffer([batch, newHeight, newWidth, numChannels], x.dtype);\n var effectiveInputSize = alignCorners ? [oldHeight - 1, oldWidth - 1] : [oldHeight, oldWidth];\n var effectiveOutputSize = alignCorners ? [newHeight - 1, newWidth - 1] : [newHeight, newWidth];\n for (var b = 0; b < batch; b++) {\n for (var r = 0; r < newHeight; r++) {\n for (var c = 0; c < newWidth; c++) {\n for (var d = 0; d < numChannels; d++) {\n var sourceFracRow = (effectiveInputSize[0]) * r / (effectiveOutputSize[0]);\n var sourceFracCol = (effectiveInputSize[1]) * c / (effectiveOutputSize[1]);\n var sourceNearestRow = Math.min(oldHeight - 1, alignCorners ? Math.round(sourceFracRow) :\n Math.floor(sourceFracRow));\n var sourceNearestCol = Math.min(oldWidth - 1, alignCorners ? Math.round(sourceFracCol) :\n Math.floor(sourceFracCol));\n var newValue = x.get(b, sourceNearestRow, sourceNearestCol, d);\n output.set(newValue, b, r, c, d);\n }\n }\n }\n }\n return output.toTensor();\n };\n MathBackendCPU.prototype.batchNormalization = function (x, mean, variance, varianceEpsilon, scale, offset) {\n var xValues = x.dataSync();\n var meanValues = mean.dataSync();\n var varianceValues = variance.dataSync();\n var scaleValues = scale ? scale.dataSync() : new Float32Array([1]);\n var offsetValues = offset ? offset.dataSync() : new Float32Array([0]);\n var outValues = new Float32Array(xValues.length);\n for (var i = 0; i < xValues.length; i++) {\n outValues[i] = offsetValues[i % offsetValues.length] +\n (xValues[i] - meanValues[i % meanValues.length]) *\n scaleValues[i % scaleValues.length] /\n Math.sqrt(varianceValues[i % varianceValues.length] + varianceEpsilon);\n }\n return ops_1.tensor4d(outValues, x.shape);\n };\n MathBackendCPU.prototype.localResponseNormalization4D = function (x, radius, bias, alpha, beta) {\n var output = ops.buffer(x.shape, 'float32');\n var rad = radius;\n var maxD = output.shape[3] - 1;\n function sumAcrossChannels(b, r, c, d) {\n var sum = 0.0;\n for (var j = Math.max(0, d - rad); j <= Math.min(d + rad, maxD); j++) {\n var z = x.get(b, r, c, j);\n sum += z * z;\n }\n return sum;\n }\n for (var b = 0; b < output.shape[0]; b++) {\n for (var r = 0; r <= output.shape[1]; r++) {\n for (var c = 0; c < output.shape[2]; c++) {\n for (var d = 0; d < output.shape[3]; d++) {\n var sum = sumAcrossChannels(b, r, c, d);\n var val = x.get(b, r, c, d) * Math.pow(bias + alpha * sum, -beta);\n output.set(val, b, r, c, d);\n }\n }\n }\n }\n return output.toTensor();\n };\n MathBackendCPU.prototype.multinomial = function (logits, normalized, numSamples, seed) {\n var probabilities = normalized ? logits : ops.softmax(logits);\n var batchSize = probabilities.shape[0];\n var numEvents = probabilities.shape[1];\n var res = ops.zeros([batchSize, numSamples], 'int32');\n var resVals = res.dataSync();\n var probVals = probabilities.dataSync();\n for (var b = 0; b < batchSize; ++b) {\n var offset = b * numEvents;\n var cdf = new Float32Array(numEvents - 1);\n cdf[0] = probVals[offset];\n for (var event_1 = 1; event_1 < cdf.length; ++event_1) {\n cdf[event_1] = cdf[event_1 - 1] + probVals[offset + event_1];\n }\n var random = seedrandom.alea(seed.toString());\n var outOffset = b * numSamples;\n for (var sampleId = 0; sampleId < numSamples; ++sampleId) {\n var r = random();\n resVals[outOffset + sampleId] = cdf.length;\n for (var event_2 = 0; event_2 < cdf.length; event_2++) {\n if (r < cdf[event_2]) {\n resVals[outOffset + sampleId] = event_2;\n break;\n }\n }\n }\n }\n return res;\n };\n MathBackendCPU.prototype.oneHot = function (indices, depth, onValue, offValue) {\n var res = new Float32Array(indices.size * depth);\n res.fill(offValue);\n for (var event_3 = 0; event_3 < indices.size; ++event_3) {\n res[event_3 * depth + indices.get(event_3)] = onValue;\n }\n return ops.tensor2d(res, [indices.size, depth]);\n };\n MathBackendCPU.prototype.broadcastedBinaryOp = function (a, b, dtype, op) {\n var newShape = broadcast_util.assertAndGetBroadcastShape(a.shape, b.shape);\n var result = ops.buffer(newShape, dtype);\n var aValues = a.dataSync();\n var bValues = b.dataSync();\n var aBroadcastDims = broadcast_util.getBroadcastDims(a.shape, newShape);\n var bBroadcastDims = broadcast_util.getBroadcastDims(b.shape, newShape);\n var aBuf = a.buffer();\n var bBuf = b.buffer();\n var _loop_2 = function (i) {\n var loc = result.indexToLoc(i);\n var aLoc = loc.slice(-a.rank);\n aBroadcastDims.forEach(function (d) { return aLoc[d] = 0; });\n var aIndex = aBuf.locToIndex(aLoc);\n var bLoc = loc.slice(-b.rank);\n bBroadcastDims.forEach(function (d) { return bLoc[d] = 0; });\n var bIndex = bBuf.locToIndex(bLoc);\n result.values[i] = op(aValues[aIndex], bValues[bIndex]);\n };\n for (var i = 0; i < result.values.length; ++i) {\n _loop_2(i);\n }\n return result.toTensor();\n };\n MathBackendCPU.prototype.dispose = function () { };\n return MathBackendCPU;\n}());\nexports.MathBackendCPU = MathBackendCPU;\nenvironment_1.ENV.registerBackend('cpu', function () { return new MathBackendCPU(); }, 1);\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"./doc\");\nvar BrowserUtil = (function () {\n function BrowserUtil() {\n }\n BrowserUtil.nextFrame = function () {\n return new Promise(function (resolve) { return requestAnimationFrame(function () { return resolve(); }); });\n };\n __decorate([\n doc_1.doc({ heading: 'Performance', subheading: 'Timing' })\n ], BrowserUtil, \"nextFrame\", null);\n return BrowserUtil;\n}());\nexports.BrowserUtil = BrowserUtil;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.DTYPE_VALUE_SIZE_MAP = {\n 'float32': 4,\n 'int32': 4,\n 'uint16': 2,\n 'uint8': 1,\n 'bool': 1,\n};\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar array_ops_1 = require(\"../ops/array_ops\");\nvar util_1 = require(\"../util\");\nvar types_1 = require(\"./types\");\nfunction encodeWeights(tensors) {\n return __awaiter(this, void 0, void 0, function () {\n var specs, dataPromises, name_1, t, tensorValues;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n specs = [];\n dataPromises = [];\n for (name_1 in tensors) {\n t = tensors[name_1];\n if (t.dtype !== 'float32' && t.dtype !== 'int32' && t.dtype !== 'bool') {\n throw new Error(\"Unsupported dtype in weight '\" + name_1 + \"': \" + t.dtype);\n }\n specs.push({ name: name_1, shape: t.shape, dtype: t.dtype });\n dataPromises.push(t.data());\n }\n return [4, Promise.all(dataPromises)];\n case 1:\n tensorValues = _a.sent();\n return [2, { data: concatenateTypedArrays(tensorValues), specs: specs }];\n }\n });\n });\n}\nexports.encodeWeights = encodeWeights;\nfunction decodeWeights(buffer, specs) {\n var out = {};\n var offset = 0;\n for (var _i = 0, specs_1 = specs; _i < specs_1.length; _i++) {\n var spec = specs_1[_i];\n var name_2 = spec.name;\n var dtype = spec.dtype;\n var shape = spec.shape;\n if (spec.quantization != null) {\n throw new Error(\"decodeWeights does not support quantization yet, but encountered \" +\n (\"weight '\" + name_2 + \" with quantization.'\"));\n }\n var size = util_1.sizeFromShape(shape);\n var value = void 0;\n if (dtype === 'float32') {\n value = array_ops_1.ArrayOps.tensor(new Float32Array(buffer, offset, size), shape, 'float32');\n }\n else if (dtype === 'int32') {\n value =\n array_ops_1.ArrayOps.tensor(new Int32Array(buffer, offset, size), shape, 'int32');\n }\n else if (dtype === 'bool') {\n value =\n array_ops_1.ArrayOps.tensor(new Uint8Array(buffer, offset, size), shape, 'bool');\n }\n else {\n throw new Error(\"Unsupported dtype in weight '\" + name_2 + \"': \" + dtype);\n }\n out[name_2] = value;\n offset += size * types_1.DTYPE_VALUE_SIZE_MAP[dtype];\n }\n return out;\n}\nexports.decodeWeights = decodeWeights;\nfunction concatenateTypedArrays(xs) {\n if (xs === null) {\n throw new Error(\"Invalid input value: \" + JSON.stringify(xs));\n }\n var totalByteLength = 0;\n xs.forEach(function (x) {\n if (x instanceof Float32Array || x instanceof Int32Array) {\n totalByteLength += x.length * 4;\n }\n else if (x instanceof Uint8Array) {\n totalByteLength += x.length;\n }\n else {\n throw new Error(\"Unsupported TypedArray subtype: \" + x.constructor.name);\n }\n });\n var y = new Uint8Array(totalByteLength);\n var offset = 0;\n xs.forEach(function (x) {\n y.set(new Uint8Array(x.buffer), offset);\n if (x instanceof Float32Array || x instanceof Int32Array) {\n offset += x.length * 4;\n }\n else {\n offset += x.length;\n }\n });\n return y.buffer;\n}\nexports.concatenateTypedArrays = concatenateTypedArrays;\nfunction stringByteLength(str) {\n return new Blob([str]).size;\n}\nexports.stringByteLength = stringByteLength;\nfunction arrayBufferToBase64String(buffer) {\n return btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)));\n}\nexports.arrayBufferToBase64String = arrayBufferToBase64String;\nfunction base64StringToArrayBuffer(str) {\n var s = atob(str);\n var buffer = new Uint8Array(s.length);\n for (var i = 0; i < s.length; ++i) {\n buffer.set([s.charCodeAt(i)], i);\n }\n return buffer.buffer;\n}\nexports.base64StringToArrayBuffer = base64StringToArrayBuffer;\nfunction concatenateArrayBuffers(buffers) {\n var totalByteLength = 0;\n buffers.forEach(function (buffer) {\n totalByteLength += buffer.byteLength;\n });\n var temp = new Uint8Array(totalByteLength);\n var offset = 0;\n buffers.forEach(function (buffer) {\n temp.set(new Uint8Array(buffer), offset);\n offset += buffer.byteLength;\n });\n return temp.buffer;\n}\nexports.concatenateArrayBuffers = concatenateArrayBuffers;\nfunction basename(path) {\n var SEPARATOR = '/';\n path = path.trim();\n while (path.endsWith(SEPARATOR)) {\n path = path.slice(0, path.length - 1);\n }\n var items = path.split(SEPARATOR);\n return items[items.length - 1];\n}\nexports.basename = basename;\nfunction getModelArtifactsInfoForKerasJSON(modelArtifacts) {\n if (modelArtifacts.modelTopology instanceof ArrayBuffer) {\n throw new Error('Expected JSON model topology, received ArrayBuffer.');\n }\n return {\n dateSaved: new Date(),\n modelTopologyType: 'KerasJSON',\n modelTopologyBytes: modelArtifacts.modelTopology == null ?\n 0 :\n stringByteLength(JSON.stringify(modelArtifacts.modelTopology)),\n weightSpecsBytes: modelArtifacts.weightSpecs == null ?\n 0 :\n stringByteLength(JSON.stringify(modelArtifacts.weightSpecs)),\n weightDataBytes: modelArtifacts.weightData == null ?\n 0 :\n modelArtifacts.weightData.byteLength,\n };\n}\nexports.getModelArtifactsInfoForKerasJSON = getModelArtifactsInfoForKerasJSON;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar IORouterRegistry = (function () {\n function IORouterRegistry() {\n this.saveRouters = [];\n this.loadRouters = [];\n }\n IORouterRegistry.getInstance = function () {\n if (IORouterRegistry.instance == null) {\n IORouterRegistry.instance = new IORouterRegistry();\n }\n return IORouterRegistry.instance;\n };\n IORouterRegistry.registerSaveRouter = function (saveRouter) {\n IORouterRegistry.getInstance().saveRouters.push(saveRouter);\n };\n IORouterRegistry.registerLoadRouter = function (loadRouter) {\n IORouterRegistry.getInstance().loadRouters.push(loadRouter);\n };\n IORouterRegistry.getSaveHandlers = function (url) {\n return IORouterRegistry.getHandlers(url, 'save');\n };\n IORouterRegistry.getLoadHandlers = function (url) {\n return IORouterRegistry.getHandlers(url, 'load');\n };\n IORouterRegistry.getHandlers = function (url, handlerType) {\n var validHandlers = [];\n var routers = handlerType === 'load' ? this.getInstance().loadRouters :\n this.getInstance().saveRouters;\n routers.forEach(function (router) {\n var handler = router(url);\n if (handler !== null) {\n validHandlers.push(handler);\n }\n });\n return validHandlers;\n };\n return IORouterRegistry;\n}());\nexports.IORouterRegistry = IORouterRegistry;\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar io_utils_1 = require(\"./io_utils\");\nvar router_registry_1 = require(\"./router_registry\");\nvar DATABASE_NAME = 'tensorflowjs';\nvar DATABASE_VERSION = 1;\nvar OBJECT_STORE_NAME = 'models_store';\nfunction deleteDatabase() {\n return __awaiter(this, void 0, void 0, function () {\n var idbFactory;\n return __generator(this, function (_a) {\n idbFactory = getIndexedDBFactory();\n return [2, new Promise(function (resolve, reject) {\n var deleteRequest = idbFactory.deleteDatabase(DATABASE_NAME);\n deleteRequest.onsuccess = function () { return resolve(); };\n deleteRequest.onerror = function (error) { return reject(error); };\n })];\n });\n });\n}\nexports.deleteDatabase = deleteDatabase;\nfunction getIndexedDBFactory() {\n if (!environment_1.ENV.get('IS_BROWSER')) {\n throw new Error('Failed to obtain IndexedDB factory because the current environment' +\n 'is not a web browser.');\n }\n var theWindow = window;\n var factory = theWindow.indexedDB || theWindow.mozIndexedDB ||\n theWindow.webkitIndexedDB || theWindow.msIndexedDB ||\n theWindow.shimIndexedDB;\n if (factory == null) {\n throw new Error('The current browser does not appear to support IndexedDB.');\n }\n return factory;\n}\nvar BrowserIndexedDB = (function () {\n function BrowserIndexedDB(modelPath) {\n this.indexedDB = getIndexedDBFactory();\n if (modelPath == null || !modelPath) {\n throw new Error('For IndexedDB, modelPath must not be null, undefined or empty.');\n }\n this.modelPath = modelPath;\n }\n BrowserIndexedDB.prototype.save = function (modelArtifacts) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n if (modelArtifacts.modelTopology instanceof ArrayBuffer) {\n throw new Error('BrowserLocalStorage.save() does not support saving model topology ' +\n 'in binary formats yet.');\n }\n return [2, this.databaseAction(this.modelPath, modelArtifacts)];\n });\n });\n };\n BrowserIndexedDB.prototype.load = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n return [2, this.databaseAction(this.modelPath)];\n });\n });\n };\n BrowserIndexedDB.prototype.databaseAction = function (modelPath, modelArtifacts) {\n var _this = this;\n return new Promise(function (resolve, reject) {\n var openRequest = _this.indexedDB.open(DATABASE_NAME, DATABASE_VERSION);\n openRequest.onupgradeneeded = function () { return _this.setUpDatabase(openRequest); };\n openRequest.onsuccess = function () {\n var db = openRequest.result;\n var tx = db.transaction(OBJECT_STORE_NAME, modelArtifacts == null ? 'readonly' : 'readwrite');\n var store = tx.objectStore(OBJECT_STORE_NAME);\n if (modelArtifacts == null) {\n var getRequest_1 = store.get(_this.modelPath);\n getRequest_1.onsuccess = function () {\n if (getRequest_1.result === undefined) {\n reject(new Error(\"Cannot find model with path '\" + _this.modelPath + \"' \" +\n \"in IndexedDB.\"));\n }\n else {\n resolve(getRequest_1.result.modelArtifacts);\n }\n };\n getRequest_1.onerror = function (error) { return reject(getRequest_1.error); };\n }\n else {\n var modelArtifactsInfo_1 = io_utils_1.getModelArtifactsInfoForKerasJSON(modelArtifacts);\n var putRequest_1 = store.put({ modelPath: _this.modelPath, modelArtifacts: modelArtifacts, modelArtifactsInfo: modelArtifactsInfo_1 });\n putRequest_1.onsuccess = function () { return resolve({ modelArtifactsInfo: modelArtifactsInfo_1 }); };\n putRequest_1.onerror = function (error) { return reject(putRequest_1.error); };\n tx.oncomplete = function () { return db.close(); };\n }\n tx.oncomplete = function () { return db.close(); };\n };\n openRequest.onerror = function (error) { return reject(openRequest.error); };\n });\n };\n BrowserIndexedDB.prototype.setUpDatabase = function (openRequest) {\n var db = openRequest.result;\n db.createObjectStore(OBJECT_STORE_NAME, { keyPath: 'modelPath' });\n };\n BrowserIndexedDB.URL_SCHEME = 'indexeddb://';\n return BrowserIndexedDB;\n}());\nexports.BrowserIndexedDB = BrowserIndexedDB;\nexports.indexedDBRouter = function (url) {\n if (!environment_1.ENV.get('IS_BROWSER')) {\n return null;\n }\n else {\n if (url.startsWith(BrowserIndexedDB.URL_SCHEME)) {\n return browserIndexedDB(url.slice(BrowserIndexedDB.URL_SCHEME.length));\n }\n else {\n return null;\n }\n }\n};\nrouter_registry_1.IORouterRegistry.registerSaveRouter(exports.indexedDBRouter);\nrouter_registry_1.IORouterRegistry.registerLoadRouter(exports.indexedDBRouter);\nfunction browserIndexedDB(modelPath) {\n return new BrowserIndexedDB(modelPath);\n}\nexports.browserIndexedDB = browserIndexedDB;\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar io_utils_1 = require(\"./io_utils\");\nvar router_registry_1 = require(\"./router_registry\");\nvar PATH_SEPARATOR = '/';\nvar PATH_PREFIX = 'tensorflowjs_models';\nvar INFO_SUFFIX = 'info';\nvar MODEL_TOPOLOGY_SUFFIX = 'model_topology';\nvar WEIGHT_SPECS_SUFFIX = 'weight_specs';\nvar WEIGHT_DATA_SUFFIX = 'weight_data';\nfunction purgeLocalStorageArtifacts() {\n if (!environment_1.ENV.get('IS_BROWSER') || typeof window.localStorage === 'undefined') {\n throw new Error('purgeLocalStorageModels() cannot proceed because local storage is ' +\n 'unavailable in the current environment.');\n }\n var LS = window.localStorage;\n var purgedModelPaths = [];\n for (var i = 0; i < LS.length; ++i) {\n var key = LS.key(i);\n var prefix = PATH_PREFIX + PATH_SEPARATOR;\n if (key.startsWith(prefix) && key.length > prefix.length) {\n var modelName = key.slice(prefix.length).split(PATH_PREFIX)[0];\n if (purgedModelPaths.indexOf(modelName) === -1) {\n purgedModelPaths.push(modelName);\n }\n }\n }\n return purgedModelPaths;\n}\nexports.purgeLocalStorageArtifacts = purgeLocalStorageArtifacts;\nvar BrowserLocalStorage = (function () {\n function BrowserLocalStorage(modelPath) {\n if (!environment_1.ENV.get('IS_BROWSER') || typeof window.localStorage === 'undefined') {\n throw new Error('The current environment does not support local storage.');\n }\n this.LS = window.localStorage;\n if (modelPath == null || !modelPath) {\n throw new Error('For local storage, modelPath must not be null, undefined or empty.');\n }\n this.modelPath = modelPath;\n var modelRoot = [PATH_PREFIX, this.modelPath].join(PATH_SEPARATOR);\n this.paths = {\n info: [modelRoot, INFO_SUFFIX].join(PATH_SEPARATOR),\n topology: [modelRoot, MODEL_TOPOLOGY_SUFFIX].join(PATH_SEPARATOR),\n weightSpecs: [modelRoot, WEIGHT_SPECS_SUFFIX].join(PATH_SEPARATOR),\n weightData: [modelRoot, WEIGHT_DATA_SUFFIX].join(PATH_SEPARATOR),\n };\n }\n BrowserLocalStorage.prototype.save = function (modelArtifacts) {\n return __awaiter(this, void 0, void 0, function () {\n var topology, weightSpecs, modelArtifactsInfo, key;\n return __generator(this, function (_a) {\n if (modelArtifacts.modelTopology instanceof ArrayBuffer) {\n throw new Error('BrowserLocalStorage.save() does not support saving model topology ' +\n 'in binary formats yet.');\n }\n else {\n topology = JSON.stringify(modelArtifacts.modelTopology);\n weightSpecs = JSON.stringify(modelArtifacts.weightSpecs);\n modelArtifactsInfo = io_utils_1.getModelArtifactsInfoForKerasJSON(modelArtifacts);\n try {\n this.LS.setItem(this.paths.info, JSON.stringify(modelArtifactsInfo));\n this.LS.setItem(this.paths.topology, topology);\n this.LS.setItem(this.paths.weightSpecs, weightSpecs);\n this.LS.setItem(this.paths.weightData, io_utils_1.arrayBufferToBase64String(modelArtifacts.weightData));\n return [2, { modelArtifactsInfo: modelArtifactsInfo }];\n }\n catch (err) {\n for (key in this.paths) {\n this.LS.removeItem(this.paths[key]);\n }\n throw new Error(\"Failed to save model '\" + this.modelPath + \"' to local storage: \" +\n \"size quota being exceeded is a possible cause of this failure: \" +\n (\"modelTopologyBytes=\" + modelArtifactsInfo.modelTopologyBytes + \", \") +\n (\"weightSpecsBytes=\" + modelArtifactsInfo.weightSpecsBytes + \", \") +\n (\"weightDataBytes=\" + modelArtifactsInfo.weightDataBytes + \".\"));\n }\n }\n return [2];\n });\n });\n };\n BrowserLocalStorage.prototype.load = function () {\n return __awaiter(this, void 0, void 0, function () {\n var info, out, topology, weightSpecs, weightDataBase64;\n return __generator(this, function (_a) {\n info = JSON.parse(this.LS.getItem(this.paths.info));\n if (info == null) {\n throw new Error(\"In local storage, there is no model with name '\" + this.modelPath + \"'\");\n }\n if (info.modelTopologyType !== 'KerasJSON') {\n throw new Error('BrowserLocalStorage does not support loading non-JSON model ' +\n 'topology yet.');\n }\n out = {};\n topology = JSON.parse(this.LS.getItem(this.paths.topology));\n if (topology == null) {\n throw new Error(\"In local storage, the topology of model '\" + this.modelPath + \"' \" +\n \"is missing.\");\n }\n out.modelTopology = topology;\n weightSpecs = JSON.parse(this.LS.getItem(this.paths.weightSpecs));\n if (weightSpecs == null) {\n throw new Error(\"In local storage, the weight specs of model '\" + this.modelPath + \"' \" +\n \"are missing.\");\n }\n out.weightSpecs = weightSpecs;\n weightDataBase64 = this.LS.getItem(this.paths.weightData);\n if (weightDataBase64 == null) {\n throw new Error(\"In local storage, the binary weight values of model \" +\n (\"'\" + this.modelPath + \"' are missing.\"));\n }\n out.weightData = io_utils_1.base64StringToArrayBuffer(weightDataBase64);\n return [2, out];\n });\n });\n };\n BrowserLocalStorage.URL_SCHEME = 'localstorage://';\n return BrowserLocalStorage;\n}());\nexports.BrowserLocalStorage = BrowserLocalStorage;\nexports.localStorageRouter = function (url) {\n if (!environment_1.ENV.get('IS_BROWSER')) {\n return null;\n }\n else {\n if (url.startsWith(BrowserLocalStorage.URL_SCHEME)) {\n return browserLocalStorage(url.slice(BrowserLocalStorage.URL_SCHEME.length));\n }\n else {\n return null;\n }\n }\n};\nrouter_registry_1.IORouterRegistry.registerSaveRouter(exports.localStorageRouter);\nrouter_registry_1.IORouterRegistry.registerLoadRouter(exports.localStorageRouter);\nfunction browserLocalStorage(modelPath) {\n return new BrowserLocalStorage(modelPath);\n}\nexports.browserLocalStorage = browserLocalStorage;\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar io_utils_1 = require(\"./io_utils\");\nvar router_registry_1 = require(\"./router_registry\");\nvar DEFAULT_FILE_NAME_PREFIX = 'model';\nvar DEFAULT_JSON_EXTENSION_NAME = '.json';\nvar DEFAULT_WEIGHT_DATA_EXTENSION_NAME = '.weights.bin';\nvar BrowserDownloads = (function () {\n function BrowserDownloads(fileNamePrefix) {\n if (!environment_1.ENV.get('IS_BROWSER')) {\n throw new Error('triggerDownloads() cannot proceed because the current environment ' +\n 'is not a browser.');\n }\n if (fileNamePrefix.startsWith(BrowserDownloads.URL_SCHEME)) {\n fileNamePrefix = fileNamePrefix.slice(BrowserDownloads.URL_SCHEME.length);\n }\n if (fileNamePrefix == null || fileNamePrefix.length === 0) {\n fileNamePrefix = DEFAULT_FILE_NAME_PREFIX;\n }\n this.modelTopologyFileName = fileNamePrefix + DEFAULT_JSON_EXTENSION_NAME;\n this.weightDataFileName =\n fileNamePrefix + DEFAULT_WEIGHT_DATA_EXTENSION_NAME;\n }\n BrowserDownloads.prototype.save = function (modelArtifacts) {\n return __awaiter(this, void 0, void 0, function () {\n var weightsURL, weightsManifest, modelTopologyAndWeightManifest, modelTopologyAndWeightManifestURL, jsonAnchor, weightDataAnchor;\n return __generator(this, function (_a) {\n weightsURL = window.URL.createObjectURL(new Blob([modelArtifacts.weightData], { type: 'application/octet-stream' }));\n if (modelArtifacts.modelTopology instanceof ArrayBuffer) {\n throw new Error('DownloadTrigger.save() does not support saving model topology ' +\n 'in binary formats yet.');\n }\n else {\n weightsManifest = [{\n paths: ['./' + this.weightDataFileName],\n weights: modelArtifacts.weightSpecs\n }];\n modelTopologyAndWeightManifest = {\n modelTopology: modelArtifacts.modelTopology,\n weightsManifest: weightsManifest\n };\n modelTopologyAndWeightManifestURL = window.URL.createObjectURL(new Blob([JSON.stringify(modelTopologyAndWeightManifest)], { type: 'application/json' }));\n jsonAnchor = this.jsonAnchor == null ? document.createElement('a') :\n this.jsonAnchor;\n jsonAnchor.download = this.modelTopologyFileName;\n jsonAnchor.href = modelTopologyAndWeightManifestURL;\n jsonAnchor.click();\n if (modelArtifacts.weightData != null) {\n weightDataAnchor = this.weightDataAnchor == null ?\n document.createElement('a') :\n this.weightDataAnchor;\n weightDataAnchor.download = this.weightDataFileName;\n weightDataAnchor.href = weightsURL;\n weightDataAnchor.click();\n }\n return [2, {\n modelArtifactsInfo: io_utils_1.getModelArtifactsInfoForKerasJSON(modelArtifacts)\n }];\n }\n return [2];\n });\n });\n };\n BrowserDownloads.URL_SCHEME = 'downloads://';\n return BrowserDownloads;\n}());\nexports.BrowserDownloads = BrowserDownloads;\nvar BrowserFiles = (function () {\n function BrowserFiles(files) {\n if (files == null || files.length < 1) {\n throw new Error(\"When calling browserFiles, at least 1 file is required, \" +\n (\"but received \" + files));\n }\n this.files = files;\n }\n BrowserFiles.prototype.load = function () {\n return __awaiter(this, void 0, void 0, function () {\n var _this = this;\n var jsonFile, weightFiles;\n return __generator(this, function (_a) {\n jsonFile = this.files[0];\n weightFiles = this.files.slice(1);\n return [2, new Promise(function (resolve, reject) {\n var jsonReader = new FileReader();\n jsonReader.onload = function (event) {\n var modelJSON = JSON.parse(event.target.result);\n var modelTopology = modelJSON.modelTopology;\n if (modelTopology == null) {\n reject(new Error(\"modelTopology field is missing from file \" + jsonFile.name));\n return;\n }\n if (weightFiles.length === 0) {\n resolve({ modelTopology: modelTopology });\n }\n var weightsManifest = modelJSON.weightsManifest;\n if (weightsManifest == null) {\n reject(new Error(\"weightManifest field is missing from file \" + jsonFile.name));\n return;\n }\n var pathToFile;\n try {\n pathToFile =\n _this.checkManifestAndWeightFiles(weightsManifest, weightFiles);\n }\n catch (err) {\n reject(err);\n return;\n }\n var weightSpecs = [];\n var paths = [];\n var perFileBuffers = [];\n weightsManifest.forEach(function (weightsGroup) {\n weightsGroup.paths.forEach(function (path) {\n paths.push(path);\n perFileBuffers.push(null);\n });\n weightSpecs.push.apply(weightSpecs, weightsGroup.weights);\n });\n weightsManifest.forEach(function (weightsGroup) {\n weightsGroup.paths.forEach(function (path) {\n var weightFileReader = new FileReader();\n weightFileReader.onload = function (event) {\n var weightData = event.target.result;\n var index = paths.indexOf(path);\n perFileBuffers[index] = weightData;\n if (perFileBuffers.indexOf(null) === -1) {\n resolve({\n modelTopology: modelTopology,\n weightSpecs: weightSpecs,\n weightData: io_utils_1.concatenateArrayBuffers(perFileBuffers),\n });\n }\n };\n weightFileReader.onerror = function (error) {\n reject(\"Failed to weights data from file of path '\" + path + \"'.\");\n return;\n };\n weightFileReader.readAsArrayBuffer(pathToFile[path]);\n });\n });\n };\n jsonReader.onerror = function (error) {\n reject(\"Failed to read model topology and weights manifest JSON \" +\n (\"from file '\" + jsonFile.name + \"'. BrowserFiles supports loading \") +\n \"Keras-style tf.Model artifacts only.\");\n return;\n };\n jsonReader.readAsText(jsonFile);\n })];\n });\n });\n };\n BrowserFiles.prototype.checkManifestAndWeightFiles = function (manifest, files) {\n var basenames = [];\n var fileNames = files.map(function (file) { return io_utils_1.basename(file.name); });\n var pathToFile = {};\n for (var _i = 0, manifest_1 = manifest; _i < manifest_1.length; _i++) {\n var group = manifest_1[_i];\n group.paths.forEach(function (path) {\n var pathBasename = io_utils_1.basename(path);\n if (basenames.indexOf(pathBasename) !== -1) {\n throw new Error(\"Duplicate file basename found in weights manifest: \" +\n (\"'\" + pathBasename + \"'\"));\n }\n basenames.push(pathBasename);\n if (fileNames.indexOf(pathBasename) === -1) {\n throw new Error(\"Weight file with basename '\" + pathBasename + \"' is not provided.\");\n }\n else {\n pathToFile[path] = files[fileNames.indexOf(pathBasename)];\n }\n });\n }\n if (basenames.length !== files.length) {\n throw new Error(\"Mismatch in the number of files in weights manifest \" +\n (\"(\" + basenames.length + \") and the number of weight files provided \") +\n (\"(\" + files.length + \").\"));\n }\n return pathToFile;\n };\n return BrowserFiles;\n}());\nexports.browserDownloadsRouter = function (url) {\n if (!environment_1.ENV.get('IS_BROWSER')) {\n return null;\n }\n else {\n if (url.startsWith(BrowserDownloads.URL_SCHEME)) {\n return browserDownloads(url.slice(BrowserDownloads.URL_SCHEME.length));\n }\n else {\n return null;\n }\n }\n};\nrouter_registry_1.IORouterRegistry.registerSaveRouter(exports.browserDownloadsRouter);\nfunction browserDownloads(fileNamePrefix) {\n if (fileNamePrefix === void 0) { fileNamePrefix = 'model'; }\n return new BrowserDownloads(fileNamePrefix);\n}\nexports.browserDownloads = browserDownloads;\nfunction browserFiles(files) {\n return new BrowserFiles(files);\n}\nexports.browserFiles = browserFiles;\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar util_1 = require(\"../util\");\nvar io_utils_1 = require(\"./io_utils\");\nvar router_registry_1 = require(\"./router_registry\");\nvar BrowserHTTPRequest = (function () {\n function BrowserHTTPRequest(path, requestInit) {\n this.DEFAULT_METHOD = 'POST';\n if (!environment_1.ENV.get('IS_BROWSER')) {\n throw new Error('browserHTTPRequest is not supported outside the web browser.');\n }\n util_1.assert(path != null && path.length > 0, 'URL path for browserHTTPRequest must not be null, undefined or ' +\n 'empty.');\n this.path = path;\n if (requestInit != null && requestInit.body != null) {\n throw new Error('requestInit is expected to have no pre-existing body, but has one.');\n }\n this.requestInit = requestInit || {};\n }\n BrowserHTTPRequest.prototype.save = function (modelArtifacts) {\n return __awaiter(this, void 0, void 0, function () {\n var init, weightsManifest, modelTopologyAndWeightManifest, response;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (modelArtifacts.modelTopology instanceof ArrayBuffer) {\n throw new Error('BrowserHTTPRequest.save() does not support saving model topology ' +\n 'in binary formats yet.');\n }\n init = Object.assign({ method: this.DEFAULT_METHOD }, this.requestInit);\n init.body = new FormData();\n weightsManifest = [{\n paths: ['./model.weights.bin'],\n weights: modelArtifacts.weightSpecs,\n }];\n modelTopologyAndWeightManifest = {\n modelTopology: modelArtifacts.modelTopology,\n weightsManifest: weightsManifest\n };\n init.body.append('model.json', new Blob([JSON.stringify(modelTopologyAndWeightManifest)], { type: 'application/json' }), 'model.json');\n if (modelArtifacts.weightData != null) {\n init.body.append('model.weights.bin', new Blob([modelArtifacts.weightData], { type: 'application/octet-stream' }), 'model.weights.bin');\n }\n return [4, fetch(this.path, init)];\n case 1:\n response = _a.sent();\n if (response.status === 200) {\n return [2, {\n modelArtifactsInfo: io_utils_1.getModelArtifactsInfoForKerasJSON(modelArtifacts),\n responses: [response],\n }];\n }\n else {\n throw new Error(\"BrowserHTTPRequest.save() failed due to HTTP response status \" +\n (response.status + \".\"));\n }\n return [2];\n }\n });\n });\n };\n BrowserHTTPRequest.URL_SCHEMES = ['http://', 'https://'];\n return BrowserHTTPRequest;\n}());\nexports.BrowserHTTPRequest = BrowserHTTPRequest;\nexports.httpRequestRouter = function (url) {\n if (!environment_1.ENV.get('IS_BROWSER')) {\n return null;\n }\n else {\n for (var _i = 0, _a = BrowserHTTPRequest.URL_SCHEMES; _i < _a.length; _i++) {\n var scheme = _a[_i];\n if (url.startsWith(scheme)) {\n return browserHTTPRequest(url);\n }\n }\n return null;\n }\n};\nrouter_registry_1.IORouterRegistry.registerSaveRouter(exports.httpRequestRouter);\nfunction browserHTTPRequest(path, requestInit) {\n return new BrowserHTTPRequest(path, requestInit);\n}\nexports.browserHTTPRequest = browserHTTPRequest;\n","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar ops_1 = require(\"../ops/ops\");\nvar util = require(\"../util\");\nvar types_1 = require(\"./types\");\nfunction loadWeights(manifest, filePathPrefix, weightNames, requestOptions) {\n if (filePathPrefix === void 0) { filePathPrefix = ''; }\n return __awaiter(this, void 0, void 0, function () {\n var groupIndicesToFetchMap, groupWeightsToFetch, weightsFound, allManifestWeightNames, weightsNotFound, groupIndicesToFetch, requests, responses, buffers, weightsTensorMap, bufferIndexOffset;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n groupIndicesToFetchMap = manifest.map(function () { return false; });\n groupWeightsToFetch = {};\n weightsFound = weightNames != null ? weightNames.map(function () { return false; }) : [];\n allManifestWeightNames = [];\n manifest.forEach(function (manifestGroupConfig, groupIndex) {\n var groupOffset = 0;\n manifestGroupConfig.weights.forEach(function (weightsEntry) {\n var rawDtype = ('quantization' in weightsEntry) ?\n weightsEntry.quantization.dtype :\n weightsEntry.dtype;\n var weightsBytes = types_1.DTYPE_VALUE_SIZE_MAP[rawDtype] *\n util.sizeFromShape(weightsEntry.shape);\n var enqueueWeightsForFetchingFn = function () {\n groupIndicesToFetchMap[groupIndex] = true;\n if (groupWeightsToFetch[groupIndex] == null) {\n groupWeightsToFetch[groupIndex] = [];\n }\n groupWeightsToFetch[groupIndex].push({\n manifestEntry: weightsEntry,\n groupOffset: groupOffset,\n sizeBytes: weightsBytes\n });\n };\n if (weightNames != null) {\n weightNames.forEach(function (weightName, weightIndex) {\n if (weightName === weightsEntry.name) {\n enqueueWeightsForFetchingFn();\n weightsFound[weightIndex] = true;\n }\n });\n }\n else {\n enqueueWeightsForFetchingFn();\n }\n allManifestWeightNames.push(weightsEntry.name);\n groupOffset += weightsBytes;\n });\n });\n if (!weightsFound.every(function (found) { return found; })) {\n weightsNotFound = weightNames.filter(function (weight, i) { return !weightsFound[i]; });\n throw new Error(\"Could not find weights in manifest with names: \" +\n (weightsNotFound.join(', ') + \". \\n\") +\n \"Manifest JSON has weights with names: \" +\n (allManifestWeightNames.join(', ') + \".\"));\n }\n groupIndicesToFetch = groupIndicesToFetchMap.reduce(function (accumulator, shouldFetch, i) {\n if (shouldFetch) {\n accumulator.push(i);\n }\n return accumulator;\n }, []);\n requests = [];\n groupIndicesToFetch.forEach(function (i) {\n manifest[i].paths.forEach(function (filepath) {\n var fetchUrl = filePathPrefix +\n (!filePathPrefix.endsWith('/') ? '/' : '') + filepath;\n requests.push(fetch(fetchUrl, requestOptions));\n });\n });\n return [4, Promise.all(requests)];\n case 1:\n responses = _a.sent();\n return [4, Promise.all(responses.map(function (response) { return response.arrayBuffer(); }))];\n case 2:\n buffers = _a.sent();\n weightsTensorMap = {};\n bufferIndexOffset = 0;\n groupIndicesToFetch.forEach(function (i) {\n var numBuffers = manifest[i].paths.length;\n var groupBytes = 0;\n for (var i_1 = 0; i_1 < numBuffers; i_1++) {\n groupBytes += buffers[bufferIndexOffset + i_1].byteLength;\n }\n var groupBuffer = new ArrayBuffer(groupBytes);\n var groupByteBuffer = new Uint8Array(groupBuffer);\n var groupBufferOffset = 0;\n for (var i_2 = 0; i_2 < numBuffers; i_2++) {\n var buffer = new Uint8Array(buffers[bufferIndexOffset + i_2]);\n groupByteBuffer.set(buffer, groupBufferOffset);\n groupBufferOffset += buffer.byteLength;\n }\n var weightsEntries = groupWeightsToFetch[i];\n weightsEntries.forEach(function (weightsEntry) {\n var byteBuffer = groupBuffer.slice(weightsEntry.groupOffset, weightsEntry.groupOffset + weightsEntry.sizeBytes);\n var typedArray;\n var dtype = weightsEntry.manifestEntry.dtype;\n if ('quantization' in weightsEntry.manifestEntry) {\n var quantization_1 = weightsEntry.manifestEntry.quantization;\n if (quantization_1.dtype !== 'uint8' && quantization_1.dtype !== 'uint16') {\n throw new Error(\"Weight \" + weightsEntry.manifestEntry.name + \" has unknown \" +\n (\"quantization dtype \" + quantization_1.dtype + \".\"));\n }\n var quantizedArray = (quantization_1.dtype === 'uint8') ?\n new Uint8Array(byteBuffer) :\n new Uint16Array(byteBuffer);\n if (dtype === 'float32') {\n typedArray = Float32Array.from(quantizedArray, function (v) { return v * quantization_1.scale + quantization_1.min; });\n }\n else if (dtype === 'int32') {\n typedArray = Int32Array.from(quantizedArray, function (v) { return Math.round(v * quantization_1.scale + quantization_1.min); });\n }\n else {\n throw new Error(\"Weight \" + weightsEntry.manifestEntry.name + \" has a dtype not \" +\n (\"supported by quantization: \" + dtype));\n }\n }\n else {\n if (dtype === 'float32') {\n typedArray = new Float32Array(byteBuffer);\n }\n else if (dtype === 'int32') {\n typedArray = new Int32Array(byteBuffer);\n }\n else {\n throw new Error(\"Weight \" + weightsEntry.manifestEntry.name + \" has unknown dtype \" +\n (dtype + \".\"));\n }\n }\n var weightName = weightsEntry.manifestEntry.name;\n if (weightsTensorMap[weightName] != null) {\n throw new Error(\"Duplicate weight with name \" + weightName + \". \" +\n \"Please make sure weights names are unique in the manifest JSON.\");\n }\n weightsTensorMap[weightName] = ops_1.tensor(typedArray, weightsEntry.manifestEntry.shape, weightsEntry.manifestEntry.dtype);\n });\n bufferIndexOffset += numBuffers;\n });\n return [2, weightsTensorMap];\n }\n });\n });\n}\nexports.loadWeights = loadWeights;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nrequire(\"./indexed_db\");\nrequire(\"./local_storage\");\nvar browser_files_1 = require(\"./browser_files\");\nexports.browserFiles = browser_files_1.browserFiles;\nvar browser_http_1 = require(\"./browser_http\");\nexports.browserHTTPRequest = browser_http_1.browserHTTPRequest;\nvar io_utils_1 = require(\"./io_utils\");\nexports.decodeWeights = io_utils_1.decodeWeights;\nexports.encodeWeights = io_utils_1.encodeWeights;\nvar router_registry_1 = require(\"./router_registry\");\nvar weights_loader_1 = require(\"./weights_loader\");\nexports.loadWeights = weights_loader_1.loadWeights;\nvar registerSaveRouter = router_registry_1.IORouterRegistry.registerSaveRouter;\nexports.registerSaveRouter = registerSaveRouter;\nvar registerLoadRouter = router_registry_1.IORouterRegistry.registerLoadRouter;\nexports.registerLoadRouter = registerLoadRouter;\nvar getSaveHandlers = router_registry_1.IORouterRegistry.getSaveHandlers;\nexports.getSaveHandlers = getSaveHandlers;\nvar getLoadHandlers = router_registry_1.IORouterRegistry.getLoadHandlers;\nexports.getLoadHandlers = getLoadHandlers;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar Serializable = (function () {\n function Serializable() {\n }\n Serializable.prototype.getClassName = function () {\n return this.constructor\n .className;\n };\n Serializable.fromConfig = function (cls, config) {\n return new cls(config);\n };\n return Serializable;\n}());\nexports.Serializable = Serializable;\nvar SerializationMap = (function () {\n function SerializationMap() {\n this.classNameMap = {};\n }\n SerializationMap.getMap = function () {\n if (SerializationMap.instance == null) {\n SerializationMap.instance = new SerializationMap();\n }\n return SerializationMap.instance;\n };\n SerializationMap.register = function (cls) {\n this.getMap().classNameMap[cls.className] = [cls, cls.fromConfig];\n };\n return SerializationMap;\n}());\nexports.SerializationMap = SerializationMap;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tensor_1 = require(\"./tensor\");\nvar util = require(\"./util\");\nexports.WEBGL_ENVS = {\n 'BACKEND': 'test-webgl'\n};\nexports.CPU_ENVS = {\n 'BACKEND': 'test-cpu'\n};\nexports.ALL_ENVS = {};\nexports.TEST_EPSILON = 1e-3;\nfunction expectArraysClose(actual, expected, epsilon) {\n if (epsilon === void 0) { epsilon = exports.TEST_EPSILON; }\n if (!(actual instanceof tensor_1.Tensor) && !(expected instanceof tensor_1.Tensor)) {\n var aType = actual.constructor.name;\n var bType = expected.constructor.name;\n if (aType !== bType) {\n throw new Error(\"Arrays are of different type actual: \" + aType + \" \" +\n (\"vs expected: \" + bType));\n }\n }\n else if (actual instanceof tensor_1.Tensor && expected instanceof tensor_1.Tensor) {\n if (actual.dtype !== expected.dtype) {\n throw new Error(\"Arrays are of different type actual: \" + actual.dtype + \" \" +\n (\"vs expected: \" + expected.dtype + \".\"));\n }\n if (!util.arraysEqual(actual.shape, expected.shape)) {\n throw new Error(\"Arrays are of different shape actual: \" + actual.shape + \" \" +\n (\"vs expected: \" + expected.shape + \".\"));\n }\n }\n var actualValues;\n var expectedValues;\n if (actual instanceof tensor_1.Tensor) {\n actualValues = actual.dataSync();\n }\n else {\n actualValues = actual;\n }\n if (expected instanceof tensor_1.Tensor) {\n expectedValues = expected.dataSync();\n }\n else {\n expectedValues = expected;\n }\n if (actualValues.length !== expectedValues.length) {\n throw new Error(\"Arrays have different lengths actual: \" + actualValues.length + \" vs \" +\n (\"expected: \" + expectedValues.length + \".\\n\") +\n (\"Actual: \" + actualValues + \".\\n\") +\n (\"Expected: \" + expectedValues + \".\"));\n }\n for (var i = 0; i < expectedValues.length; ++i) {\n var a = actualValues[i];\n var e = expectedValues[i];\n if (!areClose(a, Number(e), epsilon)) {\n throw new Error(\"Arrays differ: actual[\" + i + \"] = \" + a + \", expected[\" + i + \"] = \" + e + \".\\n\" +\n (\"Actual: \" + actualValues + \".\\n\") +\n (\"Expected: \" + expectedValues + \".\"));\n }\n }\n}\nexports.expectArraysClose = expectArraysClose;\nfunction expectPromiseToFail(fn, done) {\n fn().then(function () { return done.fail(); }, function () { return done(); });\n}\nexports.expectPromiseToFail = expectPromiseToFail;\nfunction expectArraysEqual(actual, expected) {\n return expectArraysClose(actual, expected, 0);\n}\nexports.expectArraysEqual = expectArraysEqual;\nfunction expectNumbersClose(a, e, epsilon) {\n if (epsilon === void 0) { epsilon = exports.TEST_EPSILON; }\n if (!areClose(a, e, epsilon)) {\n throw new Error(\"Numbers differ: actual === \" + a + \", expected === \" + e);\n }\n}\nexports.expectNumbersClose = expectNumbersClose;\nfunction areClose(a, e, epsilon) {\n if (isNaN(a) && isNaN(e)) {\n return true;\n }\n if (isNaN(a) || isNaN(e) || Math.abs(a - e) > epsilon) {\n return false;\n }\n return true;\n}\nfunction expectValuesInRange(actual, low, high) {\n var actualVals;\n if (actual instanceof tensor_1.Tensor) {\n actualVals = actual.dataSync();\n }\n else {\n actualVals = actual;\n }\n for (var i = 0; i < actualVals.length; i++) {\n if (actualVals[i] < low || actualVals[i] > high) {\n throw new Error(\"Value out of range:\" + actualVals[i] + \" low: \" + low + \", high: \" + high);\n }\n }\n}\nexports.expectValuesInRange = expectValuesInRange;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar version = '0.10.1';\nexports.version = version;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar webgl_util = require(\"./kernels/webgl/webgl_util\");\nexports.webgl_util = webgl_util;\nvar gpgpu_util = require(\"./kernels/webgl/gpgpu_util\");\nexports.gpgpu_util = gpgpu_util;\nvar backend_webgl_1 = require(\"./kernels/backend_webgl\");\nexports.MathBackendWebGL = backend_webgl_1.MathBackendWebGL;\nvar gpgpu_context_1 = require(\"./kernels/webgl/gpgpu_context\");\nexports.GPGPUContext = gpgpu_context_1.GPGPUContext;\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar globals_1 = require(\"../globals\");\nvar serialization_1 = require(\"../serialization\");\nvar Optimizer = (function (_super) {\n __extends(Optimizer, _super);\n function Optimizer() {\n return _super !== null && _super.apply(this, arguments) || this;\n }\n Optimizer.prototype.minimize = function (f, returnCost, varList) {\n if (returnCost === void 0) { returnCost = false; }\n var _a = this.computeGradients(f, varList), value = _a.value, grads = _a.grads;\n this.applyGradients(grads);\n var varNames = Object.keys(grads);\n varNames.forEach(function (varName) { return grads[varName].dispose(); });\n if (returnCost) {\n return value;\n }\n else {\n value.dispose();\n return null;\n }\n };\n Optimizer.prototype.computeGradients = function (f, varList) {\n return globals_1.variableGrads(f, varList);\n };\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Optimizers' })\n ], Optimizer.prototype, \"minimize\", null);\n Optimizer = __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Classes', namespace: 'train' })\n ], Optimizer);\n return Optimizer;\n}(serialization_1.Serializable));\nexports.Optimizer = Optimizer;\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar globals_1 = require(\"../globals\");\nvar ops_1 = require(\"../ops/ops\");\nvar serialization_1 = require(\"../serialization\");\nvar optimizer_1 = require(\"./optimizer\");\nvar AdadeltaOptimizer = (function (_super) {\n __extends(AdadeltaOptimizer, _super);\n function AdadeltaOptimizer(learningRate, rho, epsilon) {\n if (epsilon === void 0) { epsilon = 1e-8; }\n var _this = _super.call(this) || this;\n _this.learningRate = learningRate;\n _this.rho = rho;\n _this.epsilon = epsilon;\n _this.accumulatedGrads = {};\n _this.accumulatedUpdates = {};\n _this.c = globals_1.keep(ops_1.scalar(-learningRate));\n _this.epsilonScalar = globals_1.keep(ops_1.scalar(epsilon));\n _this.rhoScalar = globals_1.keep(ops_1.scalar(rho));\n _this.oneMinusRho = globals_1.keep(ops_1.scalar(1 - rho));\n return _this;\n }\n AdadeltaOptimizer.prototype.applyGradients = function (variableGradients) {\n var _this = this;\n var _loop_1 = function (variableName) {\n var value = environment_1.ENV.engine.registeredVariables[variableName];\n if (this_1.accumulatedGrads[variableName] == null) {\n var trainable_1 = false;\n globals_1.tidy(function () {\n _this.accumulatedGrads[variableName] =\n ops_1.zerosLike(value).variable(trainable_1);\n });\n }\n if (this_1.accumulatedUpdates[variableName] == null) {\n var trainable_2 = false;\n globals_1.tidy(function () {\n _this.accumulatedUpdates[variableName] =\n ops_1.zerosLike(value).variable(trainable_2);\n });\n }\n var gradient = variableGradients[variableName];\n var accumulatedGrad = this_1.accumulatedGrads[variableName];\n var accumulatedUpdate = this_1.accumulatedUpdates[variableName];\n globals_1.tidy(function () {\n var newAccumulatedGrad = _this.rhoScalar.mul(accumulatedGrad)\n .add(_this.oneMinusRho.mul(gradient.square()));\n var updates = accumulatedUpdate.add(_this.epsilonScalar)\n .sqrt()\n .div(accumulatedGrad.add(_this.epsilonScalar).sqrt())\n .mul(gradient);\n var newAccumulatedUpdate = _this.rhoScalar.mul(accumulatedUpdate)\n .add(_this.oneMinusRho.mul(updates.square()));\n _this.accumulatedGrads[variableName].assign(newAccumulatedGrad);\n _this.accumulatedUpdates[variableName].assign(newAccumulatedUpdate);\n var newValue = _this.c.mul(updates).add(value);\n value.assign(newValue);\n });\n };\n var this_1 = this;\n for (var variableName in variableGradients) {\n _loop_1(variableName);\n }\n };\n AdadeltaOptimizer.prototype.dispose = function () {\n var _this = this;\n this.c.dispose();\n this.epsilonScalar.dispose();\n this.rhoScalar.dispose();\n this.oneMinusRho.dispose();\n if (this.accumulatedUpdates != null) {\n Object.keys(this.accumulatedUpdates)\n .forEach(function (name) { return _this.accumulatedUpdates[name].dispose(); });\n Object.keys(this.accumulatedGrads)\n .forEach(function (name) { return _this.accumulatedGrads[name].dispose(); });\n }\n };\n AdadeltaOptimizer.prototype.getConfig = function () {\n return {\n learningRate: this.learningRate,\n rho: this.rho,\n epsilon: this.epsilon\n };\n };\n AdadeltaOptimizer.fromConfig = function (cls, config) {\n return new cls(config.learningRate, config.rho, config.epsilon);\n };\n AdadeltaOptimizer.className = 'AdadeltaOptimizer';\n return AdadeltaOptimizer;\n}(optimizer_1.Optimizer));\nexports.AdadeltaOptimizer = AdadeltaOptimizer;\nserialization_1.SerializationMap.register(AdadeltaOptimizer);\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar globals_1 = require(\"../globals\");\nvar ops_1 = require(\"../ops/ops\");\nvar serialization_1 = require(\"../serialization\");\nvar optimizer_1 = require(\"./optimizer\");\nvar AdagradOptimizer = (function (_super) {\n __extends(AdagradOptimizer, _super);\n function AdagradOptimizer(learningRate, initialAccumulatorValue) {\n if (initialAccumulatorValue === void 0) { initialAccumulatorValue = 0.1; }\n var _this = _super.call(this) || this;\n _this.learningRate = learningRate;\n _this.initialAccumulatorValue = initialAccumulatorValue;\n _this.accumulatedGrads = {};\n _this.c = globals_1.keep(ops_1.scalar(-learningRate));\n _this.epsilon = globals_1.keep(ops_1.scalar(1e-8));\n return _this;\n }\n AdagradOptimizer.prototype.applyGradients = function (variableGradients) {\n var _this = this;\n var _loop_1 = function (variableName) {\n var value = environment_1.ENV.engine.registeredVariables[variableName];\n if (this_1.accumulatedGrads[variableName] == null) {\n var trainable_1 = false;\n globals_1.tidy(function () {\n _this.accumulatedGrads[variableName] =\n ops_1.fill(value.shape, _this.initialAccumulatorValue)\n .variable(trainable_1);\n });\n }\n var gradient = variableGradients[variableName];\n var accumulatedGrad = this_1.accumulatedGrads[variableName];\n globals_1.tidy(function () {\n var newAccumulatedGrad = accumulatedGrad.add(gradient.square());\n _this.accumulatedGrads[variableName].assign(newAccumulatedGrad);\n var newValue = _this.c\n .mul(gradient.div(newAccumulatedGrad.add(_this.epsilon).sqrt()))\n .add(value);\n value.assign(newValue);\n });\n };\n var this_1 = this;\n for (var variableName in variableGradients) {\n _loop_1(variableName);\n }\n };\n AdagradOptimizer.prototype.dispose = function () {\n var _this = this;\n this.epsilon.dispose();\n this.c.dispose();\n if (this.accumulatedGrads != null) {\n Object.keys(this.accumulatedGrads)\n .forEach(function (name) { return _this.accumulatedGrads[name].dispose(); });\n }\n };\n AdagradOptimizer.prototype.getConfig = function () {\n return {\n learningRate: this.learningRate,\n initialAccumulatorValue: this.initialAccumulatorValue,\n };\n };\n AdagradOptimizer.fromConfig = function (cls, config) {\n return new cls(config.learningRate, config.initialAccumulatorValue);\n };\n AdagradOptimizer.className = 'AdagradOptimizer';\n return AdagradOptimizer;\n}(optimizer_1.Optimizer));\nexports.AdagradOptimizer = AdagradOptimizer;\nserialization_1.SerializationMap.register(AdagradOptimizer);\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar globals_1 = require(\"../globals\");\nvar ops_1 = require(\"../ops/ops\");\nvar serialization_1 = require(\"../serialization\");\nvar optimizer_1 = require(\"./optimizer\");\nvar AdamOptimizer = (function (_super) {\n __extends(AdamOptimizer, _super);\n function AdamOptimizer(learningRate, beta1, beta2, epsilon) {\n if (epsilon === void 0) { epsilon = 1e-8; }\n var _this = _super.call(this) || this;\n _this.learningRate = learningRate;\n _this.beta1 = beta1;\n _this.beta2 = beta2;\n _this.epsilon = epsilon;\n _this.accumulatedFirstMoment = {};\n _this.accumulatedSecondMoment = {};\n _this.c = globals_1.keep(ops_1.scalar(-learningRate));\n _this.epsScalar = globals_1.keep(ops_1.scalar(epsilon));\n _this.beta1Scalar = globals_1.keep(ops_1.scalar(beta1));\n _this.beta2Scalar = globals_1.keep(ops_1.scalar(beta2));\n globals_1.tidy(function () {\n _this.accBeta1 = ops_1.scalar(beta1).variable();\n _this.accBeta2 = ops_1.scalar(beta2).variable();\n });\n _this.oneMinusBeta1 = globals_1.keep(ops_1.scalar(1 - beta1));\n _this.oneMinusBeta2 = globals_1.keep(ops_1.scalar(1 - beta2));\n _this.one = globals_1.keep(ops_1.scalar(1));\n return _this;\n }\n AdamOptimizer.prototype.applyGradients = function (variableGradients) {\n var _this = this;\n globals_1.tidy(function () {\n var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1);\n var oneMinusAccBeta2 = _this.one.sub(_this.accBeta2);\n for (var variableName in variableGradients) {\n var value = environment_1.ENV.engine.registeredVariables[variableName];\n if (_this.accumulatedFirstMoment[variableName] == null) {\n var trainable = false;\n _this.accumulatedFirstMoment[variableName] =\n ops_1.zerosLike(value).variable(trainable);\n }\n if (_this.accumulatedSecondMoment[variableName] == null) {\n var trainable = false;\n _this.accumulatedSecondMoment[variableName] =\n ops_1.zerosLike(value).variable(trainable);\n }\n var gradient = variableGradients[variableName];\n var firstMoment = _this.accumulatedFirstMoment[variableName];\n var secondMoment = _this.accumulatedSecondMoment[variableName];\n var newFirstMoment = _this.beta1Scalar.mul(firstMoment)\n .add(_this.oneMinusBeta1.mul(gradient));\n var newSecondMoment = _this.beta2Scalar.mul(secondMoment)\n .add(_this.oneMinusBeta2.mul(gradient.square()));\n var biasCorrectedFirstMoment = newFirstMoment.div(oneMinusAccBeta1);\n var biasCorrectedSecondMoment = newSecondMoment.div(oneMinusAccBeta2);\n _this.accumulatedFirstMoment[variableName].assign(newFirstMoment);\n _this.accumulatedSecondMoment[variableName].assign(newSecondMoment);\n var newValue = _this.c\n .mul(biasCorrectedFirstMoment.div(_this.epsScalar.add(biasCorrectedSecondMoment.sqrt())))\n .add(value);\n value.assign(newValue);\n }\n _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1Scalar));\n _this.accBeta2.assign(_this.accBeta2.mul(_this.beta2Scalar));\n });\n };\n AdamOptimizer.prototype.dispose = function () {\n var _this = this;\n this.c.dispose();\n this.epsScalar.dispose();\n this.beta1Scalar.dispose();\n this.beta2Scalar.dispose();\n this.accBeta1.dispose();\n this.accBeta2.dispose();\n this.oneMinusBeta1.dispose();\n this.oneMinusBeta2.dispose();\n this.one.dispose();\n if (this.accumulatedFirstMoment != null) {\n Object.keys(this.accumulatedFirstMoment)\n .forEach(function (name) { return _this.accumulatedFirstMoment[name].dispose(); });\n }\n if (this.accumulatedSecondMoment != null) {\n Object.keys(this.accumulatedSecondMoment)\n .forEach(function (name) { return _this.accumulatedSecondMoment[name].dispose(); });\n }\n };\n AdamOptimizer.prototype.getConfig = function () {\n return {\n learningRate: this.learningRate,\n beta1: this.beta1,\n beta2: this.beta2,\n epsilon: this.epsilon,\n };\n };\n AdamOptimizer.fromConfig = function (cls, config) {\n return new cls(config.learningRate, config.beta1, config.beta2, config.epsilon);\n };\n AdamOptimizer.className = 'AdamOptimizer';\n return AdamOptimizer;\n}(optimizer_1.Optimizer));\nexports.AdamOptimizer = AdamOptimizer;\nserialization_1.SerializationMap.register(AdamOptimizer);\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar globals_1 = require(\"../globals\");\nvar ops_1 = require(\"../ops/ops\");\nvar serialization_1 = require(\"../serialization\");\nvar optimizer_1 = require(\"./optimizer\");\nvar AdamaxOptimizer = (function (_super) {\n __extends(AdamaxOptimizer, _super);\n function AdamaxOptimizer(learningRate, beta1, beta2, epsilon, decay) {\n if (epsilon === void 0) { epsilon = 1e-8; }\n if (decay === void 0) { decay = 0.0; }\n var _this = _super.call(this) || this;\n _this.learningRate = learningRate;\n _this.beta1 = beta1;\n _this.beta2 = beta2;\n _this.epsilon = epsilon;\n _this.decay = decay;\n _this.accumulatedFirstMoment = {};\n _this.accumulatedWeightedInfNorm = {};\n _this.c = globals_1.keep(ops_1.scalar(-learningRate));\n _this.epsScalar = globals_1.keep(ops_1.scalar(epsilon));\n _this.beta1Scalar = globals_1.keep(ops_1.scalar(beta1));\n _this.beta2Scalar = globals_1.keep(ops_1.scalar(beta2));\n _this.decayScalar = globals_1.keep(ops_1.scalar(decay));\n globals_1.tidy(function () {\n _this.iteration = ops_1.scalar(0).variable();\n _this.accBeta1 = ops_1.scalar(beta1).variable();\n });\n _this.oneMinusBeta1 = globals_1.keep(ops_1.scalar(1 - beta1));\n _this.one = globals_1.keep(ops_1.scalar(1));\n return _this;\n }\n AdamaxOptimizer.prototype.applyGradients = function (variableGradients) {\n var _this = this;\n globals_1.tidy(function () {\n var oneMinusAccBeta1 = _this.one.sub(_this.accBeta1);\n var lr = _this.c.div(_this.one.add(_this.decayScalar.mul(_this.iteration)));\n for (var variableName in variableGradients) {\n var value = environment_1.ENV.engine.registeredVariables[variableName];\n if (_this.accumulatedFirstMoment[variableName] == null) {\n var trainable = false;\n _this.accumulatedFirstMoment[variableName] =\n ops_1.zerosLike(value).variable(trainable);\n }\n if (_this.accumulatedWeightedInfNorm[variableName] == null) {\n var trainable = false;\n _this.accumulatedWeightedInfNorm[variableName] =\n ops_1.zerosLike(value).variable(trainable);\n }\n var gradient = variableGradients[variableName];\n var firstMoment = _this.accumulatedFirstMoment[variableName];\n var weightedInfNorm = _this.accumulatedWeightedInfNorm[variableName];\n var newFirstMoment = _this.beta1Scalar.mul(firstMoment)\n .add(_this.oneMinusBeta1.mul(gradient));\n var ut0 = _this.beta2Scalar.mul(weightedInfNorm);\n var ut1 = gradient.abs();\n var newWeightedInfNorm = ut0.maximum(ut1);\n _this.accumulatedFirstMoment[variableName].assign(newFirstMoment);\n _this.accumulatedWeightedInfNorm[variableName].assign(newWeightedInfNorm);\n var newValue = lr.div(oneMinusAccBeta1)\n .mul(newFirstMoment.div(_this.epsScalar.add(newWeightedInfNorm)))\n .add(value);\n value.assign(newValue);\n }\n _this.iteration.assign(_this.iteration.add(_this.one));\n _this.accBeta1.assign(_this.accBeta1.mul(_this.beta1Scalar));\n });\n };\n AdamaxOptimizer.prototype.dispose = function () {\n var _this = this;\n this.c.dispose();\n this.epsScalar.dispose();\n this.accBeta1.dispose();\n this.beta1Scalar.dispose();\n this.beta2Scalar.dispose();\n this.oneMinusBeta1.dispose();\n this.decayScalar.dispose();\n this.iteration.dispose();\n this.one.dispose();\n if (this.accumulatedFirstMoment != null) {\n Object.keys(this.accumulatedFirstMoment)\n .forEach(function (name) { return _this.accumulatedFirstMoment[name].dispose(); });\n }\n if (this.accumulatedWeightedInfNorm != null) {\n Object.keys(this.accumulatedWeightedInfNorm)\n .forEach(function (name) { return _this.accumulatedWeightedInfNorm[name].dispose(); });\n }\n };\n AdamaxOptimizer.prototype.getConfig = function () {\n return {\n learningRate: this.learningRate,\n beta1: this.beta1,\n beta2: this.beta2,\n epsilon: this.epsilon,\n decay: this.decay\n };\n };\n AdamaxOptimizer.fromConfig = function (cls, config) {\n return new cls(config.learningRate, config.beta1, config.beta2, config.epsilon, config.decay);\n };\n AdamaxOptimizer.className = 'AdamaxOptimizer';\n return AdamaxOptimizer;\n}(optimizer_1.Optimizer));\nexports.AdamaxOptimizer = AdamaxOptimizer;\nserialization_1.SerializationMap.register(AdamaxOptimizer);\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar globals_1 = require(\"../globals\");\nvar ops_1 = require(\"../ops/ops\");\nvar serialization_1 = require(\"../serialization\");\nvar optimizer_1 = require(\"./optimizer\");\nvar SGDOptimizer = (function (_super) {\n __extends(SGDOptimizer, _super);\n function SGDOptimizer(learningRate) {\n var _this = _super.call(this) || this;\n _this.learningRate = learningRate;\n _this.setLearningRate(learningRate);\n return _this;\n }\n SGDOptimizer.prototype.applyGradients = function (variableGradients) {\n var _this = this;\n var varNames = Object.keys(variableGradients);\n varNames.forEach(function (varName) {\n var gradient = variableGradients[varName];\n var value = environment_1.ENV.engine.registeredVariables[varName];\n globals_1.tidy(function () {\n var newValue = _this.c.mul(gradient).add(value);\n value.assign(newValue);\n });\n });\n };\n SGDOptimizer.prototype.setLearningRate = function (learningRate) {\n this.learningRate = learningRate;\n if (this.c != null) {\n this.c.dispose();\n }\n this.c = globals_1.keep(ops_1.scalar(-learningRate));\n };\n SGDOptimizer.prototype.dispose = function () {\n this.c.dispose();\n };\n SGDOptimizer.prototype.getConfig = function () {\n return { learningRate: this.learningRate };\n };\n SGDOptimizer.fromConfig = function (cls, config) {\n return new cls(config.learningRate);\n };\n SGDOptimizer.className = 'SGDOptimizer';\n return SGDOptimizer;\n}(optimizer_1.Optimizer));\nexports.SGDOptimizer = SGDOptimizer;\nserialization_1.SerializationMap.register(SGDOptimizer);\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar globals_1 = require(\"../globals\");\nvar ops_1 = require(\"../ops/ops\");\nvar serialization_1 = require(\"../serialization\");\nvar sgd_optimizer_1 = require(\"./sgd_optimizer\");\nvar MomentumOptimizer = (function (_super) {\n __extends(MomentumOptimizer, _super);\n function MomentumOptimizer(learningRate, momentum, useNesterov) {\n if (useNesterov === void 0) { useNesterov = false; }\n var _this = _super.call(this, learningRate) || this;\n _this.learningRate = learningRate;\n _this.momentum = momentum;\n _this.useNesterov = useNesterov;\n _this.m = ops_1.scalar(_this.momentum);\n _this.accumulations = {};\n return _this;\n }\n MomentumOptimizer.prototype.applyGradients = function (variableGradients) {\n var _this = this;\n var _loop_1 = function (variableName) {\n var value = environment_1.ENV.engine.registeredVariables[variableName];\n if (this_1.accumulations[variableName] == null) {\n var trainable_1 = false;\n globals_1.tidy(function () {\n _this.accumulations[variableName] =\n ops_1.zerosLike(value).variable(trainable_1);\n });\n }\n var accumulation = this_1.accumulations[variableName];\n var gradient = variableGradients[variableName];\n globals_1.tidy(function () {\n var newValue;\n var newAccumulation = _this.m.mul(accumulation).add(gradient);\n if (_this.useNesterov) {\n newValue =\n _this.c.mul(gradient.add(newAccumulation.mul(_this.m))).add(value);\n }\n else {\n newValue = _this.c.mul(newAccumulation).add(value);\n }\n _this.accumulations[variableName].assign(newAccumulation);\n value.assign(newValue);\n });\n };\n var this_1 = this;\n for (var variableName in variableGradients) {\n _loop_1(variableName);\n }\n };\n MomentumOptimizer.prototype.dispose = function () {\n _super.prototype.dispose.call(this);\n this.m.dispose();\n if (this.accumulations != null) {\n for (var variableName in this.accumulations) {\n this.accumulations[variableName].dispose();\n }\n }\n };\n MomentumOptimizer.prototype.setMomentum = function (momentum) {\n this.momentum = momentum;\n };\n MomentumOptimizer.prototype.getConfig = function () {\n return {\n learningRate: this.learningRate,\n momentum: this.momentum,\n useNesterov: this.useNesterov\n };\n };\n MomentumOptimizer.fromConfig = function (cls, config) {\n return new cls(config.learningRate, config.momentum, config.useNesterov);\n };\n MomentumOptimizer.className = 'MomentumOptimizer';\n return MomentumOptimizer;\n}(sgd_optimizer_1.SGDOptimizer));\nexports.MomentumOptimizer = MomentumOptimizer;\nserialization_1.SerializationMap.register(MomentumOptimizer);\n","\"use strict\";\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar environment_1 = require(\"../environment\");\nvar globals_1 = require(\"../globals\");\nvar ops_1 = require(\"../ops/ops\");\nvar serialization_1 = require(\"../serialization\");\nvar optimizer_1 = require(\"./optimizer\");\nvar RMSPropOptimizer = (function (_super) {\n __extends(RMSPropOptimizer, _super);\n function RMSPropOptimizer(learningRate, decay, momentum, epsilon, centered) {\n if (decay === void 0) { decay = 0.9; }\n if (momentum === void 0) { momentum = 0.0; }\n if (epsilon === void 0) { epsilon = 1e-8; }\n if (centered === void 0) { centered = false; }\n var _this = _super.call(this) || this;\n _this.learningRate = learningRate;\n _this.decay = decay;\n _this.momentum = momentum;\n _this.epsilon = epsilon;\n _this.accumulatedMeanSquares = {};\n _this.accumulatedMeanGrads = {};\n _this.accumulatedMoments = {};\n _this.c = globals_1.keep(ops_1.scalar(learningRate));\n _this.epsilonScalar = globals_1.keep(ops_1.scalar(epsilon));\n _this.decayScalar = globals_1.keep(ops_1.scalar(decay));\n _this.momentumScalar = globals_1.keep(ops_1.scalar(momentum));\n _this.oneMinusDecay = globals_1.keep(ops_1.scalar(1 - decay));\n _this.centered = centered;\n return _this;\n }\n RMSPropOptimizer.prototype.applyGradients = function (variableGradients) {\n var _this = this;\n var _loop_1 = function (variableName) {\n var value = environment_1.ENV.engine.registeredVariables[variableName];\n if (this_1.accumulatedMeanSquares[variableName] == null) {\n var trainable_1 = false;\n globals_1.tidy(function () {\n _this.accumulatedMeanSquares[variableName] =\n ops_1.zerosLike(value).variable(trainable_1);\n });\n }\n if (this_1.accumulatedMeanGrads[variableName] == null && this_1.centered) {\n var trainable_2 = false;\n globals_1.tidy(function () {\n _this.accumulatedMeanGrads[variableName] =\n ops_1.zerosLike(value).variable(trainable_2);\n });\n }\n if (this_1.accumulatedMoments[variableName] == null) {\n var trainable_3 = false;\n globals_1.tidy(function () {\n _this.accumulatedMoments[variableName] =\n ops_1.zerosLike(value).variable(trainable_3);\n });\n }\n var accumulatedMeanSquare = this_1.accumulatedMeanSquares[variableName];\n var accumulatedMeanGrad = this_1.accumulatedMeanGrads[variableName];\n var accumulatedMoments = this_1.accumulatedMoments[variableName];\n var gradient = variableGradients[variableName];\n globals_1.tidy(function () {\n var newAccumulatedMeanSquare = _this.decayScalar.mul(accumulatedMeanSquare)\n .add(_this.oneMinusDecay.mul(gradient.square()));\n if (_this.centered) {\n var newAccumulatedMeanGrad = _this.decayScalar.mul(accumulatedMeanGrad)\n .add(_this.oneMinusDecay.mul(gradient));\n var newAccumulatedMoments = _this.momentumScalar.mul(accumulatedMoments)\n .add(_this.c.mul(gradient).div(newAccumulatedMeanSquare\n .sub(newAccumulatedMeanGrad.square().add(_this.epsilonScalar))\n .sqrt()));\n _this.accumulatedMeanSquares[variableName].assign(newAccumulatedMeanSquare);\n _this.accumulatedMeanGrads[variableName].assign(newAccumulatedMeanGrad);\n _this.accumulatedMoments[variableName].assign(newAccumulatedMoments);\n var newValue = value.sub(newAccumulatedMoments);\n value.assign(newValue);\n }\n else {\n var newAccumulatedMeanSquare_1 = _this.decayScalar.mul(accumulatedMeanSquare)\n .add(_this.oneMinusDecay.mul(gradient.square()));\n var newAccumulatedMoments = _this.momentumScalar.mul(accumulatedMoments)\n .add(_this.c.mul(gradient).div(newAccumulatedMeanSquare_1.add(_this.epsilonScalar).sqrt()));\n _this.accumulatedMeanSquares[variableName].assign(newAccumulatedMeanSquare_1);\n _this.accumulatedMoments[variableName].assign(newAccumulatedMoments);\n var newValue = value.sub(newAccumulatedMoments);\n value.assign(newValue);\n }\n });\n };\n var this_1 = this;\n for (var variableName in variableGradients) {\n _loop_1(variableName);\n }\n };\n RMSPropOptimizer.prototype.dispose = function () {\n var _this = this;\n this.c.dispose();\n this.epsilonScalar.dispose();\n this.decayScalar.dispose();\n this.momentumScalar.dispose();\n this.oneMinusDecay.dispose();\n if (this.accumulatedMeanSquares != null) {\n Object.keys(this.accumulatedMeanSquares)\n .forEach(function (name) { return _this.accumulatedMeanSquares[name].dispose(); });\n }\n if (this.accumulatedMeanGrads != null && this.centered) {\n Object.keys(this.accumulatedMeanGrads)\n .forEach(function (name) { return _this.accumulatedMeanGrads[name].dispose(); });\n }\n if (this.accumulatedMoments != null) {\n Object.keys(this.accumulatedMoments)\n .forEach(function (name) { return _this.accumulatedMoments[name].dispose(); });\n }\n };\n RMSPropOptimizer.prototype.getConfig = function () {\n return {\n learningRate: this.learningRate,\n decay: this.decay,\n momentum: this.momentum,\n epsilon: this.epsilon,\n centered: this.centered\n };\n };\n RMSPropOptimizer.fromConfig = function (cls, config) {\n return new cls(config.learningRate, config.decay, config.momentum, config.epsilon, config.centered);\n };\n RMSPropOptimizer.className = 'RMSPropOptimizer';\n return RMSPropOptimizer;\n}(optimizer_1.Optimizer));\nexports.RMSPropOptimizer = RMSPropOptimizer;\nserialization_1.SerializationMap.register(RMSPropOptimizer);\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar doc_1 = require(\"../doc\");\nvar adadelta_optimizer_1 = require(\"./adadelta_optimizer\");\nvar adagrad_optimizer_1 = require(\"./adagrad_optimizer\");\nvar adam_optimizer_1 = require(\"./adam_optimizer\");\nvar adamax_optimizer_1 = require(\"./adamax_optimizer\");\nvar momentum_optimizer_1 = require(\"./momentum_optimizer\");\nvar rmsprop_optimizer_1 = require(\"./rmsprop_optimizer\");\nvar sgd_optimizer_1 = require(\"./sgd_optimizer\");\nvar OptimizerConstructors = (function () {\n function OptimizerConstructors() {\n }\n OptimizerConstructors.sgd = function (learningRate) {\n return new sgd_optimizer_1.SGDOptimizer(learningRate);\n };\n OptimizerConstructors.momentum = function (learningRate, momentum, useNesterov) {\n if (useNesterov === void 0) { useNesterov = false; }\n return new momentum_optimizer_1.MomentumOptimizer(learningRate, momentum, useNesterov);\n };\n OptimizerConstructors.rmsprop = function (learningRate, decay, momentum, epsilon, centered) {\n if (decay === void 0) { decay = .9; }\n if (momentum === void 0) { momentum = 0.0; }\n if (epsilon === void 0) { epsilon = 1e-8; }\n if (centered === void 0) { centered = false; }\n return new rmsprop_optimizer_1.RMSPropOptimizer(learningRate, decay, momentum, epsilon, centered);\n };\n OptimizerConstructors.adam = function (learningRate, beta1, beta2, epsilon) {\n if (learningRate === void 0) { learningRate = 0.001; }\n if (beta1 === void 0) { beta1 = 0.9; }\n if (beta2 === void 0) { beta2 = 0.999; }\n if (epsilon === void 0) { epsilon = 1e-8; }\n return new adam_optimizer_1.AdamOptimizer(learningRate, beta1, beta2, epsilon);\n };\n OptimizerConstructors.adadelta = function (learningRate, rho, epsilon) {\n if (learningRate === void 0) { learningRate = .001; }\n if (rho === void 0) { rho = .95; }\n if (epsilon === void 0) { epsilon = 1e-8; }\n return new adadelta_optimizer_1.AdadeltaOptimizer(learningRate, rho, epsilon);\n };\n OptimizerConstructors.adamax = function (learningRate, beta1, beta2, epsilon, decay) {\n if (learningRate === void 0) { learningRate = 0.002; }\n if (beta1 === void 0) { beta1 = 0.9; }\n if (beta2 === void 0) { beta2 = 0.999; }\n if (epsilon === void 0) { epsilon = 1e-8; }\n if (decay === void 0) { decay = 0.0; }\n return new adamax_optimizer_1.AdamaxOptimizer(learningRate, beta1, beta2, epsilon, decay);\n };\n OptimizerConstructors.adagrad = function (learningRate, initialAccumulatorValue) {\n if (initialAccumulatorValue === void 0) { initialAccumulatorValue = 0.1; }\n return new adagrad_optimizer_1.AdagradOptimizer(learningRate, initialAccumulatorValue);\n };\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })\n ], OptimizerConstructors, \"sgd\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })\n ], OptimizerConstructors, \"momentum\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })\n ], OptimizerConstructors, \"rmsprop\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })\n ], OptimizerConstructors, \"adam\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })\n ], OptimizerConstructors, \"adadelta\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })\n ], OptimizerConstructors, \"adamax\", null);\n __decorate([\n doc_1.doc({ heading: 'Training', subheading: 'Optimizers', namespace: 'train' })\n ], OptimizerConstructors, \"adagrad\", null);\n return OptimizerConstructors;\n}());\nexports.OptimizerConstructors = OptimizerConstructors;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar adadelta_optimizer_1 = require(\"./optimizers/adadelta_optimizer\");\nvar adagrad_optimizer_1 = require(\"./optimizers/adagrad_optimizer\");\nvar adam_optimizer_1 = require(\"./optimizers/adam_optimizer\");\nvar adamax_optimizer_1 = require(\"./optimizers/adamax_optimizer\");\nvar momentum_optimizer_1 = require(\"./optimizers/momentum_optimizer\");\nvar optimizer_constructors_1 = require(\"./optimizers/optimizer_constructors\");\nvar rmsprop_optimizer_1 = require(\"./optimizers/rmsprop_optimizer\");\nvar sgd_optimizer_1 = require(\"./optimizers/sgd_optimizer\");\n[momentum_optimizer_1.MomentumOptimizer, sgd_optimizer_1.SGDOptimizer, adadelta_optimizer_1.AdadeltaOptimizer, adagrad_optimizer_1.AdagradOptimizer,\n rmsprop_optimizer_1.RMSPropOptimizer, adamax_optimizer_1.AdamaxOptimizer, adam_optimizer_1.AdamOptimizer];\nexports.train = {\n sgd: optimizer_constructors_1.OptimizerConstructors.sgd,\n momentum: optimizer_constructors_1.OptimizerConstructors.momentum,\n adadelta: optimizer_constructors_1.OptimizerConstructors.adadelta,\n adagrad: optimizer_constructors_1.OptimizerConstructors.adagrad,\n rmsprop: optimizer_constructors_1.OptimizerConstructors.rmsprop,\n adamax: optimizer_constructors_1.OptimizerConstructors.adamax,\n adam: optimizer_constructors_1.OptimizerConstructors.adam\n};\n","\"use strict\";\nfunction __export(m) {\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\n}\nObject.defineProperty(exports, \"__esModule\", { value: true });\nrequire(\"./kernels/backend_webgl\");\nrequire(\"./kernels/backend_cpu\");\nvar browser_util_1 = require(\"./browser_util\");\nvar environment = require(\"./environment\");\nexports.environment = environment;\nvar environment_1 = require(\"./environment\");\nvar io = require(\"./io/io\");\nexports.io = io;\nvar serialization = require(\"./serialization\");\nexports.serialization = serialization;\nvar test_util = require(\"./test_util\");\nexports.test_util = test_util;\nvar util = require(\"./util\");\nexports.util = util;\nvar version_1 = require(\"./version\");\nexports.version_core = version_1.version;\nvar webgl = require(\"./webgl\");\nexports.webgl = webgl;\nvar adadelta_optimizer_1 = require(\"./optimizers/adadelta_optimizer\");\nexports.AdadeltaOptimizer = adadelta_optimizer_1.AdadeltaOptimizer;\nvar adagrad_optimizer_1 = require(\"./optimizers/adagrad_optimizer\");\nexports.AdagradOptimizer = adagrad_optimizer_1.AdagradOptimizer;\nvar adam_optimizer_1 = require(\"./optimizers/adam_optimizer\");\nexports.AdamOptimizer = adam_optimizer_1.AdamOptimizer;\nvar adamax_optimizer_1 = require(\"./optimizers/adamax_optimizer\");\nexports.AdamaxOptimizer = adamax_optimizer_1.AdamaxOptimizer;\nvar momentum_optimizer_1 = require(\"./optimizers/momentum_optimizer\");\nexports.MomentumOptimizer = momentum_optimizer_1.MomentumOptimizer;\nvar optimizer_1 = require(\"./optimizers/optimizer\");\nexports.Optimizer = optimizer_1.Optimizer;\nvar rmsprop_optimizer_1 = require(\"./optimizers/rmsprop_optimizer\");\nexports.RMSPropOptimizer = rmsprop_optimizer_1.RMSPropOptimizer;\nvar sgd_optimizer_1 = require(\"./optimizers/sgd_optimizer\");\nexports.SGDOptimizer = sgd_optimizer_1.SGDOptimizer;\nvar tensor_1 = require(\"./tensor\");\nexports.Tensor = tensor_1.Tensor;\nexports.TensorBuffer = tensor_1.TensorBuffer;\nexports.variable = tensor_1.variable;\nexports.Variable = tensor_1.Variable;\nvar types_1 = require(\"./types\");\nexports.Rank = types_1.Rank;\n__export(require(\"./ops/ops\"));\nvar loss_ops_1 = require(\"./ops/loss_ops\");\nexports.Reduction = loss_ops_1.Reduction;\n__export(require(\"./train\"));\n__export(require(\"./globals\"));\nvar environment_2 = require(\"./environment\");\nexports.ENV = environment_2.ENV;\nexports.Environment = environment_2.Environment;\nexports.setBackend = environment_1.Environment.setBackend;\nexports.getBackend = environment_1.Environment.getBackend;\nexports.disposeVariables = environment_1.Environment.disposeVariables;\nexports.memory = environment_1.Environment.memory;\nvar doc_1 = require(\"./doc\");\nexports.doc = doc_1.doc;\nexports.nextFrame = browser_util_1.BrowserUtil.nextFrame;\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tfc = require(\"@tensorflow/tfjs-core\");\nfunction createVertexProgram(gl, vertexShaderSource, fragmentShaderSource) {\n var vertexShader = tfc.webgl.webgl_util.createVertexShader(gl, vertexShaderSource);\n var fragmentShader = tfc.webgl.webgl_util.createFragmentShader(gl, fragmentShaderSource);\n var program = tfc.webgl.webgl_util.createProgram(gl);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, vertexShader); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.attachShader(program, fragmentShader); });\n tfc.webgl.webgl_util.linkProgram(gl, program);\n tfc.webgl.webgl_util.validateProgram(gl, program);\n return program;\n}\nexports.createVertexProgram = createVertexProgram;\nfunction createAndConfigureInterpolatedTexture(gl, width, height, numChannels, pixels) {\n tfc.webgl.webgl_util.validateTextureSize(gl, width, height);\n var texture = tfc.webgl.webgl_util.createTexture(gl);\n var tex2d = gl.TEXTURE_2D;\n var internalFormat = getTextureInternalFormat(gl, numChannels);\n var format = getTextureFormat(gl, numChannels);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindTexture(tex2d, texture); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MIN_FILTER, gl.LINEAR); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MAG_FILTER, gl.LINEAR); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texImage2D(tex2d, 0, internalFormat, width, height, 0, format, getTextureType(gl), pixels); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });\n return texture;\n}\nexports.createAndConfigureInterpolatedTexture = createAndConfigureInterpolatedTexture;\nfunction createAndConfigureTexture(gl, width, height, numChannels, pixels) {\n tfc.webgl.webgl_util.validateTextureSize(gl, width, height);\n var texture = tfc.webgl.webgl_util.createTexture(gl);\n var tex2d = gl.TEXTURE_2D;\n var internalFormat = getTextureInternalFormat(gl, numChannels);\n var format = getTextureFormat(gl, numChannels);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindTexture(tex2d, texture); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MIN_FILTER, gl.NEAREST); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MAG_FILTER, gl.NEAREST); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texImage2D(tex2d, 0, internalFormat, width, height, 0, format, getTextureType(gl), pixels); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });\n return texture;\n}\nexports.createAndConfigureTexture = createAndConfigureTexture;\nfunction createAndConfigureUByteTexture(gl, width, height, numChannels, pixels) {\n tfc.webgl.webgl_util.validateTextureSize(gl, width, height);\n var texture = tfc.webgl.webgl_util.createTexture(gl);\n var tex2d = gl.TEXTURE_2D;\n var internalFormat = getTextureInternalUByteFormat(gl, numChannels);\n var format = getTextureFormat(gl, numChannels);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindTexture(tex2d, texture); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MIN_FILTER, gl.NEAREST); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texParameteri(tex2d, gl.TEXTURE_MAG_FILTER, gl.NEAREST); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.texImage2D(tex2d, 0, internalFormat, width, height, 0, format, getTextureTypeUByte(gl), pixels); });\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindTexture(gl.TEXTURE_2D, null); });\n return texture;\n}\nexports.createAndConfigureUByteTexture = createAndConfigureUByteTexture;\nfunction getTextureInternalFormat(gl, numChannels) {\n if (numChannels === 4) {\n return gl.RGBA32F;\n }\n else if (numChannels === 3) {\n return gl.RGB32F;\n }\n else if (numChannels === 2) {\n return gl.RG32F;\n }\n return gl.R32F;\n}\nfunction getTextureInternalUByteFormat(gl, numChannels) {\n if (numChannels === 4) {\n return gl.RGBA8;\n }\n else if (numChannels === 3) {\n return gl.RGB8;\n }\n else if (numChannels === 2) {\n return gl.RG8;\n }\n return gl.R8;\n}\nfunction getTextureFormat(gl, numChannels) {\n if (numChannels === 4) {\n return gl.RGBA;\n }\n else if (numChannels === 3) {\n return gl.RGB;\n }\n else if (numChannels === 2) {\n return gl.RG;\n }\n return gl.RED;\n}\nfunction getTextureType(gl) {\n return gl.FLOAT;\n}\nfunction getTextureTypeUByte(gl) {\n return gl.UNSIGNED_BYTE;\n}\n//# sourceMappingURL=gl_util.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tfc = require(\"@tensorflow/tfjs-core\");\nvar gl_util = require(\"./gl_util\");\nfunction generateDistanceComputationSource(format) {\n var source = \"\\n #define DATA_NUM_PACKED_DIMENSIONS \" + format.pixelsPerPoint + \".\\n #define DATA_POINTS_PER_ROW \" + format.pointsPerRow + \".\\n #define DATA_NUM_ROWS \" + format.numRows + \".\\n #define TEXTURE_WIDTH \" + format.pointsPerRow * format.pixelsPerPoint + \".\\n\\n //returns the texture coordinate for point/dimension\\n vec2 dataTexCoordinates(int id, int dimension) {\\n float id_f = float(id);\\n float row = (floor(id_f/DATA_POINTS_PER_ROW)+0.5) / DATA_NUM_ROWS;\\n float col = ((mod(id_f,DATA_POINTS_PER_ROW)*(DATA_NUM_PACKED_DIMENSIONS)\\n + float(dimension)) + 0.5) / (TEXTURE_WIDTH);\\n return vec2(col,row);\\n }\\n\\n //compute the euclidean squared distances between two points i and j\\n float pointDistanceSquared(int i, int j) {\\n vec4 result = vec4(0,0,0,0);\\n int num_iter = int(DATA_NUM_PACKED_DIMENSIONS);\\n for(int d = 0; d < num_iter; ++d) {\\n vec4 vi = texture(data_tex,dataTexCoordinates(i,d));\\n vec4 vj = texture(data_tex,dataTexCoordinates(j,d));\\n result += (vi-vj)*(vi-vj);\\n }\\n return (result.r+result.g+result.b+result.a);\\n }\\n\\n //compute the euclidean squared distances between two points i and j\\n vec4 pointDistanceSquaredBatch(int i, int j0, int j1, int j2, int j3) {\\n vec4 result = vec4(0,0,0,0);\\n int num_iter = int(DATA_NUM_PACKED_DIMENSIONS);\\n for(int d = 0; d < num_iter; ++d) {\\n vec4 vi = texture(data_tex,dataTexCoordinates(i,d));\\n vec4 vj0 = texture(data_tex,dataTexCoordinates(j0,d));\\n vec4 vj1 = texture(data_tex,dataTexCoordinates(j1,d));\\n vec4 vj2 = texture(data_tex,dataTexCoordinates(j2,d));\\n vec4 vj3 = texture(data_tex,dataTexCoordinates(j3,d));\\n vj0 = (vi-vj0); vj0 *= vj0;\\n vj1 = (vi-vj1); vj1 *= vj1;\\n vj2 = (vi-vj2); vj2 *= vj2;\\n vj3 = (vi-vj3); vj3 *= vj3;\\n result.r += (vj0.r+vj0.g+vj0.b+vj0.a);\\n result.g += (vj1.r+vj1.g+vj1.b+vj1.a);\\n result.b += (vj2.r+vj2.g+vj2.b+vj2.a);\\n result.a += (vj3.r+vj3.g+vj3.b+vj3.a);\\n }\\n return result;\\n }\\n \";\n return source;\n}\nexports.generateDistanceComputationSource = generateDistanceComputationSource;\nfunction generateMNISTDistanceComputationSource() {\n var source = \"\\n #define POINTS_PER_ROW 250.\\n #define NUM_ROWS 240.\\n #define TEXTURE_WIDTH 3500.\\n #define TEXTURE_HEIGHT 3360.\\n #define DIGIT_WIDTH 14.\\n #define NUM_PACKED_DIMENSIONS 196\\n\\n //returns the texture coordinate for point/dimension\\n vec2 dataTexCoordinates(int id, int dimension) {\\n float id_f = float(id);\\n float dimension_f = float(dimension);\\n float col = ((mod(id_f,POINTS_PER_ROW)*DIGIT_WIDTH));\\n float row = (floor(id_f/POINTS_PER_ROW)*DIGIT_WIDTH);\\n\\n return (vec2(col,row)+\\n vec2(mod(dimension_f,DIGIT_WIDTH),floor(dimension_f/DIGIT_WIDTH))+\\n vec2(0.5,0.5)\\n )/\\n vec2(TEXTURE_WIDTH,TEXTURE_HEIGHT);\\n }\\n\\n //compute the euclidean squared distances between two points i and j\\n float pointDistanceSquared(int i, int j) {\\n vec4 result = vec4(0,0,0,0);\\n for(int d = 0; d < NUM_PACKED_DIMENSIONS; d+=1) {\\n vec4 vi = texture(data_tex,dataTexCoordinates(i,d));\\n vec4 vj = texture(data_tex,dataTexCoordinates(j,d));\\n result += (vi-vj)*(vi-vj);\\n }\\n return (result.r+result.g+result.b+result.a);\\n }\\n\\n //compute the euclidean squared distances between two points i and j\\n vec4 pointDistanceSquaredBatch(int i, int j0, int j1, int j2, int j3) {\\n vec4 result = vec4(0,0,0,0);\\n for(int d = 0; d < NUM_PACKED_DIMENSIONS; d+=1) {\\n vec4 vi = texture(data_tex,dataTexCoordinates(i,d));\\n vec4 vj0 = texture(data_tex,dataTexCoordinates(j0,d));\\n vec4 vj1 = texture(data_tex,dataTexCoordinates(j1,d));\\n vec4 vj2 = texture(data_tex,dataTexCoordinates(j2,d));\\n vec4 vj3 = texture(data_tex,dataTexCoordinates(j3,d));\\n vj0 = (vi-vj0); vj0 *= vj0;\\n vj1 = (vi-vj1); vj1 *= vj1;\\n vj2 = (vi-vj2); vj2 *= vj2;\\n vj3 = (vi-vj3); vj3 *= vj3;\\n result.r += (vj0.r+vj0.g+vj0.b+vj0.a);\\n result.g += (vj1.r+vj1.g+vj1.b+vj1.a);\\n result.b += (vj2.r+vj2.g+vj2.b+vj2.a);\\n result.a += (vj3.r+vj3.g+vj3.b+vj3.a);\\n }\\n return result;\\n }\\n \";\n return source;\n}\nexports.generateMNISTDistanceComputationSource = generateMNISTDistanceComputationSource;\nfunction generateKNNClusterTexture(numPoints, numClusters, numNeighbors) {\n var pointsPerRow = Math.floor(Math.sqrt(numPoints * numNeighbors) / numNeighbors);\n var numRows = Math.ceil(numPoints / pointsPerRow);\n var dataShape = { numPoints: numPoints, pixelsPerPoint: numNeighbors, numRows: numRows, pointsPerRow: pointsPerRow };\n var pointsPerCluster = Math.ceil(numPoints / numClusters);\n var textureValues = new Float32Array(pointsPerRow * numNeighbors * numRows * 2);\n for (var i = 0; i < numPoints; ++i) {\n var clusterId = Math.floor(i / pointsPerCluster);\n for (var n = 0; n < numNeighbors; ++n) {\n var id = (i * numNeighbors + n) * 2;\n textureValues[id] = Math.floor(Math.random() * pointsPerCluster) +\n clusterId * pointsPerCluster;\n textureValues[id + 1] = Math.random();\n }\n }\n var backend = tfc.ENV.findBackend('webgl');\n if (backend === null) {\n throw Error('WebGL backend is not available');\n }\n var gpgpu = backend.getGPGPUContext();\n var knnGraph = gl_util.createAndConfigureTexture(gpgpu.gl, pointsPerRow * numNeighbors, numRows, 2, textureValues);\n return { knnGraph: knnGraph, dataShape: dataShape };\n}\nexports.generateKNNClusterTexture = generateKNNClusterTexture;\nfunction generateKNNLineTexture(numPoints, numNeighbors) {\n var pointsPerRow = Math.floor(Math.sqrt(numPoints * numNeighbors) / numNeighbors);\n var numRows = Math.ceil(numPoints / pointsPerRow);\n var dataShape = { numPoints: numPoints, pixelsPerPoint: numNeighbors, numRows: numRows, pointsPerRow: pointsPerRow };\n var textureValues = new Float32Array(pointsPerRow * numNeighbors * numRows * 2);\n for (var i = 0; i < numPoints; ++i) {\n for (var n = 0; n < numNeighbors; ++n) {\n var id = (i * numNeighbors + n) * 2;\n textureValues[id] =\n Math.floor(i + n - (numNeighbors / 2) + numPoints) % numPoints;\n textureValues[id + 1] = 1;\n }\n }\n var backend = tfc.ENV.findBackend('webgl');\n if (backend === null) {\n throw Error('WebGL backend is not available');\n }\n var gpgpu = backend.getGPGPUContext();\n var knnGraph = gl_util.createAndConfigureTexture(gpgpu.gl, pointsPerRow * numNeighbors, numRows, 2, textureValues);\n return { knnGraph: knnGraph, dataShape: dataShape };\n}\nexports.generateKNNLineTexture = generateKNNLineTexture;\nfunction generateKNNClusterData(numPoints, numClusters, numNeighbors) {\n var pointsPerCluster = Math.ceil(numPoints / numClusters);\n var distances = new Float32Array(numPoints * numNeighbors);\n var indices = new Uint32Array(numPoints * numNeighbors);\n for (var i = 0; i < numPoints; ++i) {\n var clusterId = Math.floor(i / pointsPerCluster);\n for (var n = 0; n < numNeighbors; ++n) {\n var id = (i * numNeighbors + n);\n distances[id] = Math.random();\n indices[id] = Math.floor(Math.random() * pointsPerCluster) +\n clusterId * pointsPerCluster;\n }\n }\n return { distances: distances, indices: indices };\n}\nexports.generateKNNClusterData = generateKNNClusterData;\nfunction generateKNNLineData(numPoints, numNeighbors) {\n var distances = new Float32Array(numPoints * numNeighbors);\n var indices = new Uint32Array(numPoints * numNeighbors);\n for (var i = 0; i < numPoints; ++i) {\n for (var n = 0; n < numNeighbors; ++n) {\n var id = (i * numNeighbors + n);\n distances[id] = 1;\n indices[id] =\n Math.floor(i + n - (numNeighbors / 2) + numPoints) % numPoints;\n }\n }\n return { distances: distances, indices: indices };\n}\nexports.generateKNNLineData = generateKNNLineData;\n//# sourceMappingURL=dataset_util.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tfc = require(\"@tensorflow/tfjs-core\");\nvar gl_util = require(\"./gl_util\");\nfunction createTextureDrawerProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n uniform sampler2D texture;\\n uniform float width;\\n uniform float height;\\n\\n void main() {\\n vec2 texture_coordinates = gl_FragCoord.xy/vec2(width,height);\\n texture_coordinates.y = 1. - texture_coordinates.y;\\n vec4 texture_color = texture2D(texture,texture_coordinates);\\n gl_FragColor = texture_color;\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createTextureDrawerProgram = createTextureDrawerProgram;\nfunction executeTextureDrawerProgram(gpgpu, program, texture, width, height, targetTex) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, height, width);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var textureLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'texture');\n gpgpu.setInputMatrixTexture(texture, textureLoc, 0);\n var widthLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'width');\n gl.uniform1f(widthLoc, width);\n var heightLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'height');\n gl.uniform1f(heightLoc, height);\n gpgpu.executeProgram();\n}\nexports.executeTextureDrawerProgram = executeTextureDrawerProgram;\nfunction createAvgChannelTextureDrawerProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n uniform sampler2D texture;\\n uniform float width;\\n uniform float height;\\n\\n void main() {\\n vec2 texture_coordinates = gl_FragCoord.xy/vec2(width,height);\\n texture_coordinates.y = 1. - texture_coordinates.y;\\n vec4 texture_color = texture2D(texture,texture_coordinates);\\n float grey_scale = (texture_color.r + texture_color.g +\\n texture_color.b + texture_color.a)/4.;\\n gl_FragColor = vec4(vec3(grey_scale),1);\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createAvgChannelTextureDrawerProgram = createAvgChannelTextureDrawerProgram;\nfunction executeAvgChannelTextureDrawerProgram(gpgpu, program, texture, width, height, targetTex) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, height, width);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var textureLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'texture');\n gpgpu.setInputMatrixTexture(texture, textureLoc, 0);\n var widthLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'width');\n gl.uniform1f(widthLoc, width);\n var heightLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'height');\n gl.uniform1f(heightLoc, height);\n gpgpu.executeProgram();\n}\nexports.executeAvgChannelTextureDrawerProgram = executeAvgChannelTextureDrawerProgram;\nfunction createSplatTextureDrawerProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n uniform sampler2D splat_tex;\\n uniform sampler2D color_scale_tex;\\n uniform sampler2D drawn_embedding_tex;\\n\\n uniform float width;\\n uniform float height;\\n uniform float normalization;\\n\\n void main() {\\n float value = 0.;\\n vec2 texture_pos = vec2(-1,-1);\\n\\n if(gl_FragCoord.x < width/2. && gl_FragCoord.y >= height/2.) {\\n vec2 texture_pos = (gl_FragCoord.xy-vec2(0.,height/2.))\\n / vec2(width/2.,height/2.);\\n vec4 values = texture2D(drawn_embedding_tex,texture_pos);\\n gl_FragColor = values;\\n return;\\n\\n }else if(gl_FragCoord.x >= width/2. && gl_FragCoord.y >= height/2.) {\\n vec2 texture_pos = (gl_FragCoord.xy-vec2(width/2.,height/2.))\\n / vec2(width/2.,height/2.);\\n vec4 values = texture2D(splat_tex,texture_pos)/normalization*1.5;\\n value = values.x;\\n\\n }else if(gl_FragCoord.x < width/2. && gl_FragCoord.y < height/2.) {\\n vec2 texture_pos = gl_FragCoord.xy / vec2(width/2.,height/2.);\\n vec4 values = texture2D(splat_tex,texture_pos)/normalization*15.;\\n value = values.y;\\n\\n }else if(gl_FragCoord.x >= width/2. && gl_FragCoord.y < height/2.) {\\n vec2 texture_pos = (gl_FragCoord.xy-vec2(width/2.,0))\\n / vec2(width/2.,height/2.);\\n vec4 values = texture2D(splat_tex,texture_pos)/normalization*15.;\\n value = values.z;\\n }\\n\\n\\n vec2 color_scale_pos = vec2(-1.*value+0.5,0.5);\\n vec4 color = texture2D(color_scale_tex,color_scale_pos)/255.;\\n\\n gl_FragColor = vec4(color.xyz,1);\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createSplatTextureDrawerProgram = createSplatTextureDrawerProgram;\nfunction executeSplatTextureDrawerProgram(gpgpu, program, splatTex, colorScaleTex, drawnEmbeddingTex, normalization, textureDiameter, targetTex) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, textureDiameter, textureDiameter);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var splatLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'splat_tex');\n gpgpu.setInputMatrixTexture(splatTex, splatLocation, 0);\n var colorScaleLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'color_scale_tex');\n gpgpu.setInputMatrixTexture(colorScaleTex, colorScaleLocation, 1);\n var drawnEmbeddingLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'drawn_embedding_tex');\n gpgpu.setInputMatrixTexture(drawnEmbeddingTex, drawnEmbeddingLoc, 2);\n var widthLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'width');\n gl.uniform1f(widthLoc, textureDiameter);\n var heightLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'height');\n gl.uniform1f(heightLoc, textureDiameter);\n var normLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'normalization');\n gl.uniform1f(normLoc, normalization);\n gpgpu.executeProgram();\n}\nexports.executeSplatTextureDrawerProgram = executeSplatTextureDrawerProgram;\nfunction createSimpleEmbeddingDrawerProgram(gpgpu) {\n var vertexShaderSource = \"\\n precision highp float;\\n attribute float vertex_id;\\n\\n uniform sampler2D embedding_tex;\\n uniform vec2 minV;\\n uniform vec2 maxV;\\n uniform float pnts_per_row;\\n uniform float num_rows;\\n\\n void main() {\\n int row = int(vertex_id/pnts_per_row);\\n int column = int(mod(vertex_id,pnts_per_row));\\n float width = (pnts_per_row*2.0);\\n float row_tex = (float(row)+0.5)/num_rows;\\n vec2 tex_coords_x = vec2((float(column)*2.+0.5)/width, row_tex);\\n vec2 tex_coords_y = vec2((float(column)*2.+1.+0.5)/width, row_tex);\\n\\n float x_pnt = texture2D(embedding_tex,tex_coords_x).r;\\n float y_pnt = texture2D(embedding_tex,tex_coords_y).r;\\n vec2 vertex_coords = vec2(x_pnt,y_pnt);\\n\\n vertex_coords = (vertex_coords-minV)/(maxV-minV); // 0:1 space\\n vertex_coords = vertex_coords*2.0 - 1.0; // -1:1 space\\n\\n gl_Position = vec4(vertex_coords,0,1);\\n gl_PointSize = 4.;\\n }\\n \";\n var fragmentShaderSource = \"\\n precision highp float;\\n uniform float alpha;\\n\\n void main() {\\n float r = 0.0, delta = 0.0;\\n vec2 cxy = 2.0 * gl_PointCoord - 1.0;\\n r = dot(cxy, cxy);\\n if (r > 1.0) {\\n discard;\\n }\\n gl_FragColor = vec4(0,0.6,1,alpha);\\n }\\n \";\n return gl_util.createVertexProgram(gpgpu.gl, vertexShaderSource, fragmentShaderSource);\n}\nexports.createSimpleEmbeddingDrawerProgram = createSimpleEmbeddingDrawerProgram;\nfunction executeSimpleEmbeddingDrawerProgram(gpgpu, program, embeddingTex, numPoints, minX, minY, maxX, maxY, pntsPerRow, numRows, pointIdBuffer, alpha, targetTexDiameter, targetTex) {\n var gl = gpgpu.gl;\n var oldProgram = gpgpu.program;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, targetTexDiameter, targetTexDiameter);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gl.clearColor(1, 1, 1, 1);\n gl.clear(gl.COLOR_BUFFER_BIT);\n gpgpu.setProgram(program);\n gl.enable(gl.BLEND);\n gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, pointIdBuffer); });\n tfc.webgl.webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'vertex_id', pointIdBuffer, 1, 0, 0);\n var embeddingLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'embedding_tex');\n gpgpu.setInputMatrixTexture(embeddingTex, embeddingLocation, 0);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'pnts_per_row');\n gl.uniform1f(pntsPerRowLoc, pntsPerRow);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows');\n gl.uniform1f(numRowsLoc, numRows);\n var alphaLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'alpha');\n gl.uniform1f(alphaLoc, alpha);\n if (maxX - minX > maxY - minY) {\n maxY = (maxY + minY) / 2 + (maxX - minX) / 2;\n minY = (maxY + minY) / 2 - (maxX - minX) / 2;\n }\n else {\n maxX = (maxX + minX) / 2 + (maxY - minY) / 2;\n minX = (maxX + minX) / 2 - (maxY - minY) / 2;\n }\n var minLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'minV');\n gl.uniform2f(minLoc, minX, minY);\n var maxLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'maxV');\n gl.uniform2f(maxLoc, maxX, maxY);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.drawArrays(gl.POINTS, 0, numPoints); });\n gl.disable(gl.BLEND);\n if (oldProgram != null) {\n gpgpu.setProgram(oldProgram);\n tfc.webgl.gpgpu_util.bindVertexProgramAttributeStreams(gpgpu.gl, oldProgram, gpgpu.vertexBuffer);\n }\n}\nexports.executeSimpleEmbeddingDrawerProgram = executeSimpleEmbeddingDrawerProgram;\nfunction createColoredEmbeddingDrawerProgram(gpgpu) {\n var vertexShaderSource = \"\\n precision highp float;\\n attribute float vertex_id;\\n\\n uniform sampler2D embedding_tex;\\n uniform sampler2D color_tex;\\n uniform vec2 minV;\\n uniform vec2 maxV;\\n uniform float pnts_per_row;\\n uniform float num_rows;\\n\\n varying vec4 color;\\n\\n void main() {\\n int row = int(vertex_id/pnts_per_row);\\n int column = int(mod(vertex_id,pnts_per_row));\\n float width = (pnts_per_row*2.0);\\n float row_tex = (float(row)+0.5)/num_rows;\\n vec2 tex_coords_x = vec2((float(column)*2.+0.5)/width, row_tex);\\n vec2 tex_coords_y = vec2((float(column)*2.+1.+0.5)/width, row_tex);\\n\\n vec2 color_coords = vec2((float(column)+0.5)/pnts_per_row, row_tex);\\n color = texture2D(color_tex,color_coords);\\n\\n float x_pnt = texture2D(embedding_tex,tex_coords_x).r;\\n float y_pnt = texture2D(embedding_tex,tex_coords_y).r;\\n vec2 vertex_coords = vec2(x_pnt,y_pnt);\\n\\n vertex_coords = (vertex_coords-minV)/(maxV-minV); // 0:1 space\\n vertex_coords = vertex_coords*2.0 - 1.0; // -1:1 space\\n\\n gl_Position = vec4(vertex_coords,0,1);\\n gl_PointSize = 4.;\\n }\\n \";\n var fragmentShaderSource = \"\\n precision highp float;\\n uniform float alpha;\\n varying vec4 color;\\n\\n void main() {\\n //vec4 color = vec4(0.1,0.4,0.9,alpha);\\n float r = 0.0, delta = 0.0;\\n vec2 cxy = 2.0 * gl_PointCoord - 1.0;\\n r = dot(cxy, cxy);\\n if (r > 1.0) {\\n discard;\\n }\\n gl_FragColor = color;\\n gl_FragColor.a = alpha;\\n }\\n \";\n return gl_util.createVertexProgram(gpgpu.gl, vertexShaderSource, fragmentShaderSource);\n}\nexports.createColoredEmbeddingDrawerProgram = createColoredEmbeddingDrawerProgram;\nfunction executeColoredEmbeddingDrawerProgram(gpgpu, program, embeddingTex, numPoints, minX, minY, maxX, maxY, pntsPerRow, numRows, pointIdBuffer, alpha, targetTexDiameter, colorsTex, targetTex) {\n var gl = gpgpu.gl;\n var oldProgram = gpgpu.program;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, targetTexDiameter, targetTexDiameter);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gl.clearColor(1, 1, 1, 1);\n gl.clear(gl.COLOR_BUFFER_BIT);\n gpgpu.setProgram(program);\n gl.enable(gl.BLEND);\n gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, pointIdBuffer); });\n tfc.webgl.webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'vertex_id', pointIdBuffer, 1, 0, 0);\n var embeddingLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'embedding_tex');\n gpgpu.setInputMatrixTexture(embeddingTex, embeddingLocation, 0);\n var colorLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'color_tex');\n gpgpu.setInputMatrixTexture(colorsTex, colorLocation, 1);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'pnts_per_row');\n gl.uniform1f(pntsPerRowLoc, pntsPerRow);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows');\n gl.uniform1f(numRowsLoc, numRows);\n var alphaLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'alpha');\n gl.uniform1f(alphaLoc, alpha);\n if (maxX - minX > maxY - minY) {\n maxY = (maxY + minY) / 2 + (maxX - minX) / 2;\n minY = (maxY + minY) / 2 - (maxX - minX) / 2;\n }\n else {\n maxX = (maxX + minX) / 2 + (maxY - minY) / 2;\n minX = (maxX + minX) / 2 - (maxY - minY) / 2;\n }\n var minLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'minV');\n gl.uniform2f(minLoc, minX, minY);\n var maxLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'maxV');\n gl.uniform2f(maxLoc, maxX, maxY);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.drawArrays(gl.POINTS, 0, numPoints); });\n gl.disable(gl.BLEND);\n if (oldProgram != null) {\n gpgpu.setProgram(oldProgram);\n tfc.webgl.gpgpu_util.bindVertexProgramAttributeStreams(gpgpu.gl, oldProgram, gpgpu.vertexBuffer);\n }\n}\nexports.executeColoredEmbeddingDrawerProgram = executeColoredEmbeddingDrawerProgram;\nfunction createTexturedPointsDrawerProgram(gpgpu) {\n var vertexShaderSource = \"#version 300 es\\n precision highp float;\\n in float vertex_id;\\n\\n uniform sampler2D embedding_tex;\\n uniform sampler2D color_tex;\\n\\n uniform vec2 minV;\\n uniform vec2 maxV;\\n uniform float pnts_per_row;\\n uniform float num_rows;\\n\\n out float image_id;\\n out vec4 label_color;\\n\\n\\n void main() {\\n int row = int(vertex_id/pnts_per_row);\\n int column = int(mod(vertex_id,pnts_per_row));\\n\\n float width = (pnts_per_row*2.0);\\n float row_tex = (float(row)+0.5)/num_rows;\\n vec2 tex_coords_x = vec2((float(column)*2.+0.5)/width, row_tex);\\n vec2 tex_coords_y = vec2((float(column)*2.+1.+0.5)/width, row_tex);\\n\\n vec2 color_coords = vec2((float(column)+0.5)/pnts_per_row, row_tex);\\n label_color = texture(color_tex,color_coords);\\n\\n float x_pnt = texture(embedding_tex,tex_coords_x).r;\\n float y_pnt = texture(embedding_tex,tex_coords_y).r;\\n vec2 vertex_coords = vec2(x_pnt,y_pnt);\\n\\n vertex_coords = (vertex_coords-minV)/(maxV-minV); // 0:1 space\\n vertex_coords = vertex_coords*2.0 - 1.0; // -1:1 space\\n\\n gl_Position = vec4(vertex_coords,0,1);\\n gl_PointSize = 14.;\\n image_id = vertex_id;\\n }\\n \";\n var fragmentShaderSource = \"#version 300 es\\n precision highp float;\\n uniform float alpha;\\n uniform float pnts_per_row;\\n uniform float num_rows;\\n uniform float point_texture_diameter;\\n\\n in float image_id;\\n in vec4 label_color;\\n\\n out vec4 fragment_color;\\n\\n uniform sampler2D point_tex;\\n\\n //Random function developed by Inigo Quilez\\n //https://www.shadertoy.com/view/llGSzw\\n float hash1( uint n ) {\\n // integer hash copied from Hugo Elias\\n \\t n = (n << 13U) ^ n;\\n n = n * (n * n * 15731U + 789221U) + 1376312589U;\\n return float( n & uvec3(0x7fffffffU))/float(0x7fffffff);\\n }\\n\\n void main() {\\n vec2 cxy = gl_PointCoord*point_texture_diameter;\\n\\n float random = hash1(uint(image_id));\\n\\n int row = int(image_id/250.);\\n int col = int(mod(image_id,250.));\\n\\n\\n float col_tex = (float(col)*point_texture_diameter+0.5+cxy.x)/3500.;\\n float row_tex = (float(row)*point_texture_diameter+0.5+cxy.y)/3360.;\\n\\n vec2 tex_coords = vec2(col_tex, row_tex);\\n vec4 texture_value = texture(point_tex,tex_coords);\\n float average_value = (texture_value.r,texture_value.g,\\n texture_value.b,texture_value.a)/4.;\\n\\n\\n fragment_color = label_color;\\n fragment_color.a = average_value*1.5;\\n\\n float fade_in = 0.05;\\n if(random - alpha < fade_in) {\\n fragment_color.a *= 1. - (random - alpha)/fade_in;\\n }else if(random > alpha) {\\n fragment_color.a = 0.;\\n }\\n }\\n \";\n return gl_util.createVertexProgram(gpgpu.gl, vertexShaderSource, fragmentShaderSource);\n}\nexports.createTexturedPointsDrawerProgram = createTexturedPointsDrawerProgram;\nfunction executeTexturedPointsDrawerProgram(gpgpu, program, embeddingTex, numPoints, minX, minY, maxX, maxY, pntsPerRow, numRows, pointIdBuffer, alpha, targetTexDiameter, pointsTex, pointTextureDiameter, colorsTex, targetTex) {\n var gl = gpgpu.gl;\n var oldProgram = gpgpu.program;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, targetTexDiameter, targetTexDiameter);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gl.clearColor(1, 1, 1, 1);\n gl.clear(gl.COLOR_BUFFER_BIT);\n gpgpu.setProgram(program);\n gl.enable(gl.BLEND);\n gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, pointIdBuffer); });\n tfc.webgl.webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'vertex_id', pointIdBuffer, 1, 0, 0);\n var embeddingLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'embedding_tex');\n gpgpu.setInputMatrixTexture(embeddingTex, embeddingLocation, 0);\n var pointsTexLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'point_tex');\n gpgpu.setInputMatrixTexture(pointsTex, pointsTexLoc, 1);\n var colorsTexLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'color_tex');\n gpgpu.setInputMatrixTexture(colorsTex, colorsTexLoc, 2);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'pnts_per_row');\n gl.uniform1f(pntsPerRowLoc, pntsPerRow);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows');\n gl.uniform1f(numRowsLoc, numRows);\n var pointTextureDiameterLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'point_texture_diameter');\n gl.uniform1f(pointTextureDiameterLoc, pointTextureDiameter);\n var alphaLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'alpha');\n gl.uniform1f(alphaLoc, alpha);\n if (maxX - minX > maxY - minY) {\n maxY = (maxY + minY) / 2 + (maxX - minX) / 2;\n minY = (maxY + minY) / 2 - (maxX - minX) / 2;\n }\n else {\n maxX = (maxX + minX) / 2 + (maxY - minY) / 2;\n minX = (maxX + minX) / 2 - (maxY - minY) / 2;\n }\n var minLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'minV');\n gl.uniform2f(minLoc, minX, minY);\n var maxLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'maxV');\n gl.uniform2f(maxLoc, maxX, maxY);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.drawArrays(gl.POINTS, 0, numPoints); });\n gl.disable(gl.BLEND);\n if (oldProgram != null) {\n gpgpu.setProgram(oldProgram);\n tfc.webgl.gpgpu_util.bindVertexProgramAttributeStreams(gpgpu.gl, oldProgram, gpgpu.vertexBuffer);\n }\n}\nexports.executeTexturedPointsDrawerProgram = executeTexturedPointsDrawerProgram;\n//# sourceMappingURL=drawer_util.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tfc = require(\"@tensorflow/tfjs-core\");\nvar drawer_util = require(\"./drawer_util\");\nvar gl_util = require(\"./gl_util\");\nvar EmbeddingDrawer = (function () {\n function EmbeddingDrawer(numPoints) {\n this.numPoints = numPoints;\n var backend = tfc.ENV.findBackend('webgl');\n this.gpgpu = backend.getGPGPUContext();\n this.initializePrograms();\n }\n EmbeddingDrawer.prototype.drawPoints = function (embedding, alpha, targetTex) {\n drawer_util.executeSimpleEmbeddingDrawerProgram(this.gpgpu, this.simpleEmbeddingDrawerProgram, embedding.embeddingTexture, embedding.numPoints, embedding.minX, embedding.minY, embedding.maxX, embedding.maxY, embedding.pntsPerRow, embedding.numRows, this.vertexIdBuffer, alpha, 800, targetTex);\n };\n EmbeddingDrawer.prototype.drawColoredPoints = function (embedding, alpha, colors, targetTex) {\n drawer_util.executeColoredEmbeddingDrawerProgram(this.gpgpu, this.coloredEmbeddingDrawerProgram, embedding.embeddingTexture, embedding.numPoints, embedding.minX, embedding.minY, embedding.maxX, embedding.maxY, embedding.pntsPerRow, embedding.numRows, this.vertexIdBuffer, alpha, 800, colors, targetTex);\n };\n EmbeddingDrawer.prototype.drawTexturedPoints = function (embedding, alpha, pointsTexture, pointTextureDiameter, colorsTexture, targetTex) {\n drawer_util.executeTexturedPointsDrawerProgram(this.gpgpu, this.texturedPointsDrawerProgram, embedding.embeddingTexture, embedding.numPoints, embedding.minX, embedding.minY, embedding.maxX, embedding.maxY, embedding.pntsPerRow, embedding.numRows, this.vertexIdBuffer, alpha, 800, pointsTexture, pointTextureDiameter, colorsTexture, targetTex);\n };\n EmbeddingDrawer.prototype.drawPointsAndSplatTexture = function (embedding, splatTexture, drawnEmbeddingTex, textureNormalization) {\n drawer_util.executeSplatTextureDrawerProgram(this.gpgpu, this.splatTextureDrawerProgram, splatTexture, this.colorScaleTex, drawnEmbeddingTex, textureNormalization, 800);\n };\n EmbeddingDrawer.prototype.initializePrograms = function () {\n this.simpleEmbeddingDrawerProgram =\n drawer_util.createSimpleEmbeddingDrawerProgram(this.gpgpu);\n this.coloredEmbeddingDrawerProgram =\n drawer_util.createColoredEmbeddingDrawerProgram(this.gpgpu);\n var vertexId = new Float32Array(this.numPoints);\n var i = 0;\n for (i = 0; i < this.numPoints; ++i) {\n vertexId[i] = i;\n }\n this.vertexIdBuffer =\n tfc.webgl.webgl_util.createStaticVertexBuffer(this.gpgpu.gl, vertexId);\n this.splatTextureDrawerProgram =\n drawer_util.createSplatTextureDrawerProgram(this.gpgpu);\n this.texturedPointsDrawerProgram =\n drawer_util.createTexturedPointsDrawerProgram(this.gpgpu);\n var colors = new Float32Array([\n 178, 24, 43, 214, 96, 77, 244, 165, 130, 253, 219, 199, 255, 255,\n 255, 209, 229, 240, 146, 197, 222, 67, 147, 195, 33, 102, 172\n ]);\n this.colorScaleTex = gl_util.createAndConfigureInterpolatedTexture(this.gpgpu.gl, 9, 1, 3, colors);\n };\n return EmbeddingDrawer;\n}());\nexports.EmbeddingDrawer = EmbeddingDrawer;\n//# sourceMappingURL=drawer.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tfc = require(\"@tensorflow/tfjs-core\");\nvar gl_util = require(\"./gl_util\");\nfunction generateFragmentShaderSource(distanceComputationSource, numNeighbors) {\n var source = \"#version 300 es\\n precision highp float;\\n uniform sampler2D data_tex;\\n uniform float num_points;\\n uniform float points_per_row_knn;\\n uniform float num_rows_knn;\\n uniform float num_neighs;\\n uniform float iteration;\\n\\n #define NUM_PACKED_NEIGHBORS \" + numNeighbors / 4 + \"\\n\\n flat in vec4 knn[NUM_PACKED_NEIGHBORS];\\n flat in int point_id;\\n in float neighbor_id;\\n\\n const float MAX_DIST = 10e30;\\n\\n \" + distanceComputationSource + \"\\n\\n out vec4 fragmentColor;\\n void main() {\\n int id = int(neighbor_id/4.);\\n int channel = int(mod(neighbor_id,4.)+0.1);\\n\\n if(channel == 0) {\\n fragmentColor = vec4(knn[id].r,0,0,1);\\n }else if(channel == 1) {\\n fragmentColor = vec4(knn[id].g,0,0,1);\\n }else if(channel == 2) {\\n fragmentColor = vec4(knn[id].b,0,0,1);\\n }else if(channel == 3) {\\n fragmentColor = vec4(knn[id].a,0,0,1);\\n }\\n\\n //If the neighbor has a valid id i compute the distance squared\\n //otherwise I set it to invalid\\n if(fragmentColor.r >= 0.) {\\n fragmentColor.g = pointDistanceSquared(int(fragmentColor.r),point_id);\\n }else{\\n fragmentColor.g = MAX_DIST;\\n }\\n }\\n \";\n return source;\n}\nfunction generateVariablesAndDeclarationsSource(numNeighbors) {\n var source = \"\\n precision highp float;\\n #define NEIGH_PER_ITER 20\\n #define NUM_NEIGHBORS \" + numNeighbors + \"\\n #define NUM_NEIGHBORS_FLOAT \" + numNeighbors + \".\\n #define NUM_PACKED_NEIGHBORS \" + numNeighbors / 4 + \"\\n #define MAX_DIST 10e30\\n\\n //attributes\\n in float vertex_id;\\n //uniforms\\n uniform sampler2D data_tex;\\n uniform sampler2D starting_knn_tex;\\n uniform float num_points;\\n uniform float points_per_row_knn;\\n uniform float num_rows_knn;\\n uniform float num_neighs;\\n uniform float iteration;\\n\\n //output\\n //the indices are packed in varying vectors\\n flat out vec4 knn[NUM_PACKED_NEIGHBORS];\\n //used to recover the neighbor id in the fragment shader\\n out float neighbor_id;\\n //used to recover the point id in the fragment shader\\n //(for recomputing distances)\\n flat out int point_id;\\n\\n float distances_heap[NUM_NEIGHBORS];\\n int knn_heap[NUM_NEIGHBORS];\\n \";\n return source;\n}\nvar randomGeneratorSource = \"\\n//Random function developed by Inigo Quilez\\n//https://www.shadertoy.com/view/llGSzw\\nfloat hash1( uint n ) {\\n // integer hash copied from Hugo Elias\\n\\t n = (n << 13U) ^ n;\\n n = n * (n * n * 15731U + 789221U) + 1376312589U;\\n return float( n & uvec3(0x7fffffffU))/float(0x7fffffff);\\n}\\n\\nuint hash( uint x ) {\\n x += ( x << 10u );\\n x ^= ( x >> 6u );\\n x += ( x << 3u );\\n x ^= ( x >> 11u );\\n x += ( x << 15u );\\n return x;\\n}\\nfloat random( float f ) {\\n const uint mantissaMask = 0x007FFFFFu;\\n const uint one = 0x3F800000u;\\n\\n uint h = hash( floatBitsToUint( f ) );\\n h &= mantissaMask;\\n h |= one;\\n\\n float r2 = uintBitsToFloat( h );\\n return r2 - 1.0;\\n}\\n\\n\\n// #define HASHSCALE1 .1031\\n// float random(float p) {\\n// \\tvec3 p3 = fract(vec3(p) * HASHSCALE1);\\n// p3 += dot(p3, p3.yzx + 19.19);\\n// return fract((p3.x + p3.y) * p3.z);\\n// }\\n\\n// const vec2 randomConst = vec2(\\n// 23.14069263277926, // e^pi (Gelfond's constant)\\n// 2.665144142690225 // 2^sqrt(2) (Gelfond\\u2013Schneider constant)\\n// );\\n// float random(float seed) {\\n// return fract(cos(dot(vec2(seed,seed), randomConst)) * 12345.6789);\\n// }\\n\\n\";\nvar distancesInitializationSource = \"\\n//Reads the distances and indices from the knn texture\\nvoid initializeDistances(int pnt_id) {\\n //row coordinate in the texture\\n float row = (floor(float(pnt_id)/points_per_row_knn)+0.5)/num_rows_knn;\\n //column of the first neighbor\\n float start_col = mod(float(pnt_id),points_per_row_knn)*NUM_NEIGHBORS_FLOAT;\\n for(int n = 0; n < NUM_NEIGHBORS; n++) {\\n float col = (start_col+float(n)+0.5);\\n //normalized by the width of the texture\\n col /= (points_per_row_knn*NUM_NEIGHBORS_FLOAT);\\n //reads the index in the red channel and the distances in the green one\\n vec4 init = texture(starting_knn_tex,vec2(col,row));\\n\\n knn_heap[n] = int(init.r);\\n distances_heap[n] = init.g;\\n }\\n}\\n\";\nvar knnHeapSource = \"\\n//Swaps two points in the knn-heap\\nvoid swap(int i, int j) {\\n float swap_value = distances_heap[i];\\n distances_heap[i] = distances_heap[j];\\n distances_heap[j] = swap_value;\\n int swap_id = knn_heap[i];\\n knn_heap[i] = knn_heap[j];\\n knn_heap[j] = swap_id;\\n}\\n\\n//I can make use of the heap property but\\n//I have to implement a recursive function\\nbool inTheHeap(float dist_sq, int id) {\\n for(int i = 0; i < NUM_NEIGHBORS; ++i) {\\n if(knn_heap[i] == id) {\\n return true;\\n }\\n }\\n return false;\\n}\\n\\nvoid insertInKNN(float dist_sq, int j) {\\n //not in the KNN\\n if(dist_sq >= distances_heap[0]) {\\n return;\\n }\\n\\n //the point is already in the KNN\\n if(inTheHeap(dist_sq,j)) {\\n return;\\n }\\n\\n //Insert in the new point in the root\\n distances_heap[0] = dist_sq;\\n knn_heap[0] = j;\\n //Sink procedure\\n int swap_id = 0;\\n while(swap_id*2+1 < NUM_NEIGHBORS) {\\n int left_id = swap_id*2+1;\\n int right_id = swap_id*2+2;\\n if(distances_heap[left_id] > distances_heap[swap_id] ||\\n (right_id < NUM_NEIGHBORS &&\\n distances_heap[right_id] > distances_heap[swap_id])\\n ) {\\n if(distances_heap[left_id] > distances_heap[right_id]\\n || right_id >= NUM_NEIGHBORS) {\\n swap(swap_id,left_id);\\n swap_id = left_id;\\n }else{\\n swap(swap_id,right_id);\\n swap_id = right_id;\\n }\\n }else{\\n break;\\n }\\n }\\n}\\n\";\nvar vertexPositionSource = \"\\n //Line positions\\n float row = (floor(float(point_id)/points_per_row_knn)+0.5)/num_rows_knn;\\n row = row*2.0-1.0;\\n if(line_id < int(1)) {\\n //for the first vertex only the position is important\\n float col = (mod(float(point_id),points_per_row_knn))/(points_per_row_knn);\\n col = col*2.0-1.0;\\n gl_Position = vec4(col,row,0,1);\\n neighbor_id = 0.;\\n return;\\n }\\n //The computation of the KNN happens only for the second vertex\\n float col = (mod(float(point_id),points_per_row_knn)+1.)/(points_per_row_knn);\\n col = col*2.0-1.0;\\n gl_Position = vec4(col,row,0,1);\\n\";\nfunction createBruteForceKNNProgram(gpgpu, numNeighbors, distanceComputationSource) {\n var vertexShaderSource = \"#version 300 es\\n \" +\n generateVariablesAndDeclarationsSource(numNeighbors) +\n distancesInitializationSource + distanceComputationSource +\n knnHeapSource + (\"\\n void main() {\\n //Getting the id of the point and the line id (0/1)\\n point_id = int((vertex_id/2.0)+0.1);\\n int line_id = int(mod(vertex_id+0.1,2.));\\n if(float(point_id) >= num_points) {\\n return;\\n }\\n\\n \" + vertexPositionSource + \"\\n\\n //////////////////////////////////\\n //KNN computation\\n initializeDistances(point_id);\\n for(int i = 0; i < NEIGH_PER_ITER; i += 4) {\\n //TODO make it more readable\\n int j = int(mod(float(point_id+i)+\\n iteration*float(NEIGH_PER_ITER)+1.,num_points));\\n vec4 dist_squared = pointDistanceSquaredBatch(point_id,j,j+1,j+2,j+3);\\n insertInKNN(dist_squared.r, j);\\n insertInKNN(dist_squared.g, j+1);\\n insertInKNN(dist_squared.b, j+2);\\n insertInKNN(dist_squared.a, j+3);\\n }\\n\\n for(int n = 0; n < NUM_PACKED_NEIGHBORS; n++) {\\n knn[n].r = float(knn_heap[n*4]);\\n knn[n].g = float(knn_heap[n*4+1]);\\n knn[n].b = float(knn_heap[n*4+2]);\\n knn[n].a = float(knn_heap[n*4+3]);\\n }\\n\\n neighbor_id = NUM_NEIGHBORS_FLOAT;\\n }\\n \");\n var knnFragmentShaderSource = generateFragmentShaderSource(distanceComputationSource, numNeighbors);\n return gl_util.createVertexProgram(gpgpu.gl, vertexShaderSource, knnFragmentShaderSource);\n}\nexports.createBruteForceKNNProgram = createBruteForceKNNProgram;\nfunction createRandomSamplingKNNProgram(gpgpu, numNeighbors, distanceComputationSource) {\n var vertexShaderSource = \"#version 300 es\\n \" +\n generateVariablesAndDeclarationsSource(numNeighbors) +\n distancesInitializationSource + randomGeneratorSource +\n distanceComputationSource + knnHeapSource + (\"\\n void main() {\\n //Getting the id of the point and the line id (0/1)\\n point_id = int((vertex_id/2.0)+0.1);\\n int line_id = int(mod(vertex_id+0.1,2.));\\n if(float(point_id) >= num_points) {\\n return;\\n }\\n\\n \" + vertexPositionSource + \"\\n\\n //////////////////////////////////\\n //KNN computation\\n\\n initializeDistances(point_id);\\n for(int i = 0; i < NEIGH_PER_ITER; i += 4) {\\n //BAD SEED\\n //uint seed\\n //= uint(float(point_id) + float(NEIGH_PER_ITER)*iteration + float(i));\\n //GOOD SEED\\n //uint seed\\n //= uint(float(point_id) + float(num_points)*iteration + float(i));\\n\\n float seed\\n = float(float(point_id) + float(num_points)*iteration + float(i));\\n int j0 = int(random(seed)*num_points);\\n int j1 = int(random(seed+1.)*num_points);\\n int j2 = int(random(seed+2.)*num_points);\\n int j3 = int(random(seed+3.)*num_points);\\n\\n vec4 dist_squared = pointDistanceSquaredBatch(point_id,j0,j1,j2,j3);\\n if(j0!=point_id)insertInKNN(dist_squared.r, j0);\\n if(j1!=point_id)insertInKNN(dist_squared.g, j1);\\n if(j2!=point_id)insertInKNN(dist_squared.b, j2);\\n if(j3!=point_id)insertInKNN(dist_squared.a, j3);\\n }\\n\\n for(int n = 0; n < NUM_PACKED_NEIGHBORS; n++) {\\n knn[n].r = float(knn_heap[n*4]);\\n knn[n].g = float(knn_heap[n*4+1]);\\n knn[n].b = float(knn_heap[n*4+2]);\\n knn[n].a = float(knn_heap[n*4+3]);\\n }\\n neighbor_id = NUM_NEIGHBORS_FLOAT;\\n }\\n \");\n var knnFragmentShaderSource = generateFragmentShaderSource(distanceComputationSource, numNeighbors);\n return gl_util.createVertexProgram(gpgpu.gl, vertexShaderSource, knnFragmentShaderSource);\n}\nexports.createRandomSamplingKNNProgram = createRandomSamplingKNNProgram;\nfunction createKNNDescentProgram(gpgpu, numNeighbors, distanceComputationSource) {\n var vertexShaderSource = \"#version 300 es\\n \" +\n generateVariablesAndDeclarationsSource(numNeighbors) +\n distancesInitializationSource + randomGeneratorSource +\n distanceComputationSource + knnHeapSource + (\"\\n int fetchNeighborIdFromKNNTexture(int id, int neighbor_id) {\\n //row coordinate in the texture\\n float row = (floor(float(id)/points_per_row_knn)+0.5)/num_rows_knn;\\n //column of the first neighbor\\n float start_col = mod(float(id),points_per_row_knn)*NUM_NEIGHBORS_FLOAT;\\n //column of the neighbor of interest\\n float col = (start_col+float(neighbor_id)+0.5);\\n //normalized by the width of the texture\\n col /= (points_per_row_knn*NUM_NEIGHBORS_FLOAT);\\n //reads the index in the red channel and the distances in the green one\\n vec4 knn_link = texture(starting_knn_tex,vec2(col,row));\\n //return the index\\n return int(knn_link.r);\\n }\\n\\n int neighborOfANeighbor(int my_id, uint seed) {\\n //float random0 = hash1(seed);\\n float random0 = random(float(seed));\\n // random0 = random0*random0;\\n // random0 = 1. - random0;\\n\\n //float random1 = hash1(seed*1798191U);\\n float random1 = random(float(seed+7U));\\n // random1 = random1*random1;\\n // random1 = 1. - random1;\\n\\n //fetch a neighbor from the heap\\n int neighbor = knn_heap[int(random0*NUM_NEIGHBORS_FLOAT)];\\n //if it is not a valid pick a random point\\n if(neighbor < 0) {\\n return int(random(float(seed))*num_points);\\n }\\n\\n //if it is valid I fetch from the knn graph texture one of its neighbors\\n int neighbor2ndDegree = fetchNeighborIdFromKNNTexture(\\n neighbor,int(random1*NUM_NEIGHBORS_FLOAT));\\n //if it is not a valid pick a random point\\n if(neighbor2ndDegree < 0) {\\n return int(random(float(seed))*num_points);\\n }\\n return neighbor2ndDegree;\\n }\\n\\n void main() {\\n //Getting the id of the point and the line id (0/1)\\n point_id = int((vertex_id/2.0)+0.1);\\n int line_id = int(mod(vertex_id+0.1,2.));\\n if(float(point_id) >= num_points) {\\n return;\\n }\\n \" + vertexPositionSource + \"\\n\\n //////////////////////////////////\\n //KNN computation\\n initializeDistances(point_id);\\n for(int i = 0; i < NEIGH_PER_ITER; i += 4) {\\n //BAD SEED\\n //uint seed\\n //= uint(float(point_id) + float(NEIGH_PER_ITER)*iteration + float(i));\\n //GOOD SEED\\n uint seed\\n = uint(float(point_id) + float(num_points)*iteration + float(i));\\n int j0 = neighborOfANeighbor(point_id,seed);\\n int j1 = neighborOfANeighbor(point_id,seed+1U);\\n int j2 = neighborOfANeighbor(point_id,seed+2U);\\n int j3 = neighborOfANeighbor(point_id,seed+3U);\\n\\n vec4 dist_squared = pointDistanceSquaredBatch(point_id,j0,j1,j2,j3);\\n if(j0!=point_id)insertInKNN(dist_squared.r, j0);\\n if(j1!=point_id)insertInKNN(dist_squared.g, j1);\\n if(j2!=point_id)insertInKNN(dist_squared.b, j2);\\n if(j3!=point_id)insertInKNN(dist_squared.a, j3);\\n }\\n\\n for(int n = 0; n < NUM_PACKED_NEIGHBORS; n++) {\\n knn[n].r = float(knn_heap[n*4]);\\n knn[n].g = float(knn_heap[n*4+1]);\\n knn[n].b = float(knn_heap[n*4+2]);\\n knn[n].a = float(knn_heap[n*4+3]);\\n }\\n neighbor_id = NUM_NEIGHBORS_FLOAT;\\n }\\n \");\n var knnFragmentShaderSource = generateFragmentShaderSource(distanceComputationSource, numNeighbors);\n return gl_util.createVertexProgram(gpgpu.gl, vertexShaderSource, knnFragmentShaderSource);\n}\nexports.createKNNDescentProgram = createKNNDescentProgram;\nfunction executeKNNProgram(gpgpu, program, dataTex, startingKNNTex, iteration, knnShape, vertexIdBuffer, targetTex) {\n var gl = gpgpu.gl;\n var oldProgram = gpgpu.program;\n var oldLineWidth = gl.getParameter(gl.LINE_WIDTH);\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, knnShape.numRows, knnShape.pointsPerRow * knnShape.pixelsPerPoint);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n if (oldLineWidth !== 1) {\n gl.lineWidth(1);\n }\n gpgpu.setProgram(program);\n gl.clearColor(0., 0., 0., 0.);\n gl.clear(gl.COLOR_BUFFER_BIT);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, vertexIdBuffer); });\n tfc.webgl.webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'vertex_id', vertexIdBuffer, 1, 0, 0);\n var dataTexLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'data_tex');\n gpgpu.setInputMatrixTexture(dataTex, dataTexLoc, 0);\n var startingKNNTexLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'starting_knn_tex');\n gpgpu.setInputMatrixTexture(startingKNNTex, startingKNNTexLoc, 1);\n var iterationLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'iteration');\n gl.uniform1f(iterationLoc, iteration);\n var numPointsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_points');\n gl.uniform1f(numPointsLoc, knnShape.numPoints);\n var pntsPerRowKNNLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'points_per_row_knn');\n gl.uniform1f(pntsPerRowKNNLoc, knnShape.pointsPerRow);\n var numRowsKNNLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows_knn');\n gl.uniform1f(numRowsKNNLoc, knnShape.numRows);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.drawArrays(gl.LINES, 0, knnShape.numPoints * 2); });\n if (oldProgram != null) {\n gpgpu.setProgram(oldProgram);\n tfc.webgl.gpgpu_util.bindVertexProgramAttributeStreams(gpgpu.gl, oldProgram, gpgpu.vertexBuffer);\n }\n if (oldLineWidth !== 1) {\n gl.lineWidth(oldLineWidth);\n }\n}\nexports.executeKNNProgram = executeKNNProgram;\nfunction createCopyDistancesProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n uniform sampler2D knn_tex;\\n uniform float width;\\n uniform float height;\\n\\n void main() {\\n vec2 coordinates = gl_FragCoord.xy / vec2(width,height);\\n float distance = texture2D(knn_tex,coordinates).g;\\n gl_FragColor = vec4(distance,0,0,1);\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createCopyDistancesProgram = createCopyDistancesProgram;\nfunction executeCopyDistancesProgram(gpgpu, program, knnTex, knnShape, targetTex) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, knnShape.numRows, knnShape.pointsPerRow * knnShape.pixelsPerPoint);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var knnLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'knn_tex');\n gpgpu.setInputMatrixTexture(knnTex, knnLoc, 0);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'width');\n gl.uniform1f(pntsPerRowLoc, knnShape.pointsPerRow * knnShape.pixelsPerPoint);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'height');\n gl.uniform1f(numRowsLoc, knnShape.numRows);\n gpgpu.executeProgram();\n}\nexports.executeCopyDistancesProgram = executeCopyDistancesProgram;\nfunction createCopyIndicesProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n uniform sampler2D knn_tex;\\n uniform float width;\\n uniform float height;\\n\\n void main() {\\n vec2 coordinates = gl_FragCoord.xy / vec2(width,height);\\n float id = texture2D(knn_tex,coordinates).r;\\n gl_FragColor = vec4(id,0,0,1);\\n\\n if(id < 0.) {\\n gl_FragColor.b = 1.;\\n }\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createCopyIndicesProgram = createCopyIndicesProgram;\nfunction executeCopyIndicesProgram(gpgpu, program, knnTex, knnShape, targetTex) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, knnShape.numRows, knnShape.pointsPerRow * knnShape.pixelsPerPoint);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var knnLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'knn_tex');\n gpgpu.setInputMatrixTexture(knnTex, knnLoc, 0);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'width');\n gl.uniform1f(pntsPerRowLoc, knnShape.pointsPerRow * knnShape.pixelsPerPoint);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'height');\n gl.uniform1f(numRowsLoc, knnShape.numRows);\n gpgpu.executeProgram();\n}\nexports.executeCopyIndicesProgram = executeCopyIndicesProgram;\n//# sourceMappingURL=knn_util.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tfc = require(\"@tensorflow/tfjs-core\");\nvar dataset_util = require(\"./dataset_util\");\nvar gl_util = require(\"./gl_util\");\nvar knn_util = require(\"./knn_util\");\nfunction instanceOfRearrangedData(object) {\n return 'numPoints' in object && 'pointsPerRow' in object &&\n 'pixelsPerPoint' in object && 'numRows' in object;\n}\nfunction instanceOfCustomDataDefinition(object) {\n return 'distanceComputationCode' in object;\n}\nvar KNNEstimator = (function () {\n function KNNEstimator(dataTexture, dataFormat, numPoints, numDimensions, numNeighs, verbose) {\n if (verbose != null) {\n this.verbose = verbose;\n }\n else {\n verbose = false;\n }\n this.backend = tfc.ENV.findBackend('webgl');\n this.gpgpu = this.backend.getGPGPUContext();\n this.iteration = 0;\n this.dataTexture = dataTexture;\n if (numNeighs > 128) {\n throw new Error('kNN size must not be greater than 128');\n }\n if (numNeighs % 4 !== 0) {\n throw new Error('kNN size must be a multiple of 4');\n }\n this.numNeighs = numNeighs;\n var knnPointsPerRow = Math.ceil(Math.sqrt(numNeighs * numPoints) / numNeighs);\n this.knnDataShape = {\n numPoints: numPoints,\n pixelsPerPoint: numNeighs,\n pointsPerRow: knnPointsPerRow,\n numRows: Math.ceil(numPoints / knnPointsPerRow)\n };\n this.log('knn-pntsPerRow', this.knnDataShape.pointsPerRow);\n this.log('knn-numRows', this.knnDataShape.numRows);\n this.log('knn-pixelsPerPoint', this.knnDataShape.pixelsPerPoint);\n var distanceComputationSource;\n if (instanceOfRearrangedData(dataFormat)) {\n var rearrangedData = dataFormat;\n distanceComputationSource =\n dataset_util.generateDistanceComputationSource(rearrangedData);\n }\n else if (instanceOfCustomDataDefinition(dataFormat)) {\n var customDataDefinition = dataFormat;\n distanceComputationSource = customDataDefinition.distanceComputationCode;\n }\n this.initializeTextures();\n this.initilizeCustomWebGLPrograms(distanceComputationSource);\n }\n Object.defineProperty(KNNEstimator.prototype, \"knnShape\", {\n get: function () {\n return this.knnDataShape;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(KNNEstimator.prototype, \"numOfIterations\", {\n get: function () {\n return this.iteration;\n },\n enumerable: true,\n configurable: true\n });\n KNNEstimator.prototype.log = function (str, obj) {\n if (this.verbose) {\n if (obj != null) {\n console.log(str + \": \\t\" + obj);\n }\n else {\n console.log(str);\n }\n }\n };\n KNNEstimator.prototype.initializeTextures = function () {\n var initNeigh = new Float32Array(this.knnDataShape.pointsPerRow * this.knnDataShape.pixelsPerPoint * 2 *\n this.knnDataShape.numRows);\n var numNeighs = this.knnDataShape.pixelsPerPoint;\n for (var i = 0; i < this.knnDataShape.numPoints; ++i) {\n for (var n = 0; n < numNeighs; ++n) {\n initNeigh[(i * numNeighs + n) * 2] = -1;\n initNeigh[(i * numNeighs + n) * 2 + 1] = 10e30;\n }\n }\n this.knnTexture0 = gl_util.createAndConfigureTexture(this.gpgpu.gl, this.knnDataShape.pointsPerRow * this.knnDataShape.pixelsPerPoint, this.knnDataShape.numRows, 2, initNeigh);\n this.knnTexture1 = gl_util.createAndConfigureTexture(this.gpgpu.gl, this.knnDataShape.pointsPerRow * this.knnDataShape.pixelsPerPoint, this.knnDataShape.numRows, 2, initNeigh);\n };\n KNNEstimator.prototype.initilizeCustomWebGLPrograms = function (distanceComputationSource) {\n this.copyDistancesProgram = knn_util.createCopyDistancesProgram(this.gpgpu);\n this.copyIndicesProgram = knn_util.createCopyIndicesProgram(this.gpgpu);\n this.bruteForceKNNProgram = knn_util.createBruteForceKNNProgram(this.gpgpu, this.numNeighs, distanceComputationSource);\n this.randomSamplingKNNProgram = knn_util.createRandomSamplingKNNProgram(this.gpgpu, this.numNeighs, distanceComputationSource);\n this.kNNDescentProgram = knn_util.createKNNDescentProgram(this.gpgpu, this.numNeighs, distanceComputationSource);\n var linesVertexId = new Float32Array(this.knnDataShape.numPoints * 2);\n {\n for (var i = 0; i < this.knnDataShape.numPoints * 2; ++i) {\n linesVertexId[i] = i;\n }\n }\n this.linesVertexIdBuffer = tfc.webgl.webgl_util.createStaticVertexBuffer(this.gpgpu.gl, linesVertexId);\n };\n KNNEstimator.prototype.iterateBruteForce = function () {\n if ((this.iteration % 2) === 0) {\n this.iterateGPU(this.dataTexture, this.iteration, this.knnTexture0, this.knnTexture1);\n }\n else {\n this.iterateGPU(this.dataTexture, this.iteration, this.knnTexture1, this.knnTexture0);\n }\n ++this.iteration;\n this.gpgpu.gl.finish();\n };\n KNNEstimator.prototype.iterateRandomSampling = function () {\n if ((this.iteration % 2) === 0) {\n this.iterateRandomSamplingGPU(this.dataTexture, this.iteration, this.knnTexture0, this.knnTexture1);\n }\n else {\n this.iterateRandomSamplingGPU(this.dataTexture, this.iteration, this.knnTexture1, this.knnTexture0);\n }\n ++this.iteration;\n this.gpgpu.gl.finish();\n };\n KNNEstimator.prototype.iterateKNNDescent = function () {\n if ((this.iteration % 2) === 0) {\n this.iterateKNNDescentGPU(this.dataTexture, this.iteration, this.knnTexture0, this.knnTexture1);\n }\n else {\n this.iterateKNNDescentGPU(this.dataTexture, this.iteration, this.knnTexture1, this.knnTexture0);\n }\n ++this.iteration;\n this.gpgpu.gl.finish();\n };\n KNNEstimator.prototype.knn = function () {\n if ((this.iteration % 2) === 0) {\n return this.knnTexture0;\n }\n else {\n return this.knnTexture1;\n }\n };\n KNNEstimator.prototype.distancesTensor = function () {\n var _this = this;\n return tfc.tidy(function () {\n var distances = tfc.zeros([\n _this.knnDataShape.numRows,\n _this.knnDataShape.pointsPerRow * _this.knnDataShape.pixelsPerPoint\n ]);\n var knnTexture = _this.knn();\n knn_util.executeCopyDistancesProgram(_this.gpgpu, _this.copyDistancesProgram, knnTexture, _this.knnDataShape, _this.backend.getTexture(distances.dataId));\n return distances;\n });\n };\n KNNEstimator.prototype.indicesTensor = function () {\n var _this = this;\n return tfc.tidy(function () {\n var indices = tfc.zeros([\n _this.knnDataShape.numRows,\n _this.knnDataShape.pointsPerRow * _this.knnDataShape.pixelsPerPoint\n ]);\n var knnTexture = _this.knn();\n knn_util.executeCopyIndicesProgram(_this.gpgpu, _this.copyIndicesProgram, knnTexture, _this.knnDataShape, _this.backend.getTexture(indices.dataId));\n return indices;\n });\n };\n KNNEstimator.prototype.iterateGPU = function (dataTexture, iteration, startingKNNTexture, targetTexture) {\n knn_util.executeKNNProgram(this.gpgpu, this.bruteForceKNNProgram, dataTexture, startingKNNTexture, iteration, this.knnDataShape, this.linesVertexIdBuffer, targetTexture);\n };\n KNNEstimator.prototype.iterateRandomSamplingGPU = function (dataTexture, iteration, startingKNNTexture, targetTexture) {\n knn_util.executeKNNProgram(this.gpgpu, this.randomSamplingKNNProgram, dataTexture, startingKNNTexture, iteration, this.knnDataShape, this.linesVertexIdBuffer, targetTexture);\n };\n KNNEstimator.prototype.iterateKNNDescentGPU = function (dataTexture, iteration, startingKNNTexture, targetTexture) {\n knn_util.executeKNNProgram(this.gpgpu, this.kNNDescentProgram, dataTexture, startingKNNTexture, iteration, this.knnDataShape, this.linesVertexIdBuffer, targetTexture);\n };\n return KNNEstimator;\n}());\nexports.KNNEstimator = KNNEstimator;\n//# sourceMappingURL=knn.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tfc = require(\"@tensorflow/tfjs-core\");\nvar gl_util = require(\"./gl_util\");\nfunction createEmbeddingSplatterProgram(gpgpu) {\n var vertexShaderSource = \"#version 300 es\\n precision highp float;\\n in float vertex_id;\\n\\n uniform sampler2D embedding_tex;\\n uniform vec2 minV;\\n uniform vec2 maxV;\\n uniform float kernel_support;\\n uniform float points_per_row;\\n uniform float num_rows;\\n\\n out vec2 kernel_coords;\\n\\n void main() {\\n //TODO Clean up and check performance loss due to the conversions\\n uint pnt_id = uint((vertex_id / 4.0) + 0.1);\\n uint quad_id = uint(mod(vertex_id + 0.1,4.));\\n\\n uint row = uint((float(pnt_id) + 0.1)/points_per_row);\\n uint column = uint(float(pnt_id) - float(row) * points_per_row);\\n\\n float width = (points_per_row * 2.0);\\n float row_tex = (float(row) + 0.5) / num_rows;\\n vec2 tex_coords_x = vec2((float(column) * 2. + 0.5) / width, row_tex);\\n vec2 tex_coords_y = vec2((float(column) * 2. + 1.5) / width, row_tex);\\n\\n float x_pnt = texture(embedding_tex,tex_coords_x).r;\\n float y_pnt = texture(embedding_tex,tex_coords_y).r;\\n vec2 vertex_coords = vec2(x_pnt,y_pnt);\\n\\n if(quad_id == uint(0)) {kernel_coords = vec2(-1,-1);}\\n else if(quad_id == uint(1)) {kernel_coords = vec2(1,-1);}\\n else if(quad_id == uint(2)) {kernel_coords = vec2(1,1);}\\n else if(quad_id == uint(3)) {kernel_coords = vec2(-1,1);}\\n\\n vertex_coords += kernel_coords * kernel_support; // embedding space\\n vertex_coords = (vertex_coords - minV) / (maxV-minV); // 0:1 space\\n vertex_coords = vertex_coords * 2.0 - 1.0; // -1:1 space\\n\\n gl_Position = vec4(vertex_coords,0,1);\\n }\\n \";\n var fragmentShaderSource = \"#version 300 es\\n precision highp float;\\n uniform sampler2D kernel_tex;\\n in vec2 kernel_coords;\\n out vec4 fragmentColor;\\n\\n void main() {\\n fragmentColor = texture(kernel_tex,(kernel_coords + 1.) / 2.0);\\n }\\n \";\n return gl_util.createVertexProgram(gpgpu.gl, vertexShaderSource, fragmentShaderSource);\n}\nexports.createEmbeddingSplatterProgram = createEmbeddingSplatterProgram;\nfunction executeEmbeddingSplatterProgram(gpgpu, program, targetTex, embeddingTex, kernelTex, targetTexDiameter, numPoints, minX, minY, maxX, maxY, kernelSupport, pntsPerRow, numRows, vertexIdBuffer) {\n var gl = gpgpu.gl;\n var oldProgram = gpgpu.program;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, targetTexDiameter, targetTexDiameter);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n gl.clearColor(0., 0., 0., 0.);\n gl.clear(gl.COLOR_BUFFER_BIT);\n gl.enable(gl.BLEND);\n gl.blendFunc(gl.ONE, gl.ONE);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.bindBuffer(gl.ARRAY_BUFFER, vertexIdBuffer); });\n tfc.webgl.webgl_util.bindVertexBufferToProgramAttribute(gl, program, 'vertex_id', vertexIdBuffer, 1, 0, 0);\n var embeddingLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'embedding_tex');\n gpgpu.setInputMatrixTexture(embeddingTex, embeddingLocation, 0);\n var kernelLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'kernel_tex');\n gpgpu.setInputMatrixTexture(kernelTex, kernelLocation, 1);\n var kernelSupportLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'kernel_support');\n gl.uniform1f(kernelSupportLoc, kernelSupport);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'points_per_row');\n gl.uniform1f(pntsPerRowLoc, pntsPerRow);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows');\n gl.uniform1f(numRowsLoc, numRows);\n var minLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'minV');\n gl.uniform2f(minLoc, minX, minY);\n var maxLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'maxV');\n gl.uniform2f(maxLoc, maxX, maxY);\n tfc.webgl.webgl_util.callAndCheck(gl, function () { return gl.drawArrays(gl.TRIANGLES, 0, numPoints * 2 * 3); });\n gl.disable(gl.BLEND);\n if (oldProgram != null) {\n gpgpu.setProgram(oldProgram);\n tfc.webgl.gpgpu_util.bindVertexProgramAttributeStreams(gpgpu.gl, oldProgram, gpgpu.vertexBuffer);\n }\n}\nexports.executeEmbeddingSplatterProgram = executeEmbeddingSplatterProgram;\nfunction createQInterpolatorProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n uniform sampler2D embedding_tex;\\n uniform sampler2D splat_tex;\\n uniform vec2 minV;\\n uniform vec2 maxV;\\n uniform float points_per_row;\\n uniform float num_rows;\\n uniform float num_points;\\n\\n void main() {\\n vec2 pnt_location = gl_FragCoord.xy - vec2(0.5,0.5);\\n\\n if(pnt_location.y * points_per_row + pnt_location.x >= num_points) {\\n gl_FragColor = vec4(0,0,0,0);\\n return;\\n }\\n\\n float emb_width = (points_per_row * 2.0);\\n float emb_row_coord = (pnt_location.y + 0.5) / num_rows;\\n vec2 emb_coords_x\\n = vec2((pnt_location.x * 2.+0.5) / emb_width, emb_row_coord);\\n vec2 emb_coords_y\\n = vec2((pnt_location.x * 2. + 1.5) / emb_width, emb_row_coord);\\n\\n float x_pnt = texture2D(embedding_tex,emb_coords_x).r;\\n float y_pnt = texture2D(embedding_tex,emb_coords_y).r;\\n\\n vec2 splat_coords = vec2(x_pnt,y_pnt);\\n splat_coords = (splat_coords - minV) / (maxV - minV); // 0:1 space\\n\\n float q = (texture2D(splat_tex,splat_coords).r - 1.);\\n\\n gl_FragColor = vec4(q, 0, 0, 1);\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createQInterpolatorProgram = createQInterpolatorProgram;\nfunction executeQInterpolatorProgram(gpgpu, program, splatTex, embeddingTex, numPoints, minX, minY, maxX, maxY, pntsPerRow, numRows, targetTex) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, numRows, pntsPerRow);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var embeddingLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'embedding_tex');\n gpgpu.setInputMatrixTexture(embeddingTex, embeddingLocation, 0);\n var splatLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'splat_tex');\n gpgpu.setInputMatrixTexture(splatTex, splatLocation, 1);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'points_per_row');\n gl.uniform1f(pntsPerRowLoc, pntsPerRow);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows');\n gl.uniform1f(numRowsLoc, numRows);\n var numPointsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_points');\n gl.uniform1f(numPointsLoc, numPoints);\n var minLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'minV');\n gl.uniform2f(minLoc, minX, minY);\n var maxLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'maxV');\n gl.uniform2f(maxLoc, maxX, maxY);\n gpgpu.executeProgram();\n}\nexports.executeQInterpolatorProgram = executeQInterpolatorProgram;\nfunction createXYInterpolatorProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n uniform sampler2D embedding_tex;\\n uniform sampler2D splat_tex;\\n uniform vec2 minV;\\n uniform vec2 maxV;\\n uniform float points_per_row;\\n uniform float num_rows;\\n uniform float num_points;\\n uniform float eta;\\n\\n void main() {\\n vec2 pnt_location = gl_FragCoord.xy - vec2(0.5,0.5);\\n pnt_location.x = floor(pnt_location.x/2.+0.1);\\n\\n if(pnt_location.y*points_per_row + pnt_location.x >= num_points) {\\n gl_FragColor = vec4(0,0,0,0);\\n return;\\n }\\n\\n float emb_width = (points_per_row * 2.0);\\n float emb_row_coord = (pnt_location.y + 0.5) / num_rows;\\n vec2 emb_coords_x\\n = vec2((pnt_location.x * 2. + 0.5) / emb_width, emb_row_coord);\\n vec2 emb_coords_y\\n = vec2((pnt_location.x * 2. + 1.5) / emb_width, emb_row_coord);\\n\\n float x_pnt = texture2D(embedding_tex,emb_coords_x).r;\\n float y_pnt = texture2D(embedding_tex,emb_coords_y).r;\\n\\n vec2 splat_coords = vec2(x_pnt,y_pnt);\\n splat_coords = (splat_coords - minV) / (maxV - minV); // 0:1 space\\n\\n float q = 0.;\\n if(mod(gl_FragCoord.x - 0.5,2.) < 0.5 ) {\\n q = texture2D(splat_tex,splat_coords).g * eta * 2.;\\n }else{\\n q = texture2D(splat_tex,splat_coords).b * eta * 2.;\\n }\\n\\n gl_FragColor = vec4(q,0.0,0.0,1);\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createXYInterpolatorProgram = createXYInterpolatorProgram;\nfunction executeXYInterpolatorProgram(gpgpu, program, splatTex, embeddingTex, targetTex, numPoints, minX, minY, maxX, maxY, pntsPerRow, numRows, eta) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, numRows, pntsPerRow * 2);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var embeddingLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'embedding_tex');\n gpgpu.setInputMatrixTexture(embeddingTex, embeddingLocation, 0);\n var splatLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'splat_tex');\n gpgpu.setInputMatrixTexture(splatTex, splatLocation, 1);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'points_per_row');\n gl.uniform1f(pntsPerRowLoc, pntsPerRow);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows');\n gl.uniform1f(numRowsLoc, numRows);\n var numPointsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_points');\n gl.uniform1f(numPointsLoc, numPoints);\n var etaLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'eta');\n gl.uniform1f(etaLoc, eta);\n var minLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'minV');\n gl.uniform2f(minLoc, minX, minY);\n var maxLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'maxV');\n gl.uniform2f(maxLoc, maxX, maxY);\n gpgpu.executeProgram();\n}\nexports.executeXYInterpolatorProgram = executeXYInterpolatorProgram;\nfunction createAttractiveForcesComputationProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n\\n uniform sampler2D embedding_tex;\\n uniform sampler2D offset_tex;\\n uniform sampler2D neigh_id_tex;\\n uniform sampler2D neigh_prob_tex;\\n\\n uniform float points_per_row;\\n uniform float num_rows;\\n uniform float num_points;\\n uniform float num_neighs_per_row;\\n uniform float eta;\\n\\n void main() {\\n //add for nearest pixel interpolation\\n vec2 half_pxl = vec2(0.5,0.5);\\n\\n // Dimension of the fragment\\n // 0 -> x :1 -> y\\n float dimension = mod(gl_FragCoord.x - 0.4,2.);\\n\\n //Point location in the [points_per_row,num_rows] space\\n vec2 i_location = gl_FragCoord.xy - half_pxl;\\n i_location.x = floor(i_location.x / 2. + 0.1);\\n\\n //just an extra fragment -> return\\n if(i_location.y*points_per_row + i_location.x >= num_points) {\\n gl_FragColor = vec4(0,0,0,0);\\n return;\\n }\\n\\n //Offset coordinates for the point\\n vec2 offset_coord = (i_location + half_pxl) /\\n vec2(points_per_row,num_rows);\\n //Offset information ...\\n vec4 offset_info = texture2D(offset_tex,offset_coord);\\n //... contains the number of neighbors for the point ...\\n float num_neighs = offset_info.z;\\n //... and the coordinates of the firts neigh in the neigh textures\\n vec2 offset_neigh = offset_info.xy;\\n\\n //Computing the coordinates of the point in the texture\\n //_i represent the point to move, _j the neighbors\\n float emb_width = (points_per_row * 2.0);\\n float emb_row_i = (i_location.y + 0.5) / num_rows;\\n vec2 x_i_coord = vec2((i_location.x * 2. + 0.5) / emb_width, emb_row_i);\\n vec2 y_i_coord = vec2((i_location.x * 2. + 1.5) / emb_width, emb_row_i);\\n //getting the coordinates in the embedding\\n float x_i = texture2D(embedding_tex,x_i_coord).r;\\n float y_i = texture2D(embedding_tex,y_i_coord).r;\\n\\n //Sum of all attractive forces\\n float sum_pos = 0.;\\n\\n //Can't be higher than 1000 (perplexity is usually around 30)\\n //and a 'while' can't be used\\n for(int n = 0; n < 2000; ++n) {\\n //Actual check on number of neighbors\\n if(float(n) >= num_neighs) {\\n break;\\n }\\n\\n //Get the id and the probability for the neighbor\\n float pij = texture2D(neigh_prob_tex,\\n (offset_neigh + half_pxl) / num_neighs_per_row\\n ).r;\\n float neigh_id = texture2D(neigh_id_tex,\\n (offset_neigh + half_pxl) / num_neighs_per_row\\n ).r;\\n\\n //Getting the coordinates of the neighbor\\n vec2 j_location = vec2(mod(neigh_id + 0.1, points_per_row),\\n floor(neigh_id / points_per_row + 0.1));\\n float emb_row_j = (j_location.y + 0.5) / num_rows;\\n vec2 x_j_coord = vec2((j_location.x * 2. + 0.5) / emb_width, emb_row_j);\\n vec2 y_j_coord = vec2((j_location.x * 2. + 1.5) / emb_width, emb_row_j);\\n float x_j = texture2D(embedding_tex,x_j_coord).r;\\n float y_j = texture2D(embedding_tex,y_j_coord).r;\\n\\n //Actual computation of the attractive forces\\n float dist_x = (x_i - x_j);\\n float dist_y = (y_i - y_j);\\n float qij = 1. / (1. + dist_x * dist_x + dist_y * dist_y);\\n //the update depends on the dimension that this fragment represents\\n if(dimension < 0.5) {\\n // * 4 / (num_points*2) -> * 2 / num_points\\n sum_pos += eta * 2. * pij * qij * dist_x / (num_points);\\n }else{\\n sum_pos += eta * 2. * pij * qij * dist_y / (num_points);\\n }\\n\\n //Increase the coordinate of the neigh in the neigh_id texture\\n offset_neigh.x += 1.;\\n //check if the new neigh is in the next row\\n if(offset_neigh.x + 0.2 > num_neighs_per_row) {\\n //in that case reset the column and increase the row\\n offset_neigh.x = 0.1;\\n offset_neigh.y += 1.0;\\n }\\n }\\n\\n //The output is the sum of the attractive forces\\n gl_FragColor = vec4(sum_pos,0,0,0);\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createAttractiveForcesComputationProgram = createAttractiveForcesComputationProgram;\nfunction executeAttractiveForcesComputationProgram(gpgpu, program, embeddingTex, offsetTex, neighIdTex, neighProbTex, numPoints, neighsPerRow, pntsPerRow, numRows, eta, targetTex) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, numRows, pntsPerRow * 2);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var embeddingLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'embedding_tex');\n gpgpu.setInputMatrixTexture(embeddingTex, embeddingLocation, 3);\n var offsetLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'offset_tex');\n gpgpu.setInputMatrixTexture(offsetTex, offsetLocation, 2);\n var neighIdLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'neigh_id_tex');\n gpgpu.setInputMatrixTexture(neighIdTex, neighIdLocation, 1);\n var neighProbLocation = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'neigh_prob_tex');\n gpgpu.setInputMatrixTexture(neighProbTex, neighProbLocation, 0);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows');\n gl.uniform1f(numRowsLoc, numRows);\n var etaLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'eta');\n gl.uniform1f(etaLoc, eta);\n var neighsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_neighs_per_row');\n gl.uniform1f(neighsPerRowLoc, neighsPerRow);\n var numPointsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_points');\n gl.uniform1f(numPointsLoc, numPoints);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'points_per_row');\n gl.uniform1f(pntsPerRowLoc, pntsPerRow);\n gpgpu.executeProgram();\n}\nexports.executeAttractiveForcesComputationProgram = executeAttractiveForcesComputationProgram;\nfunction createEmbeddingInitializationProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n\\n uniform sampler2D random_tex;\\n uniform float points_per_row;\\n uniform float num_rows;\\n uniform float num_points;\\n\\n void main() {\\n //add for nearest pixel interpolation\\n vec2 half_pxl = vec2(0.5,0.5);\\n\\n // Dimension of the fragment\\n // 0 -> x :1 -> y\\n float dimension = mod(gl_FragCoord.x - 0.4,2.);\\n vec2 pnt_location = gl_FragCoord.xy - half_pxl;\\n pnt_location.x = floor(pnt_location.x / 2.);\\n\\n //just an extra fragment -> return\\n if(pnt_location.y*points_per_row + pnt_location.x >= num_points) {\\n gl_FragColor = vec4(0,0,0,1);\\n return;\\n }\\n\\n float width = (points_per_row * 2.0);\\n float row_coord = (pnt_location.y + 0.5)/num_rows;\\n vec2 rad_coord = vec2((pnt_location.x * 2. + 0.5) / width, row_coord);\\n vec2 ang_coord = vec2((pnt_location.x * 2. + 1.5) / width, row_coord);\\n\\n float rad = texture2D(random_tex,rad_coord).r * 3.;\\n float ang = texture2D(random_tex,ang_coord).r * 3.1415 * 2.;\\n\\n gl_FragColor = vec4(rad,ang,0,1);\\n\\n if(dimension < 0.5) {\\n gl_FragColor = vec4(cos(ang) * rad,0,0,0);\\n }else{\\n gl_FragColor = vec4(sin(ang) * rad,0,0,0);\\n }\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createEmbeddingInitializationProgram = createEmbeddingInitializationProgram;\nfunction executeEmbeddingInitializationProgram(gpgpu, program, randomTex, numPoints, pntsPerRow, numRows, targetTex) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, numRows, pntsPerRow * 2);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var randomLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'random_tex');\n gpgpu.setInputMatrixTexture(randomTex, randomLoc, 3);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows');\n gl.uniform1f(numRowsLoc, numRows);\n var numPointsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_points');\n gl.uniform1f(numPointsLoc, numPoints);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'points_per_row');\n gl.uniform1f(pntsPerRowLoc, pntsPerRow);\n gpgpu.executeProgram();\n}\nexports.executeEmbeddingInitializationProgram = executeEmbeddingInitializationProgram;\nfunction createDistributionParametersComputationProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n\\n #define MAX_NEIGHBORS 128\\n #define MAX_ITERATIONS 500\\n #define FLOAT_MAX 10e30\\n #define TOLERANCE 1e-5\\n\\n uniform sampler2D knn_graph_tex;\\n uniform float points_per_row;\\n uniform float num_rows;\\n uniform float num_points;\\n uniform float num_neighs;\\n uniform float perplexity;\\n\\n vec2 half_pixel = vec2(0.5,0.5);\\n float distances_squared[MAX_NEIGHBORS];\\n\\n void readDistances(vec2 point_location) {\\n for(int n = 0; n < MAX_NEIGHBORS; ++n ) {\\n if(float(n) >= num_neighs-0.1) {\\n break;\\n }\\n vec2 knn_coordinates = vec2(\\n (point_location.x * num_neighs + float(n) + half_pixel.x)\\n /(points_per_row * num_neighs),\\n (point_location.y + half_pixel.y) / num_rows\\n );\\n distances_squared[n] = texture2D(knn_graph_tex,knn_coordinates).g;\\n }\\n }\\n\\n void main() {\\n vec2 point_location = gl_FragCoord.xy - half_pixel;\\n //invalid points\\n if(point_location.y*points_per_row + point_location.x >= num_points) {\\n gl_FragColor = vec4(0,0,0,0);\\n return;\\n }\\n readDistances(point_location);\\n\\n //Beta computation\\n float beta = 1.;\\n float max_beta = FLOAT_MAX;\\n float min_beta = -FLOAT_MAX;\\n //To avoid computing the log at every iteration\\n float log_perplexity = log(perplexity);\\n float entropy_diff = 0.;\\n float entropy = 0.;\\n float sum_probabilities = 0.;\\n\\n //Binary search for a maximum of MAX_ITERATIONS\\n for(int iteration = 0; iteration < MAX_ITERATIONS; ++iteration) {\\n //At every iteration I compute the\\n //entropy enforced by the current beta\\n sum_probabilities = 0.;\\n entropy = 0.;\\n for(int n = 0; n < MAX_NEIGHBORS; ++n ) {\\n if(float(n) >= num_neighs-0.1) {\\n break;\\n }\\n float neigh_probability = exp(-beta * distances_squared[n]);\\n sum_probabilities += neigh_probability;\\n entropy += beta * distances_squared[n] * neigh_probability;\\n }\\n\\n entropy = entropy / sum_probabilities + log(sum_probabilities);\\n entropy_diff = entropy - log_perplexity;\\n\\n //the current beta is good enough!\\n if(entropy_diff < TOLERANCE && -entropy_diff < TOLERANCE) {\\n break;\\n }\\n\\n if(entropy_diff > 0.) {\\n min_beta = beta;\\n if(max_beta == FLOAT_MAX || max_beta == -FLOAT_MAX) {\\n beta *= 2.;\\n }else{\\n beta = (beta + max_beta) / 2.;\\n }\\n }else{\\n max_beta = beta;\\n if(min_beta == -FLOAT_MAX || min_beta == FLOAT_MAX) {\\n beta /= 2.;\\n }else{\\n beta = (beta + min_beta) / 2.;\\n }\\n }\\n }\\n gl_FragColor = vec4(beta,sum_probabilities,0,1);\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createDistributionParametersComputationProgram = createDistributionParametersComputationProgram;\nfunction executeDistributionParametersComputationProgram(gpgpu, program, knnGraph, numPoints, numNeighs, pntsPerRow, numRows, perplexity, targetTex) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, numRows, pntsPerRow);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var knnGraphLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'knn_graph_tex');\n gpgpu.setInputMatrixTexture(knnGraph, knnGraphLoc, 0);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows');\n gl.uniform1f(numRowsLoc, numRows);\n var numPointsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_points');\n gl.uniform1f(numPointsLoc, numPoints);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'points_per_row');\n gl.uniform1f(pntsPerRowLoc, pntsPerRow);\n var numNeighsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_neighs');\n gl.uniform1f(numNeighsLoc, numNeighs);\n var perplexityLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'perplexity');\n gl.uniform1f(perplexityLoc, perplexity);\n gpgpu.executeProgram();\n}\nexports.executeDistributionParametersComputationProgram = executeDistributionParametersComputationProgram;\nfunction createGaussiaDistributionsFromDistancesProgram(gpgpu) {\n var fragmentShaderSource = \"\\n precision highp float;\\n uniform sampler2D knn_graph_tex;\\n uniform sampler2D parameters_tex;\\n uniform float points_per_row;\\n uniform float num_rows;\\n uniform float num_points;\\n uniform float num_neighs;\\n\\n vec2 half_pixel = vec2(0.5,0.5);\\n\\n void main() {\\n vec2 point_location = gl_FragCoord.xy - half_pixel;\\n point_location.x = floor(point_location.x / num_neighs);\\n\\n //invalid points\\n if(point_location.y*points_per_row + point_location.x >= num_points) {\\n gl_FragColor = vec4(0,0,0,0);\\n return;\\n }\\n float distance_squared\\n = texture2D(knn_graph_tex,\\n gl_FragCoord.xy /\\n vec2(points_per_row*num_neighs,num_rows)\\n ).g;\\n vec2 parameters\\n = texture2D(parameters_tex,\\n (point_location.xy + half_pixel)/\\n vec2(points_per_row,num_rows)\\n ).rg;\\n float beta = parameters.r;\\n float normalization = parameters.g;\\n\\n float probability = exp(-beta * distance_squared) / normalization;\\n //check for NaN for degenerated knn (d = 0 for every point)\\n if (!(probability < 0.0 || 0.0 < probability || probability == 0.0)) {\\n probability = 0.;\\n }\\n\\n gl_FragColor = vec4(probability,0,0,1);\\n }\\n \";\n return gpgpu.createProgram(fragmentShaderSource);\n}\nexports.createGaussiaDistributionsFromDistancesProgram = createGaussiaDistributionsFromDistancesProgram;\nfunction executeGaussiaDistributionsFromDistancesProgram(gpgpu, program, knnGraph, parameters, numPoints, numNeighs, pntsPerRow, numRows, targetTex) {\n var gl = gpgpu.gl;\n if (targetTex != null) {\n gpgpu.setOutputMatrixTexture(targetTex, numRows, pntsPerRow * numNeighs);\n }\n else {\n tfc.webgl.webgl_util.bindCanvasToFramebuffer(gpgpu.gl);\n }\n gpgpu.setProgram(program);\n var knnGraphLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'knn_graph_tex');\n gpgpu.setInputMatrixTexture(knnGraph, knnGraphLoc, 0);\n var parametersLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'parameters_tex');\n gpgpu.setInputMatrixTexture(parameters, parametersLoc, 1);\n var numRowsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_rows');\n gl.uniform1f(numRowsLoc, numRows);\n var numPointsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_points');\n gl.uniform1f(numPointsLoc, numPoints);\n var pntsPerRowLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'points_per_row');\n gl.uniform1f(pntsPerRowLoc, pntsPerRow);\n var numNeighsLoc = tfc.webgl.webgl_util.getProgramUniformLocationOrThrow(gl, program, 'num_neighs');\n gl.uniform1f(numNeighsLoc, numNeighs);\n gpgpu.executeProgram();\n}\nexports.executeGaussiaDistributionsFromDistancesProgram = executeGaussiaDistributionsFromDistancesProgram;\n//# sourceMappingURL=tsne_optimizer_util.js.map","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tfc = require(\"@tensorflow/tfjs-core\");\nvar gl_util = require(\"./gl_util\");\nvar knn_util = require(\"./knn_util\");\nvar tsne_util = require(\"./tsne_optimizer_util\");\nvar TSNEOptimizer = (function () {\n function TSNEOptimizer(numPoints, verbose, splatTextureDiameter, kernelTextureRadius) {\n if (verbose != null) {\n this.verbose = verbose;\n }\n else {\n verbose = false;\n }\n this.log('Initializing the tSNE gradient descent computation...');\n this.numPoints = numPoints;\n this._iteration = 0;\n var webglVersion = tfc.ENV.get('WEBGL_VERSION');\n if (webglVersion === 1) {\n throw Error('WebGL version 1 is not supported by tfjs-tsne');\n }\n this.backend = tfc.ENV.findBackend('webgl');\n if (this.backend === null) {\n throw Error('WebGL backend is not available');\n }\n this.gpgpu = this.backend.getGPGPUContext();\n tfc.webgl.webgl_util.getExtensionOrThrow(this.gpgpu.gl, 'OES_texture_float_linear');\n this.pointsPerRow = Math.ceil(Math.sqrt(numPoints * 2));\n if (this.pointsPerRow % 2 === 1) {\n ++this.pointsPerRow;\n }\n this.pointsPerRow /= 2;\n this.numRows = Math.ceil(numPoints / this.pointsPerRow);\n this.log('\\t# points per row', this.pointsPerRow);\n this.log('\\t# rows', this.numRows);\n this._eta = 2500;\n this._momentum = tfc.scalar(0.8);\n this.rawExaggeration =\n [{ iteration: 200, value: 4 }, { iteration: 600, value: 1 }];\n this.updateExaggeration();\n if (splatTextureDiameter == null) {\n splatTextureDiameter = 5;\n }\n this.splatTextureDiameter = splatTextureDiameter;\n if (kernelTextureRadius == null) {\n kernelTextureRadius = 50;\n }\n this.kernelTextureDiameter = kernelTextureRadius * 2 + 1;\n this.initializeRepulsiveForceTextures();\n this.log('\\tSplat texture diameter', this.splatTextureDiameter);\n this.log('\\tKernel texture diameter', this.kernelTextureDiameter);\n this.initilizeCustomWebGLPrograms();\n this.initializeEmbedding();\n this.log('\\tEmbedding', this.embedding);\n this.log('\\tGradient', this.gradient);\n }\n Object.defineProperty(TSNEOptimizer.prototype, \"minX\", {\n get: function () {\n return this._minX;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"maxX\", {\n get: function () {\n return this._maxX;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"minY\", {\n get: function () {\n return this._minY;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"maxY\", {\n get: function () {\n return this._maxY;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"iteration\", {\n get: function () {\n return this._iteration;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"numberOfPoints\", {\n get: function () {\n return this.numPoints;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"numberOfPointsPerRow\", {\n get: function () {\n return this.pointsPerRow;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"numberOfRows\", {\n get: function () {\n return this.numRows;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"embeddingCoordinates\", {\n get: function () {\n return this.embedding;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"embedding2D\", {\n get: function () {\n var _this = this;\n var result = tfc.tidy(function () {\n var reshaped = _this.embedding.reshape([_this.numRows * _this.pointsPerRow, 2])\n .slice([0, 0], [_this.numPoints, 2]);\n return reshaped;\n });\n return result;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"embeddingTexture\", {\n get: function () {\n return this.backend.getTexture(this.embedding.dataId);\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"splatTexture\", {\n get: function () {\n return this._splatTexture;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"normalizationQ\", {\n get: function () {\n return this._normQ;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"exaggerationAtCurrentIteration\", {\n get: function () {\n return this._exaggeration.get();\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"exaggeration\", {\n get: function () {\n return this.rawExaggeration;\n },\n set: function (ex) {\n this.rawExaggeration = ex;\n if (typeof ex === 'number') {\n if (ex < 1) {\n throw Error('Exaggeration must be greater then or equal to one');\n }\n }\n else {\n for (var i = 0; i < ex.length; ++i) {\n if (ex[i].value < 1) {\n throw Error('Exaggeration must be greater then or equal to one');\n }\n if (ex[i].iteration < 0) {\n throw Error('Piecewise linear exaggeration function \\\n must have poistive iteration values');\n }\n }\n for (var i = 0; i < ex.length - 1; ++i) {\n if (ex[i].iteration >= ex[i + 1].iteration) {\n throw Error('Piecewise linear exaggeration function \\\n must have increasing iteration values');\n }\n }\n if (ex.length === 1) {\n this.exaggeration = ex[0].value;\n }\n }\n this.updateExaggeration();\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"momentum\", {\n get: function () {\n return this._momentum.get();\n },\n set: function (mom) {\n if (mom < 0 || mom > 1) {\n throw Error('Momentum must be in the [0,1] range');\n }\n this._momentum.dispose();\n this._momentum = tfc.scalar(mom);\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(TSNEOptimizer.prototype, \"eta\", {\n get: function () {\n return this._eta;\n },\n set: function (eta) {\n if (eta <= 0) {\n throw Error('ETA must be greater then zero');\n }\n this._eta = eta;\n },\n enumerable: true,\n configurable: true\n });\n TSNEOptimizer.prototype.dispose = function () {\n this.embedding.dispose();\n this.gradient.dispose();\n this._momentum.dispose();\n this._exaggeration.dispose();\n this.gpgpu.gl.deleteTexture(this._splatTexture);\n this.gpgpu.gl.deleteTexture(this.kernelTexture);\n if (this.kernelTexture != null) {\n this.gpgpu.gl.deleteTexture(this.probOffsetTexture);\n }\n if (this.kernelTexture != null) {\n this.gpgpu.gl.deleteTexture(this.probNeighIdTexture);\n }\n if (this.kernelTexture != null) {\n this.gpgpu.gl.deleteTexture(this.probTexture);\n }\n this.gpgpu.gl.deleteBuffer(this.splatVertexIdBuffer);\n this.gpgpu.gl.deleteProgram(this.embeddingInitializationProgram);\n this.gpgpu.gl.deleteProgram(this.embeddingSplatterProgram);\n this.gpgpu.gl.deleteProgram(this.qInterpolatorProgram);\n this.gpgpu.gl.deleteProgram(this.xyInterpolatorProgram);\n this.gpgpu.gl.deleteProgram(this.attractiveForcesProgram);\n this.gpgpu.gl.deleteProgram(this.distributionParameterssComputationProgram);\n this.gpgpu.gl.deleteProgram(this.gaussiaDistributionsFromDistancesProgram);\n };\n TSNEOptimizer.prototype.initializeEmbedding = function () {\n return __awaiter(this, void 0, void 0, function () {\n var _this = this;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (this.embedding != null) {\n this.embedding.dispose();\n }\n if (this.gradient != null) {\n this.gradient.dispose();\n }\n this.gradient = tfc.zeros([this.numRows, this.pointsPerRow * 2]);\n this.embedding = tfc.tidy(function () {\n var randomData = tfc.randomUniform([_this.numRows, _this.pointsPerRow * 2]);\n var embedding = tfc.zeros([_this.numRows, _this.pointsPerRow * 2]);\n _this.initializeEmbeddingPositions(embedding, randomData);\n return embedding;\n });\n return [4, this.computeBoundaries()];\n case 1:\n _a.sent();\n this.log('\\tmin X', this._minX);\n this.log('\\tmax X', this._maxX);\n this.log('\\tmin Y', this._minY);\n this.log('\\tmax Y', this._maxY);\n this._iteration = 0;\n return [2];\n }\n });\n });\n };\n TSNEOptimizer.prototype.initializeNeighbors = function (numNeighPerRow, offsets, probabilities, neighIds) {\n this.numNeighPerRow = numNeighPerRow;\n this.probOffsetTexture = offsets;\n this.probTexture = probabilities;\n this.probNeighIdTexture = neighIds;\n };\n TSNEOptimizer.prototype.initializeNeighborsFromKNNGraph = function (numPoints, numNeighbors, distances, indices) {\n return __awaiter(this, void 0, void 0, function () {\n var pointsPerRow, numRows, dataShape, textureValues, i, n, id, knnGraphTexture;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n pointsPerRow = Math.floor(Math.sqrt(numPoints * numNeighbors) / numNeighbors);\n numRows = Math.ceil(numPoints / pointsPerRow);\n dataShape = { numPoints: numPoints, pixelsPerPoint: numNeighbors, numRows: numRows, pointsPerRow: pointsPerRow };\n textureValues = new Float32Array(pointsPerRow * numNeighbors * numRows * 2);\n for (i = 0; i < numPoints; ++i) {\n for (n = 0; n < numNeighbors; ++n) {\n id = (i * numNeighbors + n);\n textureValues[id * 2] = indices[id];\n textureValues[id * 2 + 1] = distances[id];\n }\n }\n knnGraphTexture = gl_util.createAndConfigureTexture(this.gpgpu.gl, pointsPerRow * numNeighbors, numRows, 2, textureValues);\n return [4, this.initializeNeighborsFromKNNTexture(dataShape, knnGraphTexture)];\n case 1:\n _a.sent();\n this.gpgpu.gl.deleteTexture(knnGraphTexture);\n return [2];\n }\n });\n });\n };\n TSNEOptimizer.prototype.initializeNeighborsFromKNNTexture = function (shape, knnGraph) {\n return __awaiter(this, void 0, void 0, function () {\n var distributionParameters, gaussianDistributions, perplexity, gaussianDistributionsData, knnIndices, copyIndicesProgram, knnIndicesData, asymNeighIds, i, d, linearId, neighborCounter, neighborLinearOffset, i, i, check, maxValue, maxId, i, offsets, pointOffset, i, totalNeighbors, probabilities, neighIds, assignedNeighborCounter, i, n, linearId, pointId, probability, symMatrixDirectId, symMatrixIndirectId;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n this.log('Asymmetric neighborhood initialization...');\n if (shape.numPoints !== this.numPoints) {\n throw new Error(\"KNN size and number of points must agree\" +\n (\"(\" + shape.numPoints + \",\" + this.numPoints + \")\"));\n }\n distributionParameters = gl_util.createAndConfigureTexture(this.gpgpu.gl, shape.pointsPerRow, shape.numRows, 2);\n gaussianDistributions = tfc.zeros([shape.numRows, shape.pointsPerRow * shape.pixelsPerPoint]);\n perplexity = shape.pixelsPerPoint / 3;\n this.computeDistributionParameters(distributionParameters, shape, perplexity, knnGraph);\n this.computeGaussianDistributions(gaussianDistributions, distributionParameters, shape, knnGraph);\n return [4, gaussianDistributions.data()];\n case 1:\n gaussianDistributionsData = _a.sent();\n this.log('Gaussian distributions', gaussianDistributions);\n knnIndices = tfc.zeros([shape.numRows, shape.pointsPerRow * shape.pixelsPerPoint]);\n copyIndicesProgram = knn_util.createCopyIndicesProgram(this.gpgpu);\n knn_util.executeCopyIndicesProgram(this.gpgpu, copyIndicesProgram, knnGraph, shape, this.backend.getTexture(knnIndices.dataId));\n return [4, knnIndices.data()];\n case 2:\n knnIndicesData = _a.sent();\n this.log('knn Indices', knnIndices);\n asymNeighIds = new Float32Array(shape.numPoints * shape.pixelsPerPoint);\n for (i = 0; i < this.numPoints; ++i) {\n for (d = 0; d < shape.pixelsPerPoint; ++d) {\n linearId = i * shape.pixelsPerPoint + d;\n asymNeighIds[i * shape.pixelsPerPoint + d] = knnIndicesData[linearId];\n }\n }\n this.log('NeighIds', asymNeighIds);\n neighborCounter = new Uint32Array(this.numPoints);\n neighborLinearOffset = new Uint32Array(this.numPoints);\n for (i = 0; i < shape.numPoints * shape.pixelsPerPoint; ++i) {\n ++neighborCounter[asymNeighIds[i]];\n }\n for (i = 1; i < shape.numPoints; ++i) {\n neighborLinearOffset[i] = neighborLinearOffset[i - 1] +\n neighborCounter[i - 1] + shape.pixelsPerPoint;\n }\n this.log('Counter', neighborCounter);\n this.log('Linear offset', neighborLinearOffset);\n check = 0;\n maxValue = 0;\n maxId = 0;\n for (i = 0; i < neighborCounter.length; ++i) {\n check += neighborCounter[i];\n if (neighborCounter[i] > maxValue) {\n maxValue = neighborCounter[i];\n maxId = i;\n }\n }\n this.log('Number of indirect links', check);\n this.log('Most central point', maxId);\n this.log('Number of indirect links for the central point', maxValue);\n this.numNeighPerRow =\n Math.ceil(Math.sqrt(shape.numPoints * shape.pixelsPerPoint * 2));\n this.log('numNeighPerRow', this.numNeighPerRow);\n {\n offsets = new Float32Array(this.pointsPerRow * this.numRows * 3);\n pointOffset = 0;\n for (i = 0; i < this.numPoints; ++i) {\n totalNeighbors = shape.pixelsPerPoint + neighborCounter[i];\n offsets[i * 3 + 0] = (pointOffset) % (this.numNeighPerRow);\n offsets[i * 3 + 1] = Math.floor((pointOffset) / (this.numNeighPerRow));\n offsets[i * 3 + 2] = totalNeighbors;\n pointOffset += totalNeighbors;\n }\n this.log('Offsets', offsets);\n this.probOffsetTexture = gl_util.createAndConfigureTexture(this.gpgpu.gl, this.pointsPerRow, this.numRows, 3, offsets);\n }\n {\n probabilities = new Float32Array(this.numNeighPerRow * this.numNeighPerRow);\n neighIds = new Float32Array(this.numNeighPerRow * this.numNeighPerRow);\n assignedNeighborCounter = new Uint32Array(this.numPoints);\n for (i = 0; i < this.numPoints; ++i) {\n for (n = 0; n < shape.pixelsPerPoint; ++n) {\n linearId = i * shape.pixelsPerPoint + n;\n pointId = knnIndicesData[linearId];\n probability = gaussianDistributionsData[linearId];\n symMatrixDirectId = neighborLinearOffset[i] + n;\n symMatrixIndirectId = neighborLinearOffset[pointId] +\n shape.pixelsPerPoint +\n assignedNeighborCounter[pointId];\n probabilities[symMatrixDirectId] = probability;\n probabilities[symMatrixIndirectId] = probability;\n neighIds[symMatrixDirectId] = pointId;\n neighIds[symMatrixIndirectId] = i;\n ++assignedNeighborCounter[pointId];\n }\n }\n this.log('Probabilities', probabilities);\n this.log('Neighbors', neighIds);\n this.probTexture = gl_util.createAndConfigureTexture(this.gpgpu.gl, this.numNeighPerRow, this.numNeighPerRow, 1, probabilities);\n this.probNeighIdTexture = gl_util.createAndConfigureTexture(this.gpgpu.gl, this.numNeighPerRow, this.numNeighPerRow, 1, neighIds);\n }\n gaussianDistributions.dispose();\n knnIndices.dispose();\n this.log('...done!');\n return [2];\n }\n });\n });\n };\n TSNEOptimizer.prototype.initializedNeighborhoods = function () {\n return this.probNeighIdTexture != null;\n };\n TSNEOptimizer.prototype.updateExaggeration = function () {\n if (this._exaggeration !== undefined) {\n this._exaggeration.dispose();\n }\n if (typeof this.rawExaggeration === 'number') {\n this._exaggeration = tfc.scalar(this.rawExaggeration);\n return;\n }\n if (this._iteration <= this.rawExaggeration[0].iteration) {\n this._exaggeration = tfc.scalar(this.rawExaggeration[0].value);\n return;\n }\n if (this._iteration >=\n this.rawExaggeration[this.rawExaggeration.length - 1].iteration) {\n this._exaggeration = tfc.scalar(this.rawExaggeration[this.rawExaggeration.length - 1].value);\n return;\n }\n var i = 0;\n while (i < this.rawExaggeration.length &&\n this._iteration < this.rawExaggeration[i].iteration) {\n ++i;\n }\n var it0 = this.rawExaggeration[i].iteration;\n var it1 = this.rawExaggeration[i + 1].iteration;\n var v0 = this.rawExaggeration[i].value;\n var v1 = this.rawExaggeration[i + 1].value;\n var f = (it1 - this._iteration) / (it1 - it0);\n var v = v0 * f + v1 * (1 - f);\n this._exaggeration = tfc.scalar(v);\n };\n TSNEOptimizer.prototype.iterate = function () {\n return __awaiter(this, void 0, void 0, function () {\n var _this = this;\n var normQ, _a, _b;\n return __generator(this, function (_c) {\n switch (_c.label) {\n case 0:\n if (!this.initializedNeighborhoods()) {\n throw new Error('No neighborhoods defined. You may want to call\\\n initializeNeighbors or initializeNeighborsFromKNNGraph');\n }\n this.updateSplatTextureDiameter();\n this.updateExaggeration();\n _b = tfc.tidy(function () {\n _this.splatPoints();\n var interpQ = tfc.zeros([_this.numRows, _this.pointsPerRow]);\n var interpXY = tfc.zeros([_this.numRows, _this.pointsPerRow * 2]);\n _this.computeInterpolatedQ(interpQ);\n _this.computeInterpolatedXY(interpXY);\n var normQ = interpQ.sum();\n var repulsiveForces = interpXY.div(normQ);\n var attractiveForces = tfc.zeros([_this.numRows, _this.pointsPerRow * 2]);\n _this.computeAttractiveForces(attractiveForces);\n var gradientIter = attractiveForces.mul(_this._exaggeration).sub(repulsiveForces);\n var gradient = _this.gradient.mul(_this._momentum).sub(gradientIter);\n _this.gradient.dispose();\n return [gradient, normQ];\n }), this.gradient = _b[0], normQ = _b[1];\n _a = this;\n return [4, normQ.data()];\n case 1:\n _a._normQ = (_c.sent())[0];\n normQ.dispose();\n this.embedding = tfc.tidy(function () {\n var embedding = _this.embedding.add(_this.gradient);\n _this.embedding.dispose();\n return embedding;\n });\n this.computeBoundaries();\n ++this._iteration;\n return [2];\n }\n });\n });\n };\n TSNEOptimizer.prototype.log = function (str, obj) {\n if (this.verbose) {\n if (obj != null) {\n console.log(str + \": \\t\" + obj);\n }\n else {\n console.log(str);\n }\n }\n };\n TSNEOptimizer.prototype.initializeRepulsiveForceTextures = function () {\n this._splatTexture = gl_util.createAndConfigureInterpolatedTexture(this.gpgpu.gl, this.splatTextureDiameter, this.splatTextureDiameter, 4, null);\n this.kernelSupport = 2.5;\n var kernel = new Float32Array(this.kernelTextureDiameter * this.kernelTextureDiameter * 4);\n var kernelRadius = Math.floor(this.kernelTextureDiameter / 2);\n var j = 0;\n var i = 0;\n for (j = 0; j < this.kernelTextureDiameter; ++j) {\n for (i = 0; i < this.kernelTextureDiameter; ++i) {\n var x = (i - kernelRadius) / kernelRadius * this.kernelSupport;\n var y = (j - kernelRadius) / kernelRadius * this.kernelSupport;\n var euclSquared = x * x + y * y;\n var tStudent = 1. / (1. + euclSquared);\n var id = (j * this.kernelTextureDiameter + i) * 4;\n kernel[id + 0] = tStudent;\n kernel[id + 1] = tStudent * tStudent * x;\n kernel[id + 2] = tStudent * tStudent * y;\n kernel[id + 3] = 1;\n }\n }\n this.kernelTexture = gl_util.createAndConfigureInterpolatedTexture(this.gpgpu.gl, this.kernelTextureDiameter, this.kernelTextureDiameter, 4, kernel);\n };\n TSNEOptimizer.prototype.initilizeCustomWebGLPrograms = function () {\n this.log('\\tCreating custom programs...');\n this.embeddingInitializationProgram =\n tsne_util.createEmbeddingInitializationProgram(this.gpgpu);\n this.embeddingSplatterProgram =\n tsne_util.createEmbeddingSplatterProgram(this.gpgpu);\n var splatVertexId = new Float32Array(this.numPoints * 6);\n {\n var i = 0;\n var id = 0;\n for (i = 0; i < this.numPoints; ++i) {\n id = i * 6;\n splatVertexId[id + 0] = 0 + i * 4;\n splatVertexId[id + 1] = 1 + i * 4;\n splatVertexId[id + 2] = 2 + i * 4;\n splatVertexId[id + 3] = 0 + i * 4;\n splatVertexId[id + 4] = 2 + i * 4;\n splatVertexId[id + 5] = 3 + i * 4;\n }\n }\n this.splatVertexIdBuffer = tfc.webgl.webgl_util.createStaticVertexBuffer(this.gpgpu.gl, splatVertexId);\n this.qInterpolatorProgram =\n tsne_util.createQInterpolatorProgram(this.gpgpu);\n this.xyInterpolatorProgram =\n tsne_util.createXYInterpolatorProgram(this.gpgpu);\n this.attractiveForcesProgram =\n tsne_util.createAttractiveForcesComputationProgram(this.gpgpu);\n this.distributionParameterssComputationProgram =\n tsne_util.createDistributionParametersComputationProgram(this.gpgpu);\n this.gaussiaDistributionsFromDistancesProgram =\n tsne_util.createGaussiaDistributionsFromDistancesProgram(this.gpgpu);\n };\n TSNEOptimizer.prototype.computeBoundaries = function () {\n return __awaiter(this, void 0, void 0, function () {\n var _this = this;\n var _a, min, max, _b, _c, offsetX, _d, _e, offsetY;\n return __generator(this, function (_f) {\n switch (_f.label) {\n case 0:\n _a = tfc.tidy(function () {\n var embedding2D = _this.embedding.reshape([_this.numRows * _this.pointsPerRow, 2])\n .slice([0, 0], [_this.numPoints, 2]);\n var min = embedding2D.min(0);\n var max = embedding2D.max(0);\n return [min, max];\n }), min = _a[0], max = _a[1];\n _b = this;\n return [4, min.data()];\n case 1:\n _b._minX = (_f.sent())[0];\n _c = this;\n return [4, max.data()];\n case 2:\n _c._maxX = (_f.sent())[0];\n offsetX = (this._maxX - this._minX) * 0.05;\n this._minX -= offsetX;\n this._maxX += offsetX;\n _d = this;\n return [4, min.data()];\n case 3:\n _d._minY = (_f.sent())[1];\n _e = this;\n return [4, max.data()];\n case 4:\n _e._maxY = (_f.sent())[1];\n offsetY = (this._maxY - this._minY) * 0.05;\n this._minY -= offsetY;\n this._maxY += offsetY;\n min.dispose();\n max.dispose();\n return [2];\n }\n });\n });\n };\n TSNEOptimizer.prototype.updateSplatTextureDiameter = function () {\n var maxSpace = Math.max(this._maxX - this._minX, this._maxY - this._minY);\n var spacePerPixel = 0.35;\n var textureDiameter = Math.ceil(Math.max(maxSpace / spacePerPixel, 5));\n var percChange = Math.abs(this.splatTextureDiameter - textureDiameter) /\n this.splatTextureDiameter;\n if (percChange >= 0.2) {\n this.log('Updating splat-texture diameter', textureDiameter);\n this.gpgpu.gl.deleteTexture(this._splatTexture);\n this.splatTextureDiameter = textureDiameter;\n this._splatTexture = gl_util.createAndConfigureInterpolatedTexture(this.gpgpu.gl, this.splatTextureDiameter, this.splatTextureDiameter, 4, null);\n }\n };\n TSNEOptimizer.prototype.initializeEmbeddingPositions = function (embedding, random) {\n tsne_util.executeEmbeddingInitializationProgram(this.gpgpu, this.embeddingInitializationProgram, this.backend.getTexture(random.dataId), this.numPoints, this.pointsPerRow, this.numRows, this.backend.getTexture(embedding.dataId));\n };\n TSNEOptimizer.prototype.splatPoints = function () {\n tsne_util.executeEmbeddingSplatterProgram(this.gpgpu, this.embeddingSplatterProgram, this._splatTexture, this.backend.getTexture(this.embedding.dataId), this.kernelTexture, this.splatTextureDiameter, this.numPoints, this._minX, this._minY, this._maxX, this._maxY, this.kernelSupport, this.pointsPerRow, this.numRows, this.splatVertexIdBuffer);\n };\n TSNEOptimizer.prototype.computeInterpolatedQ = function (interpolatedQ) {\n tsne_util.executeQInterpolatorProgram(this.gpgpu, this.qInterpolatorProgram, this._splatTexture, this.backend.getTexture(this.embedding.dataId), this.numPoints, this._minX, this._minY, this._maxX, this._maxY, this.pointsPerRow, this.numRows, this.backend.getTexture(interpolatedQ.dataId));\n };\n TSNEOptimizer.prototype.computeInterpolatedXY = function (interpolatedXY) {\n tsne_util.executeXYInterpolatorProgram(this.gpgpu, this.xyInterpolatorProgram, this._splatTexture, this.backend.getTexture(this.embedding.dataId), this.backend.getTexture(interpolatedXY.dataId), this.numPoints, this._minX, this._minY, this._maxX, this._maxY, this.pointsPerRow, this.numRows, this._eta);\n };\n TSNEOptimizer.prototype.computeAttractiveForces = function (attractiveForces) {\n tsne_util.executeAttractiveForcesComputationProgram(this.gpgpu, this.attractiveForcesProgram, this.backend.getTexture(this.embedding.dataId), this.probOffsetTexture, this.probNeighIdTexture, this.probTexture, this.numPoints, this.numNeighPerRow, this.pointsPerRow, this.numRows, this._eta, this.backend.getTexture(attractiveForces.dataId));\n };\n TSNEOptimizer.prototype.computeDistributionParameters = function (distributionParameters, shape, perplexity, knnGraph) {\n tsne_util.executeDistributionParametersComputationProgram(this.gpgpu, this.distributionParameterssComputationProgram, knnGraph, shape.numPoints, shape.pixelsPerPoint, shape.pointsPerRow, shape.numRows, perplexity, distributionParameters);\n };\n TSNEOptimizer.prototype.computeGaussianDistributions = function (distributions, distributionParameters, shape, knnGraph) {\n tsne_util.executeGaussiaDistributionsFromDistancesProgram(this.gpgpu, this.gaussiaDistributionsFromDistancesProgram, knnGraph, distributionParameters, shape.numPoints, shape.pixelsPerPoint, shape.pointsPerRow, shape.numRows, this.backend.getTexture(distributions.dataId));\n };\n return TSNEOptimizer;\n}());\nexports.TSNEOptimizer = TSNEOptimizer;\n//# sourceMappingURL=tsne_optimizer.js.map","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tfc = require(\"@tensorflow/tfjs-core\");\nvar gl_util = require(\"./gl_util\");\nfunction tensorToDataTexture(tensor) {\n return __awaiter(this, void 0, void 0, function () {\n var inputShape, backend, gpgpu, numPoints, numDimensions, numChannels, pixelsPerPoint, pointsPerRow, numRows, tensorData, textureValues, p, tensorOffset, textureOffset, d, texture, shape;\n return __generator(this, function (_a) {\n inputShape = tensor.shape;\n if (inputShape.length !== 2) {\n throw Error(\"tensorToDataTexture: input tensor must be 2-dimensional\");\n }\n backend = tfc.ENV.findBackend('webgl');\n if (backend === null) {\n throw Error('WebGL backend is not available');\n }\n gpgpu = backend.getGPGPUContext();\n numPoints = inputShape[0];\n numDimensions = inputShape[1];\n numChannels = 4;\n pixelsPerPoint = Math.ceil(numDimensions / numChannels);\n pointsPerRow = Math.floor(Math.sqrt(numPoints * pixelsPerPoint)\n / pixelsPerPoint);\n numRows = Math.ceil(numPoints / pointsPerRow);\n tensorData = tensor.dataSync();\n textureValues = new Float32Array(pointsPerRow * pixelsPerPoint * numRows * numChannels);\n for (p = 0; p < numPoints; ++p) {\n tensorOffset = p * numDimensions;\n textureOffset = p * pixelsPerPoint * numChannels;\n for (d = 0; d < numDimensions; ++d) {\n textureValues[textureOffset + d] = tensorData[tensorOffset + d];\n }\n }\n console.log(tensorData);\n console.log(textureValues);\n texture = gl_util.createAndConfigureTexture(gpgpu.gl, pointsPerRow * pixelsPerPoint, numRows, 4, textureValues);\n shape = { numPoints: numPoints, pointsPerRow: pointsPerRow, numRows: numRows, pixelsPerPoint: pixelsPerPoint };\n console.log(shape);\n return [2, { shape: shape, texture: texture }];\n });\n });\n}\nexports.tensorToDataTexture = tensorToDataTexture;\n//# sourceMappingURL=tensor_to_data_texture.js.map","\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nvar __generator = (this && this.__generator) || function (thisArg, body) {\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\n function verb(n) { return function (v) { return step([n, v]); }; }\n function step(op) {\n if (f) throw new TypeError(\"Generator is already executing.\");\n while (_) try {\n if (f = 1, y && (t = y[op[0] & 2 ? \"return\" : op[0] ? \"throw\" : \"next\"]) && !(t = t.call(y, op[1])).done) return t;\n if (y = 0, t) op = [0, t.value];\n switch (op[0]) {\n case 0: case 1: t = op; break;\n case 4: _.label++; return { value: op[1], done: false };\n case 5: _.label++; y = op[1]; op = [0]; continue;\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\n default:\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\n if (t[2]) _.ops.pop();\n _.trys.pop(); continue;\n }\n op = body.call(thisArg, _);\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\n }\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tsne_optimizer_1 = require(\"./tsne_optimizer\");\nvar knn_1 = require(\"./knn\");\nvar tensor_to_data_texture_1 = require(\"./tensor_to_data_texture\");\nfunction tsne(data, config, verbose) {\n return new TSNE(data, config, verbose);\n}\nexports.tsne = tsne;\nvar TSNE = (function () {\n function TSNE(data, config, verbose) {\n this.initialized = false;\n this.probabilitiesInitialized = false;\n this.data = data;\n this.config = config;\n var inputShape = this.data.shape;\n this.numPoints = inputShape[0];\n this.numDimensions = inputShape[1];\n if (inputShape.length !== 2) {\n throw Error(\"computeTSNE: input tensor must be 2-dimensional\");\n }\n this.verbose = false;\n if (verbose != null) {\n this.verbose = verbose;\n }\n if (this.verbose === true) {\n console.log(\"Computing tSNE embedding...\");\n }\n }\n TSNE.prototype.initialize = function () {\n return __awaiter(this, void 0, void 0, function () {\n var perplexity, exaggeration, exaggerationIter, exaggerationDecayIter, momentum, _a, exaggerationPolyline;\n return __generator(this, function (_b) {\n switch (_b.label) {\n case 0:\n perplexity = 30;\n exaggeration = 4;\n exaggerationIter = 300;\n exaggerationDecayIter = 200;\n momentum = 0.8;\n if (this.config !== undefined) {\n if (this.config.perplexity !== undefined) {\n perplexity = this.config.perplexity;\n }\n if (this.config.exaggeration !== undefined) {\n exaggeration = this.config.exaggeration;\n }\n if (this.config.exaggerationIter !== undefined) {\n exaggerationIter = this.config.exaggerationIter;\n }\n if (this.config.exaggerationDecayIter !== undefined) {\n exaggerationDecayIter = this.config.exaggerationDecayIter;\n }\n if (this.config.momentum !== undefined) {\n momentum = this.config.momentum;\n }\n }\n if (perplexity > 42) {\n throw Error(\"computeTSNE: perplexity cannot be greater than 42\");\n }\n this.numNeighbors = Math.floor((perplexity * 3) / 4) * 4;\n _a = this;\n return [4, tensor_to_data_texture_1.tensorToDataTexture(this.data)];\n case 1:\n _a.packedData = _b.sent();\n if (this.verbose === true) {\n console.log(\"Number of points \" + this.numPoints);\n console.log(\"Number of dimensions \" + this.numDimensions);\n console.log(\"Number of neighbors \" + this.numNeighbors);\n }\n this.knnEstimator\n = new knn_1.KNNEstimator(this.packedData.texture, this.packedData.shape, this.numPoints, this.numDimensions, this.numNeighbors, true);\n this.optimizer = new tsne_optimizer_1.TSNEOptimizer(this.numPoints, false);\n exaggerationPolyline = [{ iteration: exaggerationIter, value: exaggeration },\n { iteration: exaggerationIter + exaggerationDecayIter, value: 1 }];\n if (this.verbose === true) {\n console.log(\"Exaggerating for \" + exaggerationPolyline[0].iteration + \" \"\n + (\"iterations with a value of \" + exaggerationPolyline[0].value + \". \")\n + (\"Exaggeration is removed after \" + exaggerationPolyline[1].iteration + \".\"));\n }\n this.optimizer.exaggeration = exaggerationPolyline;\n this.optimizer.momentum = momentum;\n return [2];\n }\n });\n });\n };\n TSNE.prototype.compute = function (iterations) {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0: return [4, this.initialize()];\n case 1:\n _a.sent();\n return [4, this.iterateKnn(100)];\n case 2:\n _a.sent();\n return [4, this.iterate(iterations)];\n case 3:\n _a.sent();\n return [2];\n }\n });\n });\n };\n TSNE.prototype.iterateKnn = function (iterations) {\n return __awaiter(this, void 0, void 0, function () {\n var iter;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!(this.initialized === false)) return [3, 2];\n return [4, this.initialize()];\n case 1:\n _a.sent();\n _a.label = 2;\n case 2:\n this.probabilitiesInitialized = false;\n for (iter = 0; iter < iterations; ++iter) {\n this.knnEstimator.iterateBruteForce();\n }\n return [2, true];\n }\n });\n });\n };\n TSNE.prototype.iterate = function (iterations) {\n return __awaiter(this, void 0, void 0, function () {\n var iter;\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (!(this.probabilitiesInitialized === false)) return [3, 2];\n return [4, this.initializeProbabilities()];\n case 1:\n _a.sent();\n _a.label = 2;\n case 2:\n iter = 0;\n _a.label = 3;\n case 3:\n if (!(iter < iterations)) return [3, 6];\n return [4, this.optimizer.iterate()];\n case 4:\n _a.sent();\n if ((this.optimizer.iteration % 100) == 0 && this.verbose === true) {\n console.log(\"Iteration \" + this.optimizer.iteration);\n }\n _a.label = 5;\n case 5:\n ++iter;\n return [3, 3];\n case 6: return [2];\n }\n });\n });\n };\n TSNE.prototype.coordinates = function () {\n return this.optimizer.embedding2D;\n };\n TSNE.prototype.knnDistance = function () {\n return 0;\n };\n TSNE.prototype.initializeProbabilities = function () {\n return __awaiter(this, void 0, void 0, function () {\n return __generator(this, function (_a) {\n switch (_a.label) {\n case 0:\n if (this.verbose === true) {\n console.log(\"Initializing probabilities\");\n }\n return [4, this.optimizer.initializeNeighborsFromKNNTexture(this.knnEstimator.knnShape, this.knnEstimator.knn())];\n case 1:\n _a.sent();\n this.probabilitiesInitialized = true;\n return [2];\n }\n });\n });\n };\n return TSNE;\n}());\nexports.TSNE = TSNE;\n//# sourceMappingURL=tsne.js.map","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar tfc = require(\"@tensorflow/tfjs-core\");\nexports.tfc = tfc;\nvar dataset_util = require(\"./dataset_util\");\nexports.dataset_util = dataset_util;\nvar drawer_1 = require(\"./drawer\");\nexports.EmbeddingDrawer = drawer_1.EmbeddingDrawer;\nvar gl_util = require(\"./gl_util\");\nexports.gl_util = gl_util;\nvar knn_1 = require(\"./knn\");\nexports.KNNEstimator = knn_1.KNNEstimator;\nvar tsne_optimizer_1 = require(\"./tsne_optimizer\");\nexports.TSNEOptimizer = tsne_optimizer_1.TSNEOptimizer;\nvar tsne_1 = require(\"./tsne\");\nexports.tsne = tsne_1.tsne;\n//# sourceMappingURL=index.js.map","/**\n * @license\n * Copyright 2018 Google Inc. All Rights Reserved.\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n * =============================================================================\n */\n\nimport * as tf_tsne from 'tfjs-tsne';\nimport {tfc as tfc} from 'tfjs-tsne';\n\nconsole.log('Texture tSNE with TensorFlow.js');\n\n// Gradient Descent parameters\nlet iterations = 0;\nlet alphaViz = 0.25;\nconst maxExaggeration = 4;\nlet exaggerationMult = 1;\n\nlet init = false;\n\n// UI elements\nconst iterateChkBx = document.getElementById('iterateChkBx');\nconst textureChkBx = document.getElementById('textureChkBx');\nconst alphaSlider = document.getElementById('alphaSlider');\n\n// Infomation\nconst numPoints = 60000;\n\n// initializing the tSNE class and the canvas drawer\nconst tsne = new tf_tsne.TSNEOptimizer(numPoints, false);\nconst drawer = new tf_tsne.EmbeddingDrawer(numPoints);\n\n// Precomputed Probabilites\n// can be loaded from the server\nconst pntsPerRow = tsne.pointsPerRow;\nconst numRows = tsne.numRows;\nconst numNeighPerRow = 2794;\n\n// The canvas used by TensorFlow.js is added to the page to enable the use of\n// custom drawers.\nconst backend = tfc.ENV.findBackend('webgl');\nconst canvas = backend.getCanvas();\ndocument.getElementById('canvas-div').appendChild(canvas);\ncanvas.height = 800;\ncanvas.width = 800;\n\nconst gpgpu = backend.getGPGPUContext();\nconst webglContext = backend.getGPGPUContext().gl;\ntfc.webgl.webgl_util.bindCanvasToFramebuffer(webglContext);\nwebglContext.clearColor(1, 1, 1, 1);\nwebglContext.clear(webglContext.COLOR_BUFFER_BIT);\n\n// Joint probability definition\nlet offsets;\nlet probabilities;\nlet neighIds;\nlet colors;\nlet mnistTexture;\n\n// Off screen render target\nconst tempTexture = tf_tsne.gl_util.createAndConfigureInterpolatedTexture(\n gpgpu.gl, 800, 800, 4);\n\n/**\n * Draw the embedding on canvas\n */\nfunction draw() {\n const embedding = {\n minX : tsne.minX,\n maxX : tsne.maxX,\n minY : tsne.minY,\n maxY : tsne.maxY,\n embeddingTexture : tsne.embeddingTexture,\n pntsPerRow : tsne.numberOfPointsPerRow,\n numRows : tsne.numberOfRows,\n numPoints : tsne.numberOfPoints\n };\n if (textureChkBx.checked === false) {\n drawer.drawTexturedPoints(embedding, alphaViz, mnistTexture, 14, colors);\n } else {\n const textureNormalization = Math.sqrt(tsne.normalizationQ);\n drawer.drawColoredPoints(embedding, alphaViz, colors, tempTexture);\n drawer.drawPointsAndSplatTexture(embedding, tsne.splatTexture, tempTexture,\n textureNormalization);\n }\n}\n\n/**\n * Perform a gradient descent iteration\n */\nfunction iterate() {\n if (init === false) {\n tsne.initializeNeighbors(numNeighPerRow, offsets, probabilities, neighIds);\n init = true;\n }\n if (iterateChkBx.checked === true) {\n requestAnimationFrame(iterate);\n }\n\n // Setting parameters the SGD parameters\n // with a linear fall-off of the exaggeration\n if (iterations >= 600) {\n tsne.exaggeration = 1.;\n } else if (iterations >= 200) {\n tsne.exaggeration =\n maxExaggeration - (maxExaggeration - 1) * (iterations - 200.) / 400.;\n } else {\n tsne.exaggeration = maxExaggeration;\n }\n tsne.exaggeration *= exaggerationMult;\n\n tsne.iterate();\n ++iterations;\n if (iterations % 100 === 0) {\n console.log('Iter #' + iterations);\n }\n\n if (iterations === 1000) {\n console.log('Switching off automatically after 1000 iterations');\n iterateChkBx.checked = false;\n }\n\n draw();\n}\n\niterateChkBx.addEventListener('click', () => { iterate(); });\n\ntextureChkBx.addEventListener('click', () => { draw(); });\n\nconst resetBtn = document.getElementById('resetBtn');\nresetBtn.addEventListener('click', () => {\n console.log('Reset!');\n tsne.initializeEmbedding();\n iterations = 0;\n exaggerationMult = 1;\n iterate();\n iterate();\n iterateChkBx.checked = false;\n});\n\nalphaSlider.addEventListener('input', () => {\n if (iterateChkBx.checked === false) {\n requestAnimationFrame(draw);\n }\n alphaViz = Number(alphaSlider.value) / Number(alphaSlider.max) / 2.;\n});\n\n////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////\n////////////////////////////////////////////////////////////////\n// Loading the textures -> switch to promises\n\n/**\n * Load the texture oReqOffsets\n */\nfunction loadOffsets() {\n return new Promise(function(resolve, reject) {\n const oReqOffsets = new XMLHttpRequest();\n oReqOffsets.open('GET', document.getElementById('offsets').href, true);\n oReqOffsets.responseType = 'arraybuffer';\n oReqOffsets.onload = (oEvent) => {\n if (oReqOffsets.status >= 200 && oReqOffsets.status < 300) {\n const arrayBufferOffsets = oReqOffsets.response;\n if (arrayBufferOffsets) {\n const byteArrayOffsets = new Float32Array(arrayBufferOffsets);\n offsets = tf_tsne.gl_util.createAndConfigureTexture(\n gpgpu.gl, pntsPerRow, numRows, 3, // offset 2D + numNeigh\n byteArrayOffsets);\n }\n resolve(oReqOffsets.response);\n } else {\n reject(\n {status : oReqOffsets.status, statusText : oReqOffsets.statusText});\n }\n };\n oReqOffsets.onerror = function() {\n reject(\n {status : oReqOffsets.status, statusText : oReqOffsets.statusText});\n };\n oReqOffsets.send();\n });\n}\n\n/**\n * Loads the labels as oReqColors\n */\nfunction loadColors() {\n return new Promise(function(resolve, reject) {\n const oReqColors = new XMLHttpRequest();\n oReqColors.open('GET', document.getElementById('colors').href, true);\n oReqColors.responseType = 'arraybuffer';\n oReqColors.onload = (oEvent) => {\n if (oReqColors.status >= 200 && oReqColors.status < 300) {\n const arrayBufferColors = oReqColors.response;\n if (arrayBufferColors) {\n const byteArrayColors = new Float32Array(arrayBufferColors);\n colors = tf_tsne.gl_util.createAndConfigureTexture(\n gpgpu.gl, pntsPerRow, numRows, 3, byteArrayColors);\n }\n resolve(oReqColors.response);\n } else {\n reject(\n {status : oReqColors.status, statusText : oReqColors.statusText});\n }\n };\n oReqColors.onerror = function() {\n reject({status : oReqColors.status, statusText : oReqColors.statusText});\n };\n oReqColors.send();\n });\n}\n\n/**\n * Load the oReqProbabilities\n */\nfunction loadProbabilities() {\n return new Promise(function(resolve, reject) {\n const oReqProbabilities = new XMLHttpRequest();\n oReqProbabilities.open('GET', document.getElementById('probabilities').href,\n true);\n oReqProbabilities.responseType = 'arraybuffer';\n oReqProbabilities.onload = (oEvent) => {\n if (oReqProbabilities.status >= 200 && oReqProbabilities.status < 300) {\n const arrayBufferProb = oReqProbabilities.response;\n if (arrayBufferProb) {\n const byteArrayProb = new Float32Array(arrayBufferProb);\n probabilities = tf_tsne.gl_util.createAndConfigureTexture(\n gpgpu.gl, numNeighPerRow, numNeighPerRow, 1, byteArrayProb);\n }\n resolve(oReqProbabilities.response);\n } else {\n reject({\n status : oReqProbabilities.status,\n statusText : oReqProbabilities.statusText\n });\n }\n };\n oReqProbabilities.onerror = function() {\n reject({\n status : oReqProbabilities.status,\n statusText : oReqProbabilities.statusText\n });\n };\n oReqProbabilities.send();\n });\n}\n\n/**\n * Loads the neighbor neighIds\n */\nfunction loadNeighIds() {\n return new Promise(function(resolve, reject) {\n const oReqNeighIds = new XMLHttpRequest();\n oReqNeighIds.open('GET', document.getElementById('neighIds').href, true);\n oReqNeighIds.responseType = 'arraybuffer';\n oReqNeighIds.onload = (oEvent) => {\n if (oReqNeighIds.status >= 200 && oReqNeighIds.status < 300) {\n const arrayBufferNeighIds = oReqNeighIds.response;\n if (arrayBufferNeighIds) {\n const byteArrayNeighIds = new Float32Array(arrayBufferNeighIds);\n neighIds = tf_tsne.gl_util.createAndConfigureTexture(\n gpgpu.gl, numNeighPerRow, numNeighPerRow, 1, byteArrayNeighIds);\n }\n resolve(oReqNeighIds.response);\n } else {\n reject({\n status : oReqNeighIds.status,\n statusText : oReqNeighIds.statusText\n });\n }\n };\n oReqNeighIds.onerror = function() {\n reject(\n {status : oReqNeighIds.status, statusText : oReqNeighIds.statusText});\n };\n oReqNeighIds.send();\n });\n}\nloadNeighIds().then(\n () => {loadMNIST(webglContext, document.getElementById('mnistImg').href)\n .then(() => {loadOffsets().then(\n () => {loadProbabilities().then(\n () => {loadColors().then(function() {\n iterate();\n showControls();\n })})})})});\n\n/**\n * Load the MNIST dataset\n * @param {WebGlContext} gl current context\n * @param {string} url input image url\n * @returns {WebGLTexture} MNISTA dataset textures\n */\nfunction loadMNIST(gl, url) {\n return new Promise(function(resolve, reject) {\n const texture = gl.createTexture();\n gl.bindTexture(gl.TEXTURE_2D, texture);\n const level = 0;\n // tslint:disable-next-line:no-any\n const internalFormat = gl.RGBA8;\n const border = 0;\n // tslint:disable-next-line:no-any\n const srcFormat = gl.RGBA;\n const srcType = gl.UNSIGNED_BYTE;\n const pixel = new Uint8Array([ 0, 0, 255, 255 ]);\n gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, 1, 1, border, srcFormat,\n srcType, pixel);\n\n const image = new Image();\n image.onload = () => {\n gl.bindTexture(gl.TEXTURE_2D, texture);\n gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, srcFormat, srcType,\n image);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);\n gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);\n };\n image.src = url;\n mnistTexture = texture;\n resolve();\n })\n}\n\n// loadMNIST(webglContext, document.getElementById('mnistImg').href);\n\nfunction showControls() {\n const hiddenIterDiv = document.querySelector('#hidden-iter-div');\n hiddenIterDiv.classList.remove('hidden');\n\n const dataLoadingDiv = document.querySelector('#data-loading-div');\n dataLoadingDiv.remove();\n}\n"]}