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C,CAAC;SACjE,EACD,IAAI,CAAC,CAAC;IACZ,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,EAAe,CAAC,CAAC;aAClC,YAAY,CAAC,iDAAiD,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE,KAAK,IAAI,EAAE;QAC5C,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3B,iBAAiB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;QAClC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aACtB,YAAY,CAAC,gDAAgD,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2020 Google LLC. All Rights Reserved.\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n * =============================================================================\n */\n\nimport * as tf from '../index';\nimport {ALL_ENVS, describeWithFlags} from '../jasmine_util';\nimport {expectArraysClose} from '../test_util';\n\ndescribeWithFlags('rsqrt', ALL_ENVS, () => {\n it('rsqrt', async () => {\n const a = tf.tensor1d([2, 4]);\n const r = tf.rsqrt(a);\n expectArraysClose(await r.data(), [1 / Math.sqrt(2), 1 / Math.sqrt(4)]);\n });\n\n it('rsqrt propagates NaNs', async () => {\n const a = tf.tensor1d([1, NaN]);\n const r = tf.rsqrt(a);\n expectArraysClose(await r.data(), [1 / Math.sqrt(1), NaN]);\n });\n\n it('gradients: Scalar', async () => {\n const a = tf.scalar(4);\n const dy = tf.scalar(8);\n\n const da = tf.grad(a => tf.rsqrt(a))(a, dy);\n\n expect(da.shape).toEqual(a.shape);\n expect(da.dtype).toEqual('float32');\n expectArraysClose(await da.data(), [(-1 * 8) / (2 * Math.pow(4, 1.5))]);\n });\n\n it('gradients: Scalar', async () => {\n const a = tf.scalar(4);\n const dy = tf.scalar(8);\n\n const da = tf.grad(a => tf.rsqrt(a.clone()).clone())(a, dy);\n\n expect(da.shape).toEqual(a.shape);\n expect(da.dtype).toEqual('float32');\n expectArraysClose(await da.data(), [(-1 * 8) / (2 * Math.pow(4, 1.5))]);\n });\n\n it('gradients: Tensor1D', async () => {\n const a = tf.tensor1d([1, 2, 3, 5]);\n const dy = tf.tensor1d([1, 2, 3, 4]);\n\n const gradients = tf.grad(a => tf.rsqrt(a))(a, dy);\n\n expect(gradients.shape).toEqual(a.shape);\n expect(gradients.dtype).toEqual('float32');\n expectArraysClose(\n await gradients.data(),\n [\n -1 * 1 / (2 * Math.pow(1, 1.5)), -1 * 2 / (2 * Math.pow(2, 1.5)),\n -1 * 3 / (2 * Math.pow(3, 1.5)), -1 * 4 / (2 * Math.pow(5, 1.5))\n ],\n 1e-1);\n });\n\n it('gradients: Tensor2D', async () => {\n const a = tf.tensor2d([3, 1, 2, 3], [2, 2]);\n const dy = tf.tensor2d([1, 2, 3, 4], [2, 2]);\n\n const gradients = tf.grad(a => tf.rsqrt(a))(a, dy);\n\n expect(gradients.shape).toEqual(a.shape);\n expect(gradients.dtype).toEqual('float32');\n expectArraysClose(\n await gradients.data(),\n [\n -1 * 1 / (2 * Math.pow(3, 1.5)), -1 * 2 / (2 * Math.pow(1, 1.5)),\n -1 * 3 / (2 * Math.pow(2, 1.5)), -1 * 4 / (2 * Math.pow(3, 1.5))\n ],\n 1e-1);\n });\n\n it('throws when passed a non-tensor', () => {\n expect(() => tf.rsqrt({} as tf.Tensor))\n .toThrowError(/Argument 'x' passed to 'rsqrt' must be a Tensor/);\n });\n\n it('accepts a tensor-like object', async () => {\n const r = tf.rsqrt([2, 4]);\n expectArraysClose(await r.data(), [1 / Math.sqrt(2), 1 / Math.sqrt(4)]);\n });\n\n it('throws for string tensor', () => {\n expect(() => tf.rsqrt('q'))\n .toThrowError(/Argument 'x' passed to 'rsqrt' must be numeric/);\n });\n});\n"]}
\No newline at end of file