UNPKG

@tensorflow/tfjs-core

Version:

Hardware-accelerated JavaScript library for machine intelligence

960 lines 88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tf = require("../index"); var test_util_1 = require("../test_util"); var jasmine_util_1 = require("../jasmine_util"); jasmine_util_1.describeWithFlags('equal', test_util_1.ALL_ENVS, function () { it('Tensor1D - int32', function () { var a = tf.tensor1d([1, 4, 5], 'int32'); var b = tf.tensor1d([2, 3, 5], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 1]); a = tf.tensor1d([2, 2, 2], 'int32'); b = tf.tensor1d([2, 2, 2], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 1, 1]); a = tf.tensor1d([0, 0], 'int32'); b = tf.tensor1d([3, 3], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0]); }); it('Tensor1D - float32', function () { var a = tf.tensor1d([1.1, 4.1, 5.1], 'float32'); var b = tf.tensor1d([2.2, 3.2, 5.1], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 1]); a = tf.tensor1d([2.31, 2.31, 2.31], 'float32'); b = tf.tensor1d([2.31, 2.31, 2.31], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 1, 1]); a = tf.tensor1d([0.45, 0.123], 'float32'); b = tf.tensor1d([3.123, 3.321], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0]); }); it('mismatched Tensor1D shapes - int32', function () { var a = tf.tensor1d([1, 2], 'int32'); var b = tf.tensor1d([1, 2, 3], 'int32'); var f = function () { tf.equal(a, b); }; expect(f).toThrowError(); }); it('mismatched Tensor1D shapes - float32', function () { var a = tf.tensor1d([1.1, 2.1], 'float32'); var b = tf.tensor1d([1.1, 2.1, 3.1], 'float32'); var f = function () { tf.equal(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor1D - float32', function () { var a = tf.tensor1d([1.1, NaN, 2.1], 'float32'); var b = tf.tensor1d([2.1, 3.1, NaN], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 0]); }); it('scalar and 1D broadcast', function () { var a = tf.scalar(2); var b = tf.tensor1d([1, 2, 3, 4, 5, 2]); var res = tf.equal(a, b); expect(res.dtype).toBe('bool'); expect(res.shape).toEqual([6]); test_util_1.expectArraysEqual(res, [0, 1, 0, 0, 0, 1]); }); it('Tensor2D - int32', function () { var a = tf.tensor2d([[1, 4, 5], [8, 9, 12]], [2, 3], 'int32'); var b = tf.tensor2d([[2, 3, 6], [7, 10, 11]], [2, 3], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 0, 0, 0, 0]); a = tf.tensor2d([[0, 0], [1, 1]], [2, 2], 'int32'); b = tf.tensor2d([[0, 0], [1, 1]], [2, 2], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 1, 1, 1]); }); it('Tensor2D - float32', function () { var a = tf.tensor2d([[1.1, 4.1, 5.1], [8.1, 9.1, 12.1]], [2, 3], 'float32'); var b = tf.tensor2d([[2.1, 4.1, 5.1], [7.1, 10.1, 11.1]], [2, 3], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 1, 1, 0, 0, 0]); a = tf.tensor2d([[0.2, 0.2], [1.2, 1.2]], [2, 2], 'float32'); b = tf.tensor2d([[0.2, 0.2], [1.2, 1.2]], [2, 2], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 1, 1, 1]); }); it('broadcasting Tensor2D shapes - int32', function () { var a = tf.tensor2d([[3], [7]], [2, 1], 'int32'); var b = tf.tensor2d([[2, 3, 4], [7, 8, 9]], [2, 3], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 1, 0, 1, 0, 0]); }); it('broadcasting Tensor2D shapes - float32', function () { var a = tf.tensor2d([[1.1], [7.1]], [2, 1], 'float32'); var b = tf.tensor2d([[0.1, 1.1, 2.1], [7.1, 8.1, 9.1]], [2, 3], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 1, 0, 1, 0, 0]); }); it('NaNs in Tensor2D - float32', function () { var a = tf.tensor2d([[1.1, NaN], [1.1, NaN]], [2, 2], 'float32'); var b = tf.tensor2d([[0.1, NaN], [1.1, NaN]], [2, 2], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 1, 0]); }); it('2D and 2D broadcast each with 1 dim', function () { var a = tf.tensor2d([1, 2, 5], [1, 3]); var b = tf.tensor2d([5, 1], [2, 1]); var res = tf.equal(a, b); expect(res.dtype).toBe('bool'); expect(res.shape).toEqual([2, 3]); test_util_1.expectArraysEqual(res, [0, 0, 1, 1, 0, 0]); }); it('2D and scalar broadcast', function () { var a = tf.tensor2d([1, 2, 3, 2, 5, 6], [2, 3]); var b = tf.scalar(2); var res = tf.equal(a, b); expect(res.dtype).toBe('bool'); expect(res.shape).toEqual([2, 3]); test_util_1.expectArraysEqual(res, [0, 1, 0, 1, 0, 0]); }); it('Tensor3D - int32', function () { var a = tf.tensor3d([[[1], [4], [5]], [[8], [9], [12]]], [2, 3, 1], 'int32'); var b = tf.tensor3d([[[2], [3], [6]], [[7], [10], [12]]], [2, 3, 1], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 0, 0, 0, 1]); a = tf.tensor3d([[[0], [0], [0]], [[1], [1], [1]]], [2, 3, 1], 'int32'); b = tf.tensor3d([[[0], [0], [0]], [[1], [1], [1]]], [2, 3, 1], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 1, 1, 1, 1, 1]); }); it('Tensor3D - float32', function () { var a = tf.tensor3d([[[1.1], [4.1], [5.1]], [[8.1], [9.1], [12.1]]], [2, 3, 1], 'float32'); var b = tf.tensor3d([[[2.1], [3.1], [6.1]], [[7.1], [10.1], [12.1]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 0, 0, 0, 1]); a = tf.tensor3d([[[0.1], [0.1], [0.1]], [[1.1], [1.1], [1.1]]], [2, 3, 1], 'float32'); b = tf.tensor3d([[[0.1], [0.1], [0.1]], [[1.1], [1.1], [1.1]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 1, 1, 1, 1, 1]); }); it('broadcasting Tensor3D shapes - int32', function () { var a = tf.tensor3d([[[1, 0], [2, 3], [4, 5]], [[6, 7], [9, 8], [10, 11]]], [2, 3, 2], 'int32'); var b = tf.tensor3d([[[1], [2], [3]], [[7], [10], [9]]], [2, 3, 1], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0]); }); it('broadcasting Tensor3D shapes - float32', function () { var a = tf.tensor3d([ [[1.1, 0.1], [2.1, 3.1], [4.1, 5.1]], [[6.1, 7.1], [9.1, 8.1], [10.1, 11.1]] ], [2, 3, 2], 'float32'); var b = tf.tensor3d([[[1.1], [2.1], [3.1]], [[7.1], [10.1], [9.1]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0]); }); it('NaNs in Tensor3D - float32', function () { var a = tf.tensor3d([[[1.1], [NaN], [1.1]], [[0.1], [0.1], [0.1]]], [2, 3, 1], 'float32'); var b = tf.tensor3d([[[0.1], [0.1], [1.1]], [[1.1], [0.1], [NaN]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 1, 0, 1, 0]); }); it('3D and scalar', function () { var a = tf.tensor3d([1, 2, 3, 4, 5, -1], [2, 3, 1]); var b = tf.scalar(-1); var res = tf.equal(a, b); expect(res.dtype).toBe('bool'); expect(res.shape).toEqual([2, 3, 1]); test_util_1.expectArraysEqual(res, [0, 0, 0, 0, 0, 1]); }); it('Tensor4D - int32', function () { var a = tf.tensor4d([1, 4, 5, 8], [2, 2, 1, 1], 'int32'); var b = tf.tensor4d([2, 3, 6, 8], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 0, 1]); a = tf.tensor4d([0, 1, 2, 3], [2, 2, 1, 1], 'int32'); b = tf.tensor4d([0, 1, 2, 3], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 1, 1, 1]); a = tf.tensor4d([1, 1, 1, 1], [2, 2, 1, 1], 'int32'); b = tf.tensor4d([2, 2, 2, 2], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 0, 0]); }); it('Tensor4D - float32', function () { var a = tf.tensor4d([1.1, 4.1, 5.1, 8.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([2.1, 3.1, 6.1, 8.1], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 0, 1]); a = tf.tensor4d([0.1, 1.1, 2.2, 3.3], [2, 2, 1, 1], 'float32'); b = tf.tensor4d([0.1, 1.1, 2.2, 3.3], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 1, 1, 1]); a = tf.tensor4d([0.1, 0.1, 0.1, 0.1], [2, 2, 1, 1], 'float32'); b = tf.tensor4d([1.1, 1.1, 1.1, 1.1], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 0, 0]); }); it('broadcasting Tensor4D shapes - int32', function () { var a = tf.tensor4d([1, 2, 5, 9], [2, 2, 1, 1], 'int32'); var b = tf.tensor4d([[[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8]]]], [2, 2, 1, 2], 'int32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 0, 0, 0, 1, 0, 0, 0]); }); it('broadcasting Tensor4D shapes - float32', function () { var a = tf.tensor4d([1.1, 2.1, 5.1, 9.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([[[[1.1, 2.1]], [[3.1, 4.1]]], [[[5.1, 6.1]], [[7.1, 8.1]]]], [2, 2, 1, 2], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [1, 0, 0, 0, 1, 0, 0, 0]); }); it('NaNs in Tensor4D - float32', function () { var a = tf.tensor4d([1.1, NaN, 1.1, 0.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([0.1, 1.1, 1.1, NaN], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.equal(a, b), [0, 0, 1, 0]); }); it('throws when passed a as a non-tensor', function () { expect(function () { return tf.equal({}, tf.scalar(1)); }) .toThrowError(/Argument 'a' passed to 'equal' must be a Tensor/); }); it('throws when passed b as a non-tensor', function () { expect(function () { return tf.equal(tf.scalar(1), {}); }) .toThrowError(/Argument 'b' passed to 'equal' must be a Tensor/); }); }); jasmine_util_1.describeWithFlags('equalStrict', test_util_1.ALL_ENVS, function () { it('Tensor1D - int32', function () { var a = tf.tensor1d([1, 4, 5], 'int32'); var b = tf.tensor1d([2, 3, 5], 'int32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 1]); a = tf.tensor1d([2, 2, 2], 'int32'); b = tf.tensor1d([2, 2, 2], 'int32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [1, 1, 1]); a = tf.tensor1d([0, 0], 'int32'); b = tf.tensor1d([3, 3], 'int32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0]); }); it('Tensor1D - float32', function () { var a = tf.tensor1d([1.1, 4.1, 5.1], 'float32'); var b = tf.tensor1d([2.2, 3.2, 5.1], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 1]); a = tf.tensor1d([2.31, 2.31, 2.31], 'float32'); b = tf.tensor1d([2.31, 2.31, 2.31], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [1, 1, 1]); a = tf.tensor1d([0.45, 0.123], 'float32'); b = tf.tensor1d([3.123, 3.321], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0]); }); it('mismatched Tensor1D shapes - int32', function () { var a = tf.tensor1d([1, 2], 'int32'); var b = tf.tensor1d([1, 2, 3], 'int32'); var f = function () { tf.equalStrict(a, b); }; expect(f).toThrowError(); }); it('mismatched Tensor1D shapes - float32', function () { var a = tf.tensor1d([1.1, 2.1], 'float32'); var b = tf.tensor1d([1.1, 2.1, 3.1], 'float32'); var f = function () { tf.equalStrict(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor1D - float32', function () { var a = tf.tensor1d([1.1, NaN, 2.1], 'float32'); var b = tf.tensor1d([2.1, 3.1, NaN], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 0]); }); it('Tensor2D - int32', function () { var a = tf.tensor2d([[1, 4, 5], [8, 9, 12]], [2, 3], 'int32'); var b = tf.tensor2d([[2, 3, 6], [7, 10, 11]], [2, 3], 'int32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 0, 0, 0, 0]); a = tf.tensor2d([[0, 0], [1, 1]], [2, 2], 'int32'); b = tf.tensor2d([[0, 0], [1, 1]], [2, 2], 'int32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [1, 1, 1, 1]); }); it('Tensor2D - float32', function () { var a = tf.tensor2d([[1.1, 4.1, 5.1], [8.1, 9.1, 12.1]], [2, 3], 'float32'); var b = tf.tensor2d([[2.1, 4.1, 5.1], [7.1, 10.1, 11.1]], [2, 3], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 1, 1, 0, 0, 0]); a = tf.tensor2d([[0.2, 0.2], [1.2, 1.2]], [2, 2], 'float32'); b = tf.tensor2d([[0.2, 0.2], [1.2, 1.2]], [2, 2], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [1, 1, 1, 1]); }); it('mismatch Tensor2D shapes - int32', function () { var a = tf.tensor2d([[3], [7]], [2, 1], 'int32'); var b = tf.tensor2d([[2, 3, 4], [7, 8, 9]], [2, 3], 'int32'); var f = function () { tf.equalStrict(a, b); }; expect(f).toThrowError(); }); it('mismatch Tensor2D shapes - float32', function () { var a = tf.tensor2d([[1.1], [7.1]], [2, 1], 'float32'); var b = tf.tensor2d([[0.1, 1.1, 2.1], [7.1, 8.1, 9.1]], [2, 3], 'float32'); var f = function () { tf.equalStrict(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor2D - float32', function () { var a = tf.tensor2d([[1.1, NaN], [1.1, NaN]], [2, 2], 'float32'); var b = tf.tensor2d([[0.1, NaN], [1.1, NaN]], [2, 2], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 1, 0]); }); it('Tensor3D - int32', function () { var a = tf.tensor3d([[[1], [4], [5]], [[8], [9], [12]]], [2, 3, 1], 'int32'); var b = tf.tensor3d([[[2], [3], [6]], [[7], [10], [12]]], [2, 3, 1], 'int32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 0, 0, 0, 1]); a = tf.tensor3d([[[0], [0], [0]], [[1], [1], [1]]], [2, 3, 1], 'int32'); b = tf.tensor3d([[[0], [0], [0]], [[1], [1], [1]]], [2, 3, 1], 'int32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [1, 1, 1, 1, 1, 1]); }); it('Tensor3D - float32', function () { var a = tf.tensor3d([[[1.1], [4.1], [5.1]], [[8.1], [9.1], [12.1]]], [2, 3, 1], 'float32'); var b = tf.tensor3d([[[2.1], [3.1], [6.1]], [[7.1], [10.1], [12.1]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 0, 0, 0, 1]); a = tf.tensor3d([[[0.1], [0.1], [0.1]], [[1.1], [1.1], [1.1]]], [2, 3, 1], 'float32'); b = tf.tensor3d([[[0.1], [0.1], [0.1]], [[1.1], [1.1], [1.1]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [1, 1, 1, 1, 1, 1]); }); it('mismatch Tensor3D shapes - int32', function () { var a = tf.tensor3d([[[1, 0], [2, 3], [4, 5]], [[6, 7], [9, 8], [10, 11]]], [2, 3, 2], 'int32'); var b = tf.tensor3d([[[1], [2], [3]], [[7], [10], [9]]], [2, 3, 1], 'int32'); var f = function () { tf.equalStrict(a, b); }; expect(f).toThrowError(); }); it('mismatch Tensor3D shapes - float32', function () { var a = tf.tensor3d([ [[1.1, 0.1], [2.1, 3.1], [4.1, 5.1]], [[6.1, 7.1], [9.1, 8.1], [10.1, 11.1]] ], [2, 3, 2], 'float32'); var b = tf.tensor3d([[[1.1], [2.1], [3.1]], [[7.1], [10.1], [9.1]]], [2, 3, 1], 'float32'); var f = function () { tf.equalStrict(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor3D - float32', function () { var a = tf.tensor3d([[[1.1], [NaN], [1.1]], [[0.1], [0.1], [0.1]]], [2, 3, 1], 'float32'); var b = tf.tensor3d([[[0.1], [0.1], [1.1]], [[1.1], [0.1], [NaN]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 1, 0, 1, 0]); }); it('Tensor4D - int32', function () { var a = tf.tensor4d([1, 4, 5, 8], [2, 2, 1, 1], 'int32'); var b = tf.tensor4d([2, 3, 6, 8], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 0, 1]); a = tf.tensor4d([0, 1, 2, 3], [2, 2, 1, 1], 'int32'); b = tf.tensor4d([0, 1, 2, 3], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [1, 1, 1, 1]); a = tf.tensor4d([1, 1, 1, 1], [2, 2, 1, 1], 'int32'); b = tf.tensor4d([2, 2, 2, 2], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 0, 0]); }); it('Tensor4D - float32', function () { var a = tf.tensor4d([1.1, 4.1, 5.1, 8.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([2.1, 3.1, 6.1, 8.1], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 0, 1]); a = tf.tensor4d([0.1, 1.1, 2.2, 3.3], [2, 2, 1, 1], 'float32'); b = tf.tensor4d([0.1, 1.1, 2.2, 3.3], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [1, 1, 1, 1]); a = tf.tensor4d([0.1, 0.1, 0.1, 0.1], [2, 2, 1, 1], 'float32'); b = tf.tensor4d([1.1, 1.1, 1.1, 1.1], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 0, 0]); }); it('mismatch Tensor4D shapes - int32', function () { var a = tf.tensor4d([1, 2, 5, 9], [2, 2, 1, 1], 'int32'); var b = tf.tensor4d([[[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8]]]], [2, 2, 1, 2], 'int32'); var f = function () { tf.equalStrict(a, b); }; expect(f).toThrowError(); }); it('mismatch Tensor4D shapes - float32', function () { var a = tf.tensor4d([1.1, 2.1, 5.1, 9.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([[[[1.1, 2.1]], [[3.1, 4.1]]], [[[5.1, 6.1]], [[7.1, 8.1]]]], [2, 2, 1, 2], 'float32'); var f = function () { tf.equalStrict(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor4D - float32', function () { var a = tf.tensor4d([1.1, NaN, 1.1, 0.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([0.1, 1.1, 1.1, NaN], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.equalStrict(a, b), [0, 0, 1, 0]); }); }); jasmine_util_1.describeWithFlags('notEqual', test_util_1.ALL_ENVS, function () { it('Tensor1D - int32', function () { var a = tf.tensor1d([1, 4, 5], 'int32'); var b = tf.tensor1d([2, 3, 5], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 0]); a = tf.tensor1d([2, 2, 2], 'int32'); b = tf.tensor1d([2, 2, 2], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 0, 0]); a = tf.tensor1d([0, 0], 'int32'); b = tf.tensor1d([3, 3], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1]); }); it('Tensor1D - float32', function () { var a = tf.tensor1d([1.1, 4.1, 5.1], 'float32'); var b = tf.tensor1d([2.2, 3.2, 5.1], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 0]); a = tf.tensor1d([2.31, 2.31, 2.31], 'float32'); b = tf.tensor1d([2.31, 2.31, 2.31], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 0, 0]); a = tf.tensor1d([0.45, 0.123], 'float32'); b = tf.tensor1d([3.123, 3.321], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1]); }); it('mismatched Tensor1D shapes - int32', function () { var a = tf.tensor1d([1, 2], 'int32'); var b = tf.tensor1d([1, 2, 3], 'int32'); var f = function () { tf.notEqual(a, b); }; expect(f).toThrowError(); }); it('mismatched Tensor1D shapes - float32', function () { var a = tf.tensor1d([1.1, 2.1], 'float32'); var b = tf.tensor1d([1.1, 2.1, 3.1], 'float32'); var f = function () { tf.notEqual(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor1D - float32', function () { var a = tf.tensor1d([1.1, NaN, 2.1], 'float32'); var b = tf.tensor1d([2.1, 3.1, NaN], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 1]); }); it('works with NaNs', function () { var a = tf.tensor1d([2, 5, NaN]); var b = tf.tensor1d([4, 5, -1]); var res = tf.notEqual(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysEqual(res, [1, 0, 1]); }); it('scalar and 1D broadcast', function () { var a = tf.scalar(2); var b = tf.tensor1d([1, 2, 3, 4, 5, 2]); var res = tf.notEqual(a, b); expect(res.dtype).toBe('bool'); expect(res.shape).toEqual([6]); test_util_1.expectArraysEqual(res, [1, 0, 1, 1, 1, 0]); }); it('Tensor2D - int32', function () { var a = tf.tensor2d([[1, 4, 5], [8, 9, 12]], [2, 3], 'int32'); var b = tf.tensor2d([[2, 3, 6], [7, 10, 11]], [2, 3], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 1, 1, 1, 1]); a = tf.tensor2d([[0, 0], [1, 1]], [2, 2], 'int32'); b = tf.tensor2d([[0, 0], [1, 1]], [2, 2], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 0, 0, 0]); }); it('Tensor2D - float32', function () { var a = tf.tensor2d([[1.1, 4.1, 5.1], [8.1, 9.1, 12.1]], [2, 3], 'float32'); var b = tf.tensor2d([[2.1, 4.1, 5.1], [7.1, 10.1, 11.1]], [2, 3], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 0, 0, 1, 1, 1]); a = tf.tensor2d([[0.2, 0.2], [1.2, 1.2]], [2, 2], 'float32'); b = tf.tensor2d([[0.2, 0.2], [1.2, 1.2]], [2, 2], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 0, 0, 0]); }); it('broadcasting Tensor2D shapes - int32', function () { var a = tf.tensor2d([[3], [7]], [2, 1], 'int32'); var b = tf.tensor2d([[2, 3, 4], [7, 8, 9]], [2, 3], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 0, 1, 0, 1, 1]); }); it('broadcasting Tensor2D shapes - float32', function () { var a = tf.tensor2d([[1.1], [7.1]], [2, 1], 'float32'); var b = tf.tensor2d([[0.1, 1.1, 2.1], [7.1, 8.1, 9.1]], [2, 3], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 0, 1, 0, 1, 1]); }); it('NaNs in Tensor2D - float32', function () { var a = tf.tensor2d([[1.1, NaN], [1.1, NaN]], [2, 2], 'float32'); var b = tf.tensor2d([[0.1, NaN], [1.1, NaN]], [2, 2], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 0, 1]); }); it('2D and scalar broadcast', function () { var a = tf.tensor2d([1, 2, 3, 2, 5, 6], [2, 3]); var b = tf.scalar(2); var res = tf.notEqual(a, b); expect(res.dtype).toBe('bool'); expect(res.shape).toEqual([2, 3]); test_util_1.expectArraysEqual(res, [1, 0, 1, 0, 1, 1]); }); it('2D and 2D broadcast each with 1 dim', function () { var a = tf.tensor2d([1, 2, 5], [1, 3]); var b = tf.tensor2d([5, 1], [2, 1]); var res = tf.notEqual(a, b); expect(res.dtype).toBe('bool'); expect(res.shape).toEqual([2, 3]); test_util_1.expectArraysEqual(res, [1, 1, 0, 0, 1, 1]); }); it('Tensor3D - int32', function () { var a = tf.tensor3d([[[1], [4], [5]], [[8], [9], [12]]], [2, 3, 1], 'int32'); var b = tf.tensor3d([[[2], [3], [6]], [[7], [10], [12]]], [2, 3, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 1, 1, 1, 0]); a = tf.tensor3d([[[0], [0], [0]], [[1], [1], [1]]], [2, 3, 1], 'int32'); b = tf.tensor3d([[[0], [0], [0]], [[1], [1], [1]]], [2, 3, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 0, 0, 0, 0, 0]); }); it('Tensor3D - float32', function () { var a = tf.tensor3d([[[1.1], [4.1], [5.1]], [[8.1], [9.1], [12.1]]], [2, 3, 1], 'float32'); var b = tf.tensor3d([[[2.1], [3.1], [6.1]], [[7.1], [10.1], [12.1]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 1, 1, 1, 0]); a = tf.tensor3d([[[0.1], [0.1], [0.1]], [[1.1], [1.1], [1.1]]], [2, 3, 1], 'float32'); b = tf.tensor3d([[[0.1], [0.1], [0.1]], [[1.1], [1.1], [1.1]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 0, 0, 0, 0, 0]); }); it('broadcasting Tensor3D shapes - int32', function () { var a = tf.tensor3d([[[1, 0], [2, 3], [4, 5]], [[6, 7], [9, 8], [10, 11]]], [2, 3, 2], 'int32'); var b = tf.tensor3d([[[1], [2], [3]], [[7], [10], [9]]], [2, 3, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1]); }); it('broadcasting Tensor3D shapes - float32', function () { var a = tf.tensor3d([ [[1.1, 0.1], [2.1, 3.1], [4.1, 5.1]], [[6.1, 7.1], [9.1, 8.1], [10.1, 11.1]] ], [2, 3, 2], 'float32'); var b = tf.tensor3d([[[1.1], [2.1], [3.1]], [[7.1], [10.1], [9.1]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1]); }); it('NaNs in Tensor3D - float32', function () { var a = tf.tensor3d([[[1.1], [NaN], [1.1]], [[0.1], [0.1], [0.1]]], [2, 3, 1], 'float32'); var b = tf.tensor3d([[[0.1], [0.1], [1.1]], [[1.1], [0.1], [NaN]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 0, 1, 0, 1]); }); it('3D and scalar', function () { var a = tf.tensor3d([1, 2, 3, 4, 5, -1], [2, 3, 1]); var b = tf.scalar(-1); var res = tf.notEqual(a, b); expect(res.dtype).toBe('bool'); expect(res.shape).toEqual([2, 3, 1]); test_util_1.expectArraysEqual(res, [1, 1, 1, 1, 1, 0]); }); it('Tensor4D - int32', function () { var a = tf.tensor4d([1, 4, 5, 8], [2, 2, 1, 1], 'int32'); var b = tf.tensor4d([2, 3, 6, 8], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 1, 0]); a = tf.tensor4d([0, 1, 2, 3], [2, 2, 1, 1], 'int32'); b = tf.tensor4d([0, 1, 2, 3], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 0, 0, 0]); a = tf.tensor4d([1, 1, 1, 1], [2, 2, 1, 1], 'int32'); b = tf.tensor4d([2, 2, 2, 2], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 1, 1]); }); it('Tensor4D - float32', function () { var a = tf.tensor4d([1.1, 4.1, 5.1, 8.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([2.1, 3.1, 6.1, 8.1], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 1, 0]); a = tf.tensor4d([0.1, 1.1, 2.2, 3.3], [2, 2, 1, 1], 'float32'); b = tf.tensor4d([0.1, 1.1, 2.2, 3.3], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 0, 0, 0]); a = tf.tensor4d([0.1, 0.1, 0.1, 0.1], [2, 2, 1, 1], 'float32'); b = tf.tensor4d([1.1, 1.1, 1.1, 1.1], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 1, 1]); }); it('broadcasting Tensor4D shapes - int32', function () { var a = tf.tensor4d([1, 2, 5, 9], [2, 2, 1, 1], 'int32'); var b = tf.tensor4d([[[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8]]]], [2, 2, 1, 2], 'int32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 1, 1, 1, 0, 1, 1, 1]); }); it('broadcasting Tensor4D shapes - float32', function () { var a = tf.tensor4d([1.1, 2.1, 5.1, 9.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([[[[1.1, 2.1]], [[3.1, 4.1]]], [[[5.1, 6.1]], [[7.1, 8.1]]]], [2, 2, 1, 2], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [0, 1, 1, 1, 0, 1, 1, 1]); }); it('NaNs in Tensor4D - float32', function () { var a = tf.tensor4d([1.1, NaN, 1.1, 0.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([0.1, 1.1, 1.1, NaN], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqual(a, b), [1, 1, 0, 1]); }); it('throws when passed a as a non-tensor', function () { expect(function () { return tf.notEqual({}, tf.scalar(1)); }) .toThrowError(/Argument 'a' passed to 'notEqual' must be a Tensor/); }); it('throws when passed b as a non-tensor', function () { expect(function () { return tf.notEqual(tf.scalar(1), {}); }) .toThrowError(/Argument 'b' passed to 'notEqual' must be a Tensor/); }); }); jasmine_util_1.describeWithFlags('notEqualStrict', test_util_1.ALL_ENVS, function () { it('Tensor1D - int32', function () { var a = tf.tensor1d([1, 4, 5], 'int32'); var b = tf.tensor1d([2, 3, 5], 'int32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 0]); a = tf.tensor1d([2, 2, 2], 'int32'); b = tf.tensor1d([2, 2, 2], 'int32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [0, 0, 0]); a = tf.tensor1d([0, 0], 'int32'); b = tf.tensor1d([3, 3], 'int32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1]); }); it('Tensor1D - float32', function () { var a = tf.tensor1d([1.1, 4.1, 5.1], 'float32'); var b = tf.tensor1d([2.2, 3.2, 5.1], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 0]); a = tf.tensor1d([2.31, 2.31, 2.31], 'float32'); b = tf.tensor1d([2.31, 2.31, 2.31], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [0, 0, 0]); a = tf.tensor1d([0.45, 0.123], 'float32'); b = tf.tensor1d([3.123, 3.321], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1]); }); it('mismatched Tensor1D shapes - int32', function () { var a = tf.tensor1d([1, 2], 'int32'); var b = tf.tensor1d([1, 2, 3], 'int32'); var f = function () { tf.notEqualStrict(a, b); }; expect(f).toThrowError(); }); it('mismatched Tensor1D shapes - float32', function () { var a = tf.tensor1d([1.1, 2.1], 'float32'); var b = tf.tensor1d([1.1, 2.1, 3.1], 'float32'); var f = function () { tf.notEqualStrict(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor1D - float32', function () { var a = tf.tensor1d([1.1, NaN, 2.1], 'float32'); var b = tf.tensor1d([2.1, 3.1, NaN], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 1]); }); it('strict version throws when x and y are different shape', function () { var a = tf.tensor1d([2]); var b = tf.tensor1d([4, 2, -1]); expect(function () { return tf.notEqualStrict(a, b); }).toThrowError(); expect(function () { return tf.notEqualStrict(b, a); }).toThrowError(); }); it('Tensor2D - int32', function () { var a = tf.tensor2d([[1, 4, 5], [8, 9, 12]], [2, 3], 'int32'); var b = tf.tensor2d([[2, 3, 6], [7, 10, 11]], [2, 3], 'int32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 1, 1, 1, 1]); a = tf.tensor2d([[0, 0], [1, 1]], [2, 2], 'int32'); b = tf.tensor2d([[0, 0], [1, 1]], [2, 2], 'int32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [0, 0, 0, 0]); }); it('Tensor2D - float32', function () { var a = tf.tensor2d([[1.1, 4.1, 5.1], [8.1, 9.1, 12.1]], [2, 3], 'float32'); var b = tf.tensor2d([[2.1, 4.1, 5.1], [7.1, 10.1, 11.1]], [2, 3], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 0, 0, 1, 1, 1]); a = tf.tensor2d([[0.2, 0.2], [1.2, 1.2]], [2, 2], 'float32'); b = tf.tensor2d([[0.2, 0.2], [1.2, 1.2]], [2, 2], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [0, 0, 0, 0]); }); it('mismatch Tensor2D shapes - int32', function () { var a = tf.tensor2d([[3], [7]], [2, 1], 'int32'); var b = tf.tensor2d([[2, 3, 4], [7, 8, 9]], [2, 3], 'int32'); var f = function () { tf.notEqualStrict(a, b); }; expect(f).toThrowError(); }); it('mismatch Tensor2D shapes - float32', function () { var a = tf.tensor2d([[1.1], [7.1]], [2, 1], 'float32'); var b = tf.tensor2d([[0.1, 1.1, 2.1], [7.1, 8.1, 9.1]], [2, 3], 'float32'); var f = function () { tf.notEqualStrict(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor2D - float32', function () { var a = tf.tensor2d([[1.1, NaN], [1.1, NaN]], [2, 2], 'float32'); var b = tf.tensor2d([[0.1, NaN], [1.1, NaN]], [2, 2], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 0, 1]); }); it('Tensor3D - int32', function () { var a = tf.tensor3d([[[1], [4], [5]], [[8], [9], [12]]], [2, 3, 1], 'int32'); var b = tf.tensor3d([[[2], [3], [6]], [[7], [10], [12]]], [2, 3, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 1, 1, 1, 0]); a = tf.tensor3d([[[0], [0], [0]], [[1], [1], [1]]], [2, 3, 1], 'int32'); b = tf.tensor3d([[[0], [0], [0]], [[1], [1], [1]]], [2, 3, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [0, 0, 0, 0, 0, 0]); }); it('Tensor3D - float32', function () { var a = tf.tensor3d([[[1.1], [4.1], [5.1]], [[8.1], [9.1], [12.1]]], [2, 3, 1], 'float32'); var b = tf.tensor3d([[[2.1], [3.1], [6.1]], [[7.1], [10.1], [12.1]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 1, 1, 1, 0]); a = tf.tensor3d([[[0.1], [0.1], [0.1]], [[1.1], [1.1], [1.1]]], [2, 3, 1], 'float32'); b = tf.tensor3d([[[0.1], [0.1], [0.1]], [[1.1], [1.1], [1.1]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [0, 0, 0, 0, 0, 0]); }); it('mismatch Tensor3D shapes - int32', function () { var a = tf.tensor3d([[[1, 0], [2, 3], [4, 5]], [[6, 7], [9, 8], [10, 11]]], [2, 3, 2], 'int32'); var b = tf.tensor3d([[[1], [2], [3]], [[7], [10], [9]]], [2, 3, 1], 'int32'); var f = function () { tf.notEqualStrict(a, b); }; expect(f).toThrowError(); }); it('mismatch Tensor3D shapes - float32', function () { var a = tf.tensor3d([ [[1.1, 0.1], [2.1, 3.1], [4.1, 5.1]], [[6.1, 7.1], [9.1, 8.1], [10.1, 11.1]] ], [2, 3, 2], 'float32'); var b = tf.tensor3d([[[1.1], [2.1], [3.1]], [[7.1], [10.1], [9.1]]], [2, 3, 1], 'float32'); var f = function () { tf.notEqualStrict(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor3D - float32', function () { var a = tf.tensor3d([[[1.1], [NaN], [1.1]], [[0.1], [0.1], [0.1]]], [2, 3, 1], 'float32'); var b = tf.tensor3d([[[0.1], [0.1], [1.1]], [[1.1], [0.1], [NaN]]], [2, 3, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 0, 1, 0, 1]); }); it('Tensor4D - int32', function () { var a = tf.tensor4d([1, 4, 5, 8], [2, 2, 1, 1], 'int32'); var b = tf.tensor4d([2, 3, 6, 8], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 1, 0]); a = tf.tensor4d([0, 1, 2, 3], [2, 2, 1, 1], 'int32'); b = tf.tensor4d([0, 1, 2, 3], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [0, 0, 0, 0]); a = tf.tensor4d([1, 1, 1, 1], [2, 2, 1, 1], 'int32'); b = tf.tensor4d([2, 2, 2, 2], [2, 2, 1, 1], 'int32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 1, 1]); }); it('Tensor4D - float32', function () { var a = tf.tensor4d([1.1, 4.1, 5.1, 8.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([2.1, 3.1, 6.1, 8.1], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 1, 0]); a = tf.tensor4d([0.1, 1.1, 2.2, 3.3], [2, 2, 1, 1], 'float32'); b = tf.tensor4d([0.1, 1.1, 2.2, 3.3], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [0, 0, 0, 0]); a = tf.tensor4d([0.1, 0.1, 0.1, 0.1], [2, 2, 1, 1], 'float32'); b = tf.tensor4d([1.1, 1.1, 1.1, 1.1], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 1, 1]); }); it('mismatch Tensor4D shapes - int32', function () { var a = tf.tensor4d([1, 2, 5, 9], [2, 2, 1, 1], 'int32'); var b = tf.tensor4d([[[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8]]]], [2, 2, 1, 2], 'int32'); var f = function () { tf.notEqualStrict(a, b); }; expect(f).toThrowError(); }); it('mismatch Tensor4D shapes - float32', function () { var a = tf.tensor4d([1.1, 2.1, 5.1, 9.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([[[[1.1, 2.1]], [[3.1, 4.1]]], [[[5.1, 6.1]], [[7.1, 8.1]]]], [2, 2, 1, 2], 'float32'); var f = function () { tf.notEqualStrict(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor4D - float32', function () { var a = tf.tensor4d([1.1, NaN, 1.1, 0.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([0.1, 1.1, 1.1, NaN], [2, 2, 1, 1], 'float32'); test_util_1.expectArraysClose(tf.notEqualStrict(a, b), [1, 1, 0, 1]); }); }); jasmine_util_1.describeWithFlags('less', test_util_1.ALL_ENVS, function () { it('Tensor1D - int32', function () { var a = tf.tensor1d([1, 4, 5], 'int32'); var b = tf.tensor1d([2, 3, 5], 'int32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 0, 0]); a = tf.tensor1d([2, 2, 2], 'int32'); b = tf.tensor1d([2, 2, 2], 'int32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 0]); a = tf.tensor1d([0, 0], 'int32'); b = tf.tensor1d([3, 3], 'int32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 1]); }); it('Tensor1D - float32', function () { var a = tf.tensor1d([1.1, 4.1, 5.1], 'float32'); var b = tf.tensor1d([2.2, 3.2, 5.1], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 0, 0]); a = tf.tensor1d([2.31, 2.31, 2.31], 'float32'); b = tf.tensor1d([2.31, 2.31, 2.31], 'float32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 0]); a = tf.tensor1d([0.45, 0.123], 'float32'); b = tf.tensor1d([3.123, 3.321], 'float32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 1]); }); it('mismatched Tensor1D shapes - int32', function () { var a = tf.tensor1d([1, 2], 'int32'); var b = tf.tensor1d([1, 2, 3], 'int32'); var f = function () { tf.less(a, b); }; expect(f).toThrowError(); }); it('mismatched Tensor1D shapes - float32', function () { var a = tf.tensor1d([1.1, 2.1], 'float32'); var b = tf.tensor1d([1.1, 2.1, 3.1], 'float32'); var f = function () { tf.less(a, b); }; expect(f).toThrowError(); }); it('NaNs in Tensor1D - float32', function () { var a = tf.tensor1d([1.1, NaN, 2.1], 'float32'); var b = tf.tensor1d([2.1, 3.1, NaN], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 0, 0]); }); it('Tensor2D - int32', function () { var a = tf.tensor2d([[1, 4, 5], [8, 9, 12]], [2, 3], 'int32'); var b = tf.tensor2d([[2, 3, 6], [7, 10, 11]], [2, 3], 'int32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 0, 1, 0, 1, 0]); a = tf.tensor2d([[0, 0], [1, 1]], [2, 2], 'int32'); b = tf.tensor2d([[0, 0], [1, 1]], [2, 2], 'int32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 0, 0]); }); it('Tensor2D - float32', function () { var a = tf.tensor2d([[1.1, 4.1, 5.1], [8.1, 9.1, 12.1]], [2, 3], 'float32'); var b = tf.tensor2d([[2.1, 3.1, 6.1], [7.1, 10.1, 11.1]], [2, 3], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 0, 1, 0, 1, 0]); a = tf.tensor2d([[0.2, 0.2], [1.2, 1.2]], [2, 2], 'float32'); b = tf.tensor2d([[0.2, 0.2], [1.2, 1.2]], [2, 2], 'float32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 0, 0]); }); it('broadcasting Tensor2D shapes - int32', function () { var a = tf.tensor2d([[3], [7]], [2, 1], 'int32'); var b = tf.tensor2d([[2, 3, 4], [7, 8, 9]], [2, 3], 'int32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 1, 0, 1, 1]); }); it('broadcasting Tensor2D shapes - float32', function () { var a = tf.tensor2d([[1.1], [7.1]], [2, 1], 'float32'); var b = tf.tensor2d([[0.1, 1.1, 2.1], [7.1, 8.1, 9.1]], [2, 3], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 1, 0, 1, 1]); }); it('NaNs in Tensor2D - float32', function () { var a = tf.tensor2d([[1.1, NaN], [0.1, NaN]], [2, 2], 'float32'); var b = tf.tensor2d([[0.1, NaN], [1.1, NaN]], [2, 2], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 1, 0]); }); it('Tensor3D - int32', function () { var a = tf.tensor3d([[[1], [4], [5]], [[8], [9], [12]]], [2, 3, 1], 'int32'); var b = tf.tensor3d([[[2], [3], [6]], [[7], [10], [11]]], [2, 3, 1], 'int32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 0, 1, 0, 1, 0]); a = tf.tensor3d([[[0], [0], [0]], [[1], [1], [1]]], [2, 3, 1], 'int32'); b = tf.tensor3d([[[0], [0], [0]], [[1], [1], [1]]], [2, 3, 1], 'int32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 0, 0, 0, 0]); }); it('Tensor3D - float32', function () { var a = tf.tensor3d([[[1.1], [4.1], [5.1]], [[8.1], [9.1], [12.1]]], [2, 3, 1], 'float32'); var b = tf.tensor3d([[[2.1], [3.1], [6.1]], [[7.1], [10.1], [11.1]]], [2, 3, 1], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 0, 1, 0, 1, 0]); a = tf.tensor3d([[[0.1], [0.1], [0.1]], [[1.1], [1.1], [1.0]]], [2, 3, 1], 'float32'); b = tf.tensor3d([[[0.1], [0.1], [0.1]], [[1.1], [1.1], [1.1]]], [2, 3, 1], 'float32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 0, 0, 0, 1]); }); it('broadcasting Tensor3D shapes - int32', function () { var a = tf.tensor3d([[[1, 0], [2, 3], [4, 5]], [[6, 7], [9, 8], [10, 11]]], [2, 3, 2], 'int32'); var b = tf.tensor3d([[[1], [2], [3]], [[7], [10], [9]]], [2, 3, 1], 'int32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0]); }); it('broadcasting Tensor3D float32', function () { var a = tf.tensor3d([ [[1.1, 0.1], [2.1, 3.1], [4.1, 5.1]], [[6.1, 7.1], [9.1, 8.1], [10.1, 11.1]] ], [2, 3, 2], 'float32'); var b = tf.tensor3d([[[1.1], [2.1], [3.1]], [[7.1], [10.1], [9.1]]], [2, 3, 1], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0]); }); it('NaNs in Tensor3D - float32', function () { var a = tf.tensor3d([[[1.1], [NaN], [1.1]], [[0.1], [0.1], [0.1]]], [2, 3, 1], 'float32'); var b = tf.tensor3d([[[0.1], [0.1], [1.1]], [[1.1], [0.1], [NaN]]], [2, 3, 1], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 0, 1, 0, 0]); }); it('Tensor4D - int32', function () { var a = tf.tensor4d([1, 4, 5, 8], [2, 2, 1, 1], 'int32'); var b = tf.tensor4d([2, 3, 6, 7], [2, 2, 1, 1], 'int32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 0, 1, 0]); a = tf.tensor4d([0, 1, 2, 3], [2, 2, 1, 1], 'int32'); b = tf.tensor4d([0, 1, 2, 3], [2, 2, 1, 1], 'int32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 0, 0]); a = tf.tensor4d([1, 1, 1, 1], [2, 2, 1, 1], 'int32'); b = tf.tensor4d([2, 2, 2, 2], [2, 2, 1, 1], 'int32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 1, 1, 1]); }); it('Tensor4D - float32', function () { var a = tf.tensor4d([1.1, 4.1, 5.1, 8.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([2.1, 3.1, 6.1, 7.1], [2, 2, 1, 1], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 0, 1, 0]); a = tf.tensor4d([0.1, 1.1, 2.2, 3.3], [2, 2, 1, 1], 'float32'); b = tf.tensor4d([0.1, 1.1, 2.2, 3.3], [2, 2, 1, 1], 'float32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 0, 0]); a = tf.tensor4d([0.1, 0.1, 0.1, 0.1], [2, 2, 1, 1], 'float32'); b = tf.tensor4d([1.1, 1.1, 1.1, 1.1], [2, 2, 1, 1], 'float32'); res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [1, 1, 1, 1]); }); it('broadcasting Tensor4D shapes - int32', function () { var a = tf.tensor4d([1, 2, 5, 9], [2, 2, 1, 1], 'int32'); var b = tf.tensor4d([[[[1, 2]], [[3, 4]]], [[[5, 6]], [[7, 8]]]], [2, 2, 1, 2], 'int32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 1, 1, 1, 0, 1, 0, 0]); }); it('broadcasting Tensor4D shapes - float32', function () { var a = tf.tensor4d([1.1, 2.1, 5.1, 9.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([[[[1.1, 2.1]], [[3.1, 4.1]]], [[[5.1, 6.1]], [[7.1, 8.1]]]], [2, 2, 1, 2], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 1, 1, 1, 0, 1, 0, 0]); }); it('NaNs in Tensor4D - float32', function () { var a = tf.tensor4d([1.1, NaN, 0.1, 0.1], [2, 2, 1, 1], 'float32'); var b = tf.tensor4d([0.1, 1.1, 1.1, NaN], [2, 2, 1, 1], 'float32'); var res = tf.less(a, b); expect(res.dtype).toBe('bool'); test_util_1.expectArraysClose(res, [0, 0, 1, 0]); }); it('throws when passed a as a non-tensor', function () { expect(function () { return tf.less({}, tf.scalar(1)); }) .toThrowError(/Argument 'a' passed to 'less' must be a Tensor/); }); it('throws when passed b as a non-tensor', function () { expect(function () { return tf.less(tf.scalar(1), {}); }) .toThrowError(/Argument 'b' passed to 'less' must be a Tensor/); }); }); jasmine_util_1.describeWithFlags('lessStrict', test_util_1.ALL_ENVS, function () { it('Tensor1D - strict version throws when a and b are different shape', function () { var a = tf.tensor1d([2]); var b = tf.tensor1d([4, 2, -1]); expect(function () { return tf.lessStrict(a, b); }).toThrowError(); expect(function () { return tf.lessStrict(b, a); }).toThrowError(); }); it('Tensor2D - strict version throws when a and b are different shape', function () { var a = tf.tensor2d([[1.1], [7.1]], [2, 1], 'float32'); var b = tf.tensor2d([[0.1, 1.1, 2.1], [7.1, 8.1, 9.1]], [2, 3], 'float32'); expect(function () { return tf.lessStrict(a, b); }).toThrowError(); expect(function () { return tf.lessStrict(b, a); }).toThrowError(); }); it('Tensor3D - strict version throws when a and b are different shape', function () { var a = tf.tensor3d([ [[1.1, 0.1], [2.1, 3.1], [4.1, 5.1]], [[6.1, 7.1], [9.1, 8.1], [10.1, 11.1]] ], [2, 3, 2], 'float32'); var b = tf.tensor3d([[[1.1], [2.1], [3.1]], [[7.1], [10.1], [9.1]]], [2, 3, 1], 'float32'); expect(function () { return tf.lessStrict(a, b); }).toThrowError(); expect(function () { return tf.lessStrict(b, a); }).toThrowError(); }); it('Tensor4D - strict version