libdl  0.0.1
Simple yet powerful deep learning
Loading...
Searching...
No Matches
math.hpp
Go to the documentation of this file.
1
21#pragma once
22
23#include "shape.hpp"
24#include "tensorptr.hpp"
25
26#include <iostream>
27#include <vector>
28
29namespace dl {
38 [[nodiscard]] TensorPtr pow(TensorPtr base, float exponent) noexcept;
39
48 [[nodiscard]] TensorPtr exp(TensorPtr x) noexcept;
49
58 [[nodiscard]] TensorPtr log(TensorPtr x) noexcept;
59
68 [[nodiscard]] TensorPtr sqrt(TensorPtr x) noexcept;
69
78 [[nodiscard]] TensorPtr rsqrt(TensorPtr x) noexcept;
79
88 [[nodiscard]] TensorPtr mean(TensorPtr x) noexcept;
99 [[nodiscard]] TensorPtr mean(TensorPtr x, int dim, bool keepdim = false) noexcept;
100
109 [[nodiscard]] TensorPtr sum(TensorPtr x) noexcept;
120 [[nodiscard]] TensorPtr sum(TensorPtr x, int dim, bool keepdim = false) noexcept;
121
130 [[nodiscard]] TensorPtr min(TensorPtr x) noexcept;
141 [[nodiscard]] TensorPtr min(TensorPtr x, int dim, bool keepdim = false) noexcept;
142
151 [[nodiscard]] TensorPtr max(TensorPtr x) noexcept;
162 [[nodiscard]] TensorPtr max(TensorPtr x, int dim, bool keepdim = false) noexcept;
172 [[nodiscard]] TensorPtr max(TensorPtr x, TensorPtr y) noexcept;
173
177 struct DOF {
178 size_t dof;
179 };
180
190 [[nodiscard]] TensorPtr var(TensorPtr x, DOF dof = DOF{1}) noexcept;
201 [[nodiscard]] TensorPtr var(TensorPtr x, int dim, DOF dof = DOF{1}) noexcept;
202
211 [[nodiscard]] TensorPtr erf(TensorPtr x) noexcept;
212
213 [[nodiscard]] TensorPtr relu(TensorPtr x) noexcept;
214
215 // Tensor-Scalar Operations
216 [[nodiscard]] TensorPtr operator+(TensorPtr left, float right) noexcept;
217 [[nodiscard]] TensorPtr operator-(TensorPtr left, float right) noexcept;
218 [[nodiscard]] TensorPtr operator*(TensorPtr left, float right) noexcept;
219 [[nodiscard]] TensorPtr operator/(TensorPtr left, float right) noexcept;
220 [[nodiscard]] TensorPtr operator+(float left, TensorPtr right) noexcept;
221 [[nodiscard]] TensorPtr operator-(float left, TensorPtr right) noexcept;
222 [[nodiscard]] TensorPtr operator*(float left, TensorPtr right) noexcept;
223 [[nodiscard]] TensorPtr operator/(float left, TensorPtr right) noexcept;
224
225 // Tensor-Tensor Operations
226 [[nodiscard]] TensorPtr operator+(TensorPtr left, TensorPtr right) noexcept;
227 [[nodiscard]] TensorPtr operator-(TensorPtr left, TensorPtr right) noexcept;
228 [[nodiscard]] TensorPtr operator*(TensorPtr left, TensorPtr right) noexcept;
229 [[nodiscard]] TensorPtr operator/(TensorPtr left, TensorPtr right) noexcept;
230
231 [[nodiscard]] TensorPtr fma(const TensorPtr& factor1, const TensorPtr& factor2, const TensorPtr& summand) noexcept;
232
233 [[nodiscard]] TensorPtr matmul(TensorPtr left, TensorPtr right) noexcept;
234
244 [[nodiscard]] TensorPtr transpose(TensorPtr x, std::vector<int>&& permutation) noexcept;
245
246 [[nodiscard]] TensorPtr softmax(TensorPtr x) noexcept;
258 [[nodiscard]] TensorPtr softmax(TensorPtr x) noexcept;
259 [[nodiscard]] TensorPtr softmax(TensorPtr x, int dim) noexcept;
260
261 std::ostream& operator<<(std::ostream&, const TensorPtr& tensor) noexcept;
262 [[nodiscard]] bool operator==(const TensorPtr& left, const TensorPtr& right) noexcept;
263 [[nodiscard]] bool
264 allclose(const TensorPtr& left, const TensorPtr& right, float rtol = 1e-5, float atol = 1e-8) noexcept;
265
273 [[nodiscard]] size_t numEntries(const TensorPtr& tensor) noexcept;
274
275 TensorPtr reshape(TensorPtr tensor, SShape shape) noexcept;
276} // namespace dl
The Tensor is a managed pointer to a tensor. It can generally be thought of like an std::unique_ptr<T...
Definition tensorptr.hpp:45
TensorPtr exp(TensorPtr x) noexcept
Computes the elementwise x -th power of e.
TensorPtr pow(TensorPtr base, float exponent) noexcept
Computes the exponent -th power of each element in base and returns the resulting tensor.
TensorPtr rsqrt(TensorPtr x) noexcept
Computes the reciprocal square root for each element in x.
TensorPtr sqrt(TensorPtr x) noexcept
Computes the elementwise square root of x .
TensorPtr log(TensorPtr x) noexcept
Natural logarithm, .
TensorPtr erf(TensorPtr x) noexcept
(Gauss) Error Function
TensorPtr mean(TensorPtr x) noexcept
Mean.
TensorPtr var(TensorPtr x, DOF dof=DOF{1}) noexcept
Variance.
TensorPtr sum(TensorPtr x) noexcept
Sum.
TensorPtr max(TensorPtr x) noexcept
Maximum.
TensorPtr min(TensorPtr x) noexcept
Minimum.
TensorPtr softmax(TensorPtr x) noexcept
Computes the softmax function of the input vector.
TensorPtr transpose(TensorPtr x, std::vector< int > &&permutation) noexcept
Transposes the given tensor at the specified coordinates.
Wrapper around std::size_t to discern between var(TensorPtr, DOF) and var(TensorPtr,...
Definition math.hpp:177