|
|
b2f9e6 |
From d945dfa4063c5cd7169acd117c15f23ba68027ed Mon Sep 17 00:00:00 2001
|
|
|
b2f9e6 |
From: Pauli Virtanen <pav@iki.fi>
|
|
|
b2f9e6 |
Date: Wed, 31 Jul 2019 23:31:22 +0300
|
|
|
b2f9e6 |
Subject: [PATCH 1/2] BUG: spatial: use c++11 construct for getting start of
|
|
|
b2f9e6 |
vector
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
gcc 9.1.1 on Fedora throws asserts and crashes at runtime on
|
|
|
b2f9e6 |
`&x.front()` when `x` is empty, so use a different construct for getting
|
|
|
b2f9e6 |
the beginning of the data block.
|
|
|
b2f9e6 |
---
|
|
|
b2f9e6 |
scipy/spatial/ckdtree.pyx | 18 +++++++++---------
|
|
|
b2f9e6 |
1 file changed, 9 insertions(+), 9 deletions(-)
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
diff --git a/scipy/spatial/ckdtree.pyx b/scipy/spatial/ckdtree.pyx
|
|
|
b2f9e6 |
index e2eea8c9097..884d49e1d34 100644
|
|
|
b2f9e6 |
--- a/scipy/spatial/ckdtree.pyx
|
|
|
b2f9e6 |
+++ b/scipy/spatial/ckdtree.pyx
|
|
|
b2f9e6 |
@@ -190,7 +190,7 @@ cdef class coo_entries:
|
|
|
b2f9e6 |
res_dtype = np.dtype(_dtype, align = True)
|
|
|
b2f9e6 |
n = <np.intp_t> self.buf.size()
|
|
|
b2f9e6 |
if NPY_LIKELY(n > 0):
|
|
|
b2f9e6 |
- pr = &self.buf.front()
|
|
|
b2f9e6 |
+ pr = self.buf.data()
|
|
|
b2f9e6 |
uintptr = <np.uintp_t> (<void*> pr)
|
|
|
b2f9e6 |
dtype = np.dtype(np.uint8)
|
|
|
b2f9e6 |
self.__array_interface__ = dict(
|
|
|
b2f9e6 |
@@ -213,7 +213,7 @@ cdef class coo_entries:
|
|
|
b2f9e6 |
dict res_dict
|
|
|
b2f9e6 |
n = <np.intp_t> self.buf.size()
|
|
|
b2f9e6 |
if NPY_LIKELY(n > 0):
|
|
|
b2f9e6 |
- pr = &self.buf.front()
|
|
|
b2f9e6 |
+ pr = self.buf.data()
|
|
|
b2f9e6 |
res_dict = dict()
|
|
|
b2f9e6 |
for k in range(n):
|
|
|
b2f9e6 |
i = pr[k].i
|
|
|
b2f9e6 |
@@ -263,7 +263,7 @@ cdef class ordered_pairs:
|
|
|
b2f9e6 |
np.intp_t n
|
|
|
b2f9e6 |
n = <np.intp_t> self.buf.size()
|
|
|
b2f9e6 |
if NPY_LIKELY(n > 0):
|
|
|
b2f9e6 |
- pr = &self.buf.front()
|
|
|
b2f9e6 |
+ pr = self.buf.data()
|
|
|
b2f9e6 |
uintptr = <np.uintp_t> (<void*> pr)
|
|
|
b2f9e6 |
dtype = np.dtype(np.intp)
|
|
|
b2f9e6 |
self.__array_interface__ = dict(
|
|
|
b2f9e6 |
@@ -284,7 +284,7 @@ cdef class ordered_pairs:
|
|
|
b2f9e6 |
np.intp_t i, n
|
|
|
b2f9e6 |
set results
|
|
|
b2f9e6 |
results = set()
|
|
|
b2f9e6 |
- pair = &self.buf.front()
|
|
|
b2f9e6 |
+ pair = self.buf.data()
|
|
|
b2f9e6 |
n = <np.intp_t> self.buf.size()
|
|
|
b2f9e6 |
if sizeof(long) < sizeof(np.intp_t):
|
|
|
b2f9e6 |
# Needed for Python 2.x on Win64
|
|
|
b2f9e6 |
@@ -593,7 +593,7 @@ cdef class cKDTree:
|
|
|
b2f9e6 |
cself = self.cself
|
|
|
b2f9e6 |
# finalize the tree points, this calls _post_init_traverse
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
- cself.ctree = &cself.tree_buffer.front()
|
|
|
b2f9e6 |
+ cself.ctree = cself.tree_buffer.data()
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
# set the size attribute after tree_buffer is built
|
|
|
b2f9e6 |
cself.size = cself.tree_buffer.size()
|
|
|
b2f9e6 |
@@ -971,7 +971,7 @@ cdef class cKDTree:
|
|
|
b2f9e6 |
m = <np.intp_t> (vvres[i].size())
|
|
|
b2f9e6 |
tmp = m * [None]
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
- cur = &vvres[i].front()
|
|
|
b2f9e6 |
+ cur = vvres[i].data()
|
|
|
b2f9e6 |
for j in range(m):
|
|
|
b2f9e6 |
tmp[j] = cur[0]
|
|
|
b2f9e6 |
cur += 1
|
|
|
b2f9e6 |
@@ -1067,7 +1067,7 @@ cdef class cKDTree:
|
|
|
b2f9e6 |
tmp = m * [None]
|
|
|
b2f9e6 |
with nogil:
|
|
|
b2f9e6 |
sort(vvres[i].begin(), vvres[i].end())
|
|
|
b2f9e6 |
- cur = &vvres[i].front()
|
|
|
b2f9e6 |
+ cur = vvres[i].data()
|
|
|
b2f9e6 |
for j in range(m):
|
|
|
b2f9e6 |
tmp[j] = cur[0]
|
|
|
b2f9e6 |
cur += 1
|
|
|
b2f9e6 |
@@ -1492,7 +1492,7 @@ cdef class cKDTree:
|
|
|
b2f9e6 |
cdef ckdtree * cself = self.cself
|
|
|
b2f9e6 |
size = cself.tree_buffer.size() * sizeof(ckdtreenode)
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
- cdef np.ndarray tree = np.asarray(<char[:size]> <char*> &cself.tree_buffer.front())
|
|
|
b2f9e6 |
+ cdef np.ndarray tree = np.asarray(<char[:size]> <char*> cself.tree_buffer.data())
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
state = (tree.copy(), self.data.copy(), self.n, self.m, self.leafsize,
|
|
|
b2f9e6 |
self.maxes, self.mins, self.indices.copy(),
|
|
|
b2f9e6 |
@@ -1511,7 +1511,7 @@ cdef class cKDTree:
|
|
|
b2f9e6 |
cself.tree_buffer = new vector[ckdtreenode]()
|
|
|
b2f9e6 |
cself.tree_buffer.resize(tree.size // sizeof(ckdtreenode))
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
- mytree = np.asarray(<char[:tree.size]> <char*> &cself.tree_buffer.front())
|
|
|
b2f9e6 |
+ mytree = np.asarray(<char[:tree.size]> <char*> cself.tree_buffer.data())
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
# set raw pointers
|
|
|
b2f9e6 |
self._pre_init()
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
From ad0f91438f49bfe277e32d2689aefeb0c11c789f Mon Sep 17 00:00:00 2001
|
|
|
b2f9e6 |
From: Pauli Virtanen <pav@iki.fi>
|
|
|
b2f9e6 |
Date: Wed, 31 Jul 2019 23:41:40 +0300
|
|
|
b2f9e6 |
Subject: [PATCH 2/2] BLD: spatial: set c++ std flags for ckdtree
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
---
|
|
|
b2f9e6 |
scipy/spatial/setup.py | 11 ++++++++++-
|
|
|
b2f9e6 |
1 file changed, 10 insertions(+), 1 deletion(-)
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
diff --git a/scipy/spatial/setup.py b/scipy/spatial/setup.py
|
|
|
b2f9e6 |
index d7e334876df..19d78593c5e 100644
|
|
|
b2f9e6 |
--- a/scipy/spatial/setup.py
|
|
|
b2f9e6 |
+++ b/scipy/spatial/setup.py
|
|
|
b2f9e6 |
@@ -4,6 +4,13 @@
|
|
|
b2f9e6 |
import glob
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
+def pre_build_hook(build_ext, ext):
|
|
|
b2f9e6 |
+ from scipy._build_utils.compiler_helper import get_cxx_std_flag
|
|
|
b2f9e6 |
+ std_flag = get_cxx_std_flag(build_ext._cxx_compiler)
|
|
|
b2f9e6 |
+ if std_flag is not None:
|
|
|
b2f9e6 |
+ ext.extra_compile_args.append(std_flag)
|
|
|
b2f9e6 |
+
|
|
|
b2f9e6 |
+
|
|
|
b2f9e6 |
def configuration(parent_package='', top_path=None):
|
|
|
b2f9e6 |
from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs
|
|
|
b2f9e6 |
from numpy.distutils.misc_util import get_info as get_misc_info
|
|
|
b2f9e6 |
@@ -55,10 +62,12 @@ def configuration(parent_package='', top_path=None):
|
|
|
b2f9e6 |
ckdtree_headers = [join('ckdtree', 'src', x) for x in ckdtree_headers]
|
|
|
b2f9e6 |
|
|
|
b2f9e6 |
ckdtree_dep = ['ckdtree.cxx'] + ckdtree_headers + ckdtree_src
|
|
|
b2f9e6 |
- config.add_extension('ckdtree',
|
|
|
b2f9e6 |
+ ext = config.add_extension('ckdtree',
|
|
|
b2f9e6 |
sources=['ckdtree.cxx'] + ckdtree_src,
|
|
|
b2f9e6 |
depends=ckdtree_dep,
|
|
|
b2f9e6 |
include_dirs=inc_dirs + [join('ckdtree', 'src')])
|
|
|
b2f9e6 |
+ ext._pre_build_hook = pre_build_hook
|
|
|
b2f9e6 |
+
|
|
|
b2f9e6 |
# _distance_wrap
|
|
|
b2f9e6 |
config.add_extension('_distance_wrap',
|
|
|
b2f9e6 |
sources=[join('src', 'distance_wrap.c')],
|