CppMatrix
|
Tensor is a matrix supports auto grad. More...
Public Types | |
using | ElementType = typename Matrix::ElementType |
Public Member Functions | |
Tensor (Matrix m) | |
Initialize a tensor with matrix data. | |
Tensor (std::initializer_list< std::initializer_list< ElementType > > initData) | |
Initialize a tensor with init data. | |
Tensor (const Tensor &other) | |
Tensor (Tensor &&other) | |
size_t | Row () const |
size_t | Column () const |
Tensor | operator- () const |
Tensor | operator+ (ElementType v) const |
Tensor | operator- (const Tensor &other) const |
Tensor | operator* (const Tensor &other) const |
Tensor | AddToRow (const Tensor &other) const |
Tensor | Pow (ElementType n) const |
Tensor | operator+ (const Tensor &other) const |
Tensor | operator* (ElementType n) const |
Tensor | operator/ (ElementType n) const |
Tensor | Exp () const |
ElementType | operator[] (size_t row, size_t column) const |
Tensor | DivBy (ElementType v) const |
Applies the element-wise function: v / x. | |
Tensor | Sum () const |
Returns the sum of all elements in the tensor. | |
Tensor | Derivative (const Tensor &x) const |
Get derivative of tensor at x . | |
Tensor | SumX () const |
Returns the sum of all elements in the tensor. | |
Tensor is a matrix supports auto grad.
|
inlineexport |
Get derivative of tensor at x
.
This function will return derivative of tensor at x
.
For example:
Because:
\[\begin{aligned} f &= 3 \cdot x + 4 \cdot y \\\\ {d \over dx}f &= {d \over dx}(3 \cdot x) + {d \over dx}(4 \cdot y) \\ &= 3 \cdot {d \over dx}x + 4 \cdot {d \over dx}y \\ &= 3 \\\\ {d \over dy}f &= {d \over dy}(3 \cdot x) + {d \over dy}(4 \cdot y) \\ &= 3 \cdot {d \over dy}x + 4 \cdot {d \over dy}y \\ &= 4 \end{aligned} \]
So after executing, f
, dx
and dy
should be:
\[\begin{aligned} f &= \begin{bmatrix} 3.4 & 6.8 & 10.2 \\ 13.6 & 17.0 & 20.4 \end{bmatrix} \\\\ dx &= \begin{bmatrix} 3 & 3 & 3 \\ 3 & 3 & 3 \end{bmatrix} \\\\ dy &= \begin{bmatrix} 4 & 4 & 4 \\ 4 & 4 & 4 \end{bmatrix} \end{aligned} \]
|
inlineexport |
Returns the sum of all elements in the tensor.
|
inlineexport |
Returns the sum of all elements in the tensor.