text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  var tf = require("../index");
  var jasmine_util_1 = require("../jasmine_util");
  var test_util_1 = require("../test_util");
  var util = require("../util");
  var rand_util_1 = require("./rand_util");
  jasmine_util_1.describeWithFlags('zeros', test_util_1.ALL_ENVS, function () {
      it('1D default dtype', function () {
          var a = tf.zeros([3]);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3]);
          test_util_1.expectArraysClose(a, [0, 0, 0]);
      });
      it('1D float32 dtype', function () {
          var a = tf.zeros([3], 'float32');
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3]);
          test_util_1.expectArraysClose(a, [0, 0, 0]);
      });
      it('1D int32 dtype', function () {
          var a = tf.zeros([3], 'int32');
          expect(a.dtype).toBe('int32');
          expect(a.shape).toEqual([3]);
          test_util_1.expectArraysEqual(a, [0, 0, 0]);
      });
      it('1D bool dtype', function () {
          var a = tf.zeros([3], 'bool');
          expect(a.dtype).toBe('bool');
          expect(a.shape).toEqual([3]);
          test_util_1.expectArraysEqual(a, [0, 0, 0]);
      });
      it('2D default dtype', function () {
          var a = tf.zeros([3, 2]);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2]);
          test_util_1.expectArraysClose(a, [0, 0, 0, 0, 0, 0]);
      });
      it('2D float32 dtype', function () {
          var a = tf.zeros([3, 2], 'float32');
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2]);
          test_util_1.expectArraysClose(a, [0, 0, 0, 0, 0, 0]);
      });
      it('2D int32 dtype', function () {
          var a = tf.zeros([3, 2], 'int32');
          expect(a.dtype).toBe('int32');
          expect(a.shape).toEqual([3, 2]);
          test_util_1.expectArraysEqual(a, [0, 0, 0, 0, 0, 0]);
      });
      it('2D bool dtype', function () {
          var a = tf.zeros([3, 2], 'bool');
          expect(a.dtype).toBe('bool');
          expect(a.shape).toEqual([3, 2]);
          test_util_1.expectArraysEqual(a, [0, 0, 0, 0, 0, 0]);
      });
      it('3D default dtype', function () {
          var a = tf.zeros([2, 2, 2]);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysClose(a, [0, 0, 0, 0, 0, 0, 0, 0]);
      });
      it('3D float32 dtype', function () {
          var a = tf.zeros([2, 2, 2], 'float32');
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysClose(a, [0, 0, 0, 0, 0, 0, 0, 0]);
      });
      it('3D int32 dtype', function () {
          var a = tf.zeros([2, 2, 2], 'int32');
          expect(a.dtype).toBe('int32');
          expect(a.shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysEqual(a, [0, 0, 0, 0, 0, 0, 0, 0]);
      });
      it('3D bool dtype', function () {
          var a = tf.zeros([2, 2, 2], 'bool');
          expect(a.dtype).toBe('bool');
          expect(a.shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysEqual(a, [0, 0, 0, 0, 0, 0, 0, 0]);
      });
      it('4D default dtype', function () {
          var a = tf.zeros([3, 2, 1, 1]);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2, 1, 1]);
          test_util_1.expectArraysClose(a, [0, 0, 0, 0, 0, 0]);
      });
      it('4D float32 dtype', function () {
          var a = tf.zeros([3, 2, 1, 1], 'float32');
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2, 1, 1]);
          test_util_1.expectArraysClose(a, [0, 0, 0, 0, 0, 0]);
      });
      it('4D int32 dtype', function () {
          var a = tf.zeros([3, 2, 1, 1], 'int32');
          expect(a.dtype).toBe('int32');
          expect(a.shape).toEqual([3, 2, 1, 1]);
          test_util_1.expectArraysEqual(a, [0, 0, 0, 0, 0, 0]);
      });
      it('4D bool dtype', function () {
          var a = tf.zeros([3, 2, 1, 1], 'bool');
          expect(a.dtype).toBe('bool');
          expect(a.shape).toEqual([3, 2, 1, 1]);
          test_util_1.expectArraysEqual(a, [0, 0, 0, 0, 0, 0]);
      });
  });
  jasmine_util_1.describeWithFlags('ones', test_util_1.ALL_ENVS, function () {
      it('1D default dtype', function () {
          var a = tf.ones([3]);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3]);
          test_util_1.expectArraysClose(a, [1, 1, 1]);
      });
      it('1D float32 dtype', function () {
          var a = tf.ones([3], 'float32');
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3]);
          test_util_1.expectArraysClose(a, [1, 1, 1]);
      });
      it('1D int32 dtype', function () {
          var a = tf.ones([3], 'int32');
          expect(a.dtype).toBe('int32');
          expect(a.shape).toEqual([3]);
          test_util_1.expectArraysEqual(a, [1, 1, 1]);
      });
      it('1D bool dtype', function () {
          var a = tf.ones([3], 'bool');
          expect(a.dtype).toBe('bool');
          expect(a.shape).toEqual([3]);
          test_util_1.expectArraysEqual(a, [1, 1, 1]);
      });
      it('2D default dtype', function () {
          var a = tf.ones([3, 2]);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2]);
          test_util_1.expectArraysClose(a, [1, 1, 1, 1, 1, 1]);
      });
      it('2D float32 dtype', function () {
          var a = tf.ones([3, 2], 'float32');
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2]);
          test_util_1.expectArraysClose(a, [1, 1, 1, 1, 1, 1]);
      });
      it('2D int32 dtype', function () {
          var a = tf.ones([3, 2], 'int32');
          expect(a.dtype).toBe('int32');
          expect(a.shape).toEqual([3, 2]);
          test_util_1.expectArraysEqual(a, [1, 1, 1, 1, 1, 1]);
      });
      it('2D bool dtype', function () {
          var a = tf.ones([3, 2], 'bool');
          expect(a.dtype).toBe('bool');
          expect(a.shape).toEqual([3, 2]);
          test_util_1.expectArraysEqual(a, [1, 1, 1, 1, 1, 1]);
      });
      it('3D default dtype', function () {
          var a = tf.ones([2, 2, 2]);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysClose(a, [1, 1, 1, 1, 1, 1, 1, 1]);
      });
      it('3D float32 dtype', function () {
          var a = tf.ones([2, 2, 2], 'float32');
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysClose(a, [1, 1, 1, 1, 1, 1, 1, 1]);
      });
      it('3D int32 dtype', function () {
          var a = tf.ones([2, 2, 2], 'int32');
          expect(a.dtype).toBe('int32');
          expect(a.shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysEqual(a, [1, 1, 1, 1, 1, 1, 1, 1]);
      });
      it('3D bool dtype', function () {
          var a = tf.ones([2, 2, 2], 'bool');
          expect(a.dtype).toBe('bool');
          expect(a.shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysEqual(a, [1, 1, 1, 1, 1, 1, 1, 1]);
      });
      it('4D default dtype', function () {
          var a = tf.ones([3, 2, 1, 1]);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2, 1, 1]);
          test_util_1.expectArraysClose(a, [1, 1, 1, 1, 1, 1]);
      });
      it('4D float32 dtype', function () {
          var a = tf.ones([3, 2, 1, 1], 'float32');
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2, 1, 1]);
          test_util_1.expectArraysClose(a, [1, 1, 1, 1, 1, 1]);
      });
      it('4D int32 dtype', function () {
          var a = tf.ones([3, 2, 1, 1], 'int32');
          expect(a.dtype).toBe('int32');
          expect(a.shape).toEqual([3, 2, 1, 1]);
          test_util_1.expectArraysEqual(a, [1, 1, 1, 1, 1, 1]);
      });
      it('4D bool dtype', function () {
          var a = tf.ones([3, 2, 1, 1], 'bool');
          expect(a.dtype).toBe('bool');
          expect(a.shape).toEqual([3, 2, 1, 1]);
          test_util_1.expectArraysEqual(a, [1, 1, 1, 1, 1, 1]);
      });
  });
  jasmine_util_1.describeWithFlags('zerosLike', test_util_1.ALL_ENVS, function () {
      it('1D default dtype', function () {
          var a = tf.tensor1d([1, 2, 3]);
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysClose(b, [0, 0, 0]);
      });
      it('1D float32 dtype', function () {
          var a = tf.tensor1d([1, 2, 3], 'float32');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysClose(b, [0, 0, 0]);
      });
      it('1D int32 dtype', function () {
          var a = tf.tensor1d([1, 2, 3], 'int32');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysEqual(b, [0, 0, 0]);
      });
      it('1D bool dtype', function () {
          var a = tf.tensor1d([1, 2, 3], 'bool');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysEqual(b, [0, 0, 0]);
      });
      it('2D default dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2]);
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(b, [0, 0, 0, 0]);
      });
      it('2D float32 dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2], 'float32');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(b, [0, 0, 0, 0]);
      });
      it('2D int32 dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2], 'int32');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysEqual(b, [0, 0, 0, 0]);
      });
      it('2D bool dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2], 'bool');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysEqual(b, [0, 0, 0, 0]);
      });
      it('3D default dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1]);
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(b, [0, 0, 0, 0]);
      });
      it('3D float32 dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1], 'float32');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(b, [0, 0, 0, 0]);
      });
      it('3D int32 dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1], 'int32');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysEqual(b, [0, 0, 0, 0]);
      });
      it('3D bool dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1], 'bool');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysEqual(b, [0, 0, 0, 0]);
      });
      it('4D default dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1]);
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysClose(b, [0, 0, 0, 0]);
      });
      it('4D float32 dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1], 'float32');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysClose(b, [0, 0, 0, 0]);
      });
      it('4D int32 dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1], 'int32');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysEqual(b, [0, 0, 0, 0]);
      });
      it('4D bool dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1], 'bool');
          var b = tf.zerosLike(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysEqual(b, [0, 0, 0, 0]);
      });
      it('throws when passed a non-tensor', function () {
          expect(function () { return tf.zerosLike({}); })
              .toThrowError(/Argument 'x' passed to 'zerosLike' must be a Tensor/);
      });
  });
  jasmine_util_1.describeWithFlags('onesLike', test_util_1.ALL_ENVS, function () {
      it('1D default dtype', function () {
          var a = tf.tensor1d([1, 2, 3]);
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysClose(b, [1, 1, 1]);
      });
      it('1D float32 dtype', function () {
          var a = tf.tensor1d([1, 2, 3], 'float32');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysClose(b, [1, 1, 1]);
      });
      it('1D int32 dtype', function () {
          var a = tf.tensor1d([1, 2, 3], 'int32');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysEqual(b, [1, 1, 1]);
      });
      it('1D bool dtype', function () {
          var a = tf.tensor1d([1, 2, 3], 'bool');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysEqual(b, [1, 1, 1]);
      });
      it('2D default dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2]);
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(b, [1, 1, 1, 1]);
      });
      it('2D float32 dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2], 'float32');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(b, [1, 1, 1, 1]);
      });
      it('2D int32 dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2], 'int32');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysEqual(b, [1, 1, 1, 1]);
      });
      it('2D bool dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2], 'bool');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysEqual(b, [1, 1, 1, 1]);
      });
      it('3D default dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1]);
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(b, [1, 1, 1, 1]);
      });
      it('3D float32 dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1], 'float32');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(b, [1, 1, 1, 1]);
      });
      it('3D int32 dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1], 'int32');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysEqual(b, [1, 1, 1, 1]);
      });
      it('3D bool dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1], 'bool');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysEqual(b, [1, 1, 1, 1]);
      });
      it('4D default dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1]);
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysClose(b, [1, 1, 1, 1]);
      });
      it('4D float32 dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1], 'float32');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysClose(b, [1, 1, 1, 1]);
      });
      it('4D int32 dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1], 'int32');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysEqual(b, [1, 1, 1, 1]);
      });
      it('4D bool dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1], 'bool');
          var b = tf.onesLike(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysEqual(b, [1, 1, 1, 1]);
      });
      it('throws when passed a non-tensor', function () {
          expect(function () { return tf.onesLike({}); })
              .toThrowError(/Argument 'x' passed to 'onesLike' must be a Tensor/);
      });
  });
  jasmine_util_1.describeWithFlags('rand', test_util_1.ALL_ENVS, function () {
      it('should return a random 1D float32 array', function () {
          var shape = [10];
          var result = tf.rand(shape, function () { return util.randUniform(0, 2); });
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 2);
          result = tf.rand(shape, function () { return util.randUniform(0, 1.5); });
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 1.5);
      });
      it('should return a random 1D int32 array', function () {
          var shape = [10];
          var result = tf.rand(shape, function () { return util.randUniform(0, 2); }, 'int32');
          expect(result.dtype).toBe('int32');
          test_util_1.expectValuesInRange(result, 0, 2);
      });
      it('should return a random 1D bool array', function () {
          var shape = [10];
          var result = tf.rand(shape, function () { return util.randUniform(0, 1); }, 'bool');
          expect(result.dtype).toBe('bool');
          test_util_1.expectValuesInRange(result, 0, 1);
      });
      it('should return a random 2D float32 array', function () {
          var shape = [3, 4];
          var result = tf.rand(shape, function () { return util.randUniform(0, 2.5); });
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 2.5);
          result = tf.rand(shape, function () { return util.randUniform(0, 1.5); }, 'float32');
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 1.5);
      });
      it('should return a random 2D int32 array', function () {
          var shape = [3, 4];
          var result = tf.rand(shape, function () { return util.randUniform(0, 2); }, 'int32');
          expect(result.dtype).toBe('int32');
          test_util_1.expectValuesInRange(result, 0, 2);
      });
      it('should return a random 2D bool array', function () {
          var shape = [3, 4];
          var result = tf.rand(shape, function () { return util.randUniform(0, 1); }, 'bool');
          expect(result.dtype).toBe('bool');
          test_util_1.expectValuesInRange(result, 0, 1);
      });
      it('should return a random 3D float32 array', function () {
          var shape = [3, 4, 5];
          var result = tf.rand(shape, function () { return util.randUniform(0, 2.5); });
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 2.5);
          result = tf.rand(shape, function () { return util.randUniform(0, 1.5); }, 'float32');
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 1.5);
      });
      it('should return a random 3D int32 array', function () {
          var shape = [3, 4, 5];
          var result = tf.rand(shape, function () { return util.randUniform(0, 2); }, 'int32');
          expect(result.dtype).toBe('int32');
          test_util_1.expectValuesInRange(result, 0, 2);
      });
      it('should return a random 3D bool array', function () {
          var shape = [3, 4, 5];
          var result = tf.rand(shape, function () { return util.randUniform(0, 1); }, 'bool');
          expect(result.dtype).toBe('bool');
          test_util_1.expectValuesInRange(result, 0, 1);
      });
      it('should return a random 4D float32 array', function () {
          var shape = [3, 4, 5, 6];
          var result = tf.rand(shape, function () { return util.randUniform(0, 2.5); });
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 2.5);
          result = tf.rand(shape, function () { return util.randUniform(0, 1.5); });
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 1.5);
      });
      it('should return a random 4D int32 array', function () {
          var shape = [3, 4, 5, 6];
          var result = tf.rand(shape, function () { return util.randUniform(0, 2); }, 'int32');
          expect(result.dtype).toBe('int32');
          test_util_1.expectValuesInRange(result, 0, 2);
      });
      it('should return a random 4D bool array', function () {
          var shape = [3, 4, 5, 6];
          var result = tf.rand(shape, function () { return util.randUniform(0, 1); }, 'bool');
          expect(result.dtype).toBe('bool');
          test_util_1.expectValuesInRange(result, 0, 1);
      });
  });
  jasmine_util_1.describeWithFlags('eye', test_util_1.ALL_ENVS, function () {
      it('1x1', function () {
          test_util_1.expectArraysClose(tf.eye(1), tf.tensor2d([[1]]));
      });
      it('2x2', function () {
          test_util_1.expectArraysClose(tf.eye(2), tf.tensor2d([[1, 0], [0, 1]]));
      });
      it('3x3', function () {
          test_util_1.expectArraysClose(tf.eye(3), tf.tensor2d([[1, 0, 0], [0, 1, 0], [0, 0, 1]]));
      });
      it('3x4', function () {
          test_util_1.expectArraysClose(tf.eye(3, 4), tf.tensor2d([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]]));
      });
      it('4x3', function () {
          test_util_1.expectArraysClose(tf.eye(4, 3), tf.tensor2d([[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, 0]]));
      });
      it('with 1D batchShape', function () {
          test_util_1.expectArraysClose(tf.eye(2, 2, [3]), tf.tensor3d([[[1, 0], [0, 1]], [[1, 0], [0, 1]], [[1, 0], [0, 1]]]));
      });
      it('with 2D batchShape', function () {
          test_util_1.expectArraysClose(tf.eye(2, 2, [2, 3]), tf.tensor4d([
              [[[1, 0], [0, 1]], [[1, 0], [0, 1]], [[1, 0], [0, 1]]],
              [[[1, 0], [0, 1]], [[1, 0], [0, 1]], [[1, 0], [0, 1]]]
          ]));
      });
      it('3x3, int32', function () {
          test_util_1.expectArraysClose(tf.eye(3, 3, null, 'int32'), tf.tensor2d([[1, 0, 0], [0, 1, 0], [0, 0, 1]], [3, 3], 'int32'));
      });
      it('3x3, bool', function () {
          test_util_1.expectArraysClose(tf.eye(3, 3, null, 'bool'), tf.tensor2d([[1, 0, 0], [0, 1, 0], [0, 0, 1]], [3, 3], 'bool'));
      });
  });
  jasmine_util_1.describeWithFlags('randomNormal', test_util_1.ALL_ENVS, function () {
      var SEED = 2002;
      var EPSILON = 0.05;
      it('should return a float32 1D of random normal values', function () {
          var SAMPLES = 10000;
          var result = tf.randomNormal([SAMPLES], 0, 0.5, null, SEED);
          expect(result.dtype).toBe('float32');
          expect(result.shape).toEqual([SAMPLES]);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 0.5, EPSILON);
          result = tf.randomNormal([SAMPLES], 0, 1.5, 'float32', SEED);
          expect(result.dtype).toBe('float32');
          expect(result.shape).toEqual([SAMPLES]);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 1.5, EPSILON);
      });
      it('should return a int32 1D of random normal values', function () {
          var SAMPLES = 10000;
          var result = tf.randomNormal([SAMPLES], 0, 2, 'int32', SEED);
          expect(result.dtype).toBe('int32');
          expect(result.shape).toEqual([SAMPLES]);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 2, EPSILON);
      });
      it('should return a float32 2D of random normal values', function () {
          var SAMPLES = 100;
          var result = tf.randomNormal([SAMPLES, SAMPLES], 0, 2.5, null, SEED);
          expect(result.dtype).toBe('float32');
          expect(result.shape).toEqual([SAMPLES, SAMPLES]);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 2.5, EPSILON);
          result = tf.randomNormal([SAMPLES, SAMPLES], 0, 3.5, 'float32', SEED);
          expect(result.dtype).toBe('float32');
          expect(result.shape).toEqual([SAMPLES, SAMPLES]);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 3.5, EPSILON);
      });
      it('should return a int32 2D of random normal values', function () {
          var SAMPLES = 100;
          var result = tf.randomNormal([SAMPLES, SAMPLES], 0, 2, 'int32', SEED);
          expect(result.dtype).toBe('int32');
          expect(result.shape).toEqual([SAMPLES, SAMPLES]);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 2, EPSILON);
      });
      it('should return a float32 3D of random normal values', function () {
          var SAMPLES_SHAPE = [20, 20, 20];
          var result = tf.randomNormal(SAMPLES_SHAPE, 0, 0.5, null, SEED);
          expect(result.dtype).toBe('float32');
          expect(result.shape).toEqual(SAMPLES_SHAPE);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 0.5, EPSILON);
          result = tf.randomNormal(SAMPLES_SHAPE, 0, 1.5, 'float32', SEED);
          expect(result.dtype).toBe('float32');
          expect(result.shape).toEqual(SAMPLES_SHAPE);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 1.5, EPSILON);
      });
      it('should return a int32 3D of random normal values', function () {
          var SAMPLES_SHAPE = [20, 20, 20];
          var result = tf.randomNormal(SAMPLES_SHAPE, 0, 2, 'int32', SEED);
          expect(result.dtype).toBe('int32');
          expect(result.shape).toEqual(SAMPLES_SHAPE);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 2, EPSILON);
      });
      it('should return a float32 4D of random normal values', function () {
          var SAMPLES_SHAPE = [10, 10, 10, 10];
          var result = tf.randomNormal(SAMPLES_SHAPE, 0, 0.5, null, SEED);
          expect(result.dtype).toBe('float32');
          expect(result.shape).toEqual(SAMPLES_SHAPE);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 0.5, EPSILON);
          result = tf.randomNormal(SAMPLES_SHAPE, 0, 1.5, 'float32', SEED);
          expect(result.dtype).toBe('float32');
          expect(result.shape).toEqual(SAMPLES_SHAPE);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 1.5, EPSILON);
      });
      it('should return a int32 4D of random normal values', function () {
          var SAMPLES_SHAPE = [10, 10, 10, 10];
          var result = tf.randomNormal(SAMPLES_SHAPE, 0, 2, 'int32', SEED);
          expect(result.dtype).toBe('int32');
          expect(result.shape).toEqual(SAMPLES_SHAPE);
          rand_util_1.jarqueBeraNormalityTest(result);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 2, EPSILON);
      });
  });
  jasmine_util_1.describeWithFlags('truncatedNormal', test_util_1.ALL_ENVS, function () {
      var EPSILON = 0.60;
      var SEED = 2002;
      function assertTruncatedValues(array, mean, stdv) {
          var bounds = mean + stdv * 2;
          var values = array.dataSync();
          for (var i = 0; i < values.length; i++) {
              expect(Math.abs(values[i])).toBeLessThanOrEqual(bounds);
          }
      }
      it('should return a random 1D float32 array', function () {
          var shape = [1000];
          var result = tf.truncatedNormal(shape, 0, 3.5, null, SEED);
          expect(result.dtype).toBe('float32');
          assertTruncatedValues(result, 0, 3.5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 3.5, EPSILON);
          result = tf.truncatedNormal(shape, 0, 4.5, 'float32', SEED);
          expect(result.dtype).toBe('float32');
          assertTruncatedValues(result, 0, 4.5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 4.5, EPSILON);
      });
      it('should return a randon 1D int32 array', function () {
          var shape = [1000];
          var result = tf.truncatedNormal(shape, 0, 5, 'int32', SEED);
          expect(result.dtype).toBe('int32');
          assertTruncatedValues(result, 0, 5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 5, EPSILON);
      });
      it('should return a 2D float32 array', function () {
          var shape = [50, 50];
          var result = tf.truncatedNormal(shape, 0, 3.5, null, SEED);
          expect(result.dtype).toBe('float32');
          assertTruncatedValues(result, 0, 3.5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 3.5, EPSILON);
          result = tf.truncatedNormal(shape, 0, 4.5, 'float32', SEED);
          expect(result.dtype).toBe('float32');
          assertTruncatedValues(result, 0, 4.5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 4.5, EPSILON);
      });
      it('should return a 2D int32 array', function () {
          var shape = [50, 50];
          var result = tf.truncatedNormal(shape, 0, 5, 'int32', SEED);
          expect(result.dtype).toBe('int32');
          assertTruncatedValues(result, 0, 5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 5, EPSILON);
      });
      it('should return a 3D float32 array', function () {
          var shape = [10, 10, 10];
          var result = tf.truncatedNormal(shape, 0, 3.5, null, SEED);
          expect(result.dtype).toBe('float32');
          assertTruncatedValues(result, 0, 3.5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 3.5, EPSILON);
          result = tf.truncatedNormal(shape, 0, 4.5, 'float32', SEED);
          expect(result.dtype).toBe('float32');
          assertTruncatedValues(result, 0, 4.5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 4.5, EPSILON);
      });
      it('should return a 3D int32 array', function () {
          var shape = [10, 10, 10];
          var result = tf.truncatedNormal(shape, 0, 5, 'int32', SEED);
          expect(result.dtype).toBe('int32');
          assertTruncatedValues(result, 0, 5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 5, EPSILON);
      });
      it('should return a 4D float32 array', function () {
          var shape = [5, 5, 5, 5];
          var result = tf.truncatedNormal(shape, 0, 3.5, null, SEED);
          expect(result.dtype).toBe('float32');
          assertTruncatedValues(result, 0, 3.5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 3.5, EPSILON);
          result = tf.truncatedNormal(shape, 0, 4.5, 'float32', SEED);
          expect(result.dtype).toBe('float32');
          assertTruncatedValues(result, 0, 4.5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 4.5, EPSILON);
      });
      it('should return a 4D int32 array', function () {
          var shape = [5, 5, 5, 5];
          var result = tf.truncatedNormal(shape, 0, 5, 'int32', SEED);
          expect(result.dtype).toBe('int32');
          assertTruncatedValues(result, 0, 5);
          rand_util_1.expectArrayInMeanStdRange(result, 0, 5, EPSILON);
      });
  });
  jasmine_util_1.describeWithFlags('randomUniform', test_util_1.ALL_ENVS, function () {
      it('should return a random 1D float32 array', function () {
          var shape = [10];
          var result = tf.randomUniform(shape, 0, 2.5);
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 2.5);
          result = tf.randomUniform(shape, 0, 1.5, 'float32');
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 1.5);
      });
      it('should return a random 1D int32 array', function () {
          var shape = [10];
          var result = tf.randomUniform(shape, 0, 2, 'int32');
          expect(result.dtype).toBe('int32');
          test_util_1.expectValuesInRange(result, 0, 2);
      });
      it('should return a random 1D bool array', function () {
          var shape = [10];
          var result = tf.randomUniform(shape, 0, 1, 'bool');
          expect(result.dtype).toBe('bool');
          test_util_1.expectValuesInRange(result, 0, 1);
      });
      it('should return a random 2D float32 array', function () {
          var shape = [3, 4];
          var result = tf.randomUniform(shape, 0, 2.5);
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 2.5);
          result = tf.randomUniform(shape, 0, 1.5, 'float32');
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 1.5);
      });
      it('should return a random 2D int32 array', function () {
          var shape = [3, 4];
          var result = tf.randomUniform(shape, 0, 2, 'int32');
          expect(result.dtype).toBe('int32');
          test_util_1.expectValuesInRange(result, 0, 2);
      });
      it('should return a random 2D bool array', function () {
          var shape = [3, 4];
          var result = tf.randomUniform(shape, 0, 1, 'bool');
          expect(result.dtype).toBe('bool');
          test_util_1.expectValuesInRange(result, 0, 1);
      });
      it('should return a random 3D float32 array', function () {
          var shape = [3, 4, 5];
          var result = tf.randomUniform(shape, 0, 2.5);
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 2.5);
          result = tf.randomUniform(shape, 0, 1.5, 'float32');
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 1.5);
      });
      it('should return a random 3D int32 array', function () {
          var shape = [3, 4, 5];
          var result = tf.randomUniform(shape, 0, 2, 'int32');
          expect(result.dtype).toBe('int32');
          test_util_1.expectValuesInRange(result, 0, 2);
      });
      it('should return a random 3D bool array', function () {
          var shape = [3, 4, 5];
          var result = tf.randomUniform(shape, 0, 1, 'bool');
          expect(result.dtype).toBe('bool');
          test_util_1.expectValuesInRange(result, 0, 1);
      });
      it('should return a random 4D float32 array', function () {
          var shape = [3, 4, 5, 6];
          var result = tf.randomUniform(shape, 0, 2.5);
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 2.5);
          result = tf.randomUniform(shape, 0, 1.5, 'float32');
          expect(result.dtype).toBe('float32');
          test_util_1.expectValuesInRange(result, 0, 1.5);
      });
      it('should return a random 4D int32 array', function () {
          var shape = [3, 4, 5, 6];
          var result = tf.randomUniform(shape, 0, 2, 'int32');
          expect(result.dtype).toBe('int32');
          test_util_1.expectValuesInRange(result, 0, 2);
      });
      it('should return a random 4D bool array', function () {
          var shape = [3, 4, 5, 6];
          var result = tf.randomUniform(shape, 0, 1, 'bool');
          expect(result.dtype).toBe('bool');
          test_util_1.expectValuesInRange(result, 0, 1);
      });
  });
  jasmine_util_1.describeWithFlags('fromPixels', test_util_1.WEBGL_ENVS, function () {
      it('ImageData 1x1x3', function () {
          var pixels = new ImageData(1, 1);
          pixels.data[0] = 0;
          pixels.data[1] = 80;
          pixels.data[2] = 160;
          pixels.data[3] = 240;
          var array = tf.fromPixels(pixels, 3);
          test_util_1.expectArraysEqual(array, [0, 80, 160]);
      });
      it('ImageData 1x1x4', function () {
          var pixels = new ImageData(1, 1);
          pixels.data[0] = 0;
          pixels.data[1] = 80;
          pixels.data[2] = 160;
          pixels.data[3] = 240;
          var array = tf.fromPixels(pixels, 4);
          test_util_1.expectArraysEqual(array, [0, 80, 160, 240]);
      });
      it('ImageData 2x2x3', function () {
          var pixels = new ImageData(2, 2);
          for (var i = 0; i < 8; i++) {
              pixels.data[i] = i * 2;
          }
          for (var i = 8; i < 16; i++) {
              pixels.data[i] = i * 2;
          }
          var array = tf.fromPixels(pixels, 3);
          test_util_1.expectArraysEqual(array, [0, 2, 4, 8, 10, 12, 16, 18, 20, 24, 26, 28]);
      });
      it('ImageData 2x2x4', function () {
          var pixels = new ImageData(2, 2);
          for (var i = 0; i < 8; i++) {
              pixels.data[i] = i * 2;
          }
          for (var i = 8; i < 16; i++) {
              pixels.data[i] = i * 2;
          }
          var array = tf.fromPixels(pixels, 4);
          test_util_1.expectArraysClose(array, new Int32Array([0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30]));
      });
      it('fromPixels, 3 channels', function () {
          var pixels = new ImageData(1, 2);
          pixels.data[0] = 2;
          pixels.data[1] = 3;
          pixels.data[2] = 4;
          pixels.data[3] = 255;
          pixels.data[4] = 5;
          pixels.data[5] = 6;
          pixels.data[6] = 7;
          pixels.data[7] = 255;
          var res = tf.fromPixels(pixels, 3);
          expect(res.shape).toEqual([2, 1, 3]);
          expect(res.dtype).toBe('int32');
          test_util_1.expectArraysClose(res, [2, 3, 4, 5, 6, 7]);
      });
      it('fromPixels, reshape, then do tf.add()', function () {
          var pixels = new ImageData(1, 1);
          pixels.data[0] = 2;
          pixels.data[1] = 3;
          pixels.data[2] = 4;
          pixels.data[3] = 255;
          var a = tf.fromPixels(pixels, 3).reshape([1, 1, 1, 3]);
          var res = a.add(tf.scalar(2, 'int32'));
          expect(res.shape).toEqual([1, 1, 1, 3]);
          expect(res.dtype).toBe('int32');
          test_util_1.expectArraysClose(res, [4, 5, 6]);
      });
      it('fromPixels + fromPixels', function () {
          var pixelsA = new ImageData(1, 1);
          pixelsA.data[0] = 255;
          pixelsA.data[1] = 3;
          pixelsA.data[2] = 4;
          pixelsA.data[3] = 255;
          var pixelsB = new ImageData(1, 1);
          pixelsB.data[0] = 5;
          pixelsB.data[1] = 6;
          pixelsB.data[2] = 7;
          pixelsB.data[3] = 255;
          var a = tf.fromPixels(pixelsA, 3).toFloat();
          var b = tf.fromPixels(pixelsB, 3).toFloat();
          var res = a.add(b);
          expect(res.shape).toEqual([1, 1, 3]);
          expect(res.dtype).toBe('float32');
          test_util_1.expectArraysClose(res, [260, 9, 11]);
      });
  });
  jasmine_util_1.describeWithFlags('toPixels no canvas', test_util_1.ALL_ENVS, function () {
      it('draws a rank-2 float32 tensor', function (done) {
          var x = tf.tensor2d([.1, .2], [2, 1], 'float32');
          tf.toPixels(x).then(function (data) {
              var expected = new Uint8ClampedArray([
                  Math.round(.1 * 255), Math.round(.1 * 255), Math.round(.1 * 255), 255,
                  Math.round(.2 * 255), Math.round(.2 * 255), Math.round(.2 * 255), 255
              ]);
              expect(data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-2 int32 tensor', function (done) {
          var x = tf.tensor2d([10, 20], [2, 1], 'int32');
          tf.toPixels(x).then(function (data) {
              var expected = new Uint8ClampedArray([10, 10, 10, 255, 20, 20, 20, 255]);
              expect(data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 float32 tensor, 1 channel', function (done) {
          var x = tf.tensor3d([.1, .2], [2, 1, 1], 'float32');
          tf.toPixels(x).then(function (data) {
              var expected = new Uint8ClampedArray([
                  Math.round(.1 * 255), Math.round(.1 * 255), Math.round(.1 * 255), 255,
                  Math.round(.2 * 255), Math.round(.2 * 255), Math.round(.2 * 255), 255
              ]);
              expect(data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 int32 tensor, 1 channel', function (done) {
          var x = tf.tensor3d([10, 20], [2, 1, 1], 'int32');
          tf.toPixels(x).then(function (data) {
              var expected = new Uint8ClampedArray([10, 10, 10, 255, 20, 20, 20, 255]);
              expect(data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 float32 tensor, 3 channel', function (done) {
          var x = tf.tensor3d([.05, .1, .15, .2, .25, .3], [2, 1, 3], 'float32');
          tf.toPixels(x).then(function (data) {
              var expected = new Uint8ClampedArray([
                  Math.round(.05 * 255), Math.round(.1 * 255), Math.round(.15 * 255), 255,
                  Math.round(.2 * 255), Math.round(.25 * 255), Math.round(.30 * 255), 255
              ]);
              expect(data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 int32 tensor, 3 channel', function (done) {
          var x = tf.tensor3d([10, 20, 30, 40, 50, 60], [2, 1, 3], 'int32');
          tf.toPixels(x).then(function (data) {
              var expected = new Uint8ClampedArray([10, 20, 30, 255, 40, 50, 60, 255]);
              expect(data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 float32 tensor, 4 channel', function (done) {
          var x = tf.tensor3d([.05, .1, .15, .2, .25, .3, .35, .4], [2, 1, 4], 'float32');
          tf.toPixels(x).then(function (data) {
              var expected = new Uint8ClampedArray([
                  Math.round(.05 * 255), Math.round(.1 * 255), Math.round(.15 * 255),
                  Math.round(.20 * 255), Math.round(.25 * 255), Math.round(.30 * 255),
                  Math.round(.35 * 255), Math.round(.4 * 255)
              ]);
              expect(data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 int32 tensor, 4 channel', function (done) {
          var x = tf.tensor3d([10, 20, 30, 40, 50, 60, 70, 80], [2, 1, 4], 'int32');
          tf.toPixels(x).then(function (data) {
              var expected = new Uint8ClampedArray([10, 20, 30, 40, 50, 60, 70, 80]);
              expect(data).toEqual(expected);
              done();
          });
      });
      it('throws for scalars', function (done) {
          test_util_1.expectPromiseToFail(function () { return tf.toPixels(tf.scalar(1)); }, done);
      });
      it('throws for rank-1 tensors', function (done) {
          test_util_1.expectPromiseToFail(function () { return tf.toPixels(tf.tensor1d([1])); }, done);
      });
      it('throws for rank-4 tensors', function (done) {
          test_util_1.expectPromiseToFail(function () { return tf.toPixels(tf.tensor4d([1], [1, 1, 1, 1])); }, done);
      });
      it('throws for bool dtype', function (done) {
          test_util_1.expectPromiseToFail(function () { return tf.toPixels(tf.tensor2d([1], [1, 1], 'bool')); }, done);
      });
      it('throws for rank-3 depth = 2', function (done) {
          test_util_1.expectPromiseToFail(function () { return tf.toPixels(tf.tensor3d([1, 2], [1, 1, 2])); }, done);
      });
      it('throws for rank-3 depth = 5', function (done) {
          test_util_1.expectPromiseToFail(function () { return tf.toPixels(tf.tensor3d([1, 2, 3, 4, 5], [1, 1, 5])); }, done);
      });
      it('throws for float32 tensor with values not in [0 - 1]', function (done) {
          test_util_1.expectPromiseToFail(function () { return tf.toPixels(tf.tensor2d([-1, .5], [1, 2])); }, done);
      });
      it('throws for int32 tensor with values not in [0 - 255]', function (done) {
          test_util_1.expectPromiseToFail(function () { return tf.toPixels(tf.tensor2d([-1, 100], [1, 2], 'int32')); }, done);
      });
      it('throws when passed a non-tensor', function (done) {
          test_util_1.expectPromiseToFail(function () { return tf.toPixels({}); }, done);
      });
  });
  jasmine_util_1.describeWithFlags('toPixels', test_util_1.WEBGL_ENVS, function () {
      it('draws a rank-2 float32 tensor, canvas', function (done) {
          var x = tf.tensor2d([.1, .2], [2, 1], 'float32');
          var canvas = document.createElement('canvas');
          tf.toPixels(x, canvas).then(function (data) {
              var expected = new Uint8ClampedArray([
                  Math.round(.1 * 255), Math.round(.1 * 255), Math.round(.1 * 255), 255,
                  Math.round(.2 * 255), Math.round(.2 * 255), Math.round(.2 * 255), 255
              ]);
              expect(data).toEqual(expected);
              var ctx = canvas.getContext('2d');
              var imgData = ctx.getImageData(0, 0, 1, 2);
              expect(imgData.data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-2 int32 tensor, canvas', function (done) {
          var x = tf.tensor2d([10, 20], [2, 1], 'int32');
          var canvas = document.createElement('canvas');
          tf.toPixels(x, canvas).then(function (data) {
              var expected = new Uint8ClampedArray([10, 10, 10, 255, 20, 20, 20, 255]);
              expect(data).toEqual(expected);
              var ctx = canvas.getContext('2d');
              var imgData = ctx.getImageData(0, 0, 1, 2);
              expect(imgData.data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 float32 tensor, 1 channel, canvas', function (done) {
          var x = tf.tensor3d([.1, .2], [2, 1, 1], 'float32');
          var canvas = document.createElement('canvas');
          tf.toPixels(x, canvas).then(function (data) {
              var expected = new Uint8ClampedArray([
                  Math.round(.1 * 255), Math.round(.1 * 255), Math.round(.1 * 255), 255,
                  Math.round(.2 * 255), Math.round(.2 * 255), Math.round(.2 * 255), 255
              ]);
              expect(data).toEqual(expected);
              var ctx = canvas.getContext('2d');
              var imgData = ctx.getImageData(0, 0, 1, 2);
              expect(imgData.data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 int32 tensor, 1 channel, canvas', function (done) {
          var x = tf.tensor3d([10, 20], [2, 1, 1], 'int32');
          var canvas = document.createElement('canvas');
          tf.toPixels(x, canvas).then(function (data) {
              var expected = new Uint8ClampedArray([10, 10, 10, 255, 20, 20, 20, 255]);
              expect(data).toEqual(expected);
              var ctx = canvas.getContext('2d');
              var imgData = ctx.getImageData(0, 0, 1, 2);
              expect(imgData.data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 float32 tensor, 3 channel, canvas', function (done) {
          var x = tf.tensor3d([.05, .1, .15, .20, .25, .30], [2, 1, 3], 'float32');
          var canvas = document.createElement('canvas');
          tf.toPixels(x, canvas).then(function (data) {
              var expected = new Uint8ClampedArray([
                  Math.round(.05 * 255), Math.round(.1 * 255), Math.round(.15 * 255), 255,
                  Math.round(.2 * 255), Math.round(.25 * 255), Math.round(.3 * 255), 255
              ]);
              expect(data).toEqual(expected);
              var ctx = canvas.getContext('2d');
              var imgData = ctx.getImageData(0, 0, 1, 2);
              expect(imgData.data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 int32 tensor, 3 channel, canvas', function (done) {
          var x = tf.tensor3d([10, 20, 30, 40, 50, 60], [2, 1, 3], 'int32');
          var canvas = document.createElement('canvas');
          tf.toPixels(x, canvas).then(function (data) {
              var expected = new Uint8ClampedArray([10, 20, 30, 255, 40, 50, 60, 255]);
              expect(data).toEqual(expected);
              var ctx = canvas.getContext('2d');
              var imgData = ctx.getImageData(0, 0, 1, 2);
              expect(imgData.data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 float32 tensor, 4 channel, canvas', function (done) {
          var x = tf.tensor3d([.05, .1, .15, 1, .20, .25, .30, 1], [2, 1, 4], 'float32');
          var canvas = document.createElement('canvas');
          tf.toPixels(x, canvas).then(function (data) {
              var expected = new Uint8ClampedArray([
                  Math.round(.05 * 255), Math.round(.1 * 255), Math.round(.15 * 255), 255,
                  Math.round(.20 * 255), Math.round(.25 * 255), Math.round(.30 * 255), 255
              ]);
              expect(data).toEqual(expected);
              var ctx = canvas.getContext('2d');
              var imgData = ctx.getImageData(0, 0, 1, 2);
              expect(imgData.data).toEqual(expected);
              done();
          });
      });
      it('draws a rank-3 int32 tensor, 4 channel, canvas', function (done) {
          var x = tf.tensor3d([10, 20, 30, 255, 50, 60, 70, 255], [2, 1, 4], 'int32');
          var canvas = document.createElement('canvas');
          tf.toPixels(x, canvas).then(function (data) {
              var expected = new Uint8ClampedArray([10, 20, 30, 255, 50, 60, 70, 255]);
              expect(data).toEqual(expected);
              var ctx = canvas.getContext('2d');
              var imgData = ctx.getImageData(0, 0, 1, 2);
              expect(imgData.data).toEqual(expected);
              done();
          });
      });
  });
  jasmine_util_1.describeWithFlags('clone', test_util_1.ALL_ENVS, function () {
      it('1D default dtype', function () {
          var a = tf.tensor1d([1, 2, 3]);
          var b = tf.clone(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysClose(b, [1, 2, 3]);
      });
      it('1D float32 dtype', function () {
          var a = tf.tensor1d([1, 2, 3], 'float32');
          var b = tf.clone(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysClose(b, [1, 2, 3]);
      });
      it('1D int32 dtype', function () {
          var a = tf.tensor1d([1, 2, 3], 'int32');
          var b = tf.clone(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysEqual(b, [1, 2, 3]);
      });
      it('1D bool dtype', function () {
          var a = tf.tensor1d([1, 1, 0], 'bool');
          var b = tf.clone(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([3]);
          test_util_1.expectArraysEqual(b, [1, 1, 0]);
      });
      it('2D default dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2]);
          var b = tf.clone(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(b, [1, 2, 3, 4]);
      });
      it('2D float32 dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2], 'float32');
          var b = tf.clone(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(b, [1, 2, 3, 4]);
      });
      it('2D int32 dtype', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2], 'int32');
          var b = tf.clone(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysEqual(b, [1, 2, 3, 4]);
      });
      it('2D bool dtype', function () {
          var a = tf.tensor2d([1, 1, 1, 0], [2, 2], 'bool');
          var b = tf.clone(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([2, 2]);
          test_util_1.expectArraysEqual(b, [1, 1, 1, 0]);
      });
      it('3D default dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1]);
          var b = tf.clone(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(b, [1, 2, 3, 4]);
      });
      it('3D float32 dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1], 'float32');
          var b = tf.clone(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(b, [1, 2, 3, 4]);
      });
      it('3D int32 dtype', function () {
          var a = tf.tensor3d([1, 2, 3, 4], [2, 2, 1], 'int32');
          var b = tf.clone(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysEqual(b, [1, 2, 3, 4]);
      });
      it('3D bool dtype', function () {
          var a = tf.tensor3d([1, 1, 1, 0], [2, 2, 1], 'bool');
          var b = tf.clone(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysEqual(b, [1, 1, 1, 0]);
      });
      it('4D default dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1]);
          var b = tf.clone(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysClose(b, [1, 2, 3, 4]);
      });
      it('4D float32 dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1], 'float32');
          var b = tf.clone(a);
          expect(b.dtype).toBe('float32');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysClose(b, [1, 2, 3, 4]);
      });
      it('4D int32 dtype', function () {
          var a = tf.tensor4d([1, 2, 3, 4], [2, 2, 1, 1], 'int32');
          var b = tf.clone(a);
          expect(b.dtype).toBe('int32');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysEqual(b, [1, 2, 3, 4]);
      });
      it('4D bool dtype', function () {
          var a = tf.tensor4d([1, 1, 1, 0], [2, 2, 1, 1], 'bool');
          var b = tf.clone(a);
          expect(b.dtype).toBe('bool');
          expect(b.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysEqual(b, [1, 1, 1, 0]);
      });
      it('gradient: 1D', function () {
          var a = tf.tensor1d([1, 2, 3]);
          var dy = tf.tensor1d([4, 5, 6]);
          var da = tf.grad(function (x) { return tf.clone(x); })(a, dy);
          expect(da.dtype).toBe('float32');
          expect(da.shape).toEqual([3]);
          test_util_1.expectArraysClose(da, [4, 5, 6]);
      });
      it('gradient: 2D int32', function () {
          var a = tf.tensor2d([1, 2, 3, 4], [2, 2], 'int32');
          var dy = tf.tensor2d([5, 6, 7, 8], [2, 2], 'float32');
          var da = tf.grad(function (x) { return tf.clone(x); })(a, dy);
          expect(da.dtype).toBe('float32');
          expect(da.shape).toEqual([2, 2]);
          test_util_1.expectArraysEqual(da, [5, 6, 7, 8]);
      });
      it('gradient: 4D bool', function () {
          var a = tf.tensor4d([1, 1, 1, 0], [2, 2, 1, 1], 'bool');
          var dy = tf.tensor4d([5, 6, 7, 8], [2, 2, 1, 1], 'float32');
          var da = tf.grad(function (x) { return tf.clone(x); })(a, dy);
          expect(da.dtype).toBe('float32');
          expect(da.shape).toEqual([2, 2, 1, 1]);
          test_util_1.expectArraysEqual(da, [5, 6, 7, 8]);
      });
      it('throws when passed a non-tensor', function () {
          expect(function () { return tf.clone({}); })
              .toThrowError(/Argument 'x' passed to 'clone' must be a Tensor/);
      });
  });
  jasmine_util_1.describeWithFlags('tile', test_util_1.ALL_ENVS, function () {
      it('1D (tile)', function () {
          var t = tf.tensor1d([1, 2, 3]);
          var t2 = tf.tile(t, [2]);
          expect(t2.shape).toEqual([6]);
          test_util_1.expectArraysClose(t2, [1, 2, 3, 1, 2, 3]);
      });
      it('2D (tile)', function () {
          var t = tf.tensor2d([1, 11, 2, 22], [2, 2]);
          var t2 = tf.tile(t, [1, 2]);
          expect(t2.shape).toEqual([2, 4]);
          test_util_1.expectArraysClose(t2, [1, 11, 1, 11, 2, 22, 2, 22]);
          t2 = tf.tile(t, [2, 1]);
          expect(t2.shape).toEqual([4, 2]);
          test_util_1.expectArraysClose(t2, [1, 11, 2, 22, 1, 11, 2, 22]);
          t2 = tf.tile(t, [2, 2]);
          expect(t2.shape).toEqual([4, 4]);
          test_util_1.expectArraysClose(t2, [1, 11, 1, 11, 2, 22, 2, 22, 1, 11, 1, 11, 2, 22, 2, 22]);
      });
      it('3D (tile)', function () {
          var t = tf.tensor3d([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2]);
          var t2 = tf.tile(t, [1, 2, 1]);
          expect(t2.shape).toEqual([2, 4, 2]);
          test_util_1.expectArraysClose(t2, [1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7, 8, 5, 6, 7, 8]);
      });
      it('propagates NaNs', function () {
          var t = tf.tensor1d([1, 2, NaN]);
          var t2 = tf.tile(t, [2]);
          expect(t2.shape).toEqual([6]);
          test_util_1.expectArraysClose(t2, [1, 2, NaN, 1, 2, NaN]);
      });
      it('1D bool (tile)', function () {
          var t = tf.tensor1d([true, false, true], 'bool');
          var t2 = tf.tile(t, [2]);
          expect(t2.shape).toEqual([6]);
          expect(t2.dtype).toBe('bool');
          test_util_1.expectArraysEqual(t2, [1, 0, 1, 1, 0, 1]);
      });
      it('2D bool (tile)', function () {
          var t = tf.tensor2d([true, false, true, true], [2, 2], 'bool');
          var t2 = tf.tile(t, [1, 2]);
          expect(t2.shape).toEqual([2, 4]);
          expect(t2.dtype).toBe('bool');
          test_util_1.expectArraysEqual(t2, [1, 0, 1, 0, 1, 1, 1, 1]);
          t2 = tf.tile(t, [2, 1]);
          expect(t2.shape).toEqual([4, 2]);
          expect(t2.dtype).toBe('bool');
          test_util_1.expectArraysEqual(t2, [1, 0, 1, 1, 1, 0, 1, 1]);
          t2 = tf.tile(t, [2, 2]);
          expect(t2.shape).toEqual([4, 4]);
          expect(t2.dtype).toBe('bool');
          test_util_1.expectArraysEqual(t2, [1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1]);
      });
      it('3D bool (tile)', function () {
          var t = tf.tensor3d([true, false, true, false, true, false, true, false], [2, 2, 2], 'bool');
          var t2 = tf.tile(t, [1, 2, 1]);
          expect(t2.shape).toEqual([2, 4, 2]);
          expect(t2.dtype).toBe('bool');
          test_util_1.expectArraysEqual(t2, [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]);
      });
      it('1D int32 (tile)', function () {
          var t = tf.tensor1d([1, 2, 5], 'int32');
          var t2 = tf.tile(t, [2]);
          expect(t2.shape).toEqual([6]);
          expect(t2.dtype).toBe('int32');
          test_util_1.expectArraysEqual(t2, [1, 2, 5, 1, 2, 5]);
      });
      it('2D int32 (tile)', function () {
          var t = tf.tensor2d([1, 2, 3, 4], [2, 2], 'int32');
          var t2 = tf.tile(t, [1, 2]);
          expect(t2.shape).toEqual([2, 4]);
          expect(t2.dtype).toBe('int32');
          test_util_1.expectArraysEqual(t2, [1, 2, 1, 2, 3, 4, 3, 4]);
          t2 = tf.tile(t, [2, 1]);
          expect(t2.shape).toEqual([4, 2]);
          expect(t2.dtype).toBe('int32');
          test_util_1.expectArraysEqual(t2, [1, 2, 3, 4, 1, 2, 3, 4]);
          t2 = tf.tile(t, [2, 2]);
          expect(t2.shape).toEqual([4, 4]);
          expect(t2.dtype).toBe('int32');
          test_util_1.expectArraysEqual(t2, [1, 2, 1, 2, 3, 4, 3, 4, 1, 2, 1, 2, 3, 4, 3, 4]);
      });
      it('3D int32 (tile)', function () {
          var t = tf.tensor3d([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2], 'int32');
          var t2 = tf.tile(t, [1, 2, 1]);
          expect(t2.shape).toEqual([2, 4, 2]);
          expect(t2.dtype).toBe('int32');
          test_util_1.expectArraysEqual(t2, [1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7, 8, 5, 6, 7, 8]);
      });
      it('1D (tile) gradient', function () {
          var x = tf.tensor1d([1, 2, 3]);
          var dy = tf.tensor1d([0.1, 0.2, 0.3, 1, 2, 3, 10, 20, 30]);
          var gradients = tf.grad(function (x) { return tf.tile(x, [3]); })(x, dy);
          test_util_1.expectArraysClose(gradients, tf.tensor1d([11.1, 22.2, 33.3]));
      });
      it('2D (tile) gradient', function () {
          var x = tf.tensor2d([[1, 2], [3, 4]], [2, 2]);
          var dy = tf.tensor2d([[1, 2, 10, 20], [3, 4, 30, 40]], [2, 4]);
          var gradients = tf.grad(function (x) { return tf.tile(x, [1, 2]); })(x, dy);
          test_util_1.expectArraysClose(gradients, tf.tensor2d([[11, 22], [33, 44]], [2, 2]));
      });
      it('3D (tile) gradient', function () {
          var x = tf.tensor3d([[[1], [2]], [[3], [4]]], [2, 2, 1]);
          var dy = tf.tensor3d([[[1, 10], [2, 20]], [[3, 30], [4, 40]]], [2, 2, 2]);
          var gradients = tf.grad(function (x) { return tf.tile(x, [1, 1, 2]); })(x, dy);
          test_util_1.expectArraysClose(gradients, tf.tensor3d([[[11], [22]], [[33], [44]]], [2, 2, 1]));
      });
      it('4D (tile) gradient', function () {
          var x = tf.tensor4d([[[[1]], [[2]]], [[[3]], [[4]]]], [2, 2, 1, 1]);
          var dy = tf.tensor4d([
              [[[1, 10], [100, 1000]], [[2, 20], [200, 2000]]],
              [[[3, 30], [300, 3000]], [[4, 40], [400, 4000]]]
          ], [2, 2, 2, 2]);
          var gradients = tf.grad(function (x) { return tf.tile(x, [1, 1, 2, 2]); })(x, dy);
          test_util_1.expectArraysClose(gradients, tf.tensor4d([[[[1111]], [[2222]]], [[[3333]], [[4444]]]], [2, 2, 1, 1]));
      });
      it('throws when passed a non-tensor', function () {
          expect(function () { return tf.tile({}, [1]); })
              .toThrowError(/Argument 'x' passed to 'tile' must be a Tensor/);
      });
  });
  jasmine_util_1.describeWithFlags('gather', test_util_1.ALL_ENVS, function () {
      it('1D (gather)', function () {
          var t = tf.tensor1d([1, 2, 3]);
          var t2 = tf.gather(t, tf.tensor1d([0, 2, 0, 1], 'int32'), 0);
          expect(t2.shape).toEqual([4]);
          test_util_1.expectArraysClose(t2, [1, 3, 1, 2]);
      });
      it('2D (gather)', function () {
          var t = tf.tensor2d([1, 11, 2, 22], [2, 2]);
          var t2 = tf.gather(t, tf.tensor1d([1, 0, 0, 1], 'int32'), 0);
          expect(t2.shape).toEqual([4, 2]);
          test_util_1.expectArraysClose(t2, [2, 22, 1, 11, 1, 11, 2, 22]);
          t2 = tf.gather(t, tf.tensor1d([1, 0, 0, 1], 'int32'), 1);
          expect(t2.shape).toEqual([2, 4]);
          test_util_1.expectArraysClose(t2, [11, 1, 1, 11, 22, 2, 2, 22]);
      });
      it('3D (gather)', function () {
          var t = tf.tensor3d([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2]);
          var t2 = tf.gather(t, tf.tensor1d([1, 0, 0, 1], 'int32'), 2);
          expect(t2.shape).toEqual([2, 2, 4]);
          test_util_1.expectArraysClose(t2, [2, 1, 1, 2, 4, 3, 3, 4, 6, 5, 5, 6, 8, 7, 7, 8]);
      });
      it('bool (gather)', function () {
          var t = tf.tensor1d([true, false, true], 'bool');
          var t2 = tf.gather(t, tf.tensor1d([0, 2, 0, 1], 'int32'), 0);
          expect(t2.shape).toEqual([4]);
          expect(t2.dtype).toBe('bool');
          expect(t2.dataSync()).toEqual(new Uint8Array([1, 1, 1, 0]));
      });
      it('int32 (gather)', function () {
          var t = tf.tensor1d([1, 2, 5], 'int32');
          var t2 = tf.gather(t, tf.tensor1d([0, 2, 0, 1], 'int32'), 0);
          expect(t2.shape).toEqual([4]);
          expect(t2.dtype).toBe('int32');
          expect(t2.dataSync()).toEqual(new Int32Array([1, 5, 1, 2]));
      });
      it('propagates NaNs', function () {
          var t = tf.tensor1d([1, 2, NaN]);
          var t2 = tf.gather(t, tf.tensor1d([0, 2, 0, 1], 'int32'), 0);
          expect(t2.shape).toEqual([4]);
          test_util_1.expectArraysClose(t2, [1, NaN, 1, 2]);
      });
      it('chaining, axis=1', function () {
          var x = tf.zeros([2, 4, 6]);
          var indices = tf.range(0, 6, 2, 'int32');
          var axis = 2;
          expect(x.gather(indices, axis).shape).toEqual([2, 4, 3]);
      });
      it('indices not int32 throws error', function () {
          var x = tf.zeros([2, 4, 6]);
          var indices = tf.range(0, 6, 2);
          var axis = 2;
          expect(function () { return x.gather(indices, axis); }).toThrowError();
      });
      it('throws when passed x as a non-tensor', function () {
          expect(function () { return tf.gather({}, tf.tensor1d([1])); })
              .toThrowError(/Argument 'x' passed to 'gather' must be a Tensor/);
      });
      it('throws when passed indices as a non-tensor', function () {
          expect(function () { return tf.gather(tf.tensor1d([1]), {}); })
              .toThrowError(/Argument 'indices' passed to 'gather' must be a Tensor/);
      });
      it('gradient 1D (gather)', function () {
          var t = tf.tensor1d([1, 2, 3]);
          var indices = tf.tensor1d([0, 2, 0, 1], 'int32');
          var dy = tf.tensor([3, 4, 5, 6]);
          var gradients = tf.grad(function (t) { return tf.gather(t, indices); })(t, dy);
          expect(gradients.shape).toEqual(t.shape);
          test_util_1.expectArraysClose(gradients, [8, 6, 4]);
      });
      it('gradient 2D (gather) axis=0', function () {
          var t = tf.tensor2d([1, 11, 2, 22], [2, 2]);
          var indices = tf.tensor1d([1, 0, 0, 1], 'int32');
          var dy = tf.tensor([3, 4, 5, 6, 7, 8, 9, 10], [4, 2]);
          var axis = 0;
          var gradients = tf.grad(function (t) { return tf.gather(t, indices, axis); })(t, dy);
          expect(gradients.shape).toEqual(t.shape);
          test_util_1.expectArraysClose(gradients, [12, 14, 12, 14]);
      });
      it('gradient 2D (gather) axis=1', function () {
          var t = tf.tensor2d([1, 11, 2, 22], [2, 2]);
          var indices = tf.tensor1d([1, 0, 0, 1], 'int32');
          var dy = tf.tensor([3, 4, 5, 6, 7, 8, 9, 10], [2, 4]);
          var axis = 1;
          var gradients = tf.grad(function (t) { return tf.gather(t, indices, axis); })(t, dy);
          expect(gradients.shape).toEqual(t.shape);
          test_util_1.expectArraysClose(gradients, [9, 9, 17, 17]);
      });
      it('gradient 3D (gather) axis=0', function () {
          var t = tf.tensor3d([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [2, 3, 2]);
          var indices = tf.tensor1d([1, 0, 0, 1], 'int32');
          var dy = tf.tensor([
              2, -3, 4, 15, 6, 0.7, 1, 18, 0.01, 0, 12, 13,
              4, 15, 12, -7, 18, 19, 2, 21, 6, 23, 24, 25
          ], [4, 3, 2]);
          var axis = 0;
          var gradients = tf.grad(function (t) { return tf.gather(t, indices, axis); })(t, dy);
          expect(gradients.shape).toEqual(t.shape);
          test_util_1.expectArraysClose(gradients, [5, 33, 12.01, -7, 30, 32, 4, 18, 10, 38, 30, 25.7]);
      });
      it('gradient 3D (gather) axis=1', function () {
          var t = tf.tensor3d([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [2, 3, 2]);
          var indices = tf.tensor1d([1, 2, 2, 1], 'int32');
          var dy = tf.tensor([2, -3, 4, 15, 6, 0.7, 1, 18, 0.01, 0, 12, 13, 4, 15, 12, -7], [2, 4, 2]);
          var axis = 1;
          var gradients = tf.grad(function (t) { return tf.gather(t, indices, axis); })(t, dy);
          expect(gradients.shape).toEqual(t.shape);
          test_util_1.expectArraysClose(gradients, [0, 0, 3, 15, 10, 15.7, 0, 0, 12.01, -7, 16, 28]);
      });
      it('gradient 3D (gather) axis=2', function () {
          var t = tf.tensor3d([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [2, 3, 2]);
          var indices = tf.tensor1d([1, 0, 1, 0], 'int32');
          var dy = tf.tensor([
              2, -3, 4, 15, 6, 0.7, 1, 18, 0.01, 0, 12, 13,
              4, 15, 12, -7, 18, 19, 2, 21, 6, 23, 24, 25
          ], [2, 3, 4]);
          var axis = 2;
          var gradients = tf.grad(function (t) { return tf.gather(t, indices, axis); })(t, dy);
          expect(gradients.shape).toEqual(t.shape);
          test_util_1.expectArraysClose(gradients, [12, 6, 18.7, 7, 13, 12.01, 8, 16, 40, 20, 48, 30]);
      });
  });
  jasmine_util_1.describeWithFlags('oneHot', test_util_1.ALL_ENVS, function () {
      it('Depth 1 throws error', function () {
          var indices = tf.tensor1d([0, 0, 0], 'int32');
          expect(function () { return tf.oneHot(indices, 1); }).toThrowError();
      });
      it('Depth 2, diagonal', function () {
          var indices = tf.tensor1d([0, 1], 'int32');
          var res = tf.oneHot(indices, 2);
          expect(res.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res, [1, 0, 0, 1]);
      });
      it('Depth 2, transposed diagonal', function () {
          var indices = tf.tensor1d([1, 0], 'int32');
          var res = tf.oneHot(indices, 2);
          expect(res.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res, [0, 1, 1, 0]);
      });
      it('Depth 3, 4 events', function () {
          var indices = tf.tensor1d([2, 1, 2, 0], 'int32');
          var res = tf.oneHot(indices, 3);
          expect(res.shape).toEqual([4, 3]);
          test_util_1.expectArraysClose(res, [0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0]);
      });
      it('Depth 2 onValue=3, offValue=-2', function () {
          var indices = tf.tensor1d([0, 1], 'int32');
          var res = tf.oneHot(indices, 2, 3, -2);
          expect(res.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res, [3, -2, -2, 3]);
      });
      it('indices not int32 throws error', function () {
          var indices = tf.tensor1d([0, 1], 'float32');
          expect(function () { return tf.oneHot(indices, 2); }).toThrowError();
      });
  });
  jasmine_util_1.describeWithFlags('linspace', test_util_1.ALL_ENVS, function () {
      it('start stop', function () {
          var a = tf.linspace(1, 10, 10);
          test_util_1.expectArraysEqual(a, [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]);
          expect(a.shape).toEqual([10]);
          var b = tf.linspace(12, 17, 8);
          test_util_1.expectArraysClose(b, [
              12., 12.71428571, 13.42857143, 14.14285714, 14.85714286, 15.57142857,
              16.28571429, 17.
          ]);
          expect(b.shape).toEqual([8]);
          var c = tf.linspace(9, 0, 6);
          test_util_1.expectArraysClose(c, [9., 7.2, 5.4, 3.6, 1.8, 0.]);
          expect(c.shape).toEqual([6]);
      });
      it('negative start stop', function () {
          var a = tf.linspace(-4, 5, 6);
          test_util_1.expectArraysClose(a, [-4., -2.2, -0.4, 1.4, 3.2, 5.]);
          expect(a.shape).toEqual([6]);
      });
      it('start negative stop', function () {
          var a = tf.linspace(4, -5, 6);
          test_util_1.expectArraysClose(a, [4., 2.2, 0.4, -1.4, -3.2, -5.]);
          expect(a.shape).toEqual([6]);
      });
      it('negative start negative stop', function () {
          var a = tf.linspace(-4, -5, 6);
          test_util_1.expectArraysClose(a, [-4., -4.2, -4.4, -4.6, -4.8, -5.]);
          expect(a.shape).toEqual([6]);
          var b = tf.linspace(-9, -4, 5);
          test_util_1.expectArraysClose(b, [-9., -7.75, -6.5, -5.25, -4.]);
          expect(b.shape).toEqual([5]);
      });
      it('should throw with no samples', function () {
          expect(function () { return tf.linspace(2, 10, 0); }).toThrow();
      });
  });
  jasmine_util_1.describeWithFlags('range', test_util_1.ALL_ENVS, function () {
      it('start stop', function () {
          var a = tf.range(0, 3);
          test_util_1.expectArraysEqual(a, [0, 1, 2]);
          expect(a.shape).toEqual([3]);
          var b = tf.range(3, 8);
          test_util_1.expectArraysEqual(b, [3, 4, 5, 6, 7]);
          expect(b.shape).toEqual([5]);
      });
      it('start stop negative', function () {
          var a = tf.range(-2, 3);
          test_util_1.expectArraysEqual(a, [-2, -1, 0, 1, 2]);
          expect(a.shape).toEqual([5]);
          var b = tf.range(4, -2);
          test_util_1.expectArraysEqual(b, [4, 3, 2, 1, 0, -1]);
          expect(b.shape).toEqual([6]);
      });
      it('start stop step', function () {
          var a = tf.range(4, 15, 4);
          test_util_1.expectArraysEqual(a, [4, 8, 12]);
          expect(a.shape).toEqual([3]);
          var b = tf.range(4, 11, 4);
          test_util_1.expectArraysEqual(b, [4, 8]);
          expect(b.shape).toEqual([2]);
          var c = tf.range(4, 17, 4);
          test_util_1.expectArraysEqual(c, [4, 8, 12, 16]);
          expect(c.shape).toEqual([4]);
          var d = tf.range(0, 30, 5);
          test_util_1.expectArraysEqual(d, [0, 5, 10, 15, 20, 25]);
          expect(d.shape).toEqual([6]);
          var e = tf.range(-3, 9, 2);
          test_util_1.expectArraysEqual(e, [-3, -1, 1, 3, 5, 7]);
          expect(e.shape).toEqual([6]);
          var f = tf.range(3, 3);
          test_util_1.expectArraysEqual(f, new Float32Array(0));
          expect(f.shape).toEqual([0]);
          var g = tf.range(3, 3, 1);
          test_util_1.expectArraysEqual(g, new Float32Array(0));
          expect(g.shape).toEqual([0]);
          var h = tf.range(3, 3, 4);
          test_util_1.expectArraysEqual(h, new Float32Array(0));
          expect(h.shape).toEqual([0]);
          var i = tf.range(-18, -2, 5);
          test_util_1.expectArraysEqual(i, [-18, -13, -8, -3]);
          expect(i.shape).toEqual([4]);
      });
      it('start stop large step', function () {
          var a = tf.range(3, 10, 150);
          test_util_1.expectArraysEqual(a, [3]);
          expect(a.shape).toEqual([1]);
          var b = tf.range(10, 500, 205);
          test_util_1.expectArraysEqual(b, [10, 215, 420]);
          expect(b.shape).toEqual([3]);
          var c = tf.range(3, -10, -150);
          test_util_1.expectArraysEqual(c, [3]);
          expect(c.shape).toEqual([1]);
          var d = tf.range(-10, -500, -205);
          test_util_1.expectArraysEqual(d, [-10, -215, -420]);
          expect(d.shape).toEqual([3]);
      });
      it('start stop negative step', function () {
          var a = tf.range(0, -10, -1);
          test_util_1.expectArraysEqual(a, [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]);
          expect(a.shape).toEqual([10]);
          var b = tf.range(0, -10);
          test_util_1.expectArraysEqual(b, [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]);
          expect(b.shape).toEqual([10]);
          var c = tf.range(3, -4, -2);
          test_util_1.expectArraysEqual(c, [3, 1, -1, -3]);
          expect(c.shape).toEqual([4]);
          var d = tf.range(-3, -18, -5);
          test_util_1.expectArraysEqual(d, [-3, -8, -13]);
          expect(d.shape).toEqual([3]);
      });
      it('start stop incompatible step', function () {
          var a = tf.range(3, 10, -2);
          test_util_1.expectArraysEqual(a, new Float32Array(0));
          expect(a.shape).toEqual([0]);
          var b = tf.range(40, 3, 2);
          test_util_1.expectArraysEqual(b, new Float32Array(0));
          expect(b.shape).toEqual([0]);
      });
      it('zero step', function () {
          expect(function () { return tf.range(2, 10, 0); }).toThrow();
      });
      it('should have default dtype', function () {
          var a = tf.range(1, 4);
          test_util_1.expectArraysEqual(a, [1, 2, 3]);
          expect(a.dtype).toEqual('float32');
          expect(a.shape).toEqual([3]);
      });
      it('should have float32 dtype', function () {
          var a = tf.range(1, 4, undefined, 'float32');
          test_util_1.expectArraysEqual(a, [1, 2, 3]);
          expect(a.dtype).toEqual('float32');
          expect(a.shape).toEqual([3]);
      });
      it('should have int32 dtype', function () {
          var a = tf.range(1, 4, undefined, 'int32');
          test_util_1.expectArraysEqual(a, [1, 2, 3]);
          expect(a.dtype).toEqual('int32');
          expect(a.shape).toEqual([3]);
      });
  });
  jasmine_util_1.describeWithFlags('fill', test_util_1.ALL_ENVS, function () {
      it('1D fill', function () {
          var a = tf.fill([3], 2);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3]);
          test_util_1.expectArraysClose(a, [2, 2, 2]);
      });
      it('2D fill', function () {
          var a = tf.fill([3, 2], 2);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2]);
          test_util_1.expectArraysClose(a, [2, 2, 2, 2, 2, 2]);
      });
      it('3D fill', function () {
          var a = tf.fill([3, 2, 1], 2);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2, 1]);
          test_util_1.expectArraysClose(a, [2, 2, 2, 2, 2, 2]);
      });
      it('4D fill', function () {
          var a = tf.fill([3, 2, 1, 2], 2);
          expect(a.dtype).toBe('float32');
          expect(a.shape).toEqual([3, 2, 1, 2]);
          test_util_1.expectArraysClose(a, [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]);
      });
  });
  jasmine_util_1.describeWithFlags('stack', test_util_1.ALL_ENVS, function () {
      it('scalars 3, 5 and 7', function () {
          var a = tf.scalar(3);
          var b = tf.scalar(5);
          var c = tf.scalar(7);
          var res = tf.stack([a, b, c]);
          expect(res.shape).toEqual([3]);
          test_util_1.expectArraysClose(res, [3, 5, 7]);
      });
      it('scalars 3, 5 and 7 along axis=1 throws error', function () {
          var a = tf.scalar(3);
          var b = tf.scalar(5);
          var c = tf.scalar(7);
          var f = function () { return tf.stack([a, b, c], 1); };
          expect(f).toThrowError();
      });
      it('non matching shapes throws error', function () {
          var a = tf.scalar(3);
          var b = tf.tensor1d([5]);
          var f = function () { return tf.stack([a, b]); };
          expect(f).toThrowError();
      });
      it('non matching dtypes throws error', function () {
          var a = tf.scalar(3);
          var b = tf.scalar(5, 'bool');
          var f = function () { return tf.stack([a, b]); };
          expect(f).toThrowError();
      });
      it('2d but axis=3 throws error', function () {
          var a = tf.zeros([2, 2]);
          var b = tf.zeros([2, 2]);
          var f = function () { return tf.stack([a, b], 3); };
          expect(f).toThrowError();
      });
      it('[1,2], [3,4] and [5,6], axis=0', function () {
          var a = tf.tensor1d([1, 2]);
          var b = tf.tensor1d([3, 4]);
          var c = tf.tensor1d([5, 6]);
          var res = tf.stack([a, b, c], 0);
          expect(res.shape).toEqual([3, 2]);
          test_util_1.expectArraysClose(res, [1, 2, 3, 4, 5, 6]);
      });
      it('[1,2], [3,4] and [5,6], axis=1', function () {
          var a = tf.tensor1d([1, 2]);
          var b = tf.tensor1d([3, 4]);
          var c = tf.tensor1d([5, 6]);
          var res = tf.stack([a, b, c], 1);
          expect(res.shape).toEqual([2, 3]);
          test_util_1.expectArraysClose(res, [1, 3, 5, 2, 4, 6]);
      });
      it('[[1,2],[3,4]] and [[5, 6], [7, 8]], axis=0', function () {
          var a = tf.tensor2d([[1, 2], [3, 4]]);
          var b = tf.tensor2d([[5, 6], [7, 8]]);
          var res = tf.stack([a, b], 0);
          expect(res.shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysClose(res, [1, 2, 3, 4, 5, 6, 7, 8]);
      });
      it('[[1,2],[3,4]] and [[5, 6], [7, 8]], axis=2', function () {
          var a = tf.tensor2d([[1, 2], [3, 4]]);
          var b = tf.tensor2d([[5, 6], [7, 8]]);
          var c = tf.tensor2d([[9, 10], [11, 12]]);
          var res = tf.stack([a, b, c], 2);
          expect(res.shape).toEqual([2, 2, 3]);
          test_util_1.expectArraysClose(res, [1, 5, 9, 2, 6, 10, 3, 7, 11, 4, 8, 12]);
      });
      it('single tensor', function () {
          var a = tf.tensor2d([[1, 2], [3, 4]]);
          var res = tf.stack([a], 2);
          expect(res.shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(res, [1, 2, 3, 4]);
      });
      it('throws when passed a non-tensor', function () {
          expect(function () { return tf.stack([{}]); })
              .toThrowError(/Argument 'tensors\[0\]' passed to 'stack' must be a Tensor/);
      });
  });
  jasmine_util_1.describeWithFlags('unstack', test_util_1.ALL_ENVS, function () {
      it('unstack by default', function () {
          var x = tf.tensor2d([1, 2, 3, 4, 5, 6, 7, 8], [2, 4]);
          var res = tf.unstack(x);
          expect(res.length).toEqual(2);
          expect(res[0].rank).toEqual(1);
          expect(res[0].shape).toEqual([4]);
          test_util_1.expectArraysClose(res[0], [1, 2, 3, 4]);
          expect(res[1].rank).toEqual(1);
          expect(res[1].shape).toEqual([4]);
          test_util_1.expectArraysClose(res[1], [5, 6, 7, 8]);
      });
      it('unstack into 3 tensors', function () {
          var x = tf.tensor2d([1, 2, 3, 4, 5, 6], [3, 2]);
          var res = tf.unstack(x, 0);
          expect(res.length).toEqual(3);
          expect(res[0].rank).toEqual(1);
          expect(res[0].shape).toEqual([2]);
          test_util_1.expectArraysClose(res[0], [1, 2]);
          expect(res[1].rank).toEqual(1);
          expect(res[1].shape).toEqual([2]);
          test_util_1.expectArraysClose(res[1], [3, 4]);
          expect(res[2].rank).toEqual(1);
          expect(res[2].shape).toEqual([2]);
          test_util_1.expectArraysClose(res[2], [5, 6]);
      });
      it('unstack by axis=1', function () {
          var x = tf.tensor2d([1, 2, 3, 4, 5, 6, 7, 8], [2, 4]);
          var res = tf.unstack(x, 1);
          expect(res.length).toEqual(4);
          expect(res[0].rank).toEqual(1);
          expect(res[0].shape).toEqual([2]);
          test_util_1.expectArraysClose(res[0], [1, 5]);
          expect(res[1].rank).toEqual(1);
          expect(res[1].shape).toEqual([2]);
          test_util_1.expectArraysClose(res[1], [2, 6]);
          expect(res[2].rank).toEqual(1);
          expect(res[2].shape).toEqual([2]);
          test_util_1.expectArraysClose(res[2], [3, 7]);
          expect(res[3].rank).toEqual(1);
          expect(res[3].shape).toEqual([2]);
          test_util_1.expectArraysClose(res[3], [4, 8]);
      });
      it('unstack rank 3 tensor', function () {
          var x = tf.tensor3d([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2]);
          var res = tf.unstack(x);
          expect(res.length).toEqual(2);
          expect(res[0].rank).toEqual(2);
          expect(res[0].shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res[0], [1, 2, 3, 4]);
          expect(res[1].rank).toEqual(2);
          expect(res[1].shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res[1], [5, 6, 7, 8]);
      });
      it('unstack rank 3 tensor with axis=1', function () {
          var x = tf.tensor3d([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2]);
          var res = tf.unstack(x, 1);
          expect(res.length).toEqual(2);
          expect(res[0].rank).toEqual(2);
          expect(res[0].shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res[0], [1, 2, 5, 6]);
          expect(res[1].rank).toEqual(2);
          expect(res[1].shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res[1], [3, 4, 7, 8]);
      });
      it('unstack rank 3 tensor with axis=2', function () {
          var x = tf.tensor3d([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2]);
          var res = tf.unstack(x, 2);
          expect(res.length).toEqual(2);
          expect(res[0].rank).toEqual(2);
          expect(res[0].shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res[0], [1, 3, 5, 7]);
          expect(res[1].rank).toEqual(2);
          expect(res[1].shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res[1], [2, 4, 6, 8]);
      });
      it('unstack rank 4 tensor', function () {
          var x = tf.tensor4d([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2, 1]);
          var res = tf.unstack(x);
          expect(res.length).toEqual(2);
          expect(res[0].rank).toEqual(3);
          expect(res[0].shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(res[0], [1, 2, 3, 4]);
          expect(res[1].rank).toEqual(3);
          expect(res[1].shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(res[1], [5, 6, 7, 8]);
      });
      it('unstack rank 4 tensor with axis=1', function () {
          var x = tf.tensor4d([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2, 1]);
          var res = tf.unstack(x, 1);
          expect(res.length).toEqual(2);
          expect(res[0].rank).toEqual(3);
          expect(res[0].shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(res[0], [1, 2, 5, 6]);
          expect(res[1].rank).toEqual(3);
          expect(res[1].shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(res[1], [3, 4, 7, 8]);
      });
      it('unstack rank 4 tensor with axis=2', function () {
          var x = tf.tensor4d([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2, 1]);
          var res = tf.unstack(x, 2);
          expect(res.length).toEqual(2);
          expect(res[0].rank).toEqual(3);
          expect(res[0].shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(res[0], [1, 3, 5, 7]);
          expect(res[1].rank).toEqual(3);
          expect(res[1].shape).toEqual([2, 2, 1]);
          test_util_1.expectArraysClose(res[1], [2, 4, 6, 8]);
      });
      it('unstack rank 4 tensor with axis=3', function () {
          var x = tf.tensor4d([1, 2, 3, 4, 5, 6, 7, 8], [2, 2, 2, 1]);
          var res = tf.unstack(x, 3);
          expect(res.length).toEqual(1);
          expect(res[0].rank).toEqual(3);
          expect(res[0].shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysClose(res[0], [1, 2, 3, 4, 5, 6, 7, 8]);
      });
  });
  jasmine_util_1.describeWithFlags('split', test_util_1.ALL_ENVS, function () {
      it('split by number', function () {
          var x = tf.tensor2d([1, 2, 3, 4, 5, 6, 7, 8], [2, 4]);
          var res = tf.split(x, 2, 1);
          expect(res.length).toEqual(2);
          expect(res[0].shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res[0], [1, 2, 5, 6]);
          expect(res[1].shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res[1], [3, 4, 7, 8]);
      });
      it('split by sizes', function () {
          var x = tf.tensor2d([1, 2, 3, 4, 5, 6, 7, 8], [2, 4]);
          var res = tf.split(x, [1, 2, 1], 1);
          expect(res.length).toEqual(3);
          expect(res[0].shape).toEqual([2, 1]);
          test_util_1.expectArraysClose(res[0], [1, 5]);
          expect(res[1].shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res[1], [2, 3, 6, 7]);
          expect(res[2].shape).toEqual([2, 1]);
          test_util_1.expectArraysClose(res[2], [4, 8]);
      });
      it('sizes to not sum to axis size throws error', function () {
          var x = tf.tensor2d([1, 2, 3, 4, 5, 6, 7, 8], [2, 4]);
          var f = function () { return tf.split(x, [1, 2], 1); };
          expect(f).toThrowError();
      });
      it('number of splits does not evenly divide axis', function () {
          var x = tf.tensor2d([1, 2, 3, 4, 5, 6, 7, 8], [2, 4]);
          var f = function () { return tf.split(x, 3, 1); };
          expect(f).toThrowError();
      });
      it('throws when passed a non-tensor', function () {
          expect(function () { return tf.split({}, 1); })
              .toThrowError(/Argument 'x' passed to 'split' must be a Tensor/);
      });
  });
  jasmine_util_1.describeWithFlags('expandDims', test_util_1.ALL_ENVS, function () {
      it('scalar, default axis is 0', function () {
          var res = tf.scalar(1).expandDims();
          expect(res.shape).toEqual([1]);
          test_util_1.expectArraysClose(res, [1]);
      });
      it('scalar, axis is out of bounds throws error', function () {
          var f = function () { return tf.scalar(1).expandDims(1); };
          expect(f).toThrowError();
      });
      it('1d, axis=0', function () {
          var res = tf.tensor1d([1, 2, 3]).expandDims(0);
          expect(res.shape).toEqual([1, 3]);
          test_util_1.expectArraysClose(res, [1, 2, 3]);
      });
      it('1d, axis=1', function () {
          var res = tf.tensor1d([1, 2, 3]).expandDims(1);
          expect(res.shape).toEqual([3, 1]);
          test_util_1.expectArraysClose(res, [1, 2, 3]);
      });
      it('2d, axis=0', function () {
          var res = tf.tensor2d([[1, 2], [3, 4], [5, 6]]).expandDims(0);
          expect(res.shape).toEqual([1, 3, 2]);
          test_util_1.expectArraysClose(res, [1, 2, 3, 4, 5, 6]);
      });
      it('2d, axis=1', function () {
          var res = tf.tensor2d([[1, 2], [3, 4], [5, 6]]).expandDims(1);
          expect(res.shape).toEqual([3, 1, 2]);
          test_util_1.expectArraysClose(res, [1, 2, 3, 4, 5, 6]);
      });
      it('2d, axis=2', function () {
          var res = tf.tensor2d([[1, 2], [3, 4], [5, 6]]).expandDims(2);
          expect(res.shape).toEqual([3, 2, 1]);
          test_util_1.expectArraysClose(res, [1, 2, 3, 4, 5, 6]);
      });
      it('throws when passed a non-tensor', function () {
          expect(function () { return tf.expandDims({}); })
              .toThrowError(/Argument 'x' passed to 'expandDims' must be a Tensor/);
      });
  });
  jasmine_util_1.describeWithFlags('cumsum', test_util_1.ALL_ENVS, function () {
      it('1D standard', function () {
          var res = tf.tensor1d([1, 2, 3, 4]).cumsum();
          expect(res.shape).toEqual([4]);
          test_util_1.expectArraysClose(res, [1, 3, 6, 10]);
      });
      it('1D reverse', function () {
          var reverse = true;
          var exclusive = false;
          var res = tf.tensor1d([1, 2, 3, 4]).cumsum(0, exclusive, reverse);
          expect(res.shape).toEqual([4]);
          test_util_1.expectArraysClose(res, [10, 9, 7, 4]);
      });
      it('1D exclusive', function () {
          var exclusive = true;
          var res = tf.tensor1d([1, 2, 3, 4]).cumsum(0, exclusive);
          expect(res.shape).toEqual([4]);
          test_util_1.expectArraysClose(res, [0, 1, 3, 6]);
      });
      it('1D exclusive reverse', function () {
          var reverse = true;
          var exclusive = true;
          var res = tf.tensor1d([1, 2, 3, 4]).cumsum(0, exclusive, reverse);
          expect(res.shape).toEqual([4]);
          test_util_1.expectArraysClose(res, [9, 7, 4, 0]);
      });
      it('gradient: 1D', function () {
          var a = tf.tensor1d([1, 2, 3]);
          var dy = tf.tensor1d([4, 5, 6]);
          var da = tf.grad(function (x) { return tf.cumsum(x); })(a, dy);
          expect(da.shape).toEqual([3]);
          test_util_1.expectArraysClose(da, [15, 11, 6]);
      });
      it('2D standard', function () {
          var res = tf.tensor2d([[1, 2], [3, 4]]).cumsum(1);
          expect(res.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res, [1, 3, 3, 7]);
      });
      it('2D reverse exclusive', function () {
          var reverse = true;
          var exclusive = true;
          var res = tf.tensor2d([[1, 2], [3, 4]]).cumsum(1, exclusive, reverse);
          expect(res.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res, [2, 0, 4, 0]);
      });
      it('2D axis=0', function () {
          var res = tf.tensor2d([[1, 2], [3, 4]]).cumsum();
          expect(res.shape).toEqual([2, 2]);
          test_util_1.expectArraysClose(res, [1, 2, 4, 6]);
      });
      it('3D standard', function () {
          var res = tf.tensor3d([[[0, 1], [2, 3]], [[4, 5], [6, 7]]]).cumsum(2);
          expect(res.shape).toEqual([2, 2, 2]);
          test_util_1.expectArraysClose(res, [0, 1, 2, 5, 4, 9, 6, 13]);
      });
  });
  //# sourceMappingURL=array_ops_test.js.map