AiLibrary  v1.3.0
A single-header C++ Library from Ailurus Studio
Math Functions

Functions providing different math methods and checks. More...

Functions

template<typename T >
INLINEai::sign (const T value)
 Returns signum of the value. More...
 
template<typename T >
INLINEai::min (const T a, const T b)
 Returns minimum of two values. More...
 
template<typename T >
INLINEai::max (const T a, const T b)
 Returns maximum of two values. More...
 
template<typename T >
INLINEai::min (const std::vector< T > &input)
 Returns minimum of vector values. More...
 
template<typename T >
INLINEai::max (const std::vector< T > &input)
 Returns maximum of vector values. More...
 
template<typename T >
INLINEai::min (const std::vector< std::vector< T > > &input)
 Returns minimum of matrix values. More...
 
template<typename T >
INLINEai::max (const std::vector< std::vector< T > > &input)
 Returns maximum of matrix values. More...
 
template<typename T >
INLINE bool ai::isSquare (const T value)
 Checks if number is square. More...
 
template<typename T >
INLINE bool ai::isSquare (const std::vector< std::vector< T > > &matrix)
 Checks if matrix is square. More...
 
template<typename T >
INLINE void ai::generateRandomVector (std::vector< T > &vector, const std::size_t length, const T min=std::numeric_limits< T >::min(), const T max=std::numeric_limits< T >::max())
 
template<typename T >
INLINE void ai::generateRandomMatrix (std::vector< std::vector< T > > &matrix, const std::size_t xSize, const std::size_t ySize, const T min=std::numeric_limits< T >::min(), const T max=std::numeric_limits< T >::max())
 Fill matrix with random values. More...
 
template<typename T >
INLINE void ai::generateRandomMatrix (std::vector< std::vector< T > > &matrix, const std::size_t size, const T min=std::numeric_limits< T >::min(), const T max=std::numeric_limits< T >::max())
 Fill matrix with random values. More...
 
template<typename T >
void ai::rotateMatrix (std::vector< std::vector< T > > &matrix, const bool rotateClockwise=false)
 Rotate square matrix. More...
 
template<typename T >
INLINE void ai::inverseMatrix (std::vector< std::vector< T > > matrix, std::vector< std::vector< T > > &inverse)
 
template<typename T >
INLINE void ai::inverseMatrix (std::vector< std::vector< T > > &matrix)
 
template<typename T >
INLINE void ai::translateMatrixIntoVector (std::vector< std::vector< T > > &matrix, std::vector< T > &vector)
 Elongates matrix into a vector. More...
 
template<typename T >
INLINE void ai::translateVectorIntoSquareMatrix (std::vector< T > &vector, std::vector< std::vector< T > > &matrix)
 Transform vector into a square matrix (if possible) More...
 
template<typename T >
INLINE void ai::generateCirculantMatrix (std::vector< std::vector< T > > &matrix, std::vector< T > &source, const bool moveToTheRight=true)
 
template<typename T >
INLINE void ai::multiply (const std::vector< std::vector< T > > &left, const std::vector< std::vector< T > > &right, std::vector< std::vector< T > > &result)
 
template<typename T >
INLINE void ai::multiply (const std::vector< std::vector< T > > &left, const std::vector< T > &right, std::vector< T > &result)
 
template<typename T >
INLINE void ai::multiply (const std::vector< T > &left, const std::vector< T > &right, T &result)
 Calculate vector-vector multiplication. More...
 
template<typename T >
INLINE void ai::multiplyElementWise (const std::vector< std::vector< T > > &left, const std::vector< std::vector< T > > &right, std::vector< std::vector< T > > &result)
 
template<typename T >
INLINE void ai::multiplyElementWise (const std::vector< T > &left, const std::vector< T > &right, std::vector< T > &result)
 
template<typename T >
INLINE void ai::multiplyComplexElementWise (const std::vector< std::vector< T > > &left, const std::vector< std::vector< T > > &right, std::vector< std::vector< T > > &result)
 
template<typename T >
INLINE std::string ai::complexIntoString (const std::vector< T > complexValue)
 
template<typename T >
INLINE void ai::conjugate (std::vector< std::vector< T > > &complexVector)
 
template<typename T >
INLINE void ai::fft (std::vector< std::vector< T > > &complexVector)
 
template<typename T >
INLINE void ai::ifft (std::vector< std::vector< T > > &complexVector)
 

