From d6e4cef65f118b1a3167b89452161dfc83c81166 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sat, 20 Feb 2016 12:17:17 +0100 Subject: [PATCH] minor formatting changes, removed missing header files referenced in setup.py --- include/pybind11/numpy.h | 64 +++++++++++++++++++--------------------- setup.py | 4 +-- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 44a0cb1c..3386876e 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -162,14 +162,13 @@ array_iterator array_end(const buffer_info& buffer) { } class common_iterator { - public: - using container_type = std::vector; using value_type = container_type::value_type; using size_type = container_type::size_type; common_iterator() : p_ptr(0), m_strides() {} + common_iterator(void* ptr, const container_type& strides, const std::vector& shape) : p_ptr(reinterpret_cast(ptr)), m_strides(strides.size()) { m_strides.back() = static_cast(strides.back()); @@ -189,30 +188,26 @@ public: } private: - char* p_ptr; container_type m_strides; }; -template -class multi_array_iterator { - +template class multi_array_iterator { public: - using container_type = std::vector; - multi_array_iterator(const std::array& buffers, - const std::vector& shape) - : m_shape(shape.size()), m_index(shape.size(), 0), m_common_iterator() { + multi_array_iterator(const std::array &buffers, + const std::vector &shape) + : m_shape(shape.size()), m_index(shape.size(), 0), + m_common_iterator() { + // Manual copy to avoid conversion warning if using std::copy - for (size_t i = 0; i < shape.size(); ++i) { + for (size_t i = 0; i < shape.size(); ++i) m_shape[i] = static_cast(shape[i]); - } container_type strides(shape.size()); - for (size_t i = 0; i < N; ++i) { + for (size_t i = 0; i < N; ++i) init_common_iterator(buffers[i], shape, m_common_iterator[i], strides); - } } multi_array_iterator& operator++() { @@ -221,16 +216,14 @@ public: if (++m_index[i] != m_shape[i]) { increment_common_iterator(i); break; - } - else { + } else { m_index[i] = 0; } } return *this; } - template - const T& data() const { + template const T& data() const { return *reinterpret_cast(m_common_iterator[K].data()); } @@ -238,7 +231,9 @@ private: using common_iter = common_iterator; - void init_common_iterator(const buffer_info& buffer, const std::vector& shape, common_iter& iterator, container_type& strides) { + void init_common_iterator(const buffer_info &buffer, + const std::vector &shape, + common_iter &iterator, container_type &strides) { auto buffer_shape_iter = buffer.shape.rbegin(); auto buffer_strides_iter = buffer.strides.rbegin(); auto shape_iter = shape.rbegin(); @@ -261,9 +256,8 @@ private: } void increment_common_iterator(size_t dim) { - std::for_each(m_common_iterator.begin(), m_common_iterator.end(), [=](common_iter& iter) { + for (auto &iter : m_common_iterator) iter.increment(dim); - }); } container_type m_shape; @@ -271,10 +265,6 @@ private: std::array m_common_iterator; }; -template struct handle_type_name> { - static PYBIND11_DESCR name() { return _("array[") + type_caster::name() + _("]"); } -}; - template bool broadcast(const std::array& buffers, int& ndim, std::vector& shape) { ndim = std::accumulate(buffers.begin(), buffers.end(), 0, [](int res, const buffer_info& buf) { @@ -286,13 +276,14 @@ bool broadcast(const std::array& buffers, int& ndim, std::vector for (size_t i = 0; i < N; ++i) { auto res_iter = shape.rbegin(); bool i_trivial_broadcast = (buffers[i].size == 1) || (buffers[i].ndim == ndim); - for (auto shape_iter = buffers[i].shape.rbegin(); shape_iter != buffers[i].shape.rend(); ++shape_iter, ++res_iter) { - if (*res_iter == 1) { + for (auto shape_iter = buffers[i].shape.rbegin(); + shape_iter != buffers[i].shape.rend(); ++shape_iter, ++res_iter) { + + if (*res_iter == 1) *res_iter = *shape_iter; - } - else if ((*shape_iter != 1) && (*res_iter != *shape_iter)) { + else if ((*shape_iter != 1) && (*res_iter != *shape_iter)) pybind11_fail("pybind11::vectorize: incompatible size/dimension of inputs!"); - } + i_trivial_broadcast = i_trivial_broadcast && (*res_iter == *shape_iter); } trivial_broadcast = trivial_broadcast && i_trivial_broadcast; @@ -350,8 +341,7 @@ struct vectorize_helper { ? *((Args *) buffers[Index].ptr) : ((Args *) buffers[Index].ptr)[i])...); } - } - else { + } else { apply_broadcast(buffers, buf, index); } @@ -359,19 +349,25 @@ struct vectorize_helper { } template - void apply_broadcast(const std::array& buffers, buffer_info& output, index_sequence) { + void apply_broadcast(const std::array &buffers, + buffer_info &output, index_sequence) { using input_iterator = multi_array_iterator; using output_iterator = array_iterator; input_iterator input_iter(buffers, output.shape); output_iterator output_end = array_end(output); - for (output_iterator iter = array_begin(output); iter != output_end; ++iter, ++input_iter) { + for (output_iterator iter = array_begin(output); + iter != output_end; ++iter, ++input_iter) { *iter = f((input_iter.template data())...); } } }; +template struct handle_type_name> { + static PYBIND11_DESCR name() { return _("array[") + type_caster::name() + _("]"); } +}; + NAMESPACE_END(detail) template diff --git a/setup.py b/setup.py index 8027088a..ae1ca8bf 100644 --- a/setup.py +++ b/setup.py @@ -27,9 +27,7 @@ setup( 'include/pybind11/functional.h', 'include/pybind11/operators.h', 'include/pybind11/pytypes.h', - 'include/pybind11/typeid.h', - 'include/pybind11/short_vector.h', - 'include/pybind11/array_iterator.h' + 'include/pybind11/typeid.h' ], classifiers=[ 'Development Status :: 5 - Production/Stable',