AiLibrary  v1.3.0
A single-header C++ Library from Ailurus Studio
ai.hh File Reference

Single-header C++ Library. More...

#include <array>
#include <cmath>
#include <chrono>
#include <limits>
#include <memory>
#include <random>
#include <string>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <stdexcept>
#include <sys/stat.h>
#include <dirent.h>
Include dependency graph for ai.hh:

Go to the source code of this file.

Namespaces

 ai
 Main namespace.
 

Macros

#define INLINE   inline
 If defined, funstions will be marked as inline. More...
 
#define AI_DIRENT_SUPPORT
 
#define AI_GCC5_SUPPORT
 
#define AI_SHELL_SUPPORT
 
#define STRINGIFY(x)   #x
 Convert a variable name into text. More...
 
#define TO_STRING(x)   STRINGIFY(x)
 Convert a variable value into text. More...
 
#define PRINT_LINE()   std::cout << "Line #" << __LINE__ << std::endl
 Print the line number. More...
 

Functions

INLINE std::string ai::getVersion ()
 Get version of the library. More...
 
template<typename T >
INLINE std::string ai::string (const T value)
 Converts input into a string. More...
 
INLINE bool ai::hasPrefix (const std::string &text, const std::string &prefix)
 Checks if a string begins with a substring. More...
 
INLINE bool ai::hasSuffix (const std::string &text, const std::string &suffix)
 Checks if a string ends with a substring. More...
 
INLINE bool ai::contains (const std::string &text, const std::string &substring)
 Checks if a string contains a substring. More...
 
INLINE std::string ai::replace (std::string text, const std::string &substring, const std::string &replacement)
 Replaces all occurrences of a substring in a copy of the initial string with your text. More...
 
INLINE void ai::applyReplace (std::string &text, const std::string &substring, const std::string &replacement)
 Modifies your string by replacing all occurrences of a substring string with your text. More...
 
INLINE bool ai::equal (const char *charString, const std::string string1)
 Checks if a char string is equal to a std::string. More...
 
INLINE std::string ai::toUpperCase (std::string input)
 Convert a string to upper case. More...
 
INLINE std::string ai::toLowerCase (std::string input)
 Convert a string to lower case. More...
 
template<typename T >
INLINE std::string ai::prependNumber (const T value, const std::size_t symbolsBeforePoint, const char symbolToPrepend='0')
 
INLINE std::size_t ai::counter (const std::size_t value=0)
 Returns ID starting from zero or the specified value. More...
 
INLINE std::string ai::marker (const std::size_t value=0)
 Returns a string containing the word "Marker" and its ID. More...
 
INLINE void ai::printMarker (const std::size_t value=0)
 Calls marker() and prints result to stdout. More...
 
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)
 
INLINE std::chrono::high_resolution_clock::time_point ai::time ()
 Returns current time point. More...
 
INLINE std::chrono::system_clock::time_point ai::systemTime ()
 Returns current time point. More...
 
INLINE double ai::duration (const std::chrono::high_resolution_clock::time_point start, const std::chrono::high_resolution_clock::time_point finish, const std::string scale=std::string("ms"))
 
INLINE double ai::duration (const std::chrono::high_resolution_clock::time_point start, const std::string scale=std::string("ms"))
 
INLINE void ai::printDuration (const std::chrono::high_resolution_clock::time_point start, const std::chrono::high_resolution_clock::time_point finish, const std::string scale=std::string("ms"), const std::size_t count=0)
 
INLINE void ai::printDuration (const std::chrono::high_resolution_clock::time_point start, const std::string scale=std::string("ms"), const std::size_t count=0)
 
INLINE std::string ai::getDateAndTime (std::chrono::system_clock::time_point timePoint=std::chrono::system_clock::now())
 Get date and time. More...
 
INLINE std::string ai::getDate (std::chrono::system_clock::time_point timePoint=std::chrono::system_clock::now())
 Get date. More...
 
INLINE std::string ai::getTime (std::chrono::system_clock::time_point timePoint=std::chrono::system_clock::now())
 Get time. More...
 
INLINE std::string ai::parseParameter (const char *input, const std::string name)
 
template<typename T >
INLINE void ai::assignFromVectorByIntervalCondition (T &value, const T parameter, const std::vector< std::vector< T > > intervals)
 
template<typename T >
INLINE void ai::assignFromVectorByIntervalCondition (T &firstValue, T &secondValue, const T parameter, const std::vector< std::vector< T > > intervals)
 
INLINE bool ai::assignBooleanParameter (const char *input, const std::string name, bool &value)
 
INLINE bool ai::assignCharParameter (const char *input, const std::string name, char &value)
 
INLINE bool ai::assignStringParameter (const char *input, const std::string name, std::string &value)
 
template<typename T >
INLINE bool ai::assignParameter (const char *input, const std::string name, T &value)
 
INLINE bool ai::assignAbsDoubleParameter (const char *input, const std::string name, double &value)
 
template<typename T >
INLINE bool ai::assignByCheckingParameter (const char *input, const std::string parameter, T &value, const T supposed)
 
INLINE void ai::clearScreen ()
 
INLINE void ai::setLocale (const std::string locale)
 
INLINE void ai::showProgressBar (double progress, const int screenWidth=80)
 
INLINE void ai::printLine (const std::string line, const int screenWidth=80)
 
template<typename T >
INLINE void ai::parseFileInMatrix (const std::string filename, const char separator, std::vector< std::vector< T > > &matrix)
 
template<typename T >
INLINE void ai::parseFileInVector (const std::string filename, const char separator, std::vector< T > &vector)
 
INLINE void ai::parseFileIntoString (const std::string filename, std::string &content)
 
template<typename T >
INLINE void ai::accumulateFileInMatrix (const std::string filename, const char separator, std::vector< std::vector< T > > &matrix)
 
template<typename T >
INLINE void ai::accumulateFileInVector (const std::string filename, const char separator, std::vector< T > &vector, const bool checkForNaN=false)
 
template<typename T >
INLINE void ai::printMatrix (const std::vector< std::vector< T > > &matrix, const bool transpose=false, const int precision=5)
 
template<typename T >
INLINE void ai::printVector (const std::vector< T > &vector, const int precision=5)
 
template<typename T >
INLINE void ai::print (const std::vector< std::vector< T > > &matrix, const bool transpose=false, const int precision=5)
 
template<typename T >
INLINE void ai::print (const std::vector< T > &vector, const int precision=5)
 
template<typename T >
INLINE void ai::print (const T value, const std::string name=std::string("Value"))
 
static std::string ai::black ("\3[30m")
 Terminal color code for black. More...
 
static std::string ai::red ("\3[31m")
 Terminal color code for red. More...
 
static std::string ai::green ("\3[32m")
 Terminal color code for green. More...
 
static std::string ai::yellow ("\3[33m")
 Terminal color code for yellow. More...
 
static std::string ai::blue ("\3[34m")
 Terminal color code for blue. More...
 
static std::string ai::magenta ("\3[35m")
 Terminal color code for magenta. More...
 
static std::string ai::cyan ("\3[36m")
 Terminal color code for cyan. More...
 
static std::string ai::white ("\3[37m")
 Terminal color code for white. More...
 
static std::string ai::bold ("\3[1m")
 Terminal style code for bold. More...
 
static std::string ai::underline ("\3[4m")
 Terminal style code for underline. More...
 
static std::string ai::reset ("\3[0m")
 Terminal code to reset special formatting. More...
 
template<typename T >
INLINE void ai::printStyle (const T income, const std::string style)
 
template<typename T >
INLINE void ai::printBlack (const T income)
 
template<typename T >
INLINE void ai::printRed (const T income)
 
template<typename T >
INLINE void ai::printGreen (const T income)
 
template<typename T >
INLINE void ai::printYellow (const T income)
 
template<typename T >
INLINE void ai::printBlue (const T income)
 
template<typename T >
INLINE void ai::printMagenta (const T income)
 
template<typename T >
INLINE void ai::printCyan (const T income)
 
template<typename T >
INLINE void ai::printWhite (const T income)
 
template<typename T >
INLINE void ai::printBold (const T income)
 
template<typename T >
INLINE void ai::printUnderline (const T income)
 
INLINE void ai::printAllStyles ()
 
INLINE void ai::clearStyles ()
 
template<typename T >
INLINE void ai::saveMatrix (const std::string filename, const std::vector< std::vector< T > > &matrix, std::string comment=std::string(), const bool transpose=false, std::string type=std::string("text"), std::string delimiter=std::string(" "), const std::size_t tokenWidth=14)
 
template<typename T >
INLINE void ai::saveVector (const std::string filename, const std::vector< T > &vector, std::string comment=std::string(), std::string type=std::string("text"), std::string delimiter=std::string("\))
 
INLINE void ai::saveLine (const std::string filename, const std::string line, std::string comment=std::string())
 
template<typename T >
INLINE void ai::save (const std::string filename, const std::vector< std::vector< T > > &matrix, std::string comment=std::string())
 
template<typename T >
INLINE void ai::save (const std::string filename, const std::vector< T > &vector, std::string comment=std::string())
 
template<typename T >
INLINE void ai::save (const std::string filename, const std::string line, std::string comment=std::string())
 
INLINE void ai::saveLog (const std::string filename, std::string log, const bool timestamp=false, const std::string stampSeparator=std::string(" "))
 
INLINE void ai::saveLog (const std::string filename, std::vector< std::string > &logs, const bool timestamp=false, const std::string stampSeparator=std::string(" "))
 
template<typename T >
INLINE bool ai::loadA3R (const std::string filename, std::vector< std::vector< T > > &positions, double &radius)
 
template<typename T >
INLINE bool ai::saveA3R (const std::string filename, const std::vector< std::vector< T > > &positions, const double radius=1)
 
template<typename T >
INLINE void ai::loadXYZ (const std::string filename, std::vector< std::vector< T > > &matrix)
 
template<typename T >
INLINE void ai::saveXYZ (const std::string filename, const std::vector< std::vector< T > > &matrix, const std::vector< T > &tones, std::string elementName="C")
 
template<typename T >
INLINE void ai::saveXYZ (const std::string filename, const std::vector< std::vector< T > > &matrix, std::string elementName="C")
 
INLINE bool ai::folderExists (const std::string name)
 Check if folder exists. More...
 
INLINE std::size_t ai::countLinesInFile (const std::string filename, const std::string token=std::string())
 
INLINE std::vector< std::string > ai::listFilesWithExtension (std::string path, const std::string extension, const std::string prefix=std::string(), const bool addPathToFileNames=false)
 
INLINE std::string ai::execute (const std::string command)
 

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

Author
Egor Starobinskii
Date
10 Feb 2019

This is a single-header C++ Library from Ailurus Studio that brings you extra time to admire life instead of coding the same functions again and again. Meets the C++11 standard.

See also
https://starobinskii.github.io/AiLibrary
https://github.com/starobinskii/AiLibrary
https://snapcraft.io/ailibrary
https://ailurus.ru/

Macro Definition Documentation

◆ AI_DIRENT_SUPPORT

#define AI_DIRENT_SUPPORT

◆ AI_GCC5_SUPPORT

#define AI_GCC5_SUPPORT

◆ AI_SHELL_SUPPORT

#define AI_SHELL_SUPPORT

◆ INLINE

#define INLINE   inline

If defined, funstions will be marked as inline. Comment the line if you want to omit this behavior