Variables

static const double ai::e = 2.71828182845904523536
 Mathematical constant 'e'. More...
 
static const double ai::pi = 3.14159265358979323846
 Mathematical constant 'pi'. More...
 

Detailed Description

Group of functions that completes standard C++ mathematical methods and helps with matrices and vectors

Function Documentation

◆ complexIntoString()

template<typename T >
INLINE std::string ai::complexIntoString ( const std::vector< T >  complexValue)
Template Parameters
TA number type
Here is the call graph for this function:

◆ conjugate()

template<typename T >
INLINE void ai::conjugate ( std::vector< std::vector< T > > &  complexVector)
Template Parameters
TA number type
Here is the caller graph for this function:

◆ fft()

template<typename T >
INLINE void ai::fft ( std::vector< std::vector< T > > &  complexVector)
Template Parameters
TA number type
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateCirculantMatrix()

template<typename T >
INLINE void ai::generateCirculantMatrix ( std::vector< std::vector< T > > &  matrix,
std::vector< T > &  source,
const bool  moveToTheRight = true 
)
Here is the call graph for this function:

◆ generateRandomMatrix() [1/2]

template<typename T >
void ai::generateRandomMatrix ( std::vector< std::vector< T > > &  matrix,
const std::size_t  xSize,
const std::size_t  ySize,
const T  min = std::numeric_limits<T>::min(),
const T  max = std::numeric_limits<T>::max() 
)

This function fills the matrix of given sizes with random values using std::random_device and generateRandomVector()

Template Parameters
TA number type
Parameters
matrixMatrix to fill
xSizeRequired length of the matrix
ySizeRequired height of the matrix
minLower limit of generated values, no limitation by default
maxUpper limit of generated values, no limitation by default
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateRandomMatrix() [2/2]

template<typename T >
void ai::generateRandomMatrix ( std::vector< std::vector< T > > &  matrix,
const std::size_t  size,
const T  min = std::numeric_limits<T>::min(),
const T  max = std::numeric_limits<T>::max() 
)

This function fills the square matrix of given sizes with random values using std::random_device and generateRandomVector()

Template Parameters
TA number type
Parameters
matrixMatrix to fill
sizeRequired size of the square matrix
minLower limit of generated values, no limitation by default
maxUpper limit of generated values, no limitation by default
Here is the call graph for this function:

◆ generateRandomVector()

