Method scatter
static member scatter: Tensor<int64> option list -> int64 list -> Tensor<'T> -> Tensor<'T>
Disperses elements from a source tensor to a new tensor according to the specified indices.
Declaration
static member scatter: indices:Tensor<int64> option list -> trgtShp:int64 list -> src:Tensor<'T> -> Tensor<'T>
Parameters
Type | Name | Description |
---|---|---|
Tensor<int64> option list | indices | A list of tensors, one per dimension of this tensor, containing the target indicies
for each element of |
int64 list | trgtShp | The shape of the resulting tensor. |
Tensor<'T> | src | The tensor containing the source values. |
Returns
Type | Description |
---|---|
Tensor<'T> | Result with the shape specified in |
Remarks
The source element with indices [i_0; i_1; i_2; ...]
is written to the target element with indices
[j_0; j_1; j_2; ...]
, where each index j_k
is given by j_k = indices.[k].[i_0; i_1; i_2; ...]
.
If indices.[k]
is None
, then j_k = i_k
is assumed instead.
If a target index occurs multiple times, the corresponding source values are summed. If a target element is not referenced by any index, it is set to zero.
The tensors indices
and src
must have the same storage.
Examples
// Sum first row of src into last element and swap rows 1 and 2.
let src = HostTensor.ofList2D [[0.0; 0.1; 0.2; 0.3]
[1.0; 1.1; 1.2; 1.3]
[2.0; 2.1; 2.2; 2.3]]
let i0 = HostTensor.ofList2D [[0L; 0L; 0L; 0L]
[2L; 2L; 2L; 2L]
[1L; 1L; 1L; 1L]]
let i1 = HostTensor.ofList2D [[3L; 3L; 3L; 3L]
[0L; 1L; 2L; 3L]
[0L; 1L; 2L; 3L]]
let s = Tensor.scatter [Some i0; Some i1] [4L; 4L] src
// s =
// [[ 0.0000 0.0000 0.0000 0.6000]
// [ 2.0000 2.1000 2.2000 2.3000]
// [ 1.0000 1.1000 1.2000 1.3000]
// [ 0.0000 0.0000 0.0000 0.0000]]