File tree Expand file tree Collapse file tree 6 files changed +378
-318
lines changed Expand file tree Collapse file tree 6 files changed +378
-318
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ include_directories(${SYMENGINE_INCLUDE_DIRS})
13
13
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR} /cmake/" )
14
14
find_package (Python REQUIRED )
15
15
find_package (Cython REQUIRED )
16
-
17
16
include_directories (${PYTHON_INCLUDE_PATH} )
18
17
19
18
if (MINGW AND ("${CMAKE_SIZEOF_VOID_P} " STREQUAL "8" ))
@@ -59,6 +58,14 @@ else()
59
58
set (HAVE_SYMENGINE_LLVM False )
60
59
endif ()
61
60
61
+ if (WITH_NUMPY )
62
+ find_package (NumPy REQUIRED )
63
+ include_directories (${NUMPY_INCLUDE_PATH} )
64
+ set (HAVE_NUMPY True )
65
+ else ()
66
+ set (HAVE_NUMPY False )
67
+ endif ()
68
+
62
69
63
70
message ("CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE} " )
64
71
message ("CMAKE_CXX_FLAGS_RELEASE : ${CMAKE_CXX_FLAGS_RELEASE} " )
@@ -68,6 +75,7 @@ message("HAVE_SYMENGINE_MPC : ${HAVE_SYMENGINE_MPC}")
68
75
message ("HAVE_SYMENGINE_PIRANHA : ${HAVE_SYMENGINE_PIRANHA} " )
69
76
message ("HAVE_SYMENGINE_FLINT : ${HAVE_SYMENGINE_FLINT} " )
70
77
message ("HAVE_SYMENGINE_LLVM : ${HAVE_SYMENGINE_LLVM} " )
78
+ message ("HAVE_NUMPY : ${HAVE_NUMPY} " )
71
79
72
80
message ("Copying source of python wrappers into: ${CMAKE_CURRENT_BINARY_DIR} " )
73
81
file (COPY symengine/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR} /symengine )
Original file line number Diff line number Diff line change @@ -43,7 +43,10 @@ Additional options to setup.py are
43
43
--define="var1=value1;var2=value2" # Give options to CMake
44
44
--inplace # Build the extension in source tree
45
45
46
- Standard options to setup.py like ` --user ` , ` --prefix ` can be used to configure install location
46
+ Standard options to setup.py like ` --user ` , ` --prefix ` can be used to
47
+ configure install location. NumPy is used if found by default, if you wish
48
+ to make your choice of NumPy use explicit: then add
49
+ e.g. `` WITH_NUMPY=False `` to `` --define `` .
47
50
48
51
Use SymEngine from Python as follows:
49
52
Original file line number Diff line number Diff line change
1
+ execute_process (
2
+ COMMAND ${PYTHON_BIN} -c "import numpy; print(numpy.get_include())"
3
+ RESULT_VARIABLE NUMPY_FIND_RESULT
4
+ OUTPUT_VARIABLE NUMPY_FIND_OUTPUT
5
+ ERROR_VARIABLE NUMPY_FIND_ERROR
6
+ OUTPUT_STRIP_TRAILING_WHITESPACE
7
+ )
8
+ if (NOT NUMPY_FIND_RESULT MATCHES 0 )
9
+ set (NUMPY_FOUND FALSE )
10
+ message (STATUS "NumPy import failure:\n ${NUMPY_FIND_ERROR} " )
11
+ else ()
12
+ find_path (NUMPY_INCLUDE_DIR numpy/arrayobject.h
13
+ HINTS "${__numpy_path} " "${NUMPY_FIND_OUTPUT} " NO_DEFAULT_PATH )
14
+ if (NUMPY_INCLUDE_DIR )
15
+ set (NUMPY_FOUND TRUE CACHE BOOL INTERNAL "NumPy found" )
16
+ INCLUDE (FindPackageHandleStandardArgs )
17
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS (NUMPY DEFAULT_MSG NUMPY_INCLUDE_PATH )
18
+ endif ()
19
+ endif ()
Original file line number Diff line number Diff line change @@ -162,6 +162,14 @@ def finalize_options(self):
162
162
# Multiple symbols can be separated with semi-colons.
163
163
if self .define :
164
164
defines = self .define .split (';' )
165
+ if not any (define .startswith ('WITH_NUMPY' ) for define in defines ):
166
+ try :
167
+ import numpy as np
168
+ except ImportError :
169
+ defines .append ('WITH_NUMPY=False' )
170
+ else :
171
+ defines .append ('WITH_NUMPY=True' )
172
+ defines .append ()
165
173
self .define = [(s .strip (), None ) if '=' not in s else
166
174
tuple (ss .strip () for ss in s .split ('=' ))
167
175
for s in defines ]
Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ DEF HAVE_SYMENGINE_MPC = ${HAVE_SYMENGINE_MPC}
3
3
DEF HAVE_SYMENGINE_PIRANHA = ${HAVE_SYMENGINE_PIRANHA}
4
4
DEF HAVE_SYMENGINE_FLINT = ${HAVE_SYMENGINE_FLINT}
5
5
DEF HAVE_SYMENGINE_LLVM = ${HAVE_SYMENGINE_LLVM}
6
+ DEF HAVE_NUMPY = ${HAVE_NUMPY}
You can’t perform that action at this time.
0 commit comments