UNPKG

2.15 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2020 Google LLC. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * =============================================================================
16 */
17import { ENGINE } from '../engine';
18import { Any } from '../kernel_names';
19import { convertToTensor } from '../tensor_util_env';
20import { op } from './operation';
21/**
22 * Computes the logical or of elements across dimensions of a `tf.Tensor`.
23 *
24 * Reduces the input along the dimensions given in `axes`. Unless `keepDims`
25 * is true, the rank of the `tf.Tensor` is reduced by 1 for each entry in
26 * `axes`. If `keepDims` is true, the reduced dimensions are retained with
27 * length 1. If `axes` has no entries, all dimensions are reduced, and an
28 * `tf.Tensor` with a single element is returned.
29 *
30 * ```js
31 * const x = tf.tensor1d([1, 1, 1], 'bool');
32 *
33 * x.any().print(); // or tf.any(x)
34 * ```
35 *
36 * ```js
37 * const x = tf.tensor2d([1, 1, 0, 0], [2, 2], 'bool');
38 *
39 * const axis = 1;
40 * x.any(axis).print(); // or tf.any(x, axis)
41 * ```
42 *
43 * @param x The input tensor. Must be of dtype bool.
44 * @param axis The dimension(s) to reduce. By default it reduces
45 * all dimensions.
46 * @param keepDims If true, retains reduced dimensions with size 1.
47 *
48 * @doc {heading: 'Operations', subheading: 'Reduction'}
49 */
50function any_(x, axis = null, keepDims = false) {
51 const $x = convertToTensor(x, 'x', 'any', 'bool');
52 const inputs = { x: $x };
53 const attrs = { axis, keepDims };
54 return ENGINE.runKernel(Any, inputs, attrs);
55}
56// tslint:disable-next-line:variable-name
57export const any = op({ any_ });
58//# sourceMappingURL=any.js.map
\No newline at end of file