Skip to content

Dev#3

Merged
Ko496-glitch merged 13 commits intomasterfrom
dev
Mar 14, 2026
Merged

Dev#3
Ko496-glitch merged 13 commits intomasterfrom
dev

Conversation

@Ko496-glitch
Copy link
Copy Markdown
Owner

Push into master

Copilot AI review requested due to automatic review settings February 19, 2026 15:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread phase1.cpp
Comment thread phase1.cpp
Comment thread phase1.cpp
Comment thread phase1.cpp
Comment thread phase1.cpp
Comment thread phase1.cpp
Comment thread phase1.cpp
Comment thread phase1.cpp
Comment thread phase1.cpp
@Ko496-glitch
Copy link
Copy Markdown
Owner Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 19, 2026

@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.
Copilot AI review requested due to automatic review settings March 8, 2026 23:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread phase1.cpp
#include<iostream>
#include<sstream>
#include<iomanip>
#include<string>
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
#include<string>
#include<string>
#include<vector>
#include<utility>
#include<ctime>

Copilot uses AI. Check for mistakes.
Comment thread phase1.cpp
ZZ p;
GenPrime(p ,PRIME_BIT ,ERR_BOUND);
ZZ_p::init(p);
long t = 8;
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

long t = 8; is unused. Please remove it (or use it) to avoid warnings and keep main() focused.

Suggested change
long t = 8;

Copilot uses AI. Check for mistakes.
Comment thread phase1.cpp
Comment on lines +116 to +127
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);

Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread Makefile
Comment on lines +2 to +6
# 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

Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
# 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

Copilot uses AI. Check for mistakes.
Comment thread phase1.cpp
Comment on lines +19 to +20
/* 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 */
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
/* 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 matrixvector multiplication (benchmark against Cooley method) */
/* Toeplitz indexing: tope_mat[(n - 1) + (j - i)] stores T[i,j] for 0 <= i,j < n */

Copilot uses AI. Check for mistakes.
Comment thread phase1.cpp
Comment on lines +39 to +51
#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

Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
#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.

Copilot uses AI. Check for mistakes.
Comment thread phase1.cpp
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);
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
vec_ZZ_p mat = mul_function(input,toep_mat, n);
mul_function(input,toep_mat, n);

Copilot uses AI. Check for mistakes.
Comment thread phase1.cpp

constexpr const long PRIME_BIT = 60;
constexpr const long ERR_BOUND = 80;
double total_time{};
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
double total_time{};
long double total_time{};

Copilot uses AI. Check for mistakes.
@Ko496-glitch Ko496-glitch merged commit 591daf2 into master Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants