Add tensor scan op

This is the initial implementation a generic scan operation.
Based on this, cumsum and cumprod method have been added to TensorBase.
This commit is contained in:
Igor Babuschkin
2016-06-02 13:35:47 +01:00
parent 0ed08fd281
commit fbd7ed6ff7
7 changed files with 351 additions and 0 deletions

View File

@@ -1168,6 +1168,44 @@ Reduce a tensor using a user-defined reduction operator. See ```SumReducer```
in TensorFunctors.h for information on how to implement a reduction operator.
## Scan Operations
A *Scan* operation returns a tensor with the same dimensions as the original
tensor. The operation performs an inclusive scan along the specified
axis, which means it computes a running total along the axis for a given
reduction operation.
If the reduction operation corresponds to summation, then this computes the
prefix sum of the tensor along the given axis.
Example:
dd a comment to this line
// Create a tensor of 2 dimensions
Eigen::Tensor<int, 2> a(2, 3);
a.setValues({{1, 2, 3}, {4, 5, 6}});
// Scan it along the second dimension (1) using summation
Eigen::Tensor<int, 2> b = a.cumsum(1);
// The result is a tensor with the same size as the input
cout << "a" << endl << a << endl << endl;
cout << "b" << endl << b << endl << endl;
=>
a
1 2 3
6 5 4
b
1 3 6
4 9 15
### <Operation> cumsum(const Index& axis)
Perform a scan by summing consecutive entries.
### <Operation> cumprod(const Index& axis)
Perform a scan by multiplying consecutive entries.
## Convolutions
### <Operation> convolve(const Kernel& kernel, const Dimensions& dims)