8000 Merge pull request #19713 from serge-sans-paille/feature/to-cxx-and-b… · numpy/numpy@53d2a83 · GitHub
[go: up one dir, main page]

Skip to content

Commit 53d2a83

Browse files
authored
Merge pull request #19713 from serge-sans-paille/feature/to-cxx-and-beyond
[demo] how-to replacing numpy custom generation engine by raw C++
2 parents d865300 + 2ae7aeb commit 53d2a83

18 files changed

+580
-435
lines changed

.github/workflows/cygwin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
python38-cython python38-pip python38-wheel python38-cffi
2525
python38-pytz python38-setuptools python38-pytest
2626
python38-hypothesis liblapack-devel libopenblas
27-
gcc-fortran git dash
27+
gcc-fortran gcc-g++ git dash
2828
- name: Set Windows PATH
2929
uses: egor-tensin/cleanup-path@v1
3030
with:

numpy/core/setup.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ def get_mathlib_info(*args):
909909
join('src', 'npysort', 'mergesort.c.src'),
910910
join('src', 'npysort', 'timsort.c.src'),
911911
join('src', 'npysort', 'heapsort.c.src'),
912-
join('src', 'npysort', 'radixsort.c.src'),
912+
join('src', 'npysort', 'radixsort.cpp'),
913913
join('src', 'common', 'npy_partition.h.src'),
914914
join('src', 'npysort', 'selection.c.src'),
915915
join('src', 'common', 'npy_binsearch.h.src'),
@@ -948,8 +948,8 @@ def generate_umath_c(ext, build_dir):
948948
join('src', 'umath', 'loops_exponent_log.dispatch.c.src'),
949949
join('src', 'umath', 'matmul.h.src'),
950950
join('src', 'umath', 'matmul.c.src'),
951-
join('src', 'umath', 'clip.h.src'),
952-
join('src', 'umath', 'clip.c.src'),
951+
join('src', 'umath', 'clip.h'),
952+
join('src', 'umath', 'clip.cpp'),
953953
join('src', 'umath', 'dispatching.c'),
954954
join('src', 'umath', 'legacy_array_method.c'),
955955
join('src', 'umath', 'ufunc_object.c'),
@@ -979,6 +979,9 @@ def generate_umath_c(ext, build_dir):
979979
svml_objs = glob.glob(svml_path + '/**/*.s', recursive=True)
980980

981981
config.add_extension('_multiarray_umath',
982+
# Forcing C language even though we have C++ sources.
983+
# It forces the C linker and don't link C++ runtime.
984+
language = 'c',
982985
sources=multiarray_src + umath_src +
983986
common_src +
984987
[generate_config_h,
@@ -993,7 +996,11 @@ def generate_umath_c(ext, build_dir):
993996
common_deps,
994997
libraries=['npymath'],
995998
extra_objects=svml_objs,
996-
extra_info=extra_info)
999+
extra_info=extra_info,
1000+
extra_cxx_compile_args=['-std=c++11',
1001+
'-D__STDC_VERSION__=0',
1002+
'-fno-exceptions',
1003+
'-fno-rtti'])
9971004

9981005
#######################################################################
9991006
# umath_tests module #

numpy/core/src/common/npy_sort.h.src

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ NPY_NO_EXPORT int atimsort_@suff@(void *vec, npy_intp *ind, npy_intp cnt, void *
4949
* #suff = bool, byte, ubyte, short, ushort, int, uint, long, ulong,
5050
* longlong, ulonglong#
5151
*/
52-
52+
#ifdef __cplusplus
53+
extern "C" {
54+
#endif
5355
NPY_NO_EXPORT int radixsort_@suff@(void *vec, npy_intp cnt, void *null);
5456
NPY_NO_EXPORT int aradixsort_@suff@(void *vec, npy_intp *ind, npy_intp cnt, void *null);
57+
#ifdef __cplusplus
58+
}
59+
#endif
5560

5661
/**end repeat**/
5762

numpy/core/src/common/numpy_tag.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef _NPY_COMMON_TAG_H_
2+
#define _NPY_COMMON_TAG_H_
3+
4+
namespace npy {
5+
6+
struct integral_tag {};
7+
struct floating_point_tag {};
8+
struct complex_tag {};
9+
struct date_tag {};
10+
11+
struct bool_tag : integral_tag { using type = npy_bool; };
12+
struct byte_tag : integral_tag {using type = npy_byte; } ;
13+
struct ubyte_tag : integral_tag {using type = npy_ubyte; } ;
14+
struct short_tag : integral_tag {using type = npy_short; } ;
15+
struct ushort_tag : integral_tag {using type = npy_ushort; } ;
16+
struct int_tag : integral_tag {using type = npy_int; } ;
17+
struct uint_tag : integral_tag {using type = npy_uint; } ;
18+
struct long_tag : integral_tag {using type = npy_long ; } ;
19+
struct ulong_tag : integral_tag {using type = npy_ulong ; } ;
20+
struct longlong_tag : integral_tag {using type = npy_longlong ; } ;
21+
struct ulonglong_tag : integral_tag {using type = npy_ulonglong ; } ;
22+
struct half_tag {using type = npy_half ; } ;
23+
struct float_tag : floating_point_tag {using type = npy_float ; } ;
24+
struct double_tag : floating_point_tag {using type = npy_double ; } ;
25+
struct longdouble_tag : floating_point_tag {using type = npy_longdouble ; } ;
26+
struct cfloat_tag : complex_tag {using type = npy_cfloat ; } ;
27+
struct cdouble_tag : complex_tag {using type = npy_cdouble ; } ;
28+
struct clongdouble_tag : complex_tag {using type = npy_clongdouble ; } ;
29+
struct datetime_tag : date_tag {using type = npy_datetime ; } ;
30+
struct timedelta_tag : date_tag {using type = npy_timedelta ; } ;
31+
32+
}
33+
34+
#endif

numpy/core/src/npymath/npy_math_private.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,29 @@ typedef union {
507507
#else /* !_MSC_VER */
508508
typedef union {
509509
npy_cdouble npy_z;
510+
#ifdef __cplusplus
511+
std::complex<double> c99z;
512+
#else
510513
complex double c99_z;
514+
#endif
511515
} __npy_cdouble_to_c99_cast;
512516

513517
typedef union {
514518
npy_cfloat npy_z;
519+
#ifdef __cplusplus
520+
std::complex<float> c99z;
521+
#else
515522
complex float c99_z;
523+
#endif
516524
} __npy_cfloat_to_c99_cast;
517525

518526
typedef union {
519527
npy_clongdouble npy_z;
528+
#ifdef __cplusplus
529+
std::complex<long double> c99_z;
530+
#else
520531
complex long double c99_z;
532+
#endif
521533
} __npy_clongdouble_to_c99_cast;
522534
#endif /* !_MSC_VER */
523535

numpy/core/src/npysort/radixsort.c.src

Lines changed: 0 additions & 231 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0