[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 1fa654cb: Library (python.h): Fixed import_arr
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 1fa654cb: Library (python.h): Fixed import_array warnings |
Date: |
Sat, 17 Sep 2022 10:05:11 -0400 (EDT) |
branch: master
commit 1fa654cbb6f3d563004bf7684438baeb207aa26d
Author: Jash Shah <jash28582@gmail.com>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Library (python.h): Fixed import_array warnings
Until now, when trying to build Gnuastro's Python Interface files
('lib/python.c') the NumPy C-API would throw "defined but not used"
warnings for the 'import_array' function.
We only need 'import_array' in order to import the NumPy C-API in Python
Extension modules. However, since the Python headers in Gnuastro only
provides utility functions for the actual Python Extension modules which
are defined in the pyGnuastro (Gnuastro Python package) source,
'import_array' can is not currently necessary when building Gnuastro.
With this commit, the 'NO_IMPORT_ARRAY' macro has been defined before
including the NumPy C-API headers. This indicates, that the 'python.c' file
has no extension modules, and thus no calls to the 'import_array' function.
Also, fixed a typo in the 'gal_fits_img_write' definition in the book.
---
doc/gnuastro.texi | 2 +-
lib/python.c | 14 ++++++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 3a45ce0e..7e1598e7 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -32250,7 +32250,7 @@ after this function or make other modifications.
@deftypefun void gal_fits_img_write (gal_data_t @code{*data}, char
@code{*filename}, gal_fits_list_key_t @code{*headers}, char
@code{*program_string})
Write the @code{input} dataset into the FITS file named @file{filename}.
-Also add the @code{headers} keywords to the newly created HDU/extension it
+Also add the @code{headers} keywords to the newly created HDU/extension
along with your program's name (@code{program_string}).
@end deftypefun
diff --git a/lib/python.c b/lib/python.c
index 3d7d74bf..d8fdfd1e 100644
--- a/lib/python.c
+++ b/lib/python.c
@@ -26,9 +26,19 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
#include <errno.h>
#include <error.h>
-/* This macro needs to be defined before including any NumPy headers
- to avoid the compiler from raising a warning message. */
+/* This macro needs to be defined before including any NumPy headers to
+ avoid the compiler from raising a warning message. */
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
+
+/* This macro needs to be defined before including any NumPy headers so
+ that the NumPY C-API can be used without having to call the
+ 'import_arra' function as mentioned here:
+ https://numpy.org/doc/1.17/reference/c-api.array.html#c.NO_IMPORT_ARRAY
+ This also helps to avoid any "defined but not used" while compiling this
+ file. */
+#define NO_IMPORT_ARRAY
+
+/* Import Numpy's necessary header(s). */
#include <numpy/arrayobject.h>
/* Gnuastro's Python headers. */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnuastro-commits] master 1fa654cb: Library (python.h): Fixed import_array warnings,
Mohammad Akhlaghi <=