Skip to content

Refine Div CPU implementation#715

Merged
jysh1214 merged 1 commit intomasterfrom
dev/alexchiang/refine-div-cpu
Nov 30, 2025
Merged

Refine Div CPU implementation#715
jysh1214 merged 1 commit intomasterfrom
dev/alexchiang/refine-div-cpu

Conversation

@jysh1214
Copy link
Collaborator

The Cytnx arithmetic implementation contained lots duplicated code across different type combinations, which caused:

  • Difficult maintenance when updating logic
  • Low code readability due to repetitive patterns

This PR refines the Div CPU implementation, similar to #651.
Our goal is to generalize all arithmetic operations using templates, and eventually refactor the multiple-dispatch mechanism for arithmetic.

template <typename TLin, typename TRin>
void ArithmeticInternalImpl(...) {
  if (type == 0)
    cytnx::linalg_internal::AddInternalImpl<TLin, TRin>(
      out, Lin, Rin, len, shape, invmapper_L, invmapper_R);
  else if (type == 1)
    cytnx::linalg_internal::MulInternalImpl<TLin, TRin>(
      out, Lin, Rin, len, shape, invmapper_L, invmapper_R);
  else if (type == 2)
    // ...
  else
    // ...
}

Next, we plan to replace the linalg_internal::lii.Ari_ii usage in arithmetic .cpp files with the std::variant + std::visit pattern, similar to what we did in commit 710c98c.

This is the last PR for Arithmetic OPs.

@jysh1214 jysh1214 requested a review from IvanaGyro November 25, 2025 17:38
@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

❌ Patch coverage is 12.18487% with 209 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.97%. Comparing base (be1cfcf) to head (282f955).
⚠️ Report is 78 commits behind head on master.

Files with missing lines Patch % Lines
...ackend/linalg_internal_cpu/Arithmetic_internal.cpp 11.00% 186 Missing ⚠️
src/backend/linalg_internal_cpu/Div_internal.hpp 20.68% 21 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #715      +/-   ##
==========================================
+ Coverage   32.07%   34.97%   +2.89%     
==========================================
  Files         215      215              
  Lines       36242    32974    -3268     
  Branches    14543    13142    -1401     
==========================================
- Hits        11626    11532      -94     
+ Misses      22692    19544    -3148     
+ Partials     1924     1898      -26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jysh1214 jysh1214 force-pushed the dev/alexchiang/refine-div-cpu branch from 8b6c42c to 282f955 Compare November 28, 2025 04:31
@jysh1214 jysh1214 merged commit c5dd9c4 into master Nov 30, 2025
7 checks passed
@jysh1214 jysh1214 deleted the dev/alexchiang/refine-div-cpu branch November 30, 2025 13:42
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