1 | /**
|
2 | * @license
|
3 | * Copyright 2021 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 | */
|
17 | /// <amd-module name="@tensorflow/tfjs-core/dist/ops/sparse/sparse_reshape" />
|
18 | import { Tensor1D, Tensor2D } from '../../tensor';
|
19 | import { NamedTensorMap } from '../../tensor_types';
|
20 | import { TensorLike } from '../../types';
|
21 | /**
|
22 | * This operation has the same semantics as reshape on the represented dense
|
23 | * tensor. The `inputIndices` are recomputed based on the requested `newShape`.
|
24 | * If one component of `newShape` is the special value -1, the size of that
|
25 | * dimension is computed so that the total dense size remains constant. At most
|
26 | * one component of `newShape` can be -1. The number of dense elements implied
|
27 | * by `newShape` must be the same as the number of dense elements originally
|
28 | * implied by `inputShape`. Reshaping does not affect the order of values in the
|
29 | * SparseTensor. If the input tensor has rank R_in and N non-empty values, and
|
30 | * `newShape` has length R_out, then `inputIndices` has shape [N, R_in],
|
31 | * `inputShape` has length R_in, `outputIndices` has shape [N, R_out], and
|
32 | * `outputShape` has length R_out.
|
33 | *
|
34 | * ```js
|
35 | * const result = tf.sparse.sparseReshape(
|
36 | * [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 2, 3]],
|
37 | * [2, 3, 6], [9, -1]);
|
38 | * console.log(result);
|
39 | * result['outputIndices'].print(); //[[0, 0], [0, 1], [1, 2], [4, 2], [8, 1]]
|
40 | * result['outputShape'].print(); // [9, 4]
|
41 | * ```
|
42 | * @param inputIndices: 2-D. N x R_in matrix with the indices of non-empty
|
43 | * values in a SparseTensor.
|
44 | * @param inputShape: 1-D. R_in Tensor1D with the input SparseTensor's dense
|
45 | * shape.
|
46 | * @param newShape: 1-D. R_out Tensor1D with the requested new dense shape.
|
47 | * @return A map with the following properties:
|
48 | * - outputIndices: 2-D. N x R_out matrix with the updated indices of
|
49 | * non-empty values in the output SparseTensor.
|
50 | * - outputShape: 1-D. R_out vector with the full dense shape of the output
|
51 | * SparseTensor. This is the same as newShape but with any -1 dimensions
|
52 | * filled in.
|
53 | * @doc {heading: 'Operations', subheading: 'Sparse'}
|
54 | */
|
55 | declare function sparseReshape_(inputIndices: Tensor2D | TensorLike, inputShape: Tensor1D | TensorLike, newShape: Tensor1D | TensorLike): NamedTensorMap;
|
56 | export declare const sparseReshape: typeof sparseReshape_;
|
57 | export {};
|