|
|
|
|
@@ -91,7 +91,7 @@ See Assigning to a TensorRef below.
|
|
|
|
|
|
|
|
|
|
## Accessing Tensor Elements
|
|
|
|
|
|
|
|
|
|
#### <data_type> tensor(index0, index1...)
|
|
|
|
|
#### data_type tensor(index0, index1...)
|
|
|
|
|
|
|
|
|
|
Return the element at position `(index0, index1...)` in tensor
|
|
|
|
|
`tensor`. You must pass as many parameters as the rank of `tensor`.
|
|
|
|
|
@@ -470,7 +470,7 @@ Represents the datatype of individual tensor elements. For example, for a
|
|
|
|
|
`Tensor<float>`, `Scalar` is the type `float`. See
|
|
|
|
|
`setConstant()`.
|
|
|
|
|
|
|
|
|
|
#### <Operation>
|
|
|
|
|
#### (Operation)
|
|
|
|
|
|
|
|
|
|
We use this pseudo type to indicate that a tensor Operation is returned by a
|
|
|
|
|
method. We indicate in the text the type and dimensions of the tensor that the
|
|
|
|
|
@@ -776,7 +776,7 @@ The chain of Operation is evaluated lazily, typically when it is assigned to a
|
|
|
|
|
tensor. See "Controlling when Expression are Evaluated" for more details about
|
|
|
|
|
their evaluation.
|
|
|
|
|
|
|
|
|
|
### <Operation> constant(const Scalar& val)
|
|
|
|
|
### (Operation) constant(const Scalar& val)
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the original tensor but
|
|
|
|
|
where all elements have the value `val`.
|
|
|
|
|
@@ -804,7 +804,7 @@ tensor, or multiply every element of a tensor by a scalar.
|
|
|
|
|
0.6 0.6 0.6
|
|
|
|
|
0.6 0.6 0.6
|
|
|
|
|
|
|
|
|
|
### <Operation> random()
|
|
|
|
|
### (Operation) random()
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the current tensor
|
|
|
|
|
but where all elements have random values.
|
|
|
|
|
@@ -834,7 +834,7 @@ All these operations take a single input tensor as argument and return a tensor
|
|
|
|
|
of the same type and dimensions as the tensor to which they are applied. The
|
|
|
|
|
requested operations are applied to each element independently.
|
|
|
|
|
|
|
|
|
|
### <Operation> operator-()
|
|
|
|
|
### (Operation) operator-()
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the original tensor
|
|
|
|
|
containing the opposite values of the original tensor.
|
|
|
|
|
@@ -853,42 +853,42 @@ containing the opposite values of the original tensor.
|
|
|
|
|
-1 -1 -1
|
|
|
|
|
-1 -1 -1
|
|
|
|
|
|
|
|
|
|
### <Operation> sqrt()
|
|
|
|
|
### (Operation) sqrt()
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the original tensor
|
|
|
|
|
containing the square roots of the original tensor.
|
|
|
|
|
|
|
|
|
|
### <Operation> rsqrt()
|
|
|
|
|
### (Operation) rsqrt()
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the original tensor
|
|
|
|
|
containing the inverse square roots of the original tensor.
|
|
|
|
|
|
|
|
|
|
### <Operation> square()
|
|
|
|
|
### (Operation) square()
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the original tensor
|
|
|
|
|
containing the squares of the original tensor values.
|
|
|
|
|
|
|
|
|
|
### <Operation> inverse()
|
|
|
|
|
### (Operation) inverse()
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the original tensor
|
|
|
|
|
containing the inverse of the original tensor values.
|
|
|
|
|
|
|
|
|
|
### <Operation> exp()
|
|
|
|
|
### (Operation) exp()
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the original tensor
|
|
|
|
|
containing the exponential of the original tensor.
|
|
|
|
|
|
|
|
|
|
### <Operation> log()
|
|
|
|
|
### (Operation) log()
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the original tensor
|
|
|
|
|
containing the natural logarithms of the original tensor.
|
|
|
|
|
|
|
|
|
|
### <Operation> abs()
|
|
|
|
|
### (Operation) abs()
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the original tensor
|
|
|
|
|
containing the absolute values of the original tensor.
|
|
|
|
|
|
|
|
|
|
### <Operation> pow(Scalar exponent)
|
|
|
|
|
### (Operation) pow(Scalar exponent)
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the original tensor
|
|
|
|
|
containing the coefficients of the original tensor to the power of the
|
|
|
|
|
@@ -915,17 +915,17 @@ cubic roots of an int Tensor:
|
|
|
|
|
0 1 2
|
|
|
|
|
3 4 5
|
|
|
|
|
|
|
|
|
|
### <Operation> operator * (Scalar scale)
|
|
|
|
|
### (Operation) operator * (Scalar scale)
|
|
|
|
|
|
|
|
|
|
Multiplies all the coefficients of the input tensor by the provided scale.
|
|
|
|
|
|
|
|
|
|
### <Operation> cwiseMax(Scalar threshold)
|
|
|
|
|
### (Operation) cwiseMax(Scalar threshold)
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
|
|
### <Operation> cwiseMin(Scalar threshold)
|
|
|
|
|
### (Operation) cwiseMin(Scalar threshold)
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
|
|
### <Operation> unaryExpr(const CustomUnaryOp& func)
|
|
|
|
|
### (Operation) unaryExpr(const CustomUnaryOp& func)
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -937,39 +937,39 @@ dimensions as the tensors to which they are applied, and unless otherwise
|
|
|
|
|
specified it is also of the same type. The requested operations are applied to
|
|
|
|
|
each pair of elements independently.
|
|
|
|
|
|
|
|
|
|
### <Operation> operator+(const OtherDerived& other)
|
|
|
|
|
### (Operation) operator+(const OtherDerived& other)
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the input tensors
|
|
|
|
|
containing the coefficient wise sums of the inputs.
|
|
|
|
|
|
|
|
|
|
### <Operation> operator-(const OtherDerived& other)
|
|
|
|
|
### (Operation) operator-(const OtherDerived& other)
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the input tensors
|
|
|
|
|
containing the coefficient wise differences of the inputs.
|
|
|
|
|
|
|
|
|
|
### <Operation> operator*(const OtherDerived& other)
|
|
|
|
|
### (Operation) operator*(const OtherDerived& other)
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the input tensors
|
|
|
|
|
containing the coefficient wise products of the inputs.
|
|
|
|
|
|
|
|
|
|
### <Operation> operator/(const OtherDerived& other)
|
|
|
|
|
### (Operation) operator/(const OtherDerived& other)
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the input tensors
|
|
|
|
|
containing the coefficient wise quotients of the inputs.
|
|
|
|
|
|
|
|
|
|
This operator is not supported for integer types.
|
|
|
|
|
|
|
|
|
|
### <Operation> cwiseMax(const OtherDerived& other)
|
|
|
|
|
### (Operation) cwiseMax(const OtherDerived& other)
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the input tensors
|
|
|
|
|
containing the coefficient wise maximums of the inputs.
|
|
|
|
|
|
|
|
|
|
### <Operation> cwiseMin(const OtherDerived& other)
|
|
|
|
|
### (Operation) cwiseMin(const OtherDerived& other)
|
|
|
|
|
|
|
|
|
|
Returns a tensor of the same type and dimensions as the input tensors
|
|
|
|
|
containing the coefficient wise mimimums of the inputs.
|
|
|
|
|
|
|
|
|
|
### <Operation> Logical operators
|
|
|
|
|
### (Operation) Logical operators
|
|
|
|
|
|
|
|
|
|
The following logical operators are supported as well:
|
|
|
|
|
|
|
|
|
|
@@ -1127,50 +1127,50 @@ scalar, represented as a zero-dimension tensor.
|
|
|
|
|
276
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> sum(const Dimensions& new_dims)
|
|
|
|
|
### <Operation> sum()
|
|
|
|
|
### (Operation) sum(const Dimensions& new_dims)
|
|
|
|
|
### (Operation) sum()
|
|
|
|
|
|
|
|
|
|
Reduce a tensor using the sum() operator. The resulting values
|
|
|
|
|
are the sum of the reduced values.
|
|
|
|
|
|
|
|
|
|
### <Operation> mean(const Dimensions& new_dims)
|
|
|
|
|
### <Operation> mean()
|
|
|
|
|
### (Operation) mean(const Dimensions& new_dims)
|
|
|
|
|
### (Operation) mean()
|
|
|
|
|
|
|
|
|
|
Reduce a tensor using the mean() operator. The resulting values
|
|
|
|
|
are the mean of the reduced values.
|
|
|
|
|
|
|
|
|
|
### <Operation> maximum(const Dimensions& new_dims)
|
|
|
|
|
### <Operation> maximum()
|
|
|
|
|
### (Operation) maximum(const Dimensions& new_dims)
|
|
|
|
|
### (Operation) maximum()
|
|
|
|
|
|
|
|
|
|
Reduce a tensor using the maximum() operator. The resulting values are the
|
|
|
|
|
largest of the reduced values.
|
|
|
|
|
|
|
|
|
|
### <Operation> minimum(const Dimensions& new_dims)
|
|
|
|
|
### <Operation> minimum()
|
|
|
|
|
### (Operation) minimum(const Dimensions& new_dims)
|
|
|
|
|
### (Operation) minimum()
|
|
|
|
|
|
|
|
|
|
Reduce a tensor using the minimum() operator. The resulting values
|
|
|
|
|
are the smallest of the reduced values.
|
|
|
|
|
|
|
|
|
|
### <Operation> prod(const Dimensions& new_dims)
|
|
|
|
|
### <Operation> prod()
|
|
|
|
|
### (Operation) prod(const Dimensions& new_dims)
|
|
|
|
|
### (Operation) prod()
|
|
|
|
|
|
|
|
|
|
Reduce a tensor using the prod() operator. The resulting values
|
|
|
|
|
are the product of the reduced values.
|
|
|
|
|
|
|
|
|
|
### <Operation> all(const Dimensions& new_dims)
|
|
|
|
|
### <Operation> all()
|
|
|
|
|
### (Operation) all(const Dimensions& new_dims)
|
|
|
|
|
### (Operation) all()
|
|
|
|
|
Reduce a tensor using the all() operator. Casts tensor to bool and then checks
|
|
|
|
|
whether all elements are true. Runs through all elements rather than
|
|
|
|
|
short-circuiting, so may be significantly inefficient.
|
|
|
|
|
|
|
|
|
|
### <Operation> any(const Dimensions& new_dims)
|
|
|
|
|
### <Operation> any()
|
|
|
|
|
### (Operation) any(const Dimensions& new_dims)
|
|
|
|
|
### (Operation) any()
|
|
|
|
|
Reduce a tensor using the any() operator. Casts tensor to bool and then checks
|
|
|
|
|
whether any element is true. Runs through all elements rather than
|
|
|
|
|
short-circuiting, so may be significantly inefficient.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> reduce(const Dimensions& new_dims, const Reducer& reducer)
|
|
|
|
|
### (Operation) reduce(const Dimensions& new_dims, const Reducer& reducer)
|
|
|
|
|
|
|
|
|
|
Reduce a tensor using a user-defined reduction operator. See `SumReducer`
|
|
|
|
|
in TensorFunctors.h for information on how to implement a reduction operator.
|
|
|
|
|
@@ -1206,8 +1206,8 @@ Example: Trace along 2 dimensions.
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> trace(const Dimensions& new_dims)
|
|
|
|
|
### <Operation> trace()
|
|
|
|
|
### (Operation) trace(const Dimensions& new_dims)
|
|
|
|
|
### (Operation) trace()
|
|
|
|
|
|
|
|
|
|
As a special case, if no parameter is passed to the operation, trace is computed
|
|
|
|
|
along *all* dimensions of the input tensor.
|
|
|
|
|
@@ -1257,18 +1257,18 @@ dd a comment to this line
|
|
|
|
|
1 3 6
|
|
|
|
|
4 9 15
|
|
|
|
|
|
|
|
|
|
### <Operation> cumsum(const Index& axis)
|
|
|
|
|
### (Operation) cumsum(const Index& axis)
|
|
|
|
|
|
|
|
|
|
Perform a scan by summing consecutive entries.
|
|
|
|
|
|
|
|
|
|
### <Operation> cumprod(const Index& axis)
|
|
|
|
|
### (Operation) cumprod(const Index& axis)
|
|
|
|
|
|
|
|
|
|
Perform a scan by multiplying consecutive entries.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Convolutions
|
|
|
|
|
|
|
|
|
|
### <Operation> convolve(const Kernel& kernel, const Dimensions& dims)
|
|
|
|
|
### (Operation) convolve(const Kernel& kernel, const Dimensions& dims)
|
|
|
|
|
|
|
|
|
|
Returns a tensor that is the output of the convolution of the input tensor with the kernel,
|
|
|
|
|
along the specified dimensions of the input tensor. The dimension size for dimensions of the output tensor
|
|
|
|
|
@@ -1311,7 +1311,7 @@ These operations return a Tensor with different dimensions than the original
|
|
|
|
|
Tensor. They can be used to access slices of tensors, see them with different
|
|
|
|
|
dimensions, or pad tensors with additional data.
|
|
|
|
|
|
|
|
|
|
### <Operation> reshape(const Dimensions& new_dims)
|
|
|
|
|
### (Operation) reshape(const Dimensions& new_dims)
|
|
|
|
|
|
|
|
|
|
Returns a view of the input tensor that has been reshaped to the specified
|
|
|
|
|
new dimensions. The argument new_dims is an array of Index values. The
|
|
|
|
|
@@ -1390,7 +1390,7 @@ Note that "b" itself was not reshaped but that instead the assignment is done to
|
|
|
|
|
the reshape view of b.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> shuffle(const Shuffle& shuffle)
|
|
|
|
|
### (Operation) shuffle(const Shuffle& shuffle)
|
|
|
|
|
|
|
|
|
|
Returns a copy of the input tensor whose dimensions have been
|
|
|
|
|
reordered according to the specified permutation. The argument shuffle
|
|
|
|
|
@@ -1431,7 +1431,7 @@ Let's rewrite the previous example to take advantage of this feature:
|
|
|
|
|
output.shuffle({2, 0, 1}) = input;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> stride(const Strides& strides)
|
|
|
|
|
### (Operation) stride(const Strides& strides)
|
|
|
|
|
|
|
|
|
|
Returns a view of the input tensor that strides (skips stride-1
|
|
|
|
|
elements) along each of the dimensions. The argument strides is an
|
|
|
|
|
@@ -1457,7 +1457,7 @@ It is possible to assign a tensor to a stride:
|
|
|
|
|
output.stride({2, 3, 4}) = input;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> slice(const StartIndices& offsets, const Sizes& extents)
|
|
|
|
|
### (Operation) slice(const StartIndices& offsets, const Sizes& extents)
|
|
|
|
|
|
|
|
|
|
Returns a sub-tensor of the given tensor. For each dimension i, the slice is
|
|
|
|
|
made of the coefficients stored between offset[i] and offset[i] + extents[i] in
|
|
|
|
|
@@ -1483,7 +1483,7 @@ the input tensor.
|
|
|
|
|
600 700
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> chip(const Index offset, const Index dim)
|
|
|
|
|
### (Operation) chip(const Index offset, const Index dim)
|
|
|
|
|
|
|
|
|
|
A chip is a special kind of slice. It is the subtensor at the given offset in
|
|
|
|
|
the dimension dim. The returned tensor has one fewer dimension than the input
|
|
|
|
|
@@ -1534,7 +1534,7 @@ lvalue. For example:
|
|
|
|
|
0 0 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> reverse(const ReverseDimensions& reverse)
|
|
|
|
|
### (Operation) reverse(const ReverseDimensions& reverse)
|
|
|
|
|
|
|
|
|
|
Returns a view of the input tensor that reverses the order of the coefficients
|
|
|
|
|
along a subset of the dimensions. The argument reverse is an array of boolean
|
|
|
|
|
@@ -1564,7 +1564,7 @@ of a 2D tensor:
|
|
|
|
|
0 100 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> broadcast(const Broadcast& broadcast)
|
|
|
|
|
### (Operation) broadcast(const Broadcast& broadcast)
|
|
|
|
|
|
|
|
|
|
Returns a view of the input tensor in which the input is replicated one to many
|
|
|
|
|
times.
|
|
|
|
|
@@ -1588,11 +1588,11 @@ made in each of the dimensions.
|
|
|
|
|
0 100 200 0 100 200
|
|
|
|
|
300 400 500 300 400 500
|
|
|
|
|
|
|
|
|
|
### <Operation> concatenate(const OtherDerived& other, Axis axis)
|
|
|
|
|
### (Operation) concatenate(const OtherDerived& other, Axis axis)
|
|
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
|
|
### <Operation> pad(const PaddingDimensions& padding)
|
|
|
|
|
### (Operation) pad(const PaddingDimensions& padding)
|
|
|
|
|
|
|
|
|
|
Returns a view of the input tensor in which the input is padded with zeros.
|
|
|
|
|
|
|
|
|
|
@@ -1617,7 +1617,7 @@ Returns a view of the input tensor in which the input is padded with zeros.
|
|
|
|
|
0 0 0 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> extract_patches(const PatchDims& patch_dims)
|
|
|
|
|
### (Operation) extract_patches(const PatchDims& patch_dims)
|
|
|
|
|
|
|
|
|
|
Returns a tensor of coefficient patches extracted from the input tensor, where
|
|
|
|
|
each patch is of dimension specified by 'patch_dims'. The returned tensor has
|
|
|
|
|
@@ -1704,7 +1704,7 @@ This code results in the following output when the data layout is RowMajor:
|
|
|
|
|
6 7
|
|
|
|
|
10 11
|
|
|
|
|
|
|
|
|
|
### <Operation> extract_image_patches(const Index patch_rows, const Index patch_cols, const Index row_stride, const Index col_stride, const PaddingType padding_type)
|
|
|
|
|
### (Operation) extract_image_patches(const Index patch_rows, const Index patch_cols, const Index row_stride, const Index col_stride, const PaddingType padding_type)
|
|
|
|
|
|
|
|
|
|
Returns a tensor of coefficient image patches extracted from the input tensor,
|
|
|
|
|
which is expected to have dimensions ordered as follows (depending on the data
|
|
|
|
|
@@ -1761,7 +1761,7 @@ sizes:
|
|
|
|
|
|
|
|
|
|
## Special Operations
|
|
|
|
|
|
|
|
|
|
### <Operation> cast<T>()
|
|
|
|
|
### (Operation) cast<T>()
|
|
|
|
|
|
|
|
|
|
Returns a tensor of type T with the same dimensions as the original tensor.
|
|
|
|
|
The returned tensor contains the values of the original tensor converted to
|
|
|
|
|
@@ -1790,7 +1790,7 @@ but you can easily cast the tensors to floats to do the division:
|
|
|
|
|
1 2 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### <Operation> eval()
|
|
|
|
|
### (Operation) eval()
|
|
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
|
|
|