Skip to content

Commit 73838ae

Browse files
peng.li24claude
andcommitted
fix: align C++ function naming with numpy API — rename norm_axis to norm, annotate naming exemptions
- norm_axis → norm in linalg submodule (pybind11 can overload by arity) - add NOTE comments for 4 exemption categories: astype_*, take_cols, *_like_bool wrappers, and native stddev - all 336 tests pass Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 4ec9ca2 commit 73838ae

8 files changed

Lines changed: 520 additions & 236 deletions

File tree

numpy/core.h

Lines changed: 284 additions & 101 deletions
Large diffs are not rendered by default.

numpy/einsum.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ inline std::string implicit_output_labels(const std::vector<std::string>& il) {
8383
// ============================================================================
8484
// Main einsum computation
8585
// ============================================================================
86+
87+
/// numpy.einsum(subscripts, *operands, out=None, dtype=None, order='K',
88+
/// casting='safe', optimize=False)
89+
// Currently supports 2-operand patterns only.
8690
template<typename T>
8791
void einsum(const std::string& subscripts,
8892
const T* a_ptr, const ptrdiff_t* a_shape, int a_ndim,
@@ -233,7 +237,7 @@ void einsum(const std::string& subscripts,
233237
result_ptr[current_output_idx] = accumulator;
234238
}
235239

236-
// Helper: compute output shape for a given einsum pattern
240+
/// numpy.einsum(subscripts, *operands) — compute output shape
237241
inline std::vector<ptrdiff_t> einsum_output_shape(const std::string& subscripts,
238242
const ptrdiff_t* a_shape, int a_ndim,
239243
const ptrdiff_t* b_shape, int b_ndim) {

numpy/linalg.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Native C++ linalg functions — zero pybind11 dependency.
2-
// Uses numpy::impl:: helpers from core.h for shared computation.
2+
// Uses numpy:: helpers from core.h for shared computation.
33

44
#pragma once
55

@@ -9,14 +9,16 @@
99
namespace numpy {
1010
namespace linalg {
1111

12+
/// numpy.linalg.norm(x, ord=None, axis=None, keepdims=False) — frobenius/vector
1213
template<typename T>
1314
inline T norm(const T* data, size_t n) {
1415
return std::sqrt(numpy::norm_sq(data, n));
1516
}
1617

18+
/// numpy.linalg.norm(x, ord=None, axis=N, keepdims=False) — N-D
1719
template<typename T>
18-
inline void norm_axis1(const T* src, double* dst, size_t rows, size_t cols) {
19-
numpy::norm_axis1(src, dst, rows, cols);
20+
inline void norm_axis(const T* src, double* dst, const ptrdiff_t* shape, int ndim, int axis) {
21+
numpy::norm_axis(src, dst, shape, ndim, axis);
2022
}
2123

2224
} // namespace linalg

0 commit comments

Comments
 (0)