25#include "DDLinkedList.h"
27#include "/Users/aaa/myfile/bitbucket/clib/AronCLibNew.h"
38#include "glm/glm/glm.hpp"
53#include <boost/filesystem.hpp>
56# if __has_include(<optional>)
58# elif __has_include(<experimental/optional>)
59# include <experimental/optional>
60# elif __has_include(<boost/optional.hpp>)
61# include <boost/optional.hpp>
63# error "Missing <optional>"
96namespace fs = boost::filesystem;
106string toStr(
const T& s);
112string toStrVar(T& s);
119template<
typename T,
typename U>
123bool compareVector(vector<T> v1, vector<T> v2);
126bool compareVector(vector<vector<T>> v1, vector<vector<T>> v2);
129vector<vector<T>> arrToVec2(T* arr,
int len,
int width);
131void printArr2(
float* arr,
int len,
int width);
135int unsignToInt(
size_t u);
137string padRight(
string s,
string pad,
int maxLen);
138string padLeft(
string s,
string pad,
int maxLen);
145int max(
int a,
int b,
int c);
146int max(
int a,
int b,
int c,
int d);
147int max(vector<int> v);
149string reverseStr(
string s);
152int strToInt(
string s);
153int numFromBase(
string fromBase,
string input);
155vector<int> range(
int a,
int b);
156vector<int> range(
int a,
int b,
int stride);
161std::map<char, int>
hexMap();
163string baseToBase(
string fromBase,
string toBase,
string input);
170vector<T> repeatVec(
int n, T t);
172vector<T>
concatVec(vector<T> v1, vector<T> v2);
181T
det2(vector<vector<T>> v2);
184vector<T>
subtract(vector<T> v1, vector<T> v2);
203 return std::chrono::duration_cast<std::chrono::milliseconds>
204 (std::chrono::high_resolution_clock::now().time_since_epoch()).count();
212 return std::chrono::duration_cast<std::chrono::microseconds>
213 (std::chrono::high_resolution_clock::now().time_since_epoch()).count();
220 return std::chrono::duration_cast<std::chrono::nanoseconds>
221 (std::chrono::high_resolution_clock::now().time_since_epoch()).count();
226int strToInt(
string s) {
232 cout<<
"int => " <<
sizeof(int)<<endl;
233 cout<<
"long => " <<
sizeof(long)<<endl;
234 cout<<
"float => " <<
sizeof(float)<<endl;
235 cout<<
"double => " <<
sizeof(double)<<endl;
236 cout<<
"size_t => " <<
sizeof(size_t)<<endl;
237 cout<<
"unsigned int => " <<
sizeof(
unsigned int)<<endl;
238 cout<<
"unsigned long => " <<
sizeof(
unsigned long)<<endl;
239 cout<<
"long long => " <<
sizeof(
long long)<<endl;
254 for(
int i = 0; i <
len(
vec); i++){
265 if(prev != -1 && curr != -1){
266 int dist = curr - prev + 1;
277 if(prev != -1 && curr != -1){
278 int dist = curr - prev + 1;
293 for(
int i = 0; i < size; i++){
303 int dist = curr - prev + 1;
304 max = dist > max ? dist : max;
311 int dist = curr - prev + 1;
312 max = dist > max ? dist : max;
340 std::map<char, int> map;
341 for(
int i = 0; i < 16; i++){
353std::map<int, char> hexMapRev(){
354 std::map<int, char> revMap;
355 std::map<char, int> map =
hexMap();
356 std::map<char, int>::iterator it = map.begin();
357 while(it != map.end()){
358 char key = it -> first;
359 int value = it -> second;
366int numFromBase(
string fromBase,
string input){
369 std::map<char, int> map =
hexMap();
370 for(
auto i :
reverseVec(range(0, input.size()))){
371 int ii = input.size() - 1 - i;
372 if(
'0' <= input[i] && input[i] <=
'9' ||
'a' <= input[i] && input[i] <=
'z'){
373 int value = map[input[i]];
375 sum += value * pow(strToInt(fromBase), ii);
384string baseToBase(
string fromBase,
string toBase,
string input){
386 int sum = numFromBase(fromBase, input);
387 std::map<int, char> map = hexMapRev();
388 int toBaseNum = strToInt(toBase);
393 int q = sum / toBaseNum;
394 int r = sum % toBaseNum;
407 string s = baseToBase(
"10",
"2", toStr2(n));
408 for(
int i = 0; i <
len(s); i++){
411 }
else if(s[i] ==
'1'){
414 printf(
"ERROR: Invalid Char");
422vector<vector<T>> arrToVec2(T* arr,
int len,
int width){
423 vector<vector<T>> vv;
428 for(
int i = 0; i < q; i++){
430 for(
int j = 0; j < width; j++){
431 v.push_back(arr[width * i + j]);
437 for(
int i = 0; i < width; i++){
439 w.push_back(arr[width * q + i]);
457int max(
int a,
int b,
int c){
458 return max(max(a, b), c);
461int max(
int a,
int b,
int c,
int d){
462 return max(max(max(a, b), c), d);
465int max(vector<int> v){
473 printf(
"ERROR: vector can not be empty\n");
474 std::exit(EXIT_FAILURE);
487long long abs_ll(
long long a){
490double abs_d(
double a){
493unsigned int abs_ui(
unsigned int a){
497string reverseStr(
string s){
499 std::reverse(rs.begin(), rs.end());
505void writeFileAppendVector(
string fname, std::vector<T>
vec) {
507 ofs.open (fname, std::ofstream::out | std::ofstream::app);
520void writeFile(
string fname,
string s) {
522 ofs.open(fname, std::ofstream::out);
527void writeFileAppend(
string fname,
string s) {
529 ofs.open(fname, std::ofstream::out | std::ofstream::app);
535void writeFileVector(
string fname, std::vector<T>
vec) {
537 ofs.open (fname, std::ofstream::out);
554 ofs.open (fname, std::ofstream::out | std::ofstream::app);
561std::pair<string, string> split(
string s,
int inx) {
562 unsigned long len = s.length();
563 if(0 <= inx && inx <=
len) {
564 string prefix = s.substr(0, inx);
565 string suffix = s.substr(inx,
len);
566 return make_pair(prefix, suffix);
568 return make_pair(
"", s);
570 return make_pair(s,
"");
588vector<int>
sumVec(vector<int> v1, vector<int> v2){
590 int diff = v2.size() > v1.size() ? v2.size() - v1.size() : v1.size() - v2.size();
591 vector<int> mv = v2.size() > v1.size() ? v2 : v1;
592 vector<int> iv = v2.size() > v1.size() ? v1 : v2;
593 vector<int> vz = repeatVec(diff, 0);
596 vector<int> ux = repeatVec(
len(mv) + 1, 0);
599 for(
int i =
len(w1) - 1; i >= 0; i--){
600 int s = w1[i] + w2[i] + c;
627template<
typename T,
typename Fun>
628static vector<vector<T>> splitWhen(Fun f,
const vector<T>&
vec) {
629 vector<vector<T>> ret;
631 for(
auto const& e :
vec) {
656 std::pair<string, string> p = split(s, inx);
657 string prefix = p.first;
658 string suffix = p.second;
659 string tail = suffix.substr(1, suffix.length());
660 return prefix + tail;
669 ret.erase(ret.begin() + inx);
689 for(
int i=toInx; i >= fromInx; i--){
690 ret.erase(ret.begin() + i);
696string repeat(
int n,
string s);
702void print(glm::vec3 v3);
703void print(glm::vec2 v2);
710void print(std::pair<T, T> pair);
713void print(vector<T>
vec);
716void printVec(vector<T>
vec);
720void print(vector< vector<T> >
vec);
726void print(
string msg, T t);
734vector<T>
operator+(vector<T> v1, vector<T> v2);
736string operator+(
const char* chars,
string s);
738string operator+(
string s,
const char* chars);
741vector<T> con(T t, vector<T> v);
746void ppf(
const char* format, ...);
757void pp(T t1, T t2, T t3);
759template<
typename T,
typename U>
760void pp(std::pair<T, U> p);
765void pp(
unsigned long n);
774 std::cout<<
"call me maybe"<<endl;
775 std::cout<<t1<<t2<<endl;
779void pp(T t1, T t2, T t3) {
780 std::cout<<t1<<t2<<t3<<endl;
782void ppf(
const char* format, ...) {
783 std::cout<<
"printf format"<<endl;
787template<
typename T,
typename U>
788void pp(std::pair<T, U> p){
793 std::cout<<
"["<<n<<
"]"<<endl;
797 std::cout<<
"["<<n<<
"]"<<endl;
801 std::cout<<
"["<<n<<
"]"<<endl;
803void pp(
unsigned long n) {
804 std::cout<<
"["<<n<<
"]"<<endl;
807void pp(
string msg0,
string msg1){
808 std::cout<<msg0<<msg1<<std::endl;
810void pp(
string msg0,
float num){
811 std::cout<<msg0<<num<<std::endl;
813void pp(
string msg0,
int num){
814 std::cout<<msg0<<num<<std::endl;
816void pp(
string msg0,
long num){
817 std::cout<<msg0<<num<<std::endl;
819void pp(
string msg0,
double num){
820 std::cout<<msg0<<num<<std::endl;
822void pp(
string msg0,
char* charPt){
823 std::cout<<msg0<<charPt<<std::endl;
837 printLnNb(s1 + s + s2);
841 int len = s.length();
842 int pad = 40 - (
len/2);
851 clock_t startTime = 0;
862 pl(
"Start StopWatch()");
869 diff = endTime - startTime;
870 std::cout<<
"Diff=["<<(float)diff/CLOCKS_PER_SEC<<
"] Seconds"<<std::endl;
871 std::cout<<
"Tick=["<<diff<<
"] ticks"<<std::endl;
875 diff = endTime - startTime;
876 std::cout<<
"Diff=["<<(float)diff/CLOCKS_PER_SEC<<
"] Seconds"<<std::endl;
877 std::cout<<
"Tick=["<<diff<<
"] ticks"<<std::endl;
881 clock_t diff = endTime - startTime;
882 std::cout<<
"Tick=["<<diff<<
"] CPU ticks"<<std::endl;
887template<
typename T =
int,
typename U =
int>
898 two(T first, U second) {
899 this -> x =
this -> first = first;
900 this -> y =
this -> second = second;
904 return "(" + toStr2(x) +
"," + toStr2(y) +
")";
913namespace AronLambda {
920 assert(
vec.size() > 0);
929 throw std::runtime_error(
"string is empty.");
938 assert(
vec.size() > 0);
953static vector<T> reverse(vector<T>
vec) {
955 for(
auto it=
vec.rbegin(); it !=
vec.rend(); it++)
961static vector<T> rev(vector<T>
vec) {
982template<
typename Fun,
typename T>
983static vector<T> takeWhile(Fun f, vector<T>
vec) {
985 for(
auto const& n :
vec) {
1000template<
typename Fun,
typename T>
1001static vector<T> dropWhile(Fun f, vector<T>
vec) {
1004 for(
auto const& n :
vec) {
1013template<
typename Fun>
1014static string takeWhile(Fun f,
string str) {
1017 for(
int i = 0; i <
len(str); i++){
1024 ret = str.substr(0, inx);
1029template<
typename Fun>
1030static string dropWhile(Fun f,
string str) {
1033 for(
int i = 0; i <
len(str); i++){
1040 ret = str.substr(inx,
len(str));
1045template<
typename Fun>
1051 for(i = 0; i < ln; i++){
1056 string s1 = str.substr(0, i);
1057 string s2 = str.substr(i, ln);
1071static vector<T> tail(vector<T>
vec) {
1073 for(
int i=1; i<
vec.size(); i++) {
1074 v.push_back(
vec.at(i));
1083template<
typename Fun,
typename T>
1084static T foldl(Fun f, T acc, vector<T>
vec) {
1086 for(
auto ite =
vec.begin(), end =
vec.end(); end != ite; ite++) {
1087 tmpAcc = f(tmpAcc, *ite);
1102template<
typename Fun,
typename T>
1103static T foldr(Fun f, T acc,
const vector<T>&
vec) {
1105 for(
int i=
vec.size() - 1; i >= 0; i--) {
1106 tmpAcc = f(
vec[i], tmpAcc);
1112static vector<T> init(
const vector<T>&
vec) {
1113 assert(
vec.size() > 0);
1115 for(
int i=0; i <
vec.size() - 1; i++) {
1116 v.push_back(
vec[i]);
1133template<
typename Fun,
typename A>
1134static vector<A> map(Fun f, vector<A>
vec) {
1136 for(
auto& v :
vec) {
1137 vec1.push_back(f(v));
1142template<
typename Fun,
typename T>
1143static vector<T> zipWith(Fun f, vector<T> v1, vector<T> v2) {
1145 int len1 = unsignToInt(v1.size());
1146 int len2 = unsignToInt(v2.size());
1147 for(
int i=0; i<min(len1, len2); i++) {
1148 for(
int j=0; j<min(len1, len2); j++) {
1149 vec.push_back(f(v1[i], v2[j]));
1167static vector<T> flat(vector<vector<T>>& vec2){
1169 for(vector<T>& v : vec2){
1184template<
typename T,
typename Fun>
1185static vector<T> filter(Fun f,
const vector<T>&
vec) {
1187 for(
auto const& v :
vec) {
1196static string take(
int n,
string s) {
1197 return s.substr(0, n);
1207static string take(
int n,
const char* str){
1213static vector<T> take(
int n,
const vector<T>&
vec) {
1216 for(
auto const& v :
vec) {
1228static vector<T> drop(
int n, vector<T>
vec) {
1231 for(
auto const& v :
vec) {
1239template<
typename Fun,
typename T>
1240static vector<T> mergeSortListLam(Fun f, vector<T> v1, vector<T> v2) {
1247 vector<T> vh1 = take(1, v1);
1248 vector<T> vh2 = take(1, v2);
1249 if (f(vh1.at(0), vh2.at(0))) {
1250 return vh1 + mergeSortListLam(f, tail(v1), v2);
1252 return vh2 + mergeSortListLam(f, v1, tail(v2));
1262static vector<T> mergeSortList(vector<T> v1, vector<T> v2) {
1269 vector<T> vh1 = take(1, v1);
1270 vector<T> vh2 = take(1, v2);
1271 if (vh1.at(0) < vh2.at(0)) {
1272 return vh1 + mergeSortList(tail(v1), v2);
1274 return vh2 + mergeSortList(v1, tail(v2));
1279static vector<T> mergeSort(vector<T> v1) {
1281 vector<T> left = take(v1.size()/2, v1);
1282 vector<T> right= drop(v1.size()/2, v1);
1283 vector<T> subl = mergeSort(left);
1284 vector<T> subr = mergeSort(right);
1285 return mergeSortList(subl, subr);
1293template<
typename T,
typename U>
1296using namespace AronLambda;
1318string toStr2(T& s) {
1319 std::ostringstream out;
1325string toStrVar(T& s) {
1326 std::ostringstream out;
1333void swap(vector<T>&
vec,
int i,
int j);
1344void swap(T arr[],
int i,
int j) {
1351void swap(vector<T>&
vec,
int i,
int j){
1371 long c = 1013904223;
1372 long m = (long)pow((
double)2, (double)32);
1373 long x1 = (a * x0 + c) % m;
1378vector<int> randomIntVec(
int count,
int max){
1381 for(
int i = 0; i < count; i++){
1383 v.push_back(x1 % max);
1394 for(
int i = 0; i < n; i++){
1396 v.push_back(n % max);
1417vector<int> allPrime(
int n) {
1421 for(
int p=3; p<n; p++) {
1422 bool isPrime =
true;
1423 for(
int i=0; i<
vec.size() && isPrime; i++) {
1434vector<int>* nPrime(
int n){
1435 vector<int>*
vec =
new vector<int>();
1437 vec -> push_back(2);
1441 bool isPrime =
true;
1442 for(
auto const& p : *
vec){
1449 vec -> push_back(num);
1455 return std::move(
vec);
1483const char* strToCharArray(
string s){
1495 std::ostringstream out;
1500template<
typename T,
typename U>
1501string toStr(std::pair<T, U> p){
1504 ret +=
toStr(p.first) +
" , ";
1505 ret +=
toStr(p.second);
1510template<
typename T,
typename U>
1511string str(std::pair<T, U> p){
1516string str(
const T& s) {
1525string trimLeft(
string str) {
1527 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](
char& x) {
1528 return !std::isspace(x);
1533string trimRight(
string str) {
1535 s.erase(std::find_if(s.rbegin(), s.rend(), [](
char& x) {
1536 return !std::isspace(x);
1537 }).base(), s.end());
1549 return trimRight(trimLeft(s));
1562string charPtrToString(
const char* pt){
1586 regex_search(s, m, rx);
1587 return m.size() > 0;
1602 regex_search(str, m, rx);
1603 return m.size() > 0;
1622 auto end = s.find(delim);
1623 while (end != std::string::npos) {
1624 vec.push_back(s.substr(start, end - start));
1625 start = end + delim.length();
1626 end = s.find(delim, start);
1628 vec.push_back(s.substr(start, s.size() - start));
1648 for(
int i=0; i<
vec.size(); i++) {
1650 fstVec.push_back(
vec[i]);
1652 sndVec.push_back(
vec[i]);
1654 return std::make_pair(fstVec, sndVec);
1662template<
typename Fun,
typename T>
1666 for(
int i=0; i<
vec.size(); i++) {
1671 return std::make_pair(fstVec,
vec);
1682 vector<T> retVec(
vec);
1683 std::replace(retVec.begin(), retVec.end(), oldVal, newVal);
1705 assert(0 <= pos && pos <=
vec.size());
1707 typename vector<T>::iterator it = v.begin();
1709 std::copy (insertVec.begin(),insertVec.end(),std::inserter(v,it));
1729 vector<std::string>
vec;
1732 sregex_token_iterator iter(s.begin(), s.end(), rgx, -1);
1733 sregex_token_iterator end;
1735 while (iter != end) {
1736 vec.push_back(*iter);
1754 return strlen(cpt) == 0;
1756 perror(
"cpt is NULL");
1769 while(fabs(x*x - a) > 0.00000001) {
1770 x = x + (a - x*x)/(2*x);
1781 return static_cast<double>(n);
1790double nthRoot(
double c,
int n,
double epsilon = 0.000001) {
1793 auto ff = [](
double xx,
int nn,
double cc) {
1795 return pow(xx, nb) - cc;
1799 auto df = [](
double xx,
int nn,
double cc) {
1801 return nn*pow(xx, bb);
1806 while(fabs(pow(x, b) - c) > epsilon) {
1807 x = x - ff(x, n, c)/df(x, n, c);
1813string charArrToString(
const char* pt) {
1819string replicate(
int n,
string s) {
1821 for(
int i=0; i<n; i++) {
1832 return replicate(n, s);
1836vector<T> repeatVec(
int n, T t) {
1838 for(
int i=0; i<n; i++) {
1845void add(vector<T>&
vec, T t){
1854 return strcmp(s1, s2);
1862 return s1.compare(s2);
1866bool compareVector(vector<T> v1, vector<T> v2){
1867 if(v1.size() == v2.size()){
1868 for(
int i = 0; i < v1.size(); i++){
1879bool compareVector(vector<vector<T>> v1, vector<vector<T>> v2){
1880 if(v1.size() == v2.size()){
1881 for(
int i = 0; i < v1.size(); i++){
1882 if(!compareVector(v1[i], v2[i])){
1896 double epsilon = 0.00001;
1897 return fabs(a-b) < epsilon;
1900void print(glm::vec3 v3) {
1901 printf(
"%2.3f %2.3f %2.3f \n",v3.x, v3.y, v3.z);
1903void print(glm::vec2 v2) {
1904 printf(
"%2.3f %2.3f \n",v2.x, v2.y);
1907void printLn(glm::vec3 v3) {
1908 printf(
"%2.3f %2.3f %2.3f ",v3.x, v3.y, v3.z);
1910void printLn(glm::vec2 v2) {
1911 printf(
"%2.3f %2.3f ",v2.x, v2.y);
1914string toString(glm::vec3 v3) {
1916 sprintf(strPt,
"%2.3f %2.3f %2.3f", v3.x, v3.y, v3.z);
1917 return charArrToString(strPt);
1957 vector<vector<T>> retMat;
1959 for(
auto const& v :
mat) {
1964 for(
int i=0; i<min; i++) {
1966 for(
int k = 0; k <
mat.size(); k++) {
1967 v.push_back(
mat[k][i]);
1969 retMat.push_back(v);
1974int inx(
int cIx,
int rIx,
int width){
1975 return cIx * width + rIx;
1999 for(
int c = 0; c < width; c++){
2000 for(
int r = c; r < width; r++){
2001 float tmp = arr[inx(c, r, width)];
2002 arr[inx(c, r, width)] = arr[inx(r, c, width)];
2003 arr[inx(r, c, width)] = tmp;
2011bool compareArray(T arr1[], T arr2[],
const int s1) {
2012 for(
int i=0; i<s1; i++) {
2013 if(arr1[i] != arr2[i])
2020void print(std::pair<T, T> pair) {
2021 cout<<
"("<<pair.first<<
" "<<pair.second<<
")"<<endl;
2026 cout<<
"("<<t.x<<
" "<<t.y<<
")";
2031void print(vector<T>
vec) {
2032 for(
auto const& v:
vec) {
2036 std::cout<<std::endl;
2040void printVec(vector<T>
vec) {
2045void print(vector< vector<T> >
vec) {
2046 for(
auto const& v:
vec) {
2049 std::cout<<std::endl;
2070 std::cout<<
"["<<t<<
"]"<<std::endl;
2074void printLnNb(T t) {
2075 std::cout<<t<<std::endl;
2086void printArr(
float arr[10],
int n,
int nCol){
2087 for(
int i = 0; i < n; i++){
2088 if((i + 1) % nCol != 0){
2091 cout<<arr[i]<<
" "<<endl;
2113 vec.insert(
vec.end(), v2.begin(), v2.end());
2117string operator+(
const char* chars,
string s) {
2118 return charArrToString(chars) + s;
2121string operator+(
string s,
const char* chars) {
2122 return s + charArrToString(chars);
2126vector<T> con(T t, vector<T> v) {
2129 for(
auto const& e: v)
2140 vector<T>* pt =
new vector<T>();
2141 for(
auto const& val:
vec) {
2142 pt -> push_back(val);
2145 return std::move(pt);
2148int unsignToInt(
size_t u){
2149 if(u > std::numeric_limits<int>::max()){
2150 throw std::overflow_error(
"ERROR: size_t > int");
2152 return static_cast<int>(u);
2163 vector<T>* pt =
new vector<T>();
2164 for(
auto const& val:
vec) {
2165 pt -> push_back(val);
2168 return std::move(pt);
2175 return unsignToInt(s.size());
2186 return unsignToInt(v.size());
2218 int mid = (lo + hi)/2;
2220 return binSearch(key, arr, lo, mid - 1);
2222 return binSearch(key, arr, mid + 1, hi);
2225 return key == arr[lo];
2238 for(
auto const& value:
vec) {
2239 newVec.push_back(a*value);
2252 for(
auto const& value:
vec) {
2253 newVec.push_back(a*value);
2259vector< vector<T> >
operator*(T a, vector< vector<T> > vec2) {
2260 vector< vector<T> > newVec2;
2262 for(
auto const&
vec : vec2) {
2263 newVec2.push_back(a*
vec);
2269vector< vector<T> >
operator*(vector< vector<T> > vec2, T a) {
2284 std::reverse(v.begin(), v.end());
2290vector<int> range(
int a,
int b) {
2293 for(
int i=a; i<=b; i += stride)
2298vector<int> range(
int a,
int b,
int stride) {
2300 for(
int i=a; i<=b; i += stride)
2306vector<int> geneVector(
int a,
int b) {
2308 std::vector<int>
vec;
2309 for(
int i=0; i<=
len; i++) {
2310 vec.push_back(a + i);
2322 if(!
isBST(curr -> left, prev))
2324 if(prev != NULL && prev -> data > curr -> data)
2327 if(!
isBST(curr -> right, curr))
2339 vector< vector<T> > vv;
2341 for(
int c=0; c<ncol; c++) {
2343 for(
int r=0; r<nrow; r++) {
2354void swapT(T array[],
int i,
int j) {
2356 array[i] = array[j];
2371 for(
int i=lo; i<=hi; i++) {
2374 swapT(array, i, bInx);
2400 vector<T> tmp(hi - lo + 1);
2403 for(
int k = 0; k <
len(
vec) && i != j; k++){
2414 for(
int k=0; k <
len(tmp); k++)
2415 vec[lo + k] = tmp[k];
2438 for(
int i = lo; i <= hi; i++){
2439 if(
vec[i] <= pivot){
2441 swap(
vec, i, bigInx);
2453void quickSortVec(vector<T>&
vec,
int lo,
int hi){
2456 quickSortVec(
vec, lo, pInx - 1);
2457 quickSortVec(
vec, pInx + 1, hi);
2473std::string replace(std::string str, regex rex, std::string rep){
2474 return std::regex_replace (str, rex, rep);
2477bool isEmptyLine(
string s){
2479 string str = replace(s, rx,
"");
2480 return len(str) == 0;
2484string getEnv(
string env){
2485 const char* pt = std::getenv(
s2c(env));
2490vector<T> getCol(
int ix, vector<vector<T>> v){
2492 if(0 <= ix && ix < tv.size()){
2495 printf(
"ERROR: Invalid index=%d\n", ix);
2511 string s = AronLambda::foldl([](
string x,
string y) {
return x +
"/" + y;},
c2s(
""),
vec);
2527 ret.push_back(s[0]);
2528 for (
int i = 0; i + 1 <
len(s); i++) {
2529 if (s[i] != s[i + 1]) {
2530 ret.push_back(s[i + 1]);
2533 ret.push_back(s[i + 1]);
2541namespace SpaceTest {
2542using namespace AronPrint;
2544 static void t(
double a,
double b,
string s =
"") {
2550 pp(
"False => " + s);
2554 static void t(
int a,
int b,
string s =
"") {
2559 pp(
"False => " + s);
2563 static void t(
long a,
long b,
string s =
"") {
2568 pp(
"False => " + s);
2572 static void t(
bool a,
bool b,
string s =
"") {
2577 pp(
"False => " + s);
2581 static void t(
string a,
string b,
string s =
"") {
2586 pp(
"False => " + s);
2591 template<
typename T>
2592 static void t(vector<T> v1, vector<T> v2,
string s =
"") {
2593 if(compareVector(v1, v2)){
2598 pp(
"False => " + s);
2603 template<
typename T>
2604 static void t(vector<vector<T>> v1, vector<vector<T>> v2,
string s =
"") {
2605 if(compareVector(v1, v2)){
2610 pp(
"False => " + s);
2619namespace AronGeometry {
2620using namespace AronPrint;
2622template<
class T =
double>
class Vector;
2624template<
class T =
double>
2635 Point(T x, T y, T z = 0.0 ) {
2642 Point<T> p(p1.x + p2.x, p1.y + p2.y, p1.z + p2.z);
2646 Point<T> p(p1.x - p2.x, p1.y - p2.y, p1.z - p2.z);
2660 Point p(x + v.x, y + v.y, z + v.z);
2663 bool operator==(
Point p0) {
2664 return x == p0.x && y == p0.y && z == p0.z;
2666 bool operator!=(
Point p0) {
2667 return x != p0.x || y != p0.y || z != p0.z;
2691 Pair pa(
this -> p0 + pair.p0, this -> p1 + pair.p1);
2695 Pair pa(
this -> p0 - pair.p0, this -> p1 - pair.p1);
2730 Vector<T> operator+(Vector<T> v) {
2731 Vector<T> v1(p0 + v.p0, p1, v.p1);
2737template<
class T =
double>
2756 double squareDist() {
2757 double d = (p1.x - p0.x)*(p1.x - p0.x) +
2758 (p1.y - p0.y)*(p1.y - p0.y);
2762 double d = (p1.x - p0.x)*(p1.x - p0.x) +
2763 (p1.y - p0.y)*(p1.y - p0.y);
2767 return isColinear3(p, p0, p1) == 0;
2779 return p == p0 || p == p1;
2782 return (p0 == s.p0 && p1 = s.p1) || (p1 = s.p0 && p0 == s.p1);
2786template<
class T =
double>
2789 return (p2.y - p.y)*(p2.x - p1.x) - (p2.x - p.x)*(p2.y - p1.y);
2791template<
class T =
double>
2792bool isCrossSegment(Point<T> p0, Point<T> p1) {
2811using namespace AronPrint;
2830 }
else if(sub.length() > 0 && sub.length() <= s.length()){
2838 for(
int i=0; i < s.length() && ret ==
false; i++){
2841 while(j < sub.length() && i + count < s.length() && sub[j] == s[i + count]){
2844 if(count == sub.length()){
2868 }
else if(sub.length() > 0 && sub.length() <= s.length()){
2876 for(
int i=0; i < s.length() && ret == -1; i++){
2879 while(j < sub.length() && i + count < s.length() && sub[j] == s[i + count]){
2882 if(count == sub.length()){
2895string fun_parent_parent();
2899int stringToInt(
string s) {
2906double stringToDouble(std::string s) {
2911long stringToLong(std::string s) {
2916float stringToFloat(std::string s) {
2921string charToString(
char ch) {
2930 std::string pretty_fun = fun_parent_parent();
2931 int len = pretty_fun.length();
2932 printf (
"[%s%.*s]\n", pretty_fun.c_str(), sz <
len ? 0 : (
int)(sz -
len), PAD);
2936void begin(
const char* name) {
2938 printf (
"[%s%.*s]\n", name, (sz < strlen(name)) ? 0 : (
int)(sz - strlen(name)), PAD);
2946 int k = strlen(pt) - 1;
2947 while(k >= 0 && pt[k] !=
'v') k--;
2949 k >= 0 ? pt[k] = 0 : printf(
"Error: invalid string format.");
2953string fun_parent() {
2958 size = backtrace (array, 10);
2959 strings = backtrace_symbols (array, size);
2962 string str = std::string(strings[1] + 62);
2968string fun_parent_parent() {
2973 size = backtrace (array, 10);
2974 strings = backtrace_symbols (array, size);
2977 string str = std::string(strings[2] + 62);
3116namespace SpaceComplex {
3163 Complex c1(x*c.x - y*c.y, x*c.y + y*c.x);
3171 return x == c.x && y == c.y;
3179 return sqrt(c.x*c.x + c.y*c.y);
3182 std::pair<double, double> polar() {
3183 double radius = norm(*
this);
3184 double radian = acos(x/radius);
3185 std::pair<double, double> pair = std::make_pair(radius, radian);
3196 double xx = (c1.x*c2.x + c1.y*c2.y)/(c2.x*c2.x + c2.y*c2.y);
3197 double yy = (c2.x*c1.y - c1.x*c2.y)/(c2.x*c2.x + c2.y*c2.y);
3207 printf(
"[%1.2f][%1.2f]\n", x, y);
3217 Complex c( p.first*cos(p.second), p.first*sin(p.second) );
3246 T** arr = (T**)
new T*[ncol];
3247 for(
int c = 0; c < ncol; c++)
3248 arr[c] = (T*)
new T[nrow];
3260 T** arr = (T**)
new T*[ncol];
3261 for(
int c = 0; c < ncol; c++)
3262 arr[c] = (T*)
new T[nrow];
3273 int ncol = vv.size();
3275 int nrow = vv[0].size();
3276 T** arr = allocateTemp<T>(ncol, nrow);
3277 for(
int c=0; c<ncol; c++) {
3278 for(
int r=0; r<nrow; r++) {
3279 arr[c][r] = vv[c][r];
3317 vector< vector<T> > v;
3318 for(
int c=0; c<ncol; c++) {
3320 for(
int r=0; r<nrow; r++) {
3321 v1.push_back(arr[c][r]);
3340 vec(
const vector<float> &v);
3343 bool operator==(
const vec &v);
3344 vec& operator=(
const vec &v);
3351 void createVec(
float* arr,
int len);
3353 vector<float> toVec();
3368 row(
const vector<float>&
vec);
3371 void createRow(
float* array,
int len);
3372 bool operator==(
const row& v);
3373 row operator=(
const row& r);
3374 float operator*(
vec& v);
3377 row operator/(
float f);
3379 vector<float> toVec();
3387vec::vec(
const vec& v) {
3390 arr = allocate<float>(ncol, nrow);
3391 for(
int i=0; i<ncol; i++){
3392 arr[i][0] = v.arr[i][0];
3396vec::vec(
const vector<float> &v){
3399 arr = allocate<float>(ncol, nrow);
3400 cout<<
"nrow="<<nrow<<endl;
3401 cout<<
"ncol="<<ncol<<endl;
3402 for(
int i=0; i < ncol; i++){
3413 arr = allocate<float>(ncol, nrow);
3416 for(
int i=0; i<ncol; i++) {
3434 for(
int i=0; i<ncol; i++) {
3435 vec.push_back(arr[i][0]);
3439vector<float> vec::toVec() {
3443vec vec::operator+(
vec v) {
3444 assert(ncol == v.ncol);
3446 for(
int i=0; i<ncol; i++){
3447 v1->arr[i][0] = arr[i][0] + v.arr[i][0];
3452vec vec::operator-(
vec& v) {
3453 assert(ncol == v.ncol);
3455 for(
int i=0; i<ncol; i++)
3456 v1->arr[i][0] = arr[i][0] - v.arr[i][0];
3462bool vec::operator==(
const vec& v) {
3463 bool ret = ncol == v.ncol;
3464 for(
int i=0; i<ncol && ret; i++) {
3465 ret = arr[i][0] == v.arr[i][0];
3471vec& vec::operator=(
const vec& v) {
3472 assert(ncol == v.ncol);
3475 arr = allocate<float>(v.ncol, v.nrow);
3476 for(
int i=0; i<ncol; i++) {
3477 arr[i][0] = v.arr[i][0];
3483void vec::createVec(
float* array,
int len) {
3484 for(
int i=0; i<
len; i++) {
3485 arr[i][0] = array[i];
3489 for(
int i=0; i<ncol; i++) {
3490 cout<<arr[i][0]<<std::endl;
3496row::row(
int col,
int row) {
3499 arr = allocate<float>(ncol, nrow);
3504 arr = allocate<float>(ncol, nrow);
3506row::row(
const vector<float>&
vec) {
3508 nrow = (int)
vec.size();
3509 arr = allocate<float>(ncol, nrow);
3510 for(
int i=0; i<nrow; i++) {
3515 for(
int i=0; i<ncol; i++) {
3523row::row(
const row& rw) {
3526 arr = allocate<float>(ncol, nrow);
3527 for(
int r=0; r<nrow; r++) {
3528 arr[0][r] = rw.arr[0][r];
3534 for(
int i=0; i<nrow; i++) {
3535 for(
int j=0; j<ncol; j++) {
3536 rw.arr[i][j] = arr[j][i];
3544 for(
int i=0; i<ncol; i++) {
3545 for(
int j=0; j<nrow; j++) {
3546 v.arr[j][i] = arr[i][j];
3558 for(
int i=0; i<nrow; i++) {
3559 vec.push_back(arr[0][i]);
3564vector<float> row::toVec() {
3569 for(
int i=0; i<nrow; i++) {
3570 cout<<arr[0][i]<<
" ";
3576bool row::operator==(
const row& r) {
3577 assert(nrow == r.nrow);
3579 for(
int i=0; i<nrow && ret; i++) {
3580 ret = arr[0][i] == r.arr[0][i];
3585row row::operator=(
const row& r) {
3588 arr = allocate<float>(ncol, nrow);
3589 for(
int i=0; i<nrow; i++) {
3590 arr[0][i] = r.arr[0][i];
3595void row::createRow(
float* array,
int len) {
3596 for(
int i=0; i<
len; i++) {
3597 arr[0][i] = array[i];
3616 mat(
const int col,
const int row);
3617 mat(vector< vector<float> > v2);
3618 mat(
const int col,
const int row, vector<float> v);
3633 Loader(
mat& m,
int ix) : m(m), ix(ix) {}
3634 Loader operator , (
float x){
3635 assert(ix < m.ncol * m.nrow);
3637 int u = ix / m.nrow;
3638 int v = ix % m.nrow;
3640 return Loader(m, ix + 1);
3643 Loader operator << (
float x){
3644 assert(ncol > 0 && nrow > 0);
3649 vector<vector<float>> toVecVec();
3654 mat operator=(
const mat& m);
3655 bool operator==(
const mat& m);
3657 mat operator-(
const mat& m);
3658 mat operator/(
float f);
3659 mat operator*(
float f);
3660 mat removeRow(
int index);
3663 mat insertVecPrevious(
int index,
vec v);
3668 mat rowMultiScala(
int index,
float f);
3669 mat vecMultiScala(
int index,
float f);
3710 mat block(
int colIndex,
int clen,
int rowIndex,
int rlen);
3733 cout<<
"empty matrix";
3736 for(
int c=0; c<ncol; c++) {
3737 for(
int r=0; r<nrow; r++) {
3744 assert(ncol == nrow);
3751void mat::identity() {
3752 assert(ncol == nrow);
3753 for(
int c=0; c<ncol; c++) {
3754 for(
int r=0; r<nrow; r++) {
3770mat::mat(
const mat& m) {
3773 arr = allocate<float>(ncol, nrow);
3774 for(
int c=0; c<ncol; c++) {
3775 for(
int r=0; r<nrow; r++) {
3776 arr[c][r] = m.arr[c][r];
3780mat::mat(
int col,
int row) {
3783 arr = allocate<float>(ncol, nrow);
3785mat::mat(vector< vector<float> > v2){
3786 assert(v2.size() > 0 && v2[0].size() > 0);
3788 nrow = v2[0].size();
3789 arr = allocate<float>(ncol, nrow);
3790 for(
int c=0; c<ncol; c++){
3791 for(
int r=0; r<nrow; r++)
3792 arr[c][r] = v2[c][r];
3795mat::mat(
int col,
int row, vector<float> v){
3798 assert(ncol >= 0 && nrow >= 0 && v.size() == ncol*nrow);
3799 arr = allocate<float>(ncol, nrow);
3800 for(
int c=0; c<ncol; c++){
3801 for(
int r=0; r<nrow; r++)
3802 arr[c][r] = v[nrow*c + r];
3807 for(
int i=0; i<ncol; i++)
3813mat vec::toMatrix() {
3815 for(
int c=0; c<ncol; c++) {
3816 for(
int r=0; r<nrow; r++) {
3817 m.arr[c][r] = arr[c][r];
3842 for(
int i = 0; i < nrow; i++){
3844 for(
int j = 0; j < ncol; j++){
3845 vm.push_back(
len(toStrVar(arr[j][i])));
3847 vmax.push_back(max(vm));
3850 vector<vector<string>> vv;
3852 for(
int i = 0; i < nrow; i++){
3854 for(
int j = 0; j < ncol; j++){
3855 string s = padRight(toStrVar(arr[j][i]), pad, vmax[i] + 1);
3866string mat::toStr() {
3868 for(
int c=0; c<ncol; c++) {
3869 for(
int r=0; r<nrow; r++) {
3870 ret += toStr2(arr[c][r]) +
" ";
3877 vector<vector<float>> mat::toVecVec(){
3878 vector<vector<float>> vv;
3879 for(
int c=0; c<ncol; c++) {
3881 for(
int r=0; r<nrow; r++) {
3882 tv.push_back(arr[c][r]);
3890 for(
int c=0; c<ncol; c++) {
3891 for(
int r=0; r<nrow; r++) {
3892 printf(
"[%*f]", 10, arr[c][r]);
3902 assert(0 <= n && n < nrow);
3904 for(
int i=0; i<ncol; i++) {
3905 v.arr[i][0] = arr[i][n];
3915 for(
int i=0; i<nrow; i++) {
3916 r.arr[0][i] = arr[index][i];
3925 assert(nrow > 0 && index >= 0 && index < nrow);
3926 mat m(ncol, nrow - 1);
3927 for(
int c=0; c<ncol; c++) {
3929 for(
int r=0; r<nrow; r++) {
3931 m.arr[c][k] = arr[c][r];
3943 assert(ncol == v.ncol && 0 <= index && index < nrow);
3944 mat mv = v.toMatrix();
3947 mat cat = left.concat(mv).concat(right);
3956mat mat::insertVecPrevious(
int index,
vec v) {
3957 assert(ncol == v.ncol && 0 <= index && index < nrow);
3958 mat mv = v.toMatrix();
3960 return mv.concat(*
this);
3964 return left.concat(mv).concat(right);
3968mat mat::removeRow(
int index) {
3969 assert(ncol > 0 && index >= 0 && index < ncol);
3970 mat m(ncol - 1, nrow);
3972 for(
int c=0; c<ncol; c++) {
3974 for(
int r=0; r<nrow; r++) {
3975 m.arr[k][r] = arr[c][r];
3982mat mat::operator+(
mat m) {
3984 for(
int c=0; c<ncol; c++) {
3985 for(
int r=0; r<nrow; r++) {
3986 m1.arr[c][r] = arr[c][r] + m.arr[c][r];
3992mat mat::operator-(
const mat &m) {
3994 for(
int c=0; c<ncol; c++) {
3995 for(
int r=0; r<nrow; r++) {
3996 m1.arr[c][r] = arr[c][r] - m.arr[c][r];
4001mat mat::operator/(
float f) {
4003 for(
int c=0; c<ncol; c++) {
4004 for(
int r=0; r<nrow; r++) {
4005 m1.arr[c][r] = arr[c][r]/f;
4011mat mat::operator*(
float f) {
4013 for(
int c=0; c<ncol; c++) {
4014 for(
int r=0; r<nrow; r++) {
4015 m1.arr[c][r] = arr[c][r]*f;
4030 assert(cStart < ncol && rStart < nrow);
4031 int ncolt = ncol - cStart;
4032 int nrowt = nrow - rStart;
4033 mat m(ncolt, nrowt);
4034 for(
int c=0; c<m.ncol; c++) {
4035 for(
int r=0; r<m.nrow; r++) {
4036 m.arr[c][r] = arr[c + cStart][r + rStart];
4081 assert(ncol > 0 && nrow > 0);
4102 assert(ncol > 0 && nrow > 0);
4119 for(
int c=0; c<m.ncol; c++) {
4120 for(
int r=0; r<m.nrow; r++) {
4121 m.arr[c][r] = arr[cIndex + c][rIndex + r];
4139 for(
int c=0; c<ncol; c++) {
4140 for(
int r=0; r<nrow; r++) {
4141 m.arr[r][c] = arr[c][r];
4148bool mat::operator==(
const mat& m) {
4149 bool ret = ncol == m.ncol && nrow == m.nrow ? true :
false;
4150 for(
int c=0; c<ncol && ret; c++) {
4151 for(
int r=0; r<nrow && ret; r++) {
4152 ret = arr[c][r] == m.arr[c][r];
4168 for(
int c=0; c<ncol; c++) {
4169 for(
int r=0; r<nrow; r++) {
4191 long max = (long)(snd - fst);
4192 for(
int c=0; c<ncol; c++) {
4193 for(
int i=0; i<nrow; i++) {
4201mat vec::operator*(
row rw) {
4203 assert(nrow == rw.ncol);
4204 mat m(ncol, rw.nrow);
4205 for(
int c=0; c<m.ncol; c++) {
4206 for(
int r=0; r<m.nrow; r++) {
4207 m.arr[c][r] = arr[c][0]*rw.arr[0][r];
4218vec mat::operator*(
vec &v) {
4219 assert(nrow == v.ncol);
4221 for(
int c=0; c<ncol; c++) {
4222 v1.arr[c][0] =
getRow(c)*v;
4226mat mat::operator*(
mat m) {
4227 assert(nrow == m.ncol);
4228 mat m1(ncol, m.nrow);
4230 for(
int r=0; r<nrow; r++) {
4236mat mat::operator=(
const mat& m) {
4240 arr = allocate<float>(ncol, nrow);
4241 for(
int c=0; c<ncol; c++) {
4242 for(
int r=0; r<nrow; r++) {
4243 arr[c][r] = m.arr[c][r];
4252 for(
int c=0; c<ncol; c++) {
4253 for(
int r=0; r<nrow; r++) {
4254 m.arr[c][r] = arr[c][r];
4261 assert(ncol == m.ncol);
4262 mat m1(ncol, nrow + m.nrow);
4263 for(
int c=0; c < ncol; c++) {
4264 for(
int r=0; r < nrow + m.nrow; r++) {
4266 m1.arr[c][r] = arr[c][r];
4268 m1.arr[c][r] = m.arr[c][r - nrow];
4283mat mat::rowMultiScala(
int index,
float f) {
4285 for(
int c=0; c < ncol; c++) {
4286 for(
int r=0; r < nrow; r++) {
4288 m.arr[c][r] = arr[c][r];
4290 m.arr[c][r] = arr[c][r]*f;
4297mat mat::vecMultiScala(
int index,
float f) {
4299 for(
int c=0; c < ncol; c++) {
4300 for(
int r=0; r < nrow; r++) {
4302 m.arr[c][r] = arr[c][r];
4304 m.arr[c][r] = arr[c][r]*f;
4315 assert(0 <= inx1 && inx1 < ncol && 0 <= inx2 && inx2 < ncol);
4319 for(
int c=0; c < ncol; c++) {
4320 for(
int r=0; r < nrow; r++) {
4322 m.arr[c][r] = r2.arr[0][r];
4323 }
else if(c == inx2){
4324 m.arr[c][r] = r1.arr[0][r];
4326 m.arr[c][r] = arr[c][r];
4333float row::dot(
vec& v) {
4334 assert(nrow == v.ncol);
4336 for(
int i=0; i<nrow; i++) {
4337 ret += arr[0][i]*v.arr[i][0];
4344float row::operator*(
vec& v) {
4347row row::operator+(
row& r) {
4348 assert(nrow == r.nrow);
4351 for(
int i=0; i<nrow; i++) {
4352 rw.arr[0][i] = arr[0][i] + r.arr[0][i];
4356row row::operator-(
row& r) {
4357 assert(nrow == r.nrow);
4360 for(
int i=0; i<nrow; i++) {
4361 rw.arr[0][i] = arr[0][i] - r.arr[0][i];
4365row row::operator/(
float f) {
4367 for(
int i=0; i<nrow; i++) {
4368 rw.arr[0][i] = arr[0][i]/f;
4373 assert(m1.ncol == m2.ncol);
4375 mat m(m1.ncol, m1.nrow + m2.nrow);
4376 for(
int c=0; c < m1.ncol; c++) {
4377 for(
int r=0; r < m1.nrow + m2.nrow; r++) {
4379 m.arr[c][r] = m1.arr[c][r];
4381 m.arr[c][r] = m2.arr[c][r - m1.nrow];
4388mat identity(
int n) {
4390 for(
int c=0; c<n; c++) {
4391 for(
int r=0; r<n; r++) {
4417 assert(a.ncol == a.nrow && a.nrow == b.ncol);
4420 for(
int c=a.ncol - 1; c >= 0; c--) {
4422 for(
int r= a.nrow - 1; r >=c; r--) {
4424 x.arr[r][0] = (b.arr[c][0] - s)/a.arr[c][r];
4426 s += a.arr[c][r]*x.arr[r][0];
4461 assert(0 <= index && index < m.nrow);
4462 mat im = identity(m.nrow);
4466 for(
int c=m.ncol-1; c > index; c--) {
4467 im.arr[c][index] = - m.arr[c][index]/m.arr[index][index];
4481 mat l = identity(m.ncol);
4482 for(
int r = 0; r < m.nrow - 1; r++) {
4488 return std::make_pair(l, l*m);
4491mat geneMat(
int ncol,
int nrow,
int init){
4494 for(
int c=0; c<ncol; c++){
4495 for(
int r=0; r<nrow; r++){
4496 m.arr[c][r] = count;
4509 for(
int c=0; c<ncol; c++) {
4510 for(
int r=0; r<nrow; r++) {
4511 m.arr[c][r] =
random(snd - fst) + fst;
4532 const float e1[4] = {1.0f, 0.0f, 0.0f, 0.0f};
4533 const float e2[4] = {0.0f, 1.0f, 0.0f, 0.0f};
4534 const float e3[4] = {0.0f, 0.0f, 1.0f, 0.0f};
4535 const float e4[4] = {0.0f, 0.0f, 0.0f, 1.0f};
4542 column[0] = column[1] = column[2] = column[3] = 0.0f;
4546 this->column[0] = other.column[0];
4547 this->column[1] = other.column[1];
4548 this->column[2] = other.column[2];
4549 this->column[3] = other.column[3];
4552 Vector4(
float x,
float y,
float z,
float w = 1.0f) {
4553 this->column[0] = x;
4554 this->column[1] = y;
4555 this->column[2] = z;
4556 this->column[3] = w;
4559 this->column[0] = arr[0];
4560 this->column[1] = arr[1];
4561 this->column[2] = arr[2];
4562 this->column[3] = arr[3];
4565 this->column[0] = arr[0];
4566 this->column[1] = arr[1];
4567 this->column[2] = arr[2];
4568 this->column[3] = arr[3];
4570 bool operator==(
const Vector4& rhs) {
4571 bool b0 = column[0] == rhs.column[0];
4572 bool b1 = column[1] == rhs.column[1];
4573 bool b2 = column[2] == rhs.column[2];
4574 bool b3 = column[3] == rhs.column[3];
4575 return (b0 && b1 && b2 && b3);
4578 this->column[0] = rhs.column[0];
4579 this->column[1] = rhs.column[1];
4580 this->column[2] = rhs.column[2];
4581 this->column[3] = rhs.column[3];
4587 v.column[0] = this->column[0] + rhs.column[0];
4588 v.column[1] = this->column[1] + rhs.column[1];
4589 v.column[2] = this->column[2] + rhs.column[2];
4596 v.column[0] = this->column[0] - rhs.column[0];
4597 v.column[1] = this->column[1] - rhs.column[1];
4598 v.column[2] = this->column[2] - rhs.column[2];
4605 v.column[0] = column[0]/n;
4606 v.column[1] = column[1]/n;
4607 v.column[2] = column[2]/n;
4613 v.column[0] = column[0] * rhs.column[0];
4614 v.column[1] = column[1] * rhs.column[1];
4615 v.column[2] = column[2] * rhs.column[2];
4616 v.column[3] = column[3] * rhs.column[3];
4617 return v[0] + v[1] + v[2] + v[3];
4626 float norm = column[0]*column[0] +
4627 column[1]*column[1] +
4628 column[2]*column[2];
4629 float n = sqrtf(norm);
4634 const float& operator[](
int index)
const {
4635 return column[index];
4639 float& operator[](
int index) {
4640 return column[index];
4647 printf(
"x=[%1.2f]\ny=[%1.2f]\nz=[%1.2f]\nw=[%1.2f]\n\n", column[0], column[1], column[2], column[3]);
4654#if __cplusplus >= 201402
4705namespace SpaceMatrix4 {
4717 Matrix4(
const Matrix4& matrix) {
4730 Matrix4(
float m[16]) {
4731 Vector4 v1({ m[0], m[1], m[2], m[3]});
4732 Vector4 v2({ m[4], m[5], m[6], m[7]});
4733 Vector4 v3({ m[8], m[9], m[10], m[11]});
4734 Vector4 v4({ m[12], m[13], m[14], m[15]});
4740 Matrix4& operator=(
const Matrix4& matrix) {
4748 bool operator==(
const Matrix4& matrix) {
4749 bool b0 =
mat[0] == matrix[0];
4750 bool b1 =
mat[1] == matrix[1];
4751 bool b2 =
mat[2] == matrix[2];
4752 bool b3 =
mat[3] == matrix[3];
4753 return (b0 && b1 && b2 && b3);
4756 const Vector4& operator[](
int index)
const {
4761 Vector4& operator[](
int index) {
4766 m[0] =
mat[0] + rhs[0];
4767 m[1] =
mat[1] + rhs[1];
4768 m[2] =
mat[2] + rhs[2];
4769 m[3] =
mat[3] + rhs[3];
4772 Matrix4 operator-(Matrix4& rhs) {
4774 m[0] =
mat[0] - rhs[0];
4775 m[1] =
mat[1] - rhs[1];
4776 m[2] =
mat[2] - rhs[2];
4777 m[3] =
mat[3] - rhs[3];
4794 cout<<
"["<<row0.dot(vect4)<<
"]"<<std::endl;
4795 cout<<
"["<<row1.dot(vect4)<<
"]"<<std::endl;
4796 cout<<
"["<<row2.dot(vect4)<<
"]"<<std::endl;
4797 cout<<
"["<<row3.dot(vect4)<<
"]"<<std::endl;
4799 Vector4 v(row0.dot(vect4), row1.dot(vect4), row2.dot(vect4), row3.dot(vect4));
4807 m[0] = (*this)*matrix[0];
4808 m[1] = (*this)*matrix[1];
4809 m[2] = (*this)*matrix[2];
4810 m[3] = (*this)*matrix[3];
4815 Matrix4 translate(
float x,
float y,
float z) {
4828 Matrix4 identity() {
4840 printf(
"[%1.2f][%1.2f][%1.2f][%1.2f]\n",
mat[0][0],
mat[1][0],
mat[2][0],
mat[3][0]);
4841 printf(
"[%1.2f][%1.2f][%1.2f][%1.2f]\n",
mat[0][1],
mat[1][1],
mat[2][1],
mat[3][1]);
4842 printf(
"[%1.2f][%1.2f][%1.2f][%1.2f]\n",
mat[0][2],
mat[1][2],
mat[2][2],
mat[3][2]);
4843 printf(
"[%1.2f][%1.2f][%1.2f][%1.2f]\n",
mat[0][3],
mat[1][3],
mat[2][3],
mat[3][3]);
4856vector<T> interleave(
const vector<T>& v1,
const vector<T>& v2) {
4858 int len1 = v1.size();
4859 int len2 = v2.size();
4861 for(
int i=0; i<std::min(len1, len2); i++) {
4862 vec.push_back(v1[i]);
4863 vec.push_back(v2[i]);
4879using namespace AronPrint;
4888string takeFileName(
string path) {
4892 if(
vec.size() > 0) {
4915string takeDirectory(
string path) {
4917 vector<string> vecDir = AronLambda::init(
vec);
4918 vector<string> pathvec;
4919 int len = vecDir.size();
4920 vector<string> vv = interleave(vecDir, repeatVec(
len,
c2s(
"/")));
4921 if(!( AronLambda::head(
vec).empty() && vecDir.size() == 1)) {
4922 pathvec = AronLambda::init(vv);
4927 return AronLambda::foldr([](
auto x,
auto y) {
4929 },
c2s(
""), pathvec);
4935vector<T> interleave(vector<T> v1, vector<T> v2, vector<T> v3){
4937 int vlen = std::min(std::min(
len(v1),
len(v2)),
len(v3));
4938 for(
int i = 0; i < vlen; i++){
4939 vec.push_back(v1[i]);
4940 vec.push_back(v2[i]);
4941 vec.push_back(v3[i]);
4954string takeExtension(
string path) {
4957 if(
vec.size() > 1) {
4974string join(vector<string>&
vec) {
4975 return trimRight( AronLambda::foldr([](
auto x,
auto y) {
4980string joinNewLine(vector<string>
vec) {
4981 return AronLambda::foldr([](
auto x,
auto y) {
4996string concatR(vector<string>&
vec,
string s) {
4997 return AronLambda::foldr([&s](
auto x,
auto y) {
5013string concatL(vector<string>&
vec,
string s) {
5014 return AronLambda::foldl([&s](
auto x,
auto y) {
5028vector<string> readFile(
string fname) {
5029 std::ifstream file(fname);
5030 vector<string> retVec;
5031 if (file.is_open()) {
5033 while(getline(file, line)) {
5034 retVec.push_back(line);
5042vector<string> readFileBackward(
string fname,
int nline){
5046 std::ifstream myFile(fname,std::ios::ate);
5047 std::streampos size = myFile.tellg();
5048 char* pt = (
char*)malloc(maxChar*
sizeof(
char));
5051 for(
int i=1;i<=size && k < nline;i++){
5052 myFile.seekg(-i,std::ios::end);
5058 printf(
"ERROR: nx > maxChar\n");
5059 printf(
"ERROR: readFileBackward(string fname, int nline)\n");
5064 vec.push_back(reverseStr(
c2s(pt)));
5066 pt = (
char*)malloc(maxChar*
sizeof(
char));
5073 return reverse(
vec);
5092string readFileStream(
const char* fpath){
5093 std::string vertexCode;
5094 std::ifstream vShaderFile;
5096 vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit);
5099 vShaderFile.open(fpath);
5100 std::stringstream vShaderStream;
5102 vShaderStream << vShaderFile.rdbuf();
5104 vShaderFile.close();
5106 vertexCode = vShaderStream.str();
5108 catch (std::ifstream::failure& e) {
5109 std::cout <<
"ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl;
5119void listDirToFile(
char * path,
char* toFile, vector<string>&
vec) {
5120 DIR * d = opendir(path);
5123 while ((dir = readdir(d)) != NULL) {
5124 if(dir->d_type != DT_DIR) {
5126 sprintf(fpath,
"%s/%s", path, dir->d_name);
5127 vec.push_back(
c2s(fpath));
5128 if(
vec.size() > 1000) {
5129 writeFileAppendVector(
c2s(toFile),
vec);
5132 }
else if(dir -> d_type == DT_DIR && strcmp(dir->d_name,
".")!=0 && strcmp(dir->d_name,
"..")!=0 ) {
5134 sprintf(fpath,
"%s/%s", path, dir->d_name);
5135 listDirToFile(fpath, toFile,
vec);
5145void listDirToVec(
char * path,
char* toFile, vector<string>&
vec) {
5146 listDirToFile(path, toFile,
vec);
5152vector<string> recurveDirBoost(
char* dir) {
5153 vector<string> retVec;
5157 if(!exists(p) || !is_directory(p)) {
5158 std::cout << p <<
" is not a path\n";
5162 fs::recursive_directory_iterator begin(p), end;
5163 std::vector<fs::directory_entry> v(begin, end);
5164 for(fs::directory_entry& f: v) {
5165 retVec.push_back(f.path().string());
5191void recurveDirToFile(
char * path,
char* toFile, vector<string>&
vec) {
5192 DIR * d = opendir(path);
5195 while ((dir = readdir(d)) != NULL) {
5196 if(dir-> d_type != DT_DIR) {
5198 sprintf(fpath,
"%s/%s", path, dir->d_name);
5199 vec.push_back(
c2s(fpath));
5200 if(
vec.size() > 1000) {
5201 writeFileAppendVector(
c2s(toFile),
vec);
5204 }
else if(dir -> d_type == DT_DIR && strcmp(dir->d_name,
".")!=0 && strcmp(dir->d_name,
"..")!=0 ) {
5206 sprintf(fpath,
"%s/%s", path, dir->d_name);
5207 listDirToFile(fpath, toFile,
vec);
5209 vec.push_back(
"Unknown_type");
5212 if(
vec.size() > 0) {
5213 writeFileAppendVector(
c2s(toFile),
vec);
5225void listDirAll(
char * path) {
5226 DIR * d = opendir(path);
5229 while ((dir = readdir(d)) != NULL) {
5230 if(dir-> d_type != DT_DIR) {
5232 sprintf(dpath,
"%s/%s", path, dir->d_name);
5233 printf(
"%s\n", dpath);
5234 }
else if(dir -> d_type == DT_DIR && strcmp(dir->d_name,
".")!=0 && strcmp(dir->d_name,
"..")!=0 ) {
5235 printf(
"%s\n", dir->d_name);
5237 sprintf(dpath,
"%s/%s", path, dir->d_name);
5238 printf(
"%s\n", dpath);
5253void listDirToVector(
char * path, vector<string>&
vec) {
5254 DIR * d = opendir(path);
5257 while ((dir = readdir(d)) != NULL) {
5258 if(dir-> d_type != DT_DIR) {
5259 char fullpath[1000];
5260 sprintf(fullpath,
"%s/%s", path, dir->d_name);
5261 vec.push_back(
c2s(fullpath));
5262 }
else if(dir -> d_type == DT_DIR && strcmp(dir->d_name,
".")!=0 && strcmp(dir->d_name,
"..")!=0 ) {
5263 char fullpath[1000];
5264 sprintf(fullpath,
"%s/%s", path, dir->d_name);
5265 listDirToVector(fullpath,
vec);
5267 vec.push_back(
"Unknown_type");
5277 if (getcwd(cwd,
sizeof(cwd)) != NULL) {
5280 perror(
"getcwd() error");
5289string intToStringLen(
int num,
int maxlen) {
5291 sprintf(buffer,
"%d", num);
5292 string zero = AronLambda::take(maxlen - strlen(buffer),
repeat(num,
"0"));
5293 return zero +
c2s(buffer);
5301std::pair<vector<string>, vector<string>> parseLambda(
string s) {
5303 vector<string>
vec = AronLambda::filter([](
auto& x) {
5304 return trim(x).length() > 0;
5307 vector<string> varv;
5308 auto f = [](
auto x) {
5309 return x ==
c2s(
"->");
5311 std::pair<vector<string>, vector<string>> pair =
breakVec(f,
vec);
5312 return std::make_pair(pair.first, AronLambda::tail(pair.second));
5324void merge(
int* arr,
int lo,
int mid,
int hi) {
5325 int len = hi - lo + 1;
5326 int* list =
new int[
len];
5330 while(i < mid + 1 || j < hi + 1) {
5334 }
else if(j >= hi + 1) {
5337 }
else if (arr[i] < arr[j]) {
5346 for(
int i=0; i<
len; i++) {
5347 arr[lo + i] = list[i];
5352void mergeSort(
int* arr,
int lo,
int hi) {
5354 int m = (lo + hi)/2;
5355 mergeSort(arr, lo, m);
5356 mergeSort(arr, m+1, hi);
5357 merge(arr, lo, m, hi);
5362void swap(
int array[],
int i,
int j) {
5364 array[i] = array[j];
5382 for(
int i=lo; i<=hi; i++) {
5384 swap(array, i, big);
5395void quickSortArr(
int array[],
int lo,
int hi) {
5398 quickSortArr(array, lo, pivot-1);
5399 quickSortArr(array, pivot+1, hi);
5405static vector<T> quickSort(vector<T>
vec) {
5406 if (
vec.size() <= 1)
5410 vector<T> rest = drop(1,
vec);
5411 vector<T> left = filter<T>([pivot](
auto x) {
5414 vector<T> right = filter<T>([pivot](
auto x) {
5417 return quickSort(left) + con(pivot, quickSort(right));
5421template<
typename Fun,
typename T>
5422static vector<T> mergeSortList(Fun f, vector<T> v1, vector<T> v2) {
5429 vector<T> vh1 = take(1, v1);
5430 vector<T> vh2 = take(1, v2);
5431 if (f(vh1.at(0), vh2.at(0))) {
5432 return vh1 + mergeSortList(f, tail(v1), v2);
5434 return vh2 + mergeSortList(f, v1, tail(v2));
5458void writeFile(
string fname,
mat& m) {
5459 for(
int i=0; i<m.nrow; i++) {
5461 writeFileAppendVector(fname,
vec);
5476 for(
int i = 0; i < min(
len(v1),
len(v2)); i++){
5498 if (
len(v2) == 2 &&
len(v2[0]) == 2){
5505 pp(
"Invalid Input.");
5525 if (
len(v1) == 2 &&
len(v2) == 2){
5532 pp(
"Invalid Input.");
5569 x = det2<T>(v11, v22);
5576 y = (-1)*det2<T>(v11, v22);
5582 z = det2<T>(v11, v22);
5586 printf(
"Invalid Input.\n");
5591void printArr2(
float* arr,
int len,
int width){
5592 vector<vector<float>> vv = arrToVec2(arr,
len, width);
5603 for(
int i = 0; i < min(
len(v1),
len(v2)); i++){
5604 v.push_back(v1[i] - v2[i]);
5610void print(
string s, T t){
5615string padRight(
string s,
string pad,
int maxLen){
5616 int diff = maxLen -
len(s);
5617 int padLen = diff > 0 ? diff : 0;
5618 string ret = s +
repeat(padLen, pad);
5622string padLeft(
string s,
string pad,
int maxLen){
5623 int diff = maxLen -
len(s);
5624 int padLen = diff > 0 ? diff : 0;
5625 string ret =
repeat(padLen, pad) + s;
double intToDouble(int n)
Definition: AronLib.h:1780
const char * s2c(string s)
Convert std::string to char*.
Definition: AronLib.h:1470
vector< vector< T > > geneMatrix(int ncol, int nrow, T init)
Generate ncol x nrow matrix with initial value @init.
Definition: AronLib.h:2338
int random(int n)
random number from 0 to n-1 NOTE: Ubuntu DOES NOT have arc4random_uniform, it works on MacOS only.
Definition: AronLib.h:1410
vector< T > operator+(vector< T > v1, vector< T > v2)
Concate two vectors, both vectors are NOT modified.
Definition: AronLib.h:2111
T partition(vector< T > &vec, int lo, int hi)
partition vector, use [hi] as pivot, like in quicksort
Definition: AronLib.h:2397
void quickSortT(T array[], int lo, int hi)
Definition: AronLib.h:2465
bool compareFloat(double a, double b)
Definition: AronLib.h:1895
uint64_t nowMicroseconds()
Definition: AronLib.h:211
bool containStrRegex(string s, regex rx)
check s contains regex pattern
Definition: AronLib.h:1584
T head(vector< T > vec)
Definition: AronLib.h:919
bool containStr(string str, string pat)
check if str contain pat
Definition: AronLib.h:1599
vector< int > randomNanoSec(int n, int max)
Definition: AronLib.h:1392
void tranmat4(float arr[16])
Definition: AronLib.h:1997
double nthRoot(double c, int n, double epsilon=0.000001)
Compute the nth root of any positive integer, n >= 1.
Definition: AronLib.h:1790
int length(string s)
length of string
Definition: AronLib.h:2174
std::map< char, int > hexMap()
Definition: AronLib.h:335
string concatValidPath(vector< string > vec)
remove adjacent duplicate char from a string
Definition: AronLib.h:2510
void writeFileAppendRow(string fname, std::vector< T > vec)
Write vector to file using space as delimiter.
Definition: AronLib.h:552
int compareCString(char *s1, char *s2)
Definition: AronLib.h:1853
string c2s(const char *pt)
string to char*
Definition: AronLib.h:1570
vector< vector< T > > transpose(vector< vector< T > > mat)
transpose matrix
Definition: AronLib.h:1956
vector< T > replaceVec(T oldVal, T newVal, vector< T > vec)
replace oldVale with newVal in a cloned vector
Definition: AronLib.h:1681
int len(string s)
length of string
Definition: AronLib.h:2192
Complex rectangular(std::pair< double, double > p)
Definition: AronLib.h:3216
vector< int > sumVec(vector< int > v1, vector< int > v2)
sum two int vectors
Definition: AronLib.h:588
vector< std::string > splitStrRegex(const string &s, string rgxStr="\\s+")
Split string with regex.
Definition: AronLib.h:1728
double squareRoot(double a)
Definition: AronLib.h:1766
vector< T > reverseVec(vector< T > vec)
Definition: AronLib.h:2282
vector< T > * moveVec(T a, vector< T > vec)
use std::move, it acts like Java. Create local object, and return it.
Definition: AronLib.h:2139
void printNb(T t)
print no bracket
Definition: AronLib.h:2064
vector< T > removeIndexRange(vector< T > &vec, int fromInx, int toInx)
remove index from to index inclusively.
Definition: AronLib.h:686
vector< T > subtract(vector< T > v1, vector< T > v2)
Definition: AronLib.h:5601
long lcgRandom(long x0)
Linear congruential generator.
Definition: AronLib.h:1369
T last(vector< T > vec)
Definition: AronLib.h:937
vector< T > * append(vector< T > vec, T a)
use std::move, it acts like Java. Create local object, and return it.
Definition: AronLib.h:2162
string toStr(const T &s)
Convert any type to std::string.
Definition: AronLib.h:1494
uint64_t nowNanoseconds()
Definition: AronLib.h:219
vector< T > concatVec(vector< T > v1, vector< T > v2)
Concat two vectors.
Definition: AronLib.h:2100
int maxConsecutiveOne(vector< int > vec)
Definition: AronLib.h:250
vector< int > toBinary(int n)
Definition: AronLib.h:405
int maxConsecutiveChar(char *arr, int size, char c)
Definition: AronLib.h:289
vector< T > operator*(T a, vector< T > vec)
scalar multiply vector
Definition: AronLib.h:2236
vector< string > splitStr(string s, string delim)
Split string with delimiter.
Definition: AronLib.h:1619
std::pair< vector< T >, vector< T > > breakVec(Fun f, vector< T > vec)
break a vector to pair
Definition: AronLib.h:1663
bool isEmpty(string s)
Definition: AronLib.h:1745
vector< T > insertAt(vector< T > vec, int pos, vector< T > insertVec)
Insert vector @insertVec into vec at position @pos.
Definition: AronLib.h:1704
string trim(string str)
trim both ends
Definition: AronLib.h:1547
const char * stringToCString(string s)
Convert std::string to char*, same as s2c(string s)
Definition: AronLib.h:1463
string removeIndex(string s, int inx)
remove char from a string
Definition: AronLib.h:655
T dotProduct(vector< T > v1, vector< T > v2)
Definition: AronLib.h:5474
string cStringToString(const char *pt)
char* to string
Definition: AronLib.h:1557
T det2(vector< vector< T > > v2)
Definition: AronLib.h:5497
const char * toCharPtr(string s)
it is same as s2c but it is better name.
Definition: AronLib.h:1479
std::pair< vector< T >, vector< T > > splitAt(int n, vector< T > vec)
split vector to pair of vector
Definition: AronLib.h:1645
vector< T > crossProduct(vector< T > v1, vector< T > v2)
Definition: AronLib.h:5563
int partitionT(T array[], int lo, int hi)
partition array inline
Definition: AronLib.h:2367
int partitionInline(vector< T > &vec, int lo, int hi)
partition vector inline
Definition: AronLib.h:2434
bool isBST(Node< int > *curr, Node< int > *&prev)
Check whether a Binary Tree is BST.
Definition: AronLib.h:2320
int compareString(string s1, string s2)
Definition: AronLib.h:1861
uint64_t nowMilliseconds()
Definition: AronLib.h:202
string removeAdjacentDuplicateChar(string s, char c)
remove adjacent duplicate char from a string
Definition: AronLib.h:2524
bool binSearch(T key, T arr[], int lo, int hi)
binary search on a sorted array
Definition: AronLib.h:2216
string repeat(int n, string s)
Repeating n copy of s. The function is inspired by Haskell repeat.
Definition: AronLib.h:1831
Definition: AronLib.h:2681
Definition: AronLib.h:2625
Definition: AronLib.h:2738
Definition: AronLib_tmp.h:2619
Definition: DDLinkedList.h:9
Inspired from Eigen Lib.
Definition: AronLib.h:3629
Definition: AronLib.h:3604
mat take(int len)
Take first n columns from a matrix.
Definition: AronLib.h:4049
mat removeVec(int index)
Get an index Column or Vector from a matrix.
Definition: AronLib.h:3924
void geneMatRandom(int fst, int snd)
Generate a random matrix in interval @fst and @snd [fst, snd)
Definition: AronLib.h:4189
mat insertVecNext(int index, vec v)
Add vector to the right of index, Should I change the name to insertVecRight()
Definition: AronLib.h:3942
mat drop(int len)
Drop first n columns from a matrix.
Definition: AronLib.h:4061
mat tail()
Drop the first column from a matrix.
Definition: AronLib.h:4101
void geneMat(int init)
Generate matrix from init to ncol*nrow.
Definition: AronLib.h:4166
mat init()
Drop the last column from a matrix.
Definition: AronLib.h:4080
mat block(int colIndex, int clen, int rowIndex, int rlen)
subblock of a matrix
Definition: AronLib.h:4117
mat transpose()
tranpose matrix
Definition: AronLib.h:4137
row getRow(int n)
Get an index row from a matrix.
Definition: AronLib.h:3913
mat subMatrix(int colIndex, int rowIndex)
/Library/WebServer/Documents/zsurface/pdf/submatrix_get.pdf 1 2 3 subMatrix(1, 0) => 4 5 6 4 5 6
Definition: AronLib.h:4029
void print()
print the matrix
Definition: AronLib.h:3840
mat swapRow(int inx1, int inx2)
Add test cases.
Definition: AronLib.h:4314
vec getVec(int n)
Definition: AronLib.h:3901
Definition: AronLib.h:3357
vector< float > toVector()
Convert row to vector.
Definition: AronLib.h:3556
Definition: AronLib.h:3332
vector< float > toVector()
Definition: AronLib.h:3432
Complex(double x_, double y_)
Definition: AronLib.h:3132
Complex operator-(Complex &c)
Definition: AronLib.h:3150
friend Complex operator/(const Complex &c1, const Complex &c2)
division for complex number
Definition: AronLib.h:3195
Complex operator*(const Complex &c)
Definition: AronLib.h:3162
Complex()
Definition: AronLib.h:3125
bool operator==(const Complex &c)
Definition: AronLib.h:3170
void print()
Definition: AronLib.h:3206
Complex operator+(Complex &c)
Definition: AronLib.h:3140
Definition: AronLib.h:4529
Vector4()
Definition: AronLib.h:4541
Definition: AronLib.h:850
Definition: AronLib_tmp.h:725
include all the sorting algorithms etc.
int partition(int array[], int lo, int hi)
partition array to to left and right, using [hi] as pivot
Definition: AronLib.h:5378
complex number representation and operation number
Two dimensional array represents matrix, column and row vector.
Definition: AronLib.h:3231
T ** vecVecToArrArr(vector< vector< T > > vv)
Convert Vector< Vector<T> > to dynamic T**.
Definition: AronLib.h:3272
std::pair< mat, mat > utri(mat m)
Assume the diagonal entries are not zero, compute the U triangle matrix Lk..(L2 (L1 A))= U TODO: fix ...
Definition: AronLib.h:4477
vector< vector< T > > arrArrToVecVec(T **arr, int ncol, int nrow)
Convert T** arr to vector<vector<T>> v2.
Definition: AronLib.h:3316
vec backwardSubstitute(mat a, vec b)
Backward Substitute.
Definition: AronLib.h:4416
T ** allocate(int ncol, int nrow)
Allocate a matrix: height = ncol, width = nrow.
Definition: AronLib.h:3259
mat geneMatRandom(int ncol, int nrow, int fst, int snd)
Generate random matrix in interval from fst to snd.
Definition: AronLib.h:4507
T ** allocateTemp(int ncol, int nrow)
Allocate ncol, nrow two dimension array for any type, return a pointer.
Definition: AronLib.h:3245
mat ltri(mat m, int index)
Get the L triangle from a matrix.
Definition: AronLib.h:4460
many function can be global actually
int substringFirstIndex(string sub, string s)
find the index of sub in string s
Definition: AronLib.h:2864
bool isSubstring(string sub, string s)
Check whether sub is the substring of s.
Definition: AronLib.h:2825