🌐 AI搜索 & 代理 主页
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
370daf3
remove begin repeat and use macros
scratchmex Dec 3, 2025
df1167e
Merge remote-tracking branch 'upstream/main' into gh-29528--scalartypes
scratchmex Dec 3, 2025
dba6e5a
use macros for bit count and unary defs
scratchmex Dec 3, 2025
9e7ec22
migrate scalartypes.c.src to C++ (for now scalartypes.cpp.src)
scratchmex Dec 3, 2025
d3efc87
solve all writable-strings warnings
scratchmex Dec 3, 2025
69fa910
learning struct factories at top level and compile time. introduce `m…
scratchmex Dec 3, 2025
b09125a
remove all designated initializers to make MSVC happy
scratchmex Dec 4, 2025
3ed09f5
missing extern "C" for MSVC
scratchmex Dec 4, 2025
86096b3
convert all pymethoddefs and its methods to c++ templates (when possi…
scratchmex Dec 4, 2025
3c1499b
refactor buffer protocol to use c++ templates
scratchmex Dec 4, 2025
d0eafef
remove constexpr to make MSVC happy (again)
scratchmex Dec 5, 2025
99a6b4d
Merge remote-tracking branch 'upstream/main'
scratchmex Dec 5, 2025
5a3a5a7
refactor str and repr impls to use c++ templates
scratchmex Dec 5, 2025
78201cb
fix py funcs signature to have all make factories constexpr
scratchmex Dec 5, 2025
2f158c3
expand all templating from initialize_numeric_types to explicit defs
scratchmex Dec 5, 2025
09264f0
simplify (a lot) tp_as_number definitions
scratchmex Dec 6, 2025
86f7ba9
expand some generic method definitions
scratchmex Dec 6, 2025
cf47013
refactor dunder index and hash to use c++ templates
scratchmex Dec 6, 2025
7ea0cfb
expand scalar kinds table
scratchmex Dec 6, 2025
0e0d841
refactor scalarobj definitions with struct factory and c++ templates
scratchmex Dec 6, 2025
3af9ac3
refactor dunder new impls to use c++ templates
scratchmex Dec 6, 2025
029e65c
rename scalartypes.cpp.src to scalartypes.cpp (pure c++ YEAH)
scratchmex Dec 6, 2025
c233cb5
fix GCC conflicts
scratchmex Dec 6, 2025
d3d85c9
use a workaround for old compilers that have ill-formed static_assert
scratchmex Dec 6, 2025
140a199
run clang-format (not all changes)
scratchmex Dec 7, 2025
b13e002
missing constexpr
scratchmex Dec 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def setup(app):

def _get_c_source_file(obj):
if issubclass(obj, numpy.generic):
return r"_core/src/multiarray/scalartypes.c.src"
return r"_core/src/multiarray/scalartypes.cpp"
elif obj is numpy.ndarray:
return r"_core/src/multiarray/arrayobject.c"
else:
Expand Down
6 changes: 3 additions & 3 deletions numpy/_core/arrayprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# and by Travis Oliphant 2005-8-22 for numpy


# Note: Both scalartypes.c.src and arrayprint.py implement strs for numpy
# scalars but for different purposes. scalartypes.c.src has str/reprs for when
# Note: Both scalartypes.cpp and arrayprint.py implement strs for numpy
# scalars but for different purposes. scalartypes.cpp has str/reprs for when
# the scalar is printed on its own, while arrayprint.py has strs for when
# scalars are printed inside an ndarray. Only the latter strs are currently
# user-customizable.
Expand Down Expand Up @@ -1485,7 +1485,7 @@ def __call__(self, x):
def _void_scalar_to_string(x, is_repr=True):
"""
Implements the repr for structured-void scalars. It is called from the
scalartypes.c.src code, and is placed here because it uses the elementwise
scalartypes.cpp code, and is placed here because it uses the elementwise
formatters defined above.
"""
options = format_options.get().copy()
Expand Down
2 changes: 1 addition & 1 deletion numpy/_core/code_generators/genapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_processor():
join('multiarray', 'nditer_templ.c.src'),
join('multiarray', 'number.c'),
join('multiarray', 'refcount.c'),
join('multiarray', 'scalartypes.c.src'),
join('multiarray', 'scalartypes.cpp'),
join('multiarray', 'scalarapi.c'),
join('multiarray', 'sequence.c'),
join('multiarray', 'shape.c'),
Expand Down
2 changes: 1 addition & 1 deletion numpy/_core/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ src_multiarray = multiarray_gen_headers + [
'src/multiarray/npy_static_data.c',
'src/multiarray/number.c',
'src/multiarray/refcount.c',
src_file.process('src/multiarray/scalartypes.c.src'),
'src/multiarray/scalartypes.cpp',
'src/multiarray/sequence.c',
'src/multiarray/scalarapi.c',
'src/multiarray/shape.c',
Expand Down
9 changes: 9 additions & 0 deletions numpy/_core/src/common/npy_longdouble.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#ifndef NUMPY_CORE_SRC_COMMON_NPY_LONGDOUBLE_H_
#define NUMPY_CORE_SRC_COMMON_NPY_LONGDOUBLE_H_


#include "npy_config.h"
#include "numpy/ndarraytypes.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Convert a npy_longdouble to a python `long` integer.
*
* Results are rounded towards zero.
Expand All @@ -24,4 +29,8 @@ npy_longdouble_to_PyLong(npy_longdouble ldval);
NPY_VISIBILITY_HIDDEN npy_longdouble
npy_longdouble_from_PyLong(PyObject *long_obj);

#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_COMMON_NPY_LONGDOUBLE_H_ */
8 changes: 8 additions & 0 deletions numpy/_core/src/multiarray/_datetime.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef NUMPY_CORE_SRC_MULTIARRAY__DATETIME_H_
#define NUMPY_CORE_SRC_MULTIARRAY__DATETIME_H_

#ifdef __cplusplus
extern "C" {
#endif

extern NPY_NO_EXPORT char const *_datetime_strings[NPY_DATETIME_NUMUNITS];
extern NPY_NO_EXPORT int _days_per_month_table[2][12];

Expand Down Expand Up @@ -335,4 +339,8 @@ datetime_hash(PyArray_DatetimeMetaData *meta, npy_datetime dt);
NPY_NO_EXPORT npy_hash_t
timedelta_hash(PyArray_DatetimeMetaData *meta, npy_timedelta td);

#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_MULTIARRAY__DATETIME_H_ */
7 changes: 7 additions & 0 deletions numpy/_core/src/multiarray/array_api_standard.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef NUMPY_CORE_SRC_MULTIARRAY_ARRAY_API_STANDARD_H_
#define NUMPY_CORE_SRC_MULTIARRAY_ARRAY_API_STANDARD_H_

#ifdef __cplusplus
extern "C" {
#endif

NPY_NO_EXPORT PyObject *
array_device(PyObject *NPY_UNUSED(self), void *NPY_UNUSED(ignored));
Expand All @@ -11,4 +14,8 @@ array_to_device(PyObject *self, PyObject *args, PyObject *kwds);
NPY_NO_EXPORT PyObject *
array_array_namespace(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds);

#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_MULTIARRAY_ARRAY_API_STANDARD_H_ */
8 changes: 8 additions & 0 deletions numpy/_core/src/multiarray/conversion_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include "numpy/ndarraytypes.h"

#ifdef __cplusplus
extern "C" {
#endif

NPY_NO_EXPORT int
PyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq);

Expand Down Expand Up @@ -122,4 +126,8 @@ extern NPY_NO_EXPORT NPY_TLS int evil_global_disable_warn_O4O8_flag;
NPY_NO_EXPORT int
_not_NoValue(PyObject *obj, PyObject **out);

#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_MULTIARRAY_CONVERSION_UTILS_H_ */
8 changes: 8 additions & 0 deletions numpy/_core/src/multiarray/ctors.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef NUMPY_CORE_SRC_MULTIARRAY_CTORS_H_
#define NUMPY_CORE_SRC_MULTIARRAY_CTORS_H_

#ifdef __cplusplus
extern "C" {
#endif

extern NPY_NO_EXPORT const char *npy_no_copy_err_msg;


Expand Down Expand Up @@ -135,4 +139,8 @@ NPY_NO_EXPORT PyObject *
PyArray_Empty_int(int nd, npy_intp const *dims, PyArray_Descr *descr,
PyArray_DTypeMeta *dtype, int is_f_order);

#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_MULTIARRAY_CTORS_H_ */
8 changes: 8 additions & 0 deletions numpy/_core/src/multiarray/dragon4.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@

#include "numpy/arrayscalars.h"

#ifdef __cplusplus
extern "C" {
#endif

/* Half binary format */
#define NPY_HALF_BINFMT_NAME IEEE_binary16

Expand Down Expand Up @@ -135,4 +139,8 @@ Dragon4_Scientific(PyObject *obj, DigitMode digit_mode, int precision,
int min_digits, int sign, TrimMode trim, int pad_left,
int exp_digits);

#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_MULTIARRAY_DRAGON4_H_ */
8 changes: 8 additions & 0 deletions numpy/_core/src/multiarray/flagsobject.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef NUMPY_CORE_SRC_FLAGSOBJECT_H_
#define NUMPY_CORE_SRC_FLAGSOBJECT_H_

#ifdef __cplusplus
extern "C" {
#endif


/* Array Flags Object */
typedef struct PyArrayFlagsObject {
Expand All @@ -19,4 +23,8 @@ NPY_NO_EXPORT void
PyArray_UpdateFlags(PyArrayObject *ret, int flagmask);


#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_FLAGSOBJECT_H_ */
8 changes: 8 additions & 0 deletions numpy/_core/src/multiarray/mapping.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef NUMPY_CORE_SRC_MULTIARRAY_MAPPING_H_
#define NUMPY_CORE_SRC_MULTIARRAY_MAPPING_H_

#ifdef __cplusplus
extern "C" {
#endif

extern NPY_NO_EXPORT PyMappingMethods array_as_mapping;

/* Indexing types */
Expand Down Expand Up @@ -184,4 +188,8 @@ NPY_NO_EXPORT PyObject *
PyArray_MapIterArrayCopyIfOverlap(PyArrayObject * a, PyObject * index,
int copy_if_overlap, PyArrayObject *extra_op);

#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_MULTIARRAY_MAPPING_H_ */
8 changes: 8 additions & 0 deletions numpy/_core/src/multiarray/multiarraymodule.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_
#define NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_

#ifdef __cplusplus
extern "C" {
#endif

/*
* A struct storing thread-unsafe global state for the _multiarray_umath
* module. We should refactor so the global state is thread-safe,
Expand Down Expand Up @@ -85,4 +89,8 @@ NPY_VISIBILITY_HIDDEN extern npy_thread_unsafe_state_struct npy_thread_unsafe_st
NPY_NO_EXPORT int
get_legacy_print_mode(void);

#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_MULTIARRAY_MULTIARRAYMODULE_H_ */
8 changes: 8 additions & 0 deletions numpy/_core/src/multiarray/npy_buffer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef NUMPY_CORE_SRC_MULTIARRAY_NPY_BUFFER_H_
#define NUMPY_CORE_SRC_MULTIARRAY_NPY_BUFFER_H_

#ifdef __cplusplus
extern "C" {
#endif

extern NPY_NO_EXPORT PyBufferProcs array_as_buffer;

NPY_NO_EXPORT int
Expand All @@ -12,4 +16,8 @@ _descriptor_from_pep3118_format(char const *s);
NPY_NO_EXPORT int
void_getbuffer(PyObject *obj, Py_buffer *view, int flags);

#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_MULTIARRAY_NPY_BUFFER_H_ */
8 changes: 8 additions & 0 deletions numpy/_core/src/multiarray/number.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef NUMPY_CORE_SRC_MULTIARRAY_NUMBER_H_
#define NUMPY_CORE_SRC_MULTIARRAY_NUMBER_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
PyObject *add;
PyObject *subtract;
Expand Down Expand Up @@ -66,4 +70,8 @@ NPY_NO_EXPORT PyObject *
PyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,
int rtype, PyArrayObject *out);

#ifdef __cplusplus
}
#endif

#endif /* NUMPY_CORE_SRC_MULTIARRAY_NUMBER_H_ */
Loading
Loading