diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c025b4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +NTL/ +.DS_Store diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cf6c835 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +CXX = clang++ +# Added Homebrew include path +CXXFLAGS = -O3 -std=c++17 -I./NTL/include -I/opt/homebrew/include +# Added Homebrew library path +LDFLAGS = -L./NTL/src -L/opt/homebrew/lib -lntl -lgmp + +TARGET = phase1 +SRC = phase1.cpp + +all: $(TARGET) + +$(TARGET): $(SRC) + $(CXX) $(CXXFLAGS) $(SRC) $(LDFLAGS) -o $(TARGET) + +clean: + rm -f $(TARGET) diff --git a/conv_impl.cpp b/conv_impl.cpp new file mode 100755 index 0000000..d56a535 Binary files /dev/null and b/conv_impl.cpp differ diff --git a/phase1 b/phase1 new file mode 100755 index 0000000..49e1ebd Binary files /dev/null and b/phase1 differ diff --git a/phase1.cpp b/phase1.cpp new file mode 100644 index 0000000..be4b591 --- /dev/null +++ b/phase1.cpp @@ -0,0 +1,147 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +constexpr const long PRIME_BIT = 60; +constexpr const long ERR_BOUND = 80; +double total_time{}; + +using namespace std; +using namespace NTL; + +std::vector>global; +/* O(n^2) compute for toeplitz matrix with input vector Benchmarking against Cooley method */ +/* from 1d -> 2d we use V[(n-1) + ( j- i) * xj)] j: 0 -> n */ + +vec_ZZ_p mul_norm(const vec_ZZ_p &input, const vec_ZZ_p &tope_mat, long n){ + vec_ZZ_p res; + res.SetLength(n); + + for(long i{};i +void routine_check(const vec_ZZ_p &toep_mat, const vec_ZZ_p &input, long n, Func mul_function){ + + long double curr_time = GetTime(); + vec_ZZ_p mat = mul_function(input,toep_mat, n); + long double final_time = GetTime() - curr_time; + global.push_back({n,final_time}); + std::cout << "[ time: " << final_time << "]" << std::endl; +} + + +void print_matrix(const vec_ZZ_p &toep_mat, long n) { + const int width = 30; + + auto print_separator = [&]() { + std::cout << "+"; + for(long i = 0; i < n; ++i) + std::cout << std::string(width, '-') << "+"; + std::cout << "\n"; + }; + + std::cout << "\n--- Toeplitz Matrix Verification (n=" << n << ") ---\n"; + + print_separator(); + + for(long i = 0; i < n; ++i) { + std::cout << "|"; + + for(long j = 0; j < n; ++j) { + long index = (n-1) + (j-i); + + std::ostringstream oss; + oss << toep_mat[index]; + std::string s = oss.str(); + + std::cout << std::setw(width) << s << "|"; + } + + std::cout << "\n"; + print_separator(); + } +} + +int main(){ + + ZZ p; + GenPrime(p ,PRIME_BIT ,ERR_BOUND); + ZZ_p::init(p); + long t = 8; + SetSeed(to_ZZ(time(nullptr))); + + long start,step,end; + + std::cout << "Please Enter the Start value: " << std::endl; + std::cin >> start; + std::cout << "Please Enter the Step value: " << std::endl; + std::cin >> step; + std::cout << "Please Enter the End value: " << std::endl; + std::cin >> end; + + + while(start != end){ + + vec_ZZ_p input; + input.SetLength(start); + + for(long i{};i< start; ++i){ + random(input[i]); + } + vec_ZZ_p toep_mat; + + toep_mat.SetLength(2*start-1); + + for(long i{};i<2*start-1;++i){ + random(toep_mat[i]); + } + print_matrix(toep_mat, start); + routine_check(toep_mat,input, start, mul_norm); + start += step; + } + + std::cout << "\n"; + + std::cout << "FINAL SUMMARY ---------------------------------- " << std::endl; + for(auto&[n,final_time]:global){ + total_time += final_time; + std::cout << "For n: " << n << " " << " Time taken: " << final_time << std::endl; + } + std::cout << "\n"; + std::cout << "Total time taken: " << " " << total_time << std::endl; + + return 0; +}