Dev#3
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request introduces a C++ implementation for benchmarking Toeplitz matrix-vector multiplication using the NTL library. The PR adds a basic benchmark framework comparing a naive O(n²) implementation against a planned O(n log n) Cooley method (currently incomplete). However, the PR contains several critical issues including committed binary files and code defects.
Changes:
- Added phase1.cpp with Toeplitz matrix multiplication implementation and benchmarking framework
- Added Makefile for building with NTL and GMP dependencies via Homebrew
- Added .gitignore for NTL directory and .DS_Store files
- Incorrectly committed two compiled binary files (phase1 and conv_impl.cpp)
Reviewed changes
Copilot reviewed 2 out of 5 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| phase1.cpp | Main source file implementing naive Toeplitz matrix multiplication, benchmarking utilities, and user input for performance testing |
| phase1 | Compiled Mach-O binary that should not be in version control |
| conv_impl.cpp | Appears to be a misnamed compiled binary that should not be in version control |
| Makefile | Build configuration for compiling with clang++, NTL, and GMP libraries |
| .gitignore | Excludes NTL directory and .DS_Store, but missing binary exclusions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@Ko496-glitch I've opened a new pull request, #4, to work on those changes. Once the pull request is ready, I'll request review from you. |
[WIP] Add C++ benchmarking for Toeplitz matrix-vector multiplication
Updated project description and removed redundant lines.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 6 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #include<iostream> | ||
| #include<sstream> | ||
| #include<iomanip> | ||
| #include<string> |
There was a problem hiding this comment.
This file uses std::vector/std::pair and time(nullptr) but does not include the standard headers that define them. Add the appropriate includes (e.g., <vector>, <utility>, <ctime>) instead of relying on transitive includes.
| #include<string> | |
| #include<string> | |
| #include<vector> | |
| #include<utility> | |
| #include<ctime> |
| ZZ p; | ||
| GenPrime(p ,PRIME_BIT ,ERR_BOUND); | ||
| ZZ_p::init(p); | ||
| long t = 8; |
There was a problem hiding this comment.
long t = 8; is unused. Please remove it (or use it) to avoid warnings and keep main() focused.
| long t = 8; |
| 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); | ||
|
|
There was a problem hiding this comment.
User inputs are used directly as vector lengths (input.SetLength(start) and toep_mat.SetLength(2*start-1)) without validation. Negative/zero/very large values can trigger SetLength exceptions or huge allocations; validate start > 0, end bounds, and guard against overflow in 2*start-1 before allocating.
| # 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 | ||
|
|
There was a problem hiding this comment.
The build hardcodes Homebrew-specific include/library paths (/opt/homebrew/...) and references ./NTL/... even though NTL/ is ignored in .gitignore and not present in the repo. Make the dependency discovery configurable (e.g., via NTL_PREFIX/GMP_PREFIX variables or pkg-config) so the project builds on non-macOS setups and in CI.
| # 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 | |
| # Optional prefixes for NTL and GMP installations. | |
| # Users/CI can set these when invoking make, e.g.: | |
| # make NTL_PREFIX=/usr/local GMP_PREFIX=/usr | |
| NTL_PREFIX ?= | |
| GMP_PREFIX ?= | |
| CXXFLAGS = -O3 -std=c++17 | |
| LDFLAGS = -lntl -lgmp | |
| # If NTL_PREFIX is provided, add its include/lib directories | |
| ifneq ($(NTL_PREFIX),) | |
| CXXFLAGS += -I$(NTL_PREFIX)/include | |
| LDFLAGS += -L$(NTL_PREFIX)/lib | |
| endif | |
| # If GMP_PREFIX is provided, add its include/lib directories | |
| ifneq ($(GMP_PREFIX),) | |
| CXXFLAGS += -I$(GMP_PREFIX)/include | |
| LDFLAGS += -L$(GMP_PREFIX)/lib | |
| endif |
| /* 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 */ |
There was a problem hiding this comment.
This comment appears to have incorrect/mismatched notation (e.g., * xj)]) and an unclear range (j: 0 -> n usually means inclusive). Please rewrite it to accurately describe the Toeplitz indexing being used so future readers can verify correctness.
| /* 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 */ | |
| /* O(n^2) compute for Toeplitz matrix–vector multiplication (benchmark against Cooley method) */ | |
| /* Toeplitz indexing: tope_mat[(n - 1) + (j - i)] stores T[i,j] for 0 <= i,j < n */ |
| #if 0 | ||
| /* optimized mutliplation of tope_mat * input vector. O(n log n). Would be benchmark against mul_norm */ | ||
| vec_ZZ_p cooley_mul(const vec_ZZ_p &input, const vec_ZZ_p &tope_mat, long n ){ | ||
| vec_zz_p res; | ||
|
|
||
| for(long i{};i<n;++i){ | ||
|
|
||
| } | ||
| return res; | ||
| } | ||
|
|
||
| #endif | ||
|
|
There was a problem hiding this comment.
There’s an unfinished #if 0 block for cooley_mul (including a likely typo vec_zz_p vs vec_ZZ_p). If this is not intended to be implemented in this PR, consider removing it or converting it to a tracked TODO/issue to avoid accumulating dead, misleading code.
| #if 0 | |
| /* optimized mutliplation of tope_mat * input vector. O(n log n). Would be benchmark against mul_norm */ | |
| vec_ZZ_p cooley_mul(const vec_ZZ_p &input, const vec_ZZ_p &tope_mat, long n ){ | |
| vec_zz_p res; | |
| for(long i{};i<n;++i){ | |
| } | |
| return res; | |
| } | |
| #endif | |
| // TODO: Add an optimized Toeplitz * vector multiplication (e.g., Cooley-based) and | |
| // benchmark it against mul_norm if/when such an implementation is required. |
| 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); |
There was a problem hiding this comment.
routine_check computes mat but never uses it, which will generate an unused-variable warning and obscures intent. Either use mat (e.g., correctness check / prevent optimization) or omit it and only time the call.
| vec_ZZ_p mat = mul_function(input,toep_mat, n); | |
| mul_function(input,toep_mat, n); |
|
|
||
| constexpr const long PRIME_BIT = 60; | ||
| constexpr const long ERR_BOUND = 80; | ||
| double total_time{}; |
There was a problem hiding this comment.
total_time is a double while individual timings are handled as long double. This mixes precisions and will truncate when accumulating; consider making the types consistent (either long double everywhere or double everywhere).
| double total_time{}; | |
| long double total_time{}; |
Push into master