Numerical computing patterns for C++20 including matrix operations, iterative solvers, numerical stability, data pipelines, and HPC I/O with MPI-IO and HDF5.
View on GitHubysyecust/everything-claude-code
everything-claude-code
skills/numerical-patterns/SKILL.md
January 25, 2026
Select agents to install to:
npx add-skill https://github.com/ysyecust/everything-claude-code/blob/main/skills/numerical-patterns/SKILL.md -a claude-code --skill numerical-patternsInstallation paths:
.claude/skills/numerical-patterns/# Numerical Computing Patterns for C++20
Domain knowledge for scientific computing, numerical methods, and HPC I/O operations.
## Matrix Operations
### Dense Matrix with BLAS Integration
```cpp
#include <span>
#include <vector>
class DenseMatrix {
public:
DenseMatrix(size_t rows, size_t cols)
: rows_(rows), cols_(cols), data_(rows * cols, 0.0) {}
double& operator()(size_t i, size_t j) { return data_[i * cols_ + j]; }
double operator()(size_t i, size_t j) const { return data_[i * cols_ + j]; }
size_t Rows() const { return rows_; }
size_t Cols() const { return cols_; }
std::span<double> Data() { return data_; }
std::span<const double> Data() const { return data_; }
// Matrix-vector product: y = A * x
void Apply(std::span<double> y, std::span<const double> x) const {
assert(x.size() == cols_ && y.size() == rows_);
for (size_t i = 0; i < rows_; ++i) {
double sum = 0.0;
for (size_t j = 0; j < cols_; ++j) {
sum += data_[i * cols_ + j] * x[j];
}
y[i] = sum;
}
}
private:
size_t rows_, cols_;
std::vector<double> data_; // Row-major
};
```
### Sparse Matrix (CSR Format)
```cpp
class SparseMatrixCSR {
public:
SparseMatrixCSR(size_t rows, size_t cols,
std::vector<double> values,
std::vector<int> col_indices,
std::vector<int> row_ptr)
: rows_(rows), cols_(cols),
values_(std::move(values)),
col_indices_(std::move(col_indices)),
row_ptr_(std::move(row_ptr)) {}
// SpMV: y = A * x
void Apply(std::span<double> y, std::span<const double> x) const {
assert(x.size() == cols_ && y.size() == rows_);
for (size_t i = 0; i < rows_; ++i) {
double sum = 0.0;
for (int k = row_ptr_[i]; k < row_ptr_[i + 1]; ++k) {
sum += values_[k] * x[col_indices_[k]];
}
y[i] = sum;
}
}
size_t Rows() const { return rows_; }
size_t Cols() const { return cols_; }
size_t Nnz() const { retu