# Algorithms_in_C++: math/large_number.h Source File

large_number.h
Go to the documentation of this file.
/**
* @file
* @brief Library to perform arithmatic operations on arbitrarily large
* numbers.
* \author [Krishna Vedala](https://github.com/kvedala)
*/
#ifndef MATH_LARGE_NUMBER_H_
#define MATH_LARGE_NUMBER_H_
#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <cstring>
#include <iostream>
#include <type_traits>
#include <vector>
/**
* Store large unsigned numbers as a C++ vector
* The class provides convenience functions to add a
* digit to the number, perform multiplication of
* large number with long unsigned integers.
**/
class large_number {
public:
/**< initializer with value = 1 */
large_number() { _digits.push_back(1); }
// /**< initializer from an integer */
// explicit large_number(uint64_t n) {
// uint64_t carry = n;
// do {
// add_digit(carry % 10);
// carry /= 10;
// } while (carry != 0);
// }
/**< initializer from an integer */
explicit large_number(int n) {
int carry = n;
do {
add_digit(carry % 10);
carry /= 10;
} while (carry != 0);
}
/**< initializer from another large_number */
large_number(const large_number &a) : _digits(a._digits) {}
/**< initializer from a vector */
explicit large_number(std::vector<unsigned char> &vec) : _digits(vec) {}
/**< initializer from a string */
explicit large_number(char const *number_str) {
for (size_t i = strlen(number_str); i > 0; i--) {
char a = number_str[i - 1] - '0';
if (a >= 0 && a <= 9)
_digits.push_back(a);
}
}
/**
* Function to check implementation
**/
static bool test() {
std::cout << "------ Checking `large_number` class implementations\t"
<< std::endl;
large_number a(40);
// 1. test multiplication
a *= 10;
if (a != large_number(400)) {
std::cerr << "\tFailed 1/6 (" << a << "!=400)" << std::endl;
return false;
}
std::cout << "\tPassed 1/6...";
// 2. test compound addition with integer
a += 120;
if (a != large_number(520)) {
std::cerr << "\tFailed 2/6 (" << a << "!=520)" << std::endl;
return false;
}
std::cout << "\tPassed 2/6...";
// 3. test compound multiplication again
a *= 10;
if (a != large_number(5200)) {
std::cerr << "\tFailed 3/6 (" << a << "!=5200)" << std::endl;
return false;
}
std::cout << "\tPassed 3/6...";
// 4. test increment (prefix)
++a;
if (a != large_number(5201)) {
std::cerr << "\tFailed 4/6 (" << a << "!=5201)" << std::endl;
return false;
}
std::cout << "\tPassed 4/6...";
// 5. test increment (postfix)
a++;
if (a != large_number(5202)) {
std::cerr << "\tFailed 5/6 (" << a << "!=5202)" << std::endl;
return false;
}
std::cout << "\tPassed 5/6...";
// 6. test addition with another large number
a = a + large_number("7000000000000000000000000000000");
if (a != large_number("7000000000000000000000000005202")) {
std::cerr << "\tFailed 6/6 (" << a
<< "!=7000000000000000000000000005202)" << std::endl;
return false;
}
std::cout << "\tPassed 6/6..." << std::endl;
return true;
}
/**
* add a digit at MSB to the large number
**/
void add_digit(unsigned int value) {
if (value > 9) {
std::cerr << "digit > 9!!\n";
exit(EXIT_FAILURE);
}
_digits.push_back(value);
}
/**
* Get number of digits in the number
**/
size_t num_digits() const { return _digits.size(); }
/**
* operator over load to access the
* i^th digit conveniently and also
* assign value to it
**/
inline unsigned char &operator[](size_t n) { return this->_digits[n]; }
inline const unsigned char &operator[](size_t n) const {
return this->_digits[n];
}
/**
* operator overload to compare two numbers
**/
friend std::ostream &operator<<(std::ostream &out, const large_number &a) {
for (size_t i = a.num_digits(); i > 0; i--)
out << static_cast<int>(a[i - 1]);
return out;
}
/**
* operator overload to compare two numbers
**/
friend bool operator==(large_number const &a, large_number const &b) {
size_t N = a.num_digits();
if (N != b.num_digits())
return false;
for (size_t i = 0; i < N; i++)
if (a[i] != b[i])
return false;
return true;
}
/**
* operator overload to compare two numbers
**/
friend bool operator!=(large_number const &a, large_number const &b) {
return !(a == b);
}
/**
* operator overload to increment (prefix)
**/
large_number &operator++() {
(*this) += 1;
return *this;
}
/**
* operator overload to increment (postfix)
**/
large_number &operator++(int) {
static large_number tmp(_digits);
++(*this);
return tmp;
}
/**
* operator overload to add
**/
large_number &operator+=(large_number n) {
// if adding with another large_number
large_number *b = reinterpret_cast< large_number *>(&n);
const size_t max_L = std::max(this->num_digits(), b->num_digits());
unsigned int carry = 0;
size_t i;
for (i = 0; i < max_L || carry != 0; i++) {
if (i < b->num_digits())
carry += (*b)[i];
if (i < this->num_digits())
carry += (*this)[i];
if (i < this->num_digits())
(*this)[i] = carry % 10;
else
this->add_digit(carry % 10);
carry /= 10;
}
return *this;
}
large_number &operator+=(int n) { return (*this) += large_number(n); }
// large_number &operator+=(uint64_t n) { return (*this) += large_number(n);
// }
/**
* operator overload to perform addition
**/
template <class T>
friend large_number &operator+(const large_number &a, const T &b) {
static large_number c = a;
c += b;
return c;
}
/**
* assignment operator
**/
large_number &operator=(const large_number &b) {
this->_digits = b._digits;
return *this;
}
/**
* operator overload to increment
**/
template <class T>
large_number &operator*=(const T n) {
static_assert(std::is_integral<T>::value,
"Must be integer addition unsigned integer types.");
this->multiply(n);
return *this;
}
/**
* returns i^th digit as an ASCII character
**/
char digit_char(size_t i) const {
return _digits[num_digits() - i - 1] + '0';
}
private:
/**
* multiply large number with another integer and
* store the result in the same large number
**/
template <class T>
void multiply(const T n) {
static_assert(std::is_integral<T>::value,
"Can only have integer types.");
// assert(!(std::is_signed<T>::value)); //, "Implemented only for
// unsigned integer types.");
size_t i;
uint64_t carry = 0, temp;
for (i = 0; i < this->num_digits(); i++) {
temp = static_cast<uint64_t>((*this)[i]) * n;
temp += carry;
if (temp < 10) {
carry = 0;
} else {
carry = temp / 10;
temp = temp % 10;
}
(*this)[i] = temp;
}
while (carry != 0) {
this->add_digit(carry % 10);
carry /= 10;
}
}
std::vector<unsigned char>
_digits; /**< where individual digits are stored */
};
#endif // MATH_LARGE_NUMBER_H_
number_of_digits
int number_of_digits(int num)
Definition: armstrong_number.cpp:21
binExpo
int binExpo(int a, int b)
Definition: binary_exponent.cpp:28
large_number::add_digit
void add_digit(unsigned int value)
Definition: large_number.h:118
std::showpoint
T showpoint(T... args)
stack::pop
void pop()
Definition: stack.h:99
is_armstrong
bool is_armstrong(int number)
Definition: armstrong_number.cpp:36
trie
Definition: trie_tree.cpp:8
std::srand
T srand(T... args)
main
int main()
Definition: double_factorial.cpp:67
main
int main()
Definition: gcd_of_n_numbers.cpp:28
std::setprecision
T setprecision(T... args)
std::vector::resize
T resize(T... args)
std::bitset< MAXN >
std::make_tuple
T make_tuple(T... args)
CycleCheck::isCyclicBFS
static bool isCyclicBFS(Graph const &graph)
Definition: cycle_check_directed_graph.cpp:241
std::strlen
T strlen(T... args)
std::domain_error
STL class.
std::string
STL class.
std::shared_ptr
STL class.
MAX
#define MAX
Definition: fibonacci_fast.cpp:27
Graph::addVertices
void addVertices(unsigned int num=1)
Definition: cycle_check_directed_graph.cpp:122
test1
bool test1()
Definition: large_factorial.cpp:17
std::list
STL class.
std::fabs
T fabs(T... args)
std::inner_product
T inner_product(T... args)
std::clock_t
gcd
int gcd(int num1, int num2)
Definition: gcd_iterative_euclidean.cpp:15
Complex
Class Complex to represent complex numbers as a field.
Definition: complex_numbers.cpp:20
std::move
T move(T... args)
main
int main()
Main function.
Definition: fibonacci.cpp:28
operator+
std::vector< T > operator+(std::vector< T > const &A, std::vector< T > const &B)
Definition: ordinary_least_squares_regressor.cpp:198
large_number::operator<<
friend std::ostream & operator<<(std::ostream &out, const large_number &a)
Definition: large_number.h:146
large_number::large_number
large_number(std::vector< unsigned char > &vec)
Definition: large_number.h:51
std::atan2
T atan2(T... args)
update_step
void update_step(T *r, T *r0, const T2 quotient)
Definition: extended_euclid_algorithm.cpp:24
std::pair
graph
Definition: bfs.cpp:3
double_factorial_iterative
uint64_t double_factorial_iterative(uint64_t n)
Definition: double_factorial.cpp:17
std::cos
T cos(T... args)
machine_learning::adaline::adaline
adaline(int num_features, const double eta=0.01f, const double accuracy=1e-5)
Definition: adaline_learning.cpp:53
Trie
Definition: trie_modern.cpp:16
std::vector< int >
std::system
T system(T... args)
std::unordered_map::find
T find(T... args)
test1
void test1()
Definition: kohonen_som_topology.cpp:359
std::string::size
T size(T... args)
machine_learning::adaline::fit
double fit(const std::vector< double > &x, const int &y)
Definition: adaline_learning.cpp:112
Complex::arg
double arg() const
Member function to give the argument of our complex number.
Definition: complex_numbers.cpp:87
ans
ll ans(ll n)
Definition: matrix_exponentiation.cpp:91
std::stack
STL class.
Complex::operator*
Complex operator*(const Complex &other)
Operator overload of '*' on Complex class. Operator overload to be able to multiple two complex numbe...
Definition: complex_numbers.cpp:117
large_number
Definition: large_number.h:24
fib
large_number fib(uint64_t n)
Definition: fibonacci_large.cpp:24
main
int main()
Definition: fibonacci_fast.cpp:51
print
void print(uint32_t N)
Definition: sieve_of_eratosthenes.cpp:40
std::iterator
main
int main(int argc, char **argv)
Definition: kohonen_som_topology.cpp:566
Trie::hasChildren
static bool hasChildren(std::shared_ptr< TrieNode > node)
Definition: trie_modern.cpp:41
Complex::operator-
Complex operator-(const Complex &other)
Operator overload of '-' on Complex class. Operator overload to be able to subtract two complex numbe...
Definition: complex_numbers.cpp:106
Complex::Complex
Complex(const Complex &other)
Copy Constructor.
Definition: complex_numbers.cpp:58
std::queue::emplace
T emplace(T... args)
Complex::Complex
Complex(double x=0.f, double y=0.f, bool is_polar=false)
Complex Constructor which initialises our complex number.
Definition: complex_numbers.cpp:43
Complex::abs
double abs() const
Member function to give the modulus of our complex number. Member function to which gives the absolut...
Definition: complex_numbers.cpp:79
main
int main(int argc, char *argv[])
Definition: large_factorial.cpp:89
test_3d_classes
void test_3d_classes(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_trace.cpp:347
Trie::TrieNode
Definition: trie_modern.cpp:26
std::distance
T distance(T... args)
gcd
int gcd(int num1, int num2)
Definition: gcd_recursive_euclidean.cpp:14
large_number.h
Library to perform arithmatic operations on arbitrarily large numbers.
node
Definition: avltree.cpp:13
get_rand
double get_rand()
Function to get random numbers to generate our complex numbers for test.
Definition: complex_numbers.cpp:201
binExpo_alt
int binExpo_alt(int a, int b)
Definition: binary_exponent.cpp:42
graph::explore
void explore(int, vector< bool > &)
Utility function for depth first seach algorithm this function explores the vertex which is passed in...
Definition: connected_components.cpp:101
std::search
T search(T... args)
save_nd_data
int save_nd_data(const char *fname, const std::vector< std::valarray< double >> &X)
Definition: kohonen_som_trace.cpp:57
node
struct list node
std::scanf
T scanf(T... args)
get_clock_diff
double get_clock_diff(clock_t start_t, clock_t end_t)
Definition: kohonen_som_trace.cpp:438
std::setfill
T setfill(T... args)
std::reverse
T reverse(T... args)
Graph::Graph
Graph(unsigned int vertices, std::vector< Edge > const &edges)
Definition: cycle_check_directed_graph.cpp:90
std::vector::back
T back(T... args)
machine_learning::adaline::predict
int predict(const std::vector< double > &x, double *out=nullptr)
Definition: adaline_learning.cpp:92
tests
void tests()
Definition: complex_numbers.cpp:206
machine_learning
Machine learning algorithms.
Complex::operator=
const Complex & operator=(const Complex &other)
Operator overload of '=' on Complex class. Operator overload to be able to copy RHS instance of Compl...
Definition: complex_numbers.cpp:160
is_square
bool is_square(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:57
main
int main()
Definition: gcd_recursive_euclidean.cpp:42
machine_learning::update_weights
double update_weights(const std::valarray< double > &X, std::vector< std::vector< std::valarray< double >>> *W, std::vector< std::valarray< double >> *D, double alpha, int R)
Definition: kohonen_som_topology.cpp:193
std::queue
STL class.
large_number::num_digits
size_t num_digits() const
Definition: large_number.h:130
Graph
Definition: bellman_ford.cpp:13
Solution
Definition: bridge_finding_with_tarjan_algorithm.cpp:13
get_min_2d
void get_min_2d(const std::vector< std::valarray< double >> &X, double *val, int *x_idx, int *y_idx)
Definition: kohonen_som_topology.cpp:99
std::queue::front
T front(T... args)
std::sort
T sort(T... args)
machine_learning::adaline::check_size_match
bool check_size_match(const std::vector< double > &x)
Definition: adaline_learning.cpp:176
std::sqrt
T sqrt(T... args)
stack_idx
int stack_idx
pointer to track stack index
Definition: paranthesis_matching.cpp:23
Entry
Definition: double_hash_hash_table.cpp:28
test1
void test1()
Definition: kohonen_som_trace.cpp:225
large_number::operator+=
large_number & operator+=(large_number n)
Definition: large_number.h:192
query
Definition: mo.cpp:6
operator*
std::vector< std::vector< T > > operator*(std::vector< std::vector< T >> const &A, std::vector< std::vector< T >> const &B)
Definition: ordinary_least_squares_regressor.cpp:74
is_prime
bool is_prime(T num)
Definition: check_prime.cpp:22
fast_power_recursive
double fast_power_recursive(T a, T b)
Definition: fast_power.cpp:26
std::tie
T tie(T... args)
Node
Definition: linkedlist_implentation_usingarray.cpp:14
std::vector::push_back
T push_back(T... args)
test
void test(uint64_t n, uint64_t expected)
Definition: double_factorial.cpp:42
Point::y
int y
Point respect to x coordinate.
Definition: line_segment_intersection.cpp:14
graph::depth_first_search
void depth_first_search()
Function that perfoms depth first search algorithm on graph.
Definition: connected_components.cpp:83
std::clock
T clock(T... args)
main
int main(int argc, char **argv)
Definition: kohonen_som_trace.cpp:443
Complex::real
double real() const
Member function to get real value of our complex number. Member function (getter) to access the class...
Definition: complex_numbers.cpp:64
large_number::large_number
large_number(const large_number &a)
Definition: large_number.h:48
fibonacci
int fibonacci(unsigned int n)
Definition: fibonacci.cpp:17
Trie::insert
void insert(const std::string &word)
Definition: trie_modern.cpp:109
operator<<
std::ostream & operator<<(std::ostream &out, std::vector< std::vector< T >> const &v)
Definition: ordinary_least_squares_regressor.cpp:22
CycleCheck::isCyclicDFS
static bool isCyclicDFS(Graph const &graph)
Definition: cycle_check_directed_graph.cpp:206
test3
void test3()
Definition: kohonen_som_topology.cpp:523
createNode
node * createNode(int data)
Definition: avltree.cpp:21
CycleCheck
Definition: cycle_check_directed_graph.cpp:153
CycleCheck::isCyclicDFSHelper
static bool isCyclicDFSHelper(AdjList const &adjList, std::vector< nodeStates > *state, unsigned int node)
Definition: cycle_check_directed_graph.cpp:165
main
int main()
Definition: hill_cipher.cpp:532
large_number::operator*=
large_number & operator*=(const T n)
Definition: large_number.h:238
large_number::large_number
large_number()
Definition: large_number.h:27
init
void init()
Definition: sieve_of_eratosthenes.cpp:52
main
int main()
Main function.
Definition: binary_exponent.cpp:55
MinHeapNode
Definition: huffman.cpp:7
main
int main()
Definition: line_segment_intersection.cpp:92
main
int main()
Definition: connected_components.cpp:111
Complex::operator/
Complex operator/(const Complex &other)
Operator overload of '/' on Complex class. Operator overload to be able to divide two complex numbers...
Definition: complex_numbers.cpp:142
large_number::operator++
large_number & operator++()
Definition: large_number.h:175
test1
void test1(double eta=0.01)
Definition: adaline_learning.cpp:204
insert
node * insert(node *root, int item)
Definition: avltree.cpp:66
std::printf
T printf(T... args)
std::vector::at
T at(T... args)
large_number::digit_char
char digit_char(size_t i) const
Definition: large_number.h:248
large_number::operator[]
unsigned char & operator[](size_t n)
Definition: large_number.h:137
std::cout
h
int h(int key)
Definition: hash_search.cpp:45
std::ofstream
STL class.
SegmentIntersection::direction
int direction(Point first_point, Point second_point, Point third_point)
Definition: line_segment_intersection.cpp:63
Graph::getAdjList
std::remove_reference_t< AdjList > const & getAdjList() const
Definition: cycle_check_directed_graph.cpp:105
machine_learning::adaline::eta
const double eta
learning rate of the algorithm
Definition: adaline_learning.cpp:187
std::min_element
T min_element(T... args)
phiFunction
uint64_t phiFunction(uint64_t n)
Definition: eulers_totient_function.cpp:32
std::queue::pop
T pop(T... args)
std::stack::top
T top(T... args)
Edge::Edge
Edge(unsigned int source, unsigned int destination)
Definition: cycle_check_directed_graph.cpp:42
Trie::Trie
Trie()
constructor to initialise the root of the trie.
Definition: trie_modern.cpp:103
mst
Definition: prims_minimum_spanning_tree.cpp:9
Graph::addEdge
void addEdge(unsigned int source, unsigned int destination)
Definition: cycle_check_directed_graph.cpp:140
test
void test()
Definition: armstrong_number.cpp:59
std::ofstream::close
T close(T... args)
main
int main()
Definition: factorial.cpp:15
large_number::multiply
void multiply(const T n)
Definition: large_number.h:258
Complex::operator~
Complex operator~() const
Operator overload of '~' on Complex class. Operator overload of the BITWISE NOT which gives us the co...
Definition: complex_numbers.cpp:130
std::perror
T perror(T... args)
operator<<
std::ostream & operator<<(std::ostream &os, const Complex &num)
Operator overload of '<<' of ostream for Complex class. Overloaded insersion operator to accommodate ...
Definition: complex_numbers.cpp:186
ll
#define ll
Definition: matrix_exponentiation.cpp:33
std::set::erase
T erase(T... args)
machine_learning::adaline::weights
std::vector< double > weights
weights of the neural network
Definition: adaline_learning.cpp:189
std::valarray
STL class.
SegmentIntersection
Definition: line_segment_intersection.cpp:22
main
int main()
Definition: ordinary_least_squares_regressor.cpp:410
std::complex::real
T real(T... args)
predict_OLS_regressor
std::vector< float > predict_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< float > const &beta)
Definition: ordinary_least_squares_regressor.cpp:342
std::runtime_error
STL class.
large_number::operator=
large_number & operator=(const large_number &b)
Definition: large_number.h:229
main
int main()
Main function.
Definition: extended_euclid_algorithm.cpp:87
std::ifstream::open
T open(T... args)
test_3d_classes1
void test_3d_classes1(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_topology.cpp:399
fib
uint64_t fib(uint64_t n)
Definition: fibonacci_fast.cpp:30
std::invalid_argument
STL class.
test2
void test2()
Definition: kohonen_som_topology.cpp:439
SegmentIntersection::on_segment
bool on_segment(Point first_point, Point second_point, Point third_point)
Definition: line_segment_intersection.cpp:75
operator==
bool operator==(const Complex &a, const Complex &b)
Operator overload of '==' on Complex class. Logical Equal overload for our Complex class.
Definition: complex_numbers.cpp:175
std::remove
T remove(T... args)
large_number::_digits
std::vector< unsigned char > _digits
Definition: large_number.h:285
endl
#define endl
Definition: matrix_exponentiation.cpp:36
stack::push
void push(Type item)
Definition: stack.h:83
test2
void test2()
Definition: kohonen_som_trace.cpp:305
std::is_integral
main
int main()
Definition: check_prime.cpp:45
test2
bool test2()
Definition: large_factorial.cpp:54
Graph::Graph
Graph(unsigned int vertices, AdjList &&adjList)
Definition: cycle_check_directed_graph.cpp:78
std::priority_queue
STL class.
std::rand
T rand(T... args)
save_2d_data
int save_2d_data(const char *fname, const std::vector< std::valarray< double >> &X)
Definition: kohonen_som_topology.cpp:62
test_lamniscate
void test_lamniscate(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_trace.cpp:267
std::swap
T swap(T... args)
main
int main()
Definition: trie_modern.cpp:160
std::min
T min(T... args)
std::sin
T sin(T... args)
Edge
Definition: bellman_ford.cpp:7
graph::getConnectedComponents
int getConnectedComponents()
Function the calculates the connected compoents in the graph by performing the depth first search on ...
Definition: connected_components.cpp:63
sum_of_divisor
int sum_of_divisor(int num)
Definition: check_amicable_pair.cpp:21
stack::top
Type top()
Definition: stack.h:93
data
int data[MAX]
test data
Definition: hash_search.cpp:24
Complex::imag
double imag() const
Member function to get imaginary value of our complex number. Member function (getter) to access the ...
Definition: complex_numbers.cpp:70
std::round
T round(T... args)
queue
Definition: queue.h:17
large_number::test
static bool test()
Definition: large_number.h:65
fit_OLS_regressor
std::vector< float > fit_OLS_regressor(std::vector< std::vector< T >> const &X, std::vector< T > const &Y)
Definition: ordinary_least_squares_regressor.cpp:312
operator-
std::vector< T > operator-(std::vector< T > const &A, std::vector< T > const &B)
Definition: ordinary_least_squares_regressor.cpp:177
std::set::lower_bound
T lower_bound(T... args)
std::endl
T endl(T... args)
main
int main()
Definition: armstrong_number.cpp:77
get_inverse
std::vector< std::vector< float > > get_inverse(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:220
main
int main()
Definition: complex_numbers.cpp:268
std::left
T left(T... args)
graph::adj
vector< vector< int > > adj
adj stores adjacency list representation of graph
Definition: connected_components.cpp:40
large_number::operator==
friend bool operator==(large_number const &a, large_number const &b)
Definition: large_number.h:155
machine_learning::adaline::operator<<
friend std::ostream & operator<<(std::ostream &out, const adaline &ada)
Definition: adaline_learning.cpp:74
std::exp
T exp(T... args)
std::begin
T begin(T... args)
machine_learning::save_u_matrix
int save_u_matrix(const char *fname, const std::vector< std::vector< std::valarray< double >>> &W)
Definition: kohonen_som_topology.cpp:135
factorial
unsigned int factorial(unsigned int n)
Definition: factorial.cpp:8
std::greater
std
STL namespace.
tests
void tests()
Definition: double_factorial.cpp:50
std::set::insert
T insert(T... args)
show
void show(const struct tower *const F, const struct tower *const T, const struct tower *const U)
Definition: tower_of_hanoi.cpp:19
compare
Definition: huffman.cpp:28
std::ios_base::sync_with_stdio
T sync_with_stdio(T... args)
stack
Definition: stack.h:26
get_clock_diff
double get_clock_diff(clock_t start_t, clock_t end_t)
Definition: kohonen_som_topology.cpp:561
gcd
int gcd(int *a, int n)
Definition: gcd_of_n_numbers.cpp:15
main
int main()
Definition: fast_power.cpp:68
double_factorial_recursive
uint64_t double_factorial_recursive(uint64_t n)
Definition: double_factorial.cpp:30
std::count
T count(T... args)
Trie::search
bool search(const std::string &word)
Definition: trie_modern.cpp:132
std::fixed
T fixed(T... args)
Item
Definition: knapsack.cpp:4
std::strtoull
T strtoull(T... args)
std::queue::empty
T empty(T... args)
std::vector::assign
T assign(T... args)
stack::display
void display()
Definition: stack.h:29
extendedEuclid
void extendedEuclid(T A, T B, T *GCD, T2 *x, T2 *y)
Definition: extended_euclid_algorithm.cpp:70
test3
void test3()
Definition: kohonen_som_trace.cpp:402
std::stack::push
T push(T... args)
graph::graph
graph(int n)
Constructor that intiliazes the graph on creation and set the connected components to 0.
Definition: connected_components.cpp:53
test
void test()
Definition: check_amicable_pair.cpp:56
ols_test
void ols_test()
Definition: ordinary_least_squares_regressor.cpp:358
stack::isEmptyStack
bool isEmptyStack()
Definition: stack.h:80
Graph::getVertices
std::remove_reference_t< unsigned int > const & getVertices() const
Definition: cycle_check_directed_graph.cpp:112
std::complex
STL class.
std::complex::imag
T imag(T... args)
lca
Definition: lca.cpp:10
add
std::string add(std::string a, std::string b)
Definition: string_fibonacci.cpp:24
large_number::large_number
large_number(int n)
Definition: large_number.h:39
std::make_pair
T make_pair(T... args)
std::time
T time(T... args)
std::malloc
T malloc(T... args)
std::set::end
T end(T... args)
stack
char stack[MAX]
Definition: paranthesis_matching.cpp:20
Complex::operator+
Complex operator+(const Complex &other)
Operator overload of '+' on Complex class. Operator overload to be able to add two complex numbers.
Definition: complex_numbers.cpp:95
extendedEuclid_1
void extendedEuclid_1(T1 A, T1 B, T1 *GCD, T2 *x, T2 *y)
Definition: extended_euclid_algorithm.cpp:41
std::setw
T setw(T... args)
machine_learning::adaline::accuracy
const double accuracy
model fit convergence accuracy
Definition: adaline_learning.cpp:188
main
int main()
Definition: gcd_iterative_euclidean.cpp:47
std::max
T max(T... args)
test_2d_classes
void test_2d_classes(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_topology.cpp:320
std::range_error
STL class.
Point
Definition: line_segment_intersection.cpp:12
large_number::operator!=
friend bool operator!=(large_number const &a, large_number const &b)
Definition: large_number.h:168
machine_learning::kohonen_som
void kohonen_som(const std::vector< std::valarray< double >> &X, std::vector< std::vector< std::valarray< double >>> *W, double alpha_min)
Definition: kohonen_som_topology.cpp:261
push
void push(char ch)
push byte to stack variable
Definition: paranthesis_matching.cpp:26
Trie::removeWordHelper
std::shared_ptr< TrieNode > removeWordHelper(const std::string &word, std::shared_ptr< TrieNode > curr, size_t index)
Definition: trie_modern.cpp:64
test_3d_classes2
void test_3d_classes2(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_topology.cpp:479
pop
char pop()
pop a byte out of stack variable
Definition: paranthesis_matching.cpp:29
machine_learning::adaline::fit
void fit(std::vector< double > const (&X)[N], const int *y)
Definition: adaline_learning.cpp:136
_random
double _random(double a, double b)
Definition: kohonen_som_topology.cpp:50
Graph::addEdge
void addEdge(Edge const &edge)
Definition: cycle_check_directed_graph.cpp:128
fast_power_linear
double fast_power_linear(T a, T b)
Definition: fast_power.cpp:50
std::cin
Graph::Graph
Graph(unsigned int vertices, AdjList const &adjList)
Definition: cycle_check_directed_graph.cpp:70
large_number::operator++
large_number & operator++(int)
Definition: large_number.h:183
sorting::quickSort
void quickSort(int arr[], int low, int high)
Definition: quick_sort.cpp:63
test2
void test2(double eta=0.01)
Definition: adaline_learning.cpp:238
std::partition
T partition(T... args)
test3
void test3(double eta=0.01)
Definition: adaline_learning.cpp:289
std::unordered_map< unsigned int, std::vector< unsigned int > >
machine_learning::adaline
Definition: adaline_learning.cpp:44
main
int main(int argc, char *argv[])
Main function.
Definition: eulers_totient_function.cpp:48
large_number::operator+
friend large_number & operator+(const large_number &a, const T &b)
Definition: large_number.h:220
std::vector::data
T data(T... args)
std::ofstream::is_open
T is_open(T... args)
std::set
STL class.
graph::addEdge
void addEdge(int, int)
Function that add edge between two nodes or vertices of graph.
Definition: connected_components.cpp:75
operator/
std::vector< float > operator/(std::vector< T > const &A, float const scalar)
Definition: ordinary_least_squares_regressor.cpp:168
machine_learning::kohonen_som_tracer
void kohonen_som_tracer(const std::vector< std::valarray< double >> &X, std::vector< std::valarray< double >> *W, double alpha_min)
Definition: kohonen_som_trace.cpp:145
graph::connected_components
int connected_components
keep track of connected components
Definition: connected_components.cpp:43
are_amicable
bool are_amicable(int x, int y)
Definition: check_amicable_pair.cpp:48
std::exit
T exit(T... args)
stack::clear
void clear()
Definition: stack.h:112
main
int main(int argc, char **argv)
Definition: adaline_learning.cpp:333
list< int >
std::memset
T memset(T... args)
std::hash
test_circle
void test_circle(std::vector< std::valarray< double >> *data)
Definition: kohonen_som_trace.cpp:188
main
int main()
Definition: check_amicable_pair.cpp:68
std::next
T next(T... args)
stack.h
This class specifies the basic operation on a stack as a linked list.
std::ifstream
STL class.
std::pow
T pow(T... args)
get_transpose
std::vector< std::vector< T > > get_transpose(std::vector< std::vector< T >> const &A)
Definition: ordinary_least_squares_regressor.cpp:291