Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
steps:

- name: Check Out Repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v2
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
- id: isort
args: ["--profile", "black", "--filter-files"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.6.0
rev: v3.21.2
hooks:
- id: pyupgrade
- repo: https://github.com/PyCQA/flake8
Expand Down
4 changes: 2 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ endif
@cd main; $(MAKE) clean
@rm -fr bin lib

clean: clean-light clean-test python_clean clean-debian
clean: clean-light clean-test clean-debian
@echo " CLEAN libvtkfortran"
@cd libvtkfortran; $(MAKE) clean
@echo " CLEAN libjudy"
Expand Down Expand Up @@ -547,7 +547,7 @@ install: default fltools
cp -R schemas $(DESTDIR)$(datadir)/fluidity/
mkdir -p $(DESTDIR)$(datadir)/diamond/schemata
$(SED) 's/$${datadir}/$(subst /,\/,$(datadir))/g' schemas/flml.in > $(DESTDIR)$(datadir)/diamond/schemata/flml
cd python ; python3 setup.py install --root=$(shell echo ${DESTDIR} | sed 's/^$$/\//') --prefix="$(prefix)" $$FLUIDITY_PYTHON_INSTALL_ARGS
cd python ; python3 -m pip install --root=$(shell echo ${DESTDIR} | sed 's/^$$/\//') --prefix="$(prefix)" $$FLUIDITY_PYTHON_INSTALL_ARGS .
cp -R examples $(DESTDIR)$(docdir)/fluidity
find $(DESTDIR)$(docdir)/fluidity/examples -type f -exec $(SED) -i "s/\.\.\/\.\.\/\.\.\/bin\///" '{}' \;
find $(DESTDIR)$(docdir)/fluidity/examples -type f -exec $(SED) -i "s/\.\.\/\.\.\/bin\///" '{}' \;
Expand Down
2 changes: 1 addition & 1 deletion climatology/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LINKER = $(CXX)
CXXFLAGS = -I../include @CXXFLAGS@ @CPPFLAGS@

LFLAGS = @LDFLAGS@
LIBS = -L../lib/ @LIBS@ @FLIBS@ @LAPACK_LIBS@
LIBS = -L../lib/ @LIBS@

.SUFFIXES: .cpp .o

Expand Down
23 changes: 21 additions & 2 deletions femtools/embed_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ USA
#ifdef HAVE_NUMPY
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "numpy/arrayobject.h"

static int ensure_numpy_api(void) {
if (PyArray_API != NULL) {
return 0;
}
Comment on lines +48 to +50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment what this does? Is it checking whether numpy has been "imported" already?

#if NPY_ABI_VERSION < 0x02000000
return _import_array();
#else
return PyArray_ImportNumPyAPI();
#endif
}
#endif

void deallocate_c_array(void *ptr) {
Expand Down Expand Up @@ -448,7 +459,11 @@ void set_tensor_field_from_python(char *function, int function_len, int dim,
*stat = 1;
return;
#else
import_array();
if (ensure_numpy_api() < 0) {
PyErr_Print();
*stat = 1;
return;
}

set_field_from_python(function, function_len, dim, nodes, NULL, x, y, z, t, NULL, stat,
result_dim, (void**)&result, set_tensor_result_double, NULL);
Expand Down Expand Up @@ -637,7 +652,11 @@ void set_field_from_python_fields(char *function, int function_len, int dim, int
#else
PyObject *pLocals, *pFunc, *pNames, *pT, *pdT, *pPos, *pArgs, *pKwArgs, *pResult;

import_array();
if (ensure_numpy_api() < 0) {
PyErr_Print();
*stat = 1;
return;
}

// load the user's function as a Python object -- borrows locals
pLocals = PyDict_New();
Expand Down
19 changes: 18 additions & 1 deletion femtools/python_statec.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#define ALLOW_IMPORT_ARRAY
#include "python_statec.h"

#ifdef HAVE_NUMPY
static int ensure_numpy_api(void) {
if (PyArray_API != NULL) {
return 0;
}
#if NPY_ABI_VERSION < 0x02000000
return _import_array();
#else
return PyArray_ImportNumPyAPI();
#endif
}
#endif

#if PY_MAJOR_VERSION >= 3
#define PyInt_FromLong PyLong_FromLong
#define PyString_FromString PyUnicode_FromString
Expand Down Expand Up @@ -47,7 +60,11 @@ void python_init_(void){
#endif
#ifdef HAVE_NUMPY
// Enable use of NumPy arrays in C
import_array();
if (ensure_numpy_api() < 0) {
PyErr_Print();
fprintf(stderr, "Error: Initializing the NumPy C API failed.\n");
return;
}

// Import the NumPy module in our Python interpreter
if(PyRun_SimpleString("import numpy") == -1)
Expand Down
Loading