Skip to content

Add CSR matrix builder with deduplication and optimize assembly with binary search - #6

Merged
deltaeecs merged 5 commits into
masterfrom
copilot/add-csr-matrix-deduplication
Dec 8, 2025
Merged

Add CSR matrix builder with deduplication and optimize assembly with binary search#6
deltaeecs merged 5 commits into
masterfrom
copilot/add-csr-matrix-deduplication

Conversation

Copilot AI commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

Adds support for building CSR matrices from COO triplets with automatic deduplication, and optimizes the Assemble function from O(n) to O(log n) per lookup.

Changes

New cCSRMatrixBuilder class (include/CSRMatrixBuilder.h)

  • Builds CSR matrices from triplets with configurable duplicate handling (accumulate or overwrite)
  • Handles unsorted input, sparse patterns, out-of-range entries
  • Uses robust hash combining (boost-style) to minimize collisions

Performance optimization (include/CSRComm.h)

  • Replaced linear search with binary search in CSRComm::Assemble
  • Significant speedup for rows with many columns (O(log n) vs O(n))

Utility functions

  • BuildCSRFromTriplets(): convenience wrapper for one-step construction
  • ValidateCSRMatrix(): checks row pointer consistency, column sorting, bounds

Example Usage

// Build from unsorted triplets with automatic deduplication
cCSRMatrixBuilder<double> builder;
builder.AddEntry(0, 0, 1.0);
builder.AddEntry(0, 0, 2.0);  // Duplicate - will accumulate
builder.AddEntry(1, 1, 3.0);

auto matrix = builder.Build(0, 2, 2);
// Result: (0,0) = 3.0, (1,1) = 3.0

// Or use convenience function
std::vector<cTriplet<double>> triplets = {...};
auto matrix = BuildCSRFromTriplets(triplets, 0, rows, cols);

Testing

Added 31 test cases covering:

  • Duplicate accumulation (same element multiple times)
  • Edge cases: empty matrices, single elements, all duplicates
  • Binary search correctness: first/middle/last column, large rows (1000+ columns)
  • Row range subsets, unsorted input, validation edge cases

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

新增功能:CSR 矩阵构建过程中,同一进程内提供了重复元素时,要支持自动去重,新增对应的测试用例,并调试通过。此外,考虑更多类似的边缘场景处理,增加相应的测试用例。然后完成 TODO 中的性能优化,并保证测试通过。如果你有更多想添加的合理功能点,也请新增并验证通过。


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Dec 8, 2025
Copilot AI and others added 4 commits December 8, 2025 02:14
…ary search

Co-authored-by: deltaeecs <48714525+deltaeecs@users.noreply.github.com>
… utilities

Co-authored-by: deltaeecs <48714525+deltaeecs@users.noreply.github.com>
…alization

Co-authored-by: deltaeecs <48714525+deltaeecs@users.noreply.github.com>
Copilot AI changed the title [WIP] Add automatic deduplication for CSR matrix construction Add CSR matrix builder with deduplication and optimize assembly with binary search Dec 8, 2025
Copilot AI requested a review from deltaeecs December 8, 2025 02:28
@deltaeecs
deltaeecs marked this pull request as ready for review December 8, 2025 02:29
@deltaeecs
deltaeecs merged commit abddd2b into master Dec 8, 2025
1 check passed
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.

2 participants