libdl  0.0.1
Simple yet powerful deep learning
Loading...
Searching...
No Matches
math.hpp File Reference

Implements auto-diff enabled wrappers around their concrete tensor implementations. More...

#include "shape.hpp"
#include "tensorptr.hpp"
#include <iostream>
#include <vector>
Include dependency graph for math.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dl::DOF
 Wrapper around std::size_t to discern between var(TensorPtr, DOF) and var(TensorPtr, size_t). More...
 

Functions

TensorPtr dl::pow (TensorPtr base, float exponent) noexcept
 Computes the exponent -th power of each element in base and returns the resulting tensor.
 
TensorPtr dl::exp (TensorPtr x) noexcept
 Computes the elementwise x -th power of e.
 
TensorPtr dl::log (TensorPtr x) noexcept
 Natural logarithm, \(\log_e(\,\cdot\,)\).
 
TensorPtr dl::sqrt (TensorPtr x) noexcept
 Computes the elementwise square root of x .
 
TensorPtr dl::rsqrt (TensorPtr x) noexcept
 Computes the reciprocal square root for each element in x.
 
TensorPtr dl::mean (TensorPtr x) noexcept
 Mean.
 
TensorPtr dl::mean (TensorPtr x, int dim, bool keepdim=false) noexcept
 Mean along a specified axis.
 
TensorPtr dl::sum (TensorPtr x) noexcept
 Sum.
 
TensorPtr dl::sum (TensorPtr x, int dim, bool keepdim=false) noexcept
 Sum along a specified axis.
 
TensorPtr dl::min (TensorPtr x) noexcept
 Minimum.
 
TensorPtr dl::min (TensorPtr x, int dim, bool keepdim=false) noexcept
 Minimum along a specified axis.
 
TensorPtr dl::max (TensorPtr x) noexcept
 Maximum.
 
TensorPtr dl::max (TensorPtr x, int dim, bool keepdim=false) noexcept
 Maximum along a specified axis.
 
TensorPtr dl::max (TensorPtr x, TensorPtr y) noexcept
 Elementwise maximum.
 
TensorPtr dl::var (TensorPtr x, DOF dof=DOF{1}) noexcept
 Variance.
 
TensorPtr dl::var (TensorPtr x, int dim, DOF dof=DOF{1}) noexcept
 Variance along a specified axis.
 
TensorPtr dl::erf (TensorPtr x) noexcept
 (Gauss) Error Function
 
TensorPtr dl::relu (TensorPtr x) noexcept
 
TensorPtr dl::operator+ (TensorPtr left, float right) noexcept
 
TensorPtr dl::operator- (TensorPtr left, float right) noexcept
 
TensorPtr dl::operator* (TensorPtr left, float right) noexcept
 
TensorPtr dl::operator/ (TensorPtr left, float right) noexcept
 
TensorPtr dl::operator+ (float left, TensorPtr right) noexcept
 
TensorPtr dl::operator- (float left, TensorPtr right) noexcept
 
TensorPtr dl::operator* (float left, TensorPtr right) noexcept
 
TensorPtr dl::operator/ (float left, TensorPtr right) noexcept
 
TensorPtr dl::operator+ (TensorPtr left, TensorPtr right) noexcept
 
TensorPtr dl::operator- (TensorPtr left, TensorPtr right) noexcept
 
TensorPtr dl::operator* (TensorPtr left, TensorPtr right) noexcept
 
TensorPtr dl::operator/ (TensorPtr left, TensorPtr right) noexcept
 
TensorPtr dl::fma (const TensorPtr &factor1, const TensorPtr &factor2, const TensorPtr &summand) noexcept
 
TensorPtr dl::matmul (TensorPtr left, TensorPtr right) noexcept
 
TensorPtr dl::transpose (TensorPtr x, std::vector< int > &&permutation) noexcept
 Transposes the given tensor at the specified coordinates.
 
TensorPtr dl::softmax (TensorPtr x) noexcept
 Computes the softmax function of the input vector.
 
TensorPtr dl::softmax (TensorPtr x, int dim) noexcept
 
std::ostreamdl::operator<< (std::ostream &, const TensorPtr &tensor) noexcept
 
bool dl::operator== (const TensorPtr &left, const TensorPtr &right) noexcept
 
bool dl::allclose (const TensorPtr &left, const TensorPtr &right, float rtol=1e-5, float atol=1e-8) noexcept
 
size_t dl::numEntries (const TensorPtr &tensor) noexcept
 Returns the number of entries in the tensor.
 
TensorPtr dl::reshape (TensorPtr tensor, SShape shape) noexcept
 

Detailed Description

Implements auto-diff enabled wrappers around their concrete tensor implementations.

Definition in file math.hpp.

Function Documentation

◆ numEntries()

size_t dl::numEntries ( const TensorPtr tensor)
noexcept

Returns the number of entries in the tensor.

This is equivalent to the product of the shape.

Parameters
tensorThe tensor to count the number of entries for.
Returns
size_t The number of entries in tensor.

◆ softmax()

TensorPtr dl::softmax ( TensorPtr  x)
noexcept

Computes the softmax function of the input vector.

Let \(x \in \mathbb R^n\) be a vector, the softmax is defined as

\[ \text{softmax}\colon \mathbb R^n \to \mathbb R^n ~\text{via}~ x\mapsto \left(\frac{e^{x_i}}{\sum_{j=1}^n e^{x_j}}\right)_{1\leq i\leq n}. \]

Parameters
xthe input tensor.
Returns
TensorPtr the softmax of x .

◆ transpose()

TensorPtr dl::transpose ( TensorPtr  x,
std::vector< int > &&  permutation 
)
noexcept

Transposes the given tensor at the specified coordinates.

Transposes the given tensor by permuting the dimensions. For example, if the input was a matrix, then \(x \in \mathbb{R}^n\times m\) the matrix transposition could be computed via dl::transpose(x, {0, 1});.

Parameters
xthe tensor to be tranposed.
permutationthe permutation to apply to the dimensions.
Returns
a new tensor with the permutation permutation applied to the dimensions.