template<typename T >
INLINE void ai::generateRandomVector ( std::vector< T > &  vector,
const std::size_t  length,
const T  min = std::numeric_limits<T>::min(),
const T  max = std::numeric_limits<T>::max() 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ifft()

template<typename T >
INLINE void ai::ifft ( std::vector< std::vector< T > > &  complexVector)
Template Parameters
TA number type
Here is the call graph for this function:

◆ inverseMatrix() [1/2]

template<typename T >
INLINE void ai::inverseMatrix ( std::vector< std::vector< T > >  matrix,
std::vector< std::vector< T > > &  inverse 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inverseMatrix() [2/2]

template<typename T >
INLINE void ai::inverseMatrix ( std::vector< std::vector< T > > &  matrix)
Here is the call graph for this function:

◆ isSquare() [1/2]

template<typename T >
bool ai::isSquare ( const T  value)

This function checks if number is square

Template Parameters
TA number type
Parameters
valueNumber to test
Returns
True if number is a square, false otherwise
Here is the caller graph for this function:

◆ isSquare() [2/2]

template<typename T >
bool ai::isSquare ( const std::vector< std::vector< T > > &  matrix)

This function checks if matrix is square

Template Parameters
TA number type
Parameters
matrixMatrix to test
Returns
True if matrix is square, false otherwise

◆ max() [1/3]

template<typename T >
T ai::max ( const T  a,
const T  b 
)

This function compares two values and returns a maximum

Template Parameters
TA number type
Parameters
aFirst number
bSecond number
Returns
Maximum of two values
Here is the caller graph for this function:

◆ max() [2/3]

template<typename T >
T ai::max ( const std::vector< T > &  input)

This function compares vector values using max() and returns a maximum

Template Parameters
TA number type
Parameters
inputVector to search for a maximum value
Returns
Maximum of vector values
Here is the call graph for this function:

◆ max() [3/3]

template<typename T >
T ai::max ( const std::vector< std::vector< T > > &  input)

This function compares matrix values using max() and returns a maximum

Template Parameters
TA number type
Parameters
inputMatrix to search for a maximum value
Returns
Maximum of matrix values
Here is the call graph for this function:

◆ min() [1/3]

template<typename T >
T ai::min ( const T  a,
const T  b 
)

This function compares two values and returns a minimum

Template Parameters
TA number type
Parameters
aFirst number
bSecond number
Returns
Minimum of two values
Here is the caller graph for this function:

◆ min() [2/3]

template<typename T >
T ai::min ( const std::vector< T > &  input)

This function compares vector values using min() and returns a minimum

Template Parameters
TA number type
Parameters
inputVector to search for a minimum value
Returns
Minimum of vector values
Here is the call graph for this function:

◆ min() [3/3]

template<typename T >
T ai::min ( const std::vector< std::vector< T > > &  input)

This function compares matrix values using min() and returns a minimum

Template Parameters
TA number type
Parameters
inputMatrix to search for a minimum value
Returns
Minimum of matrix values
Here is the call graph for this function:

◆ multiply() [1/3]

template<typename T >
INLINE void ai::multiply ( const std::vector< std::vector< T > > &  left,
const std::vector< std::vector< T > > &  right,
std::vector< std::vector< T > > &  result 
)

◆ multiply() [2/3]

template<typename T >
INLINE void ai::multiply ( const std::vector< std::vector< T > > &  left,
const std::vector< T > &  right,
std::vector< T > &  result 
)

◆ multiply() [3/3]

template<typename T >
void ai::multiply ( const std::vector< T > &  left,
const std::vector< T > &  right,
T &  result 
)

This function calculates vector-vector multiplication

Template Parameters
TA number type
Parameters
leftLeft vector to multiply
rightRight vector to multiply
resultVariable to store result
Exceptions
std::runtime_errorIf input sizes are inappropriate

◆ multiplyComplexElementWise()

template<typename T >
INLINE void ai::multiplyComplexElementWise ( const std::vector< std::vector< T > > &  left,
const std::vector< std::vector< T > > &  right,
std::vector< std::vector< T > > &  result 
)
Template Parameters
TA number type

◆ multiplyElementWise() [1/2]

template<typename T >
INLINE void ai::multiplyElementWise ( const std::vector< std::vector< T > > &  left,
const std::vector< std::vector< T > > &  right,
std::vector< std::vector< T > > &  result 
)

◆ multiplyElementWise() [2/2]

template<typename T >
INLINE void ai::multiplyElementWise ( const std::vector< T > &  left,
const std::vector< T > &  right,
std::vector< T > &  result 
)

◆ rotateMatrix()

template<typename T >
void ai::rotateMatrix ( std::vector< std::vector< T > > &  matrix,
const bool  rotateClockwise = false 
)

This function rotates the square matrix 90 degrees clockwise or anticlockwise

Template Parameters
TAny copiable type
Parameters
matrixMatrix to rotate
rotateClockwiseOptional. If true, rotate clockwise. Otherwise, rotate anticlockwise (default)

◆ sign()

template<typename T >
T ai::sign ( const T  value)

This function returns signum of the number value (usign copysign())

Template Parameters
TA number type
Parameters
valueThe number to which signum is applied
Returns
-1 for negative values, +1 for positive, 0 for zero

◆ translateMatrixIntoVector()

template<typename T >
void ai::translateMatrixIntoVector ( std::vector< std::vector< T > > &  matrix,
std::vector< T > &  vector 
)

This function converts the matrix into a vector, writing each row one after another in a line

Template Parameters
TA number type
Parameters
matrixMatrix to tranform
vectorVector to store the result

◆ translateVectorIntoSquareMatrix()

template<typename T >
void ai::translateVectorIntoSquareMatrix ( std::vector< T > &  vector,
std::vector< std::vector< T > > &  matrix 
)

This function converts the vector into a matrix, if possible. Otherwise, an exception will be thrown at runtime

Template Parameters
TA number type
Parameters
vectorVector to tranform
matrixMatrix to store the result
Exceptions
std::runtime_errorIf matrix is not square
Here is the call graph for this function:

Variable Documentation

◆ e

const double ai::e = 2.71828182845904523536
static

Mathematical constant $e$ (20 decimal places)

◆ pi

const double ai::pi = 3.14159265358979323846
static

Mathematical constant $\pi$ (20 decimal places)