diff --git a/.gitignore b/.gitignore index d55858e..a171841 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ __pycache__ .DS_Store a.out +a.exe +numpp.hpp.gch +.vscode diff --git a/README.md b/README.md index 3403c7b..e7c9718 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # NumPP ## C++ Port to NumPy + + +main.cpp will work fine with Codeblocks diff --git a/src/numpp.cpp b/src/numpp.cpp index 8dd44e0..0848eb6 100644 --- a/src/numpp.cpp +++ b/src/numpp.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "numpp.hpp" @@ -22,6 +23,7 @@ template numpp::numpp(vector dim) { this->dim = dim; this->ndim = 1; + is_zero = false; for(int i=0; idim.size(); i++) this->ndim *= this->dim[i]; try { @@ -59,6 +61,63 @@ void numpp::reshape(vector new_dim) { cerr<<"\033[1;31m Error\033[0m: Invalid dimensions!"; } +template +uint64_t numpp::max() { + long long int maximum=data[0]; + long i=1; + while(i!=ndim) + { + if(data[i]>maximum) + maximum=data[i++]; + } + return maximum; + +} + +template +uint64_t numpp::min() { + long long int minimum=data[0]; + long i=1; + while(i!=ndim) + { + if(data[i] +void numpp::zeros() { + is_zero = true; +} + +template +void numpp::print() { + long i=1; + cout< void numpp::push_vec(vector dim, vector data) { if(shape_match(dim)) { @@ -73,3 +132,128 @@ void numpp::push_vec(vector dim, vector data) { else cerr<<"\033[1;31m Error\033[0m: Dimension doesn't match declared numpp dimension!\n"; } + +template +void numpp::add(numpp np1,numpp np2){ + cout<dim.size()*dim.size();i++) + { + this->data[i]=np1.data[i]+np2.data[i]; + cout<data[i]<<" "; + } +} +template +void numpp::sub(numpp np1,numpp np2){ + cout<dim.size()*dim.size();i++) + { + this->data[i]=np1.data[i]-np2.data[i]; + cout<data[i]<<" "; + } +} + +template +void numpp::search(T a, string ch) { + if(ch == "linear") { + int count=0; + for(int i=0; i data[j+1]) { + temp=data[j]; + data[j]=data[j+1]; + data[j+1]=temp; + } + } + } + int count=0; + int start, end, middle; + start=0; + end=ndim-1; + for(int i=0;idata[middle]) + start=middle+1; + else + end=middle-1; + } + if(count>0) + cout< +void numpp::sort(string ch) { + if(ch=="Bubble") { + int i, j; + T temp; + for (i = 0; i < ndim-1; i++) { + for (j = 0; j < ndim-i-1; j++) { + if (data[j] > data[j+1]) { + temp=data[j]; + data[j]=data[j+1]; + data[j+1]=temp; + } + } + } + } else if(ch=="Insertion") { + int i, j; + T key; + for (i = 1; i < ndim; i++) { + key = data[i]; + j = i - 1; + while (j >= 0 && data[j] > key) { + data[j + 1] = data[j]; + j = j - 1; + } + data[j + 1] = key; + } + } else if(ch=="Selection") { + int i, j, min_idx; + T temp; + + for (i = 0; i < ndim-1; i++) { + min_idx = i; + for (j = i+1; j < ndim; j++) + if (data[j] < data[min_idx]) + min_idx = j; + temp=data[min_idx]; + data[min_idx]=data[i]; + data[i]=temp; + } + for(i=0;i + void numpp::random_normal(double mean, double stddev) { + default_random_engine generator; + normal_distribution distribution(mean, stddev); + this->data.clear(); + for(int i=0; indim; i++) + this->data.push_back(distribution(generator)); + } + + template + void numpp::random_uniform(double mean, double stddev) { + default_random_engine generator; + uniform_real_distribution distribution(mean, stddev); + this->data.clear(); + for(int i=0; indim; i++) + this->data.push_back(distribution(generator)); + } diff --git a/src/numpp.hpp b/src/numpp.hpp index e0976f8..254f401 100644 --- a/src/numpp.hpp +++ b/src/numpp.hpp @@ -10,6 +10,7 @@ class numpp { private: vector dim; vector data; + bool is_zero; uint64_t ndim; int shape_match(vector); public: @@ -17,6 +18,16 @@ class numpp { void shape(); void reshape(vector); void push_vec(vector, vector); + uint64_t max(); + uint64_t min(); + void zeros(); + void print(); + void add(numpp,numpp); + void sub(numpp,numpp); + void search(T, string); + void sort(string); + void random_normal(double, double); + void random_uniform(double, double); }; #endif diff --git a/src/old/Makefile b/src/old/Makefile deleted file mode 100644 index 109cb7d..0000000 --- a/src/old/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -arr: - - g++ -std=c++11 -o arr arr.cpp - - ./arr diff --git a/src/old/array.cpp b/src/old/array.cpp deleted file mode 100644 index d95cc09..0000000 --- a/src/old/array.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include - -using namespace std; - -using namespace std::chrono; - -vector split_string(string s) { - vector ret_vec; - string buf = ""; - int temp; - for(int i=0; i> temp; - ret_vec.push_back(temp); - buf = ""; - continue; - } - buf += s[i]; - } - - stringstream int_str(buf); - int_str >> temp; - ret_vec.push_back(temp); - - return ret_vec; -} - -vector mul_ret(vector dimensions) { - - reverse(dimensions.begin(), dimensions.end()); - - vector ret_arr; - int mul = 1; - for(int i=0; i partitioning(int size, int partition_size) { - vector ret_vec; - for(int i=0; i row, int prev_dim=0) { - int ind=0; - //vector indexing; - int indexing; - for(int i=0; i 0) - ind = 0; - if(row[i] > idx) { - return indexing; - } - if(idx == row[i]) { - return ind; - } - indexing = ind; - ind++; - } - return ind-1; -} - -int main() { - - string s; - - cout<<"Enter the dimensions: "; - getline(cin, s); - - auto start = high_resolution_clock::now(); - - std::string::iterator end_pos = std::remove(s.begin(), s.end(), ' '); - s.erase(end_pos, s.end()); - - vector dimensions = split_string(s); - dimensions.push_back(1); - - int npp_arr_size = 1; - - for(int i=0; i mul_vector = mul_ret(dimensions); - - vector > partitions; - - for(int i=1; i(stop - start); - - cout<<"Time taken for array creation and partition: "<().swap(mul_vector); - - vector true_index; - - int mode; - - cout<<"Mode: "; - cin>>mode; - - if(mode == 0) { - for(int idx=0; idx"; - - for(int i=0; i 0) { - true_index.push_back(index(idx, partitions[i], dimensions[i])); - } else { - true_index.push_back(index(idx, partitions[i])); - } - } - cout<>idx; - - for(int i=0; i 0) { - cout< -#include -#include -#include -#include -#include - -#include - -using namespace std; - -using namespace std::chrono; - -template -class nparr { - private: - string dim; - vector dimensions; - vector > partitions; - - vector split_string(string s) { - vector ret_vec; - string buf = ""; - int temp; - for(int i=0; i> temp; - ret_vec.push_back(temp); - buf = ""; - continue; - } - buf += s[i]; - } - - stringstream int_str(buf); - int_str >> temp; - ret_vec.push_back(temp); - - return ret_vec; - } - - vector mul_ret(vector dimensions) { - - reverse(dimensions.begin(), dimensions.end()); - - vector ret_arr; - int mul = 1; - for(int i=0; i partitioning(int size, int partition_size) { - vector ret_vec; - for(int i=0; i row, int prev_dim=0) { - int ind=0; - int indexing; - for(int i=0; i 0) - ind = 0; - if(row[i] > idx) { - return indexing; - } - if(idx == row[i]) { - return ind; - } - indexing = ind; - ind++; - } - return ind-1; - } - - public: - int npp_arr_size = 1; - - nparr(string s) { - dim = s; - - string::iterator end_pos = remove(dim.begin(), dim.end(), ' '); - dim.erase(end_pos, dim.end()); - - dimensions = split_string(dim); - dimensions.push_back(1); - - for(int i=0; i mul_vector = mul_ret(dimensions); - - for(int i=1; i np("100, 100"); - - return 0; -} diff --git a/src/test.cpp b/src/test.cpp index 5b36562..1deb96c 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -14,6 +14,22 @@ int main() { numpp np({2, 2}); auto start = high_resolution_clock::now(); + + np.push_vec({2, 2}, {1, 2, 3, 4}); + + cout<(stop - start); + + cout<