From f5a9873bbb5488bcba3e37f92b4ec09a8db76081 Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Fri, 2 Jul 2021 21:23:15 -0700 Subject: Fix Tensor documentation page. The extra [TOC] tag is generating a huge floating duplicated table-of-contents, which obscures the majority of the page (see bottom of https://eigen.tuxfamily.org/dox/unsupported/eigen_tensors.html). Remove it. Also, headers do not support markup (see [doxygen bug](https://github.com/doxygen/doxygen/issues/7467)), so backticks like ``` ``` end up generating titles that looks like ``` Constructor Tensor ``` Removing backticks for now. To generate proper formatted headers, we must directly use html instead of markdown, i.e. ```

Constructor Tensor<double,2>

``` which is ugly. Fixes #2254. --- unsupported/Eigen/CXX11/src/Tensor/README.md | 156 +++++++++++++-------------- 1 file changed, 77 insertions(+), 79 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/README.md b/unsupported/Eigen/CXX11/src/Tensor/README.md index 0ef212a51..d4d3d5986 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/README.md +++ b/unsupported/Eigen/CXX11/src/Tensor/README.md @@ -3,8 +3,6 @@ Tensors are multidimensional arrays of elements. Elements are typically scalars, but more complex types such as strings are also supported. -[TOC] - ## Tensor Classes You can manipulate a tensor with one of the following classes. They all are in @@ -21,7 +19,7 @@ matrix. Tensors of this class are resizable. For example, if you assign a tensor of a different size to a Tensor, that tensor is resized to match its new value. -#### Constructor `Tensor(size0, size1, ...)` +#### Constructor Tensor(size0, size1, ...) Constructor for a Tensor. The constructor must be passed `rank` integers indicating the sizes of the instance along each of the the `rank` @@ -34,7 +32,7 @@ dimensions. // Resize t_3d by assigning a tensor of different sizes, but same rank. t_3d = Tensor(3, 4, 3); -#### Constructor `Tensor(size_array)` +#### Constructor Tensor(size_array) Constructor where the sizes for the constructor are specified as an array of values instead of an explicitly list of parameters. The array type to use is @@ -45,7 +43,7 @@ from an initializer list. Tensor t_2d({5, 7}); -### Class `TensorFixedSize>` +### Class TensorFixedSize> Class to use for tensors of fixed size, where the size is known at compile time. Fixed sized tensors can provide very fast computations because all their @@ -57,7 +55,7 @@ tensor data is held onto the stack and does not cause heap allocation and free. // Create a 4 x 3 tensor of floats. TensorFixedSize> t_4x3; -### Class `TensorMap>` +### Class TensorMap> This is the class to use to create a tensor on top of memory allocated and owned by another part of your code. It allows to view any piece of allocated @@ -67,7 +65,7 @@ data are stored. A TensorMap is not resizable because it does not own the memory where its data are stored. -#### Constructor `TensorMap>(data, size0, size1, ...)` +#### Constructor TensorMap>(data, size0, size1, ...) Constructor for a Tensor. The constructor must be passed a pointer to the storage for the data, and "rank" size attributes. The storage has to be @@ -87,13 +85,13 @@ large enough to hold all the data. TensorMap> t_12(t_4x3.data(), 12); -#### Class `TensorRef` +#### Class TensorRef See Assigning to a TensorRef below. ## Accessing Tensor Elements -#### ` tensor(index0, index1...)` +#### tensor(index0, index1...) Return the element at position `(index0, index1...)` in tensor `tensor`. You must pass as many parameters as the rank of `tensor`. @@ -278,7 +276,7 @@ Simiarly, assigning an expression to a TensorMap causes its evaluation. Like tensors of type TensorFixedSize, TensorMaps cannot be resized so they have to have the rank and sizes of the expression that are assigned to them. -#### Calling `eval()`. +#### Calling eval(). When you compute large composite expressions, you sometimes want to tell Eigen that an intermediate value in the expression tree is worth evaluating ahead of @@ -355,7 +353,7 @@ call for the right hand side: (Y / (Y.sum(depth_dim).eval().reshape(dims2d).broadcast(bcast))).eval(); -#### Assigning to a `TensorRef`. +#### Assigning to a TensorRef. If you need to access only a few elements from the value of an expression you can avoid materializing the value in a full tensor by using a TensorRef. @@ -455,24 +453,24 @@ memory for tensors with cuda. In the documentation of the tensor methods and Operation we mention datatypes that are tensor-type specific: -#### `::``Dimensions` +#### ::Dimensions Acts like an array of ints. Has an `int size` attribute, and can be indexed like an array to access individual values. Used to represent the dimensions of a tensor. See `dimensions()`. -#### `::``Index` +#### ::Index Acts like an `int`. Used for indexing tensors along their dimensions. See `operator()`, `dimension()`, and `size()`. -#### `::``Scalar` +#### ::Scalar Represents the datatype of individual tensor elements. For example, for a `Tensor`, `Scalar` is the type `float`. See `setConstant()`. -#### `` +#### 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 @@ -492,7 +490,7 @@ Tensor, TensorFixedSize, and TensorMap. ## Metadata -### `int NumDimensions` +### int NumDimensions Constant value indicating the number of dimensions of a Tensor. This is also known as the tensor "rank". @@ -501,7 +499,7 @@ known as the tensor "rank". cout << "Dims " << a.NumDimensions; => Dims 2 -### `Dimensions dimensions()` +### Dimensions dimensions() Returns an array-like object representing the dimensions of the tensor. The actual type of the `dimensions()` result is `::``Dimensions`. @@ -519,7 +517,7 @@ If you use a C++11 compiler, you can use `auto` to simplify the code: << ", dim 1: " << d[1]; => Dim size: 2, dim 0: 3, dim 1: 4 -### `Index dimension(Index n)` +### Index dimension(Index n) Returns the n-th dimension of the tensor. The actual type of the `dimension()` result is `::``Index`, but you can @@ -530,7 +528,7 @@ always use it like an int. cout << "Dim 1: " << dim1; => Dim 1: 4 -### `Index size()` +### Index size() Returns the total number of elements in the tensor. This is the product of all the tensor dimensions. The actual type of the `size()` result is @@ -605,7 +603,7 @@ You can use one of the methods below to initialize the tensor memory. These have an immediate effect on the tensor and return the tensor itself as a result. These are not tensor Operations which delay evaluation. -### ` setConstant(const Scalar& val)` +### setConstant(const Scalar& val) Sets all elements of the tensor to the constant value `val`. `Scalar` is the type of data stored in the tensor. You can pass any value that is @@ -633,7 +631,7 @@ has a copy constructor and an `operator=()`: yolo yolo yolo -### ` setZero()` +### setZero() Fills the tensor with zeros. Equivalent to `setConstant(Scalar(0))`. Returns the tensor itself in case you want to chain another call. @@ -647,7 +645,7 @@ Returns the tensor itself in case you want to chain another call. 0 0 0 0 -### ` setValues({..initializer_list})` +### setValues({..initializer_list}) Fills the tensor with explicit values specified in a std::initializer_list. The type of the initializer list depends on the type and rank of the tensor. @@ -683,7 +681,7 @@ code only sets the values of the first row of the tensor. 10 20 30 1000 1000 1000 -### ` setRandom()` +### setRandom() Fills the tensor with random values. Returns the tensor itself in case you want to chain another call. @@ -750,7 +748,7 @@ values of a tensor expression, the expression must either be evaluated or wrapped in a TensorRef. -### `Scalar* data()` and `const Scalar* data() const` +### Scalar* data() and const Scalar* data() const Returns a pointer to the storage for the tensor. The pointer is const if the tensor was const. This allows direct access to the data. The layout of the @@ -778,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. -### ` constant(const Scalar& val)` +### 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`. @@ -806,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 -### ` random()` +### random() Returns a tensor of the same type and dimensions as the current tensor but where all elements have random values. @@ -836,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. -### ` operator-()` +### operator-() Returns a tensor of the same type and dimensions as the original tensor containing the opposite values of the original tensor. @@ -855,42 +853,42 @@ containing the opposite values of the original tensor. -1 -1 -1 -1 -1 -1 -### ` sqrt()` +### sqrt() Returns a tensor of the same type and dimensions as the original tensor containing the square roots of the original tensor. -### ` rsqrt()` +### rsqrt() Returns a tensor of the same type and dimensions as the original tensor containing the inverse square roots of the original tensor. -### ` square()` +### square() Returns a tensor of the same type and dimensions as the original tensor containing the squares of the original tensor values. -### ` inverse()` +### inverse() Returns a tensor of the same type and dimensions as the original tensor containing the inverse of the original tensor values. -### ` exp()` +### exp() Returns a tensor of the same type and dimensions as the original tensor containing the exponential of the original tensor. -### ` log()` +### log() Returns a tensor of the same type and dimensions as the original tensor containing the natural logarithms of the original tensor. -### ` abs()` +### abs() Returns a tensor of the same type and dimensions as the original tensor containing the absolute values of the original tensor. -### ` pow(Scalar exponent)` +### 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 @@ -917,17 +915,17 @@ cubic roots of an int Tensor: 0 1 2 3 4 5 -### ` operator * (Scalar scale)` +### operator * (Scalar scale) Multiplies all the coefficients of the input tensor by the provided scale. -### ` cwiseMax(Scalar threshold)` +### cwiseMax(Scalar threshold) TODO -### ` cwiseMin(Scalar threshold)` +### cwiseMin(Scalar threshold) TODO -### ` unaryExpr(const CustomUnaryOp& func)` +### unaryExpr(const CustomUnaryOp& func) TODO @@ -939,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. -### ` operator+(const OtherDerived& other)` +### 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. -### ` operator-(const OtherDerived& other)` +### 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. -### ` operator*(const OtherDerived& other)` +### 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. -### ` operator/(const OtherDerived& other)` +### 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. -### ` cwiseMax(const OtherDerived& other)` +### 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. -### ` cwiseMin(const OtherDerived& other)` +### 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. -### ` Logical operators` +### Logical operators The following logical operators are supported as well: @@ -1129,50 +1127,50 @@ scalar, represented as a zero-dimension tensor. 276 -### ` sum(const Dimensions& new_dims)` -### ` sum()` +### sum(const Dimensions& new_dims) +### sum() Reduce a tensor using the sum() operator. The resulting values are the sum of the reduced values. -### ` mean(const Dimensions& new_dims)` -### ` mean()` +### mean(const Dimensions& new_dims) +### mean() Reduce a tensor using the mean() operator. The resulting values are the mean of the reduced values. -### ` maximum(const Dimensions& new_dims)` -### ` maximum()` +### maximum(const Dimensions& new_dims) +### maximum() Reduce a tensor using the maximum() operator. The resulting values are the largest of the reduced values. -### ` minimum(const Dimensions& new_dims)` -### ` minimum()` +### minimum(const Dimensions& new_dims) +### minimum() Reduce a tensor using the minimum() operator. The resulting values are the smallest of the reduced values. -### ` prod(const Dimensions& new_dims)` -### ` prod()` +### prod(const Dimensions& new_dims) +### prod() Reduce a tensor using the prod() operator. The resulting values are the product of the reduced values. -### ` all(const Dimensions& new_dims)` -### ` all()` +### all(const Dimensions& new_dims) +### 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. -### ` any(const Dimensions& new_dims)` -### ` any()` +### any(const Dimensions& new_dims) +### 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. -### ` reduce(const Dimensions& new_dims, const Reducer& reducer)` +### 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. @@ -1208,8 +1206,8 @@ Example: Trace along 2 dimensions. 15 -### ` trace(const Dimensions& new_dims)` -### ` trace()` +### trace(const Dimensions& new_dims) +### trace() As a special case, if no parameter is passed to the operation, trace is computed along *all* dimensions of the input tensor. @@ -1259,18 +1257,18 @@ dd a comment to this line 1 3 6 4 9 15 -### ` cumsum(const Index& axis)` +### cumsum(const Index& axis) Perform a scan by summing consecutive entries. -### ` cumprod(const Index& axis)` +### cumprod(const Index& axis) Perform a scan by multiplying consecutive entries. ## Convolutions -### ` convolve(const Kernel& kernel, const Dimensions& dims)` +### 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 @@ -1313,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. -### ` reshape(const Dimensions& new_dims)` +### 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 @@ -1392,7 +1390,7 @@ Note that "b" itself was not reshaped but that instead the assignment is done to the reshape view of b. -### ` shuffle(const Shuffle& shuffle)` +### shuffle(const Shuffle& shuffle) Returns a copy of the input tensor whose dimensions have been reordered according to the specified permutation. The argument shuffle @@ -1433,7 +1431,7 @@ Let's rewrite the previous example to take advantage of this feature: output.shuffle({2, 0, 1}) = input; -### ` stride(const Strides& strides)` +### 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 @@ -1459,7 +1457,7 @@ It is possible to assign a tensor to a stride: output.stride({2, 3, 4}) = input; -### ` slice(const StartIndices& offsets, const Sizes& extents)` +### 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 @@ -1485,7 +1483,7 @@ the input tensor. 600 700 -### ` chip(const Index offset, const Index dim)` +### 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 @@ -1536,7 +1534,7 @@ lvalue. For example: 0 0 0 -### ` reverse(const ReverseDimensions& reverse)` +### 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 @@ -1566,7 +1564,7 @@ of a 2D tensor: 0 100 200 -### ` broadcast(const Broadcast& broadcast)` +### broadcast(const Broadcast& broadcast) Returns a view of the input tensor in which the input is replicated one to many times. @@ -1590,11 +1588,11 @@ made in each of the dimensions. 0 100 200 0 100 200 300 400 500 300 400 500 -### ` concatenate(const OtherDerived& other, Axis axis)` +### concatenate(const OtherDerived& other, Axis axis) TODO -### ` pad(const PaddingDimensions& padding)` +### pad(const PaddingDimensions& padding) Returns a view of the input tensor in which the input is padded with zeros. @@ -1619,7 +1617,7 @@ Returns a view of the input tensor in which the input is padded with zeros. 0 0 0 0 -### ` extract_patches(const PatchDims& patch_dims)` +### 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 @@ -1706,7 +1704,7 @@ This code results in the following output when the data layout is RowMajor: 6 7 10 11 -### ` extract_image_patches(const Index patch_rows, const Index patch_cols, const Index row_stride, const Index col_stride, const PaddingType padding_type)` +### 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 @@ -1763,7 +1761,7 @@ sizes: ## Special Operations -### ` cast()` +### cast() 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 @@ -1792,7 +1790,7 @@ but you can easily cast the tensors to floats to do the division: 1 2 2 -### ` eval()` +### eval() TODO -- cgit v1.2.3