Skip to content

Commit d82044b

Browse files
committed
msvc compatibility
1 parent 367f1f6 commit d82044b

6 files changed

Lines changed: 55 additions & 27 deletions

File tree

setup.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
sys.exit('Sorry, Python < 2.7 is not supported')
2626

2727
import os
28+
import platform
2829

2930
from setuptools import setup
3031
from setuptools.extension import Extension
@@ -39,28 +40,36 @@
3940
# Definitions
4041
#########################################################
4142

42-
extra_compile_args_math_optimized = ['-fopenmp', '-march=native', '-O2', '-msse', '-msse2', '-mfma', '-mfpmath=sse']
43-
extra_compile_args_math_debug = ['-fopenmp', '-march=native', '-O0', '-g']
43+
system = platform.system()
4444

45-
extra_compile_args_nonmath_optimized = ['-O2']
46-
extra_compile_args_nonmath_debug = ['-O0', '-g']
45+
if system == "Windows":
46+
my_extra_compile_args_math = ["/openmp"]
47+
my_extra_compile_args_nonmath = []
48+
my_extra_link_args = []
49+
debug = False
50+
else:
51+
extra_compile_args_math_optimized = ['-fopenmp', '-march=native', '-O2', '-msse', '-msse2', '-mfma', '-mfpmath=sse']
52+
extra_compile_args_math_debug = ['-fopenmp', '-march=native', '-O0', '-g']
4753

48-
extra_link_args_optimized = ['-fopenmp']
49-
extra_link_args_debug = ['-fopenmp']
54+
extra_compile_args_nonmath_optimized = ['-O2']
55+
extra_compile_args_nonmath_debug = ['-O0', '-g']
5056

57+
extra_link_args_optimized = ['-fopenmp']
58+
extra_link_args_debug = ['-fopenmp']
5159

52-
if build_type == 'optimized':
53-
my_extra_compile_args_math = extra_compile_args_math_optimized
54-
my_extra_compile_args_nonmath = extra_compile_args_nonmath_optimized
55-
my_extra_link_args = extra_link_args_optimized
56-
debug = False
57-
print( "build configuration selected: optimized" )
58-
else: # build_type == 'debug':
59-
my_extra_compile_args_math = extra_compile_args_math_debug
60-
my_extra_compile_args_nonmath = extra_compile_args_nonmath_debug
61-
my_extra_link_args = extra_link_args_debug
62-
debug = True
63-
print( "build configuration selected: debug" )
60+
61+
if build_type == 'optimized':
62+
my_extra_compile_args_math = extra_compile_args_math_optimized
63+
my_extra_compile_args_nonmath = extra_compile_args_nonmath_optimized
64+
my_extra_link_args = extra_link_args_optimized
65+
debug = False
66+
print( "build configuration selected: optimized" )
67+
else: # build_type == 'debug':
68+
my_extra_compile_args_math = extra_compile_args_math_debug
69+
my_extra_compile_args_nonmath = extra_compile_args_nonmath_debug
70+
my_extra_link_args = extra_link_args_debug
71+
debug = True
72+
print( "build configuration selected: debug" )
6473

6574

6675
#########################################################
@@ -95,12 +104,16 @@ def ext(extName):
95104
extra_compile_args=my_extra_compile_args_nonmath
96105
)
97106
def ext_math(extName):
107+
if system == "Windows":
108+
libraries = []
109+
else:
110+
libraries = ["m"] # "m" links libm, the math library on unix-likes; see http://docs.cython.org/src/tutorial/external.html
98111
extPath = extName.replace(".", os.path.sep)+".pyx"
99112
return Extension( extName,
100113
[extPath],
101114
extra_compile_args=my_extra_compile_args_math,
102115
extra_link_args=my_extra_link_args,
103-
libraries=["m"] # "m" links libm, the math library on unix-likes; see http://docs.cython.org/src/tutorial/external.html
116+
libraries=libraries
104117
)
105118

106119
# http://stackoverflow.com/questions/13628979/setuptools-how-to-make-package-contain-extra-data-folder-and-all-folders-inside

wlsqm/fitter/expert.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ host : in, ExpertSolver instance to use as host for guest mode. (Def
223223

224224
# Create the Cases, adding them to the manager.
225225
#
226-
cdef double nan = 0./0. # FIXME: IEEE-754 abuse
226+
cdef double zero = 0
227+
cdef double nan = zero/zero # FIXME: IEEE-754 abuse
227228
cdef double xi=nan, yi=nan, zi=nan # pass invalid coordinates for now, we'll fill them in later
228229

229230
if host is None: # usual mode of operation (create geometry data locally)
@@ -849,7 +850,9 @@ cdef void expert_interpolate_nearest( int dimension, xi_tree, infra.CaseManager*
849850
#
850851
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.cKDTree.query.html#scipy.spatial.cKDTree.query
851852
# "Missing neighbors are indicated with self.n."
852-
cdef double nan = 0./0. # FIXME: IEEE-754 abuse
853+
854+
cdef double zero = 0
855+
cdef double nan = zero/zero # FIXME: IEEE-754 abuse
853856
if (np.asanyarray(I) == manager.ncases).any():
854857
for j in range(nx):
855858
out[j] = nan

wlsqm/fitter/impl.pyx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,8 @@ cdef void preprocess_A( infra.Case* case, int debug ) nogil:
733733
#
734734
cdef void solve( infra.Case* case, double[::view.generic] fk, double[::view.generic,::view.contiguous] sens, int do_sens, int taskid ) nogil:
735735

736-
cdef double nan = 0./0. # FIXME: a better way to get NaN than to abuse IEEE-754 specification?
736+
cdef double zero = 0
737+
cdef double nan = zero/zero # FIXME: a better way to get NaN than to abuse IEEE-754 specification?
737738

738739
cdef int no = case.no
739740
cdef int nr = case.nr
@@ -862,7 +863,8 @@ cdef void solve( infra.Case* case, double[::view.generic] fk, double[::view.gene
862863
#
863864
cdef void solve_contig( infra.Case* case, double* fk, double* fi, double[::view.generic,::view.contiguous] sens, int do_sens, int taskid ) nogil:
864865

865-
cdef double nan = 0./0. # FIXME: a better way to get NaN than to abuse IEEE-754 specification?
866+
cdef double zero = 0
867+
cdef double nan = zero/zero # FIXME: a better way to get NaN than to abuse IEEE-754 specification?
866868

867869
cdef int no = case.no
868870
cdef int nr = case.nr

wlsqm/fitter/infra.pyx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ cimport wlsqm.fitter.defs as defs # C constants
4646
# http://stackoverflow.com/questions/109023/how-to-count-the-number-of-set-bits-in-a-32-bit-integer (algorithms, suggestions)
4747
# https://gist.github.com/craffel/e470421958cad33df550 (Cython defs; on popcounting a NumPy array)
4848
#
49-
cdef extern int __builtin_popcount(unsigned int) nogil
50-
cdef extern int __builtin_popcountll(unsigned long long) nogil
49+
cdef extern from "popcount.h":
50+
int __builtin_popcount(unsigned int) nogil
51+
int __builtin_popcountll(unsigned long long) nogil
5152

5253
#####################################
5354
# Helper functions
@@ -541,7 +542,8 @@ cdef Case* Case_new( int dimension, int order, double xi, double yi, double zi,
541542
raise MemoryError("Out of memory trying to allocate a Case object")
542543

543544
# tag unused components as NaN
544-
cdef double nan = 0./0. # NaN as per IEEE-754
545+
cdef double zero = 0
546+
cdef double nan = zero/zero # NaN as per IEEE-754
545547
self.xi = xi
546548
self.yi = yi if dimension >= 2 else nan
547549
self.zi = zi if dimension == 3 else nan

wlsqm/fitter/interp.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ Return value : rank-1 array, function value at each x.
104104

105105
cdef double[::1] out = np.empty( (nx,), dtype=np.float64 )
106106

107-
cdef double nan = 0./0.
107+
cdef double zero = 0
108+
cdef double nan = zero/zero
108109
cdef double x0, y0, z0
109110
if dimension >= 2:
110111
x0 = xi[0]

wlsqm/fitter/popcount.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
#ifdef _MSC_VER
4+
#include <intrin.h>
5+
#define __builtin_popcount __popcnt
6+
#define __builtin_popcountll __popcnt64
7+
#endif

0 commit comments

Comments
 (0)