Skip to content

Commit 61ac598

Browse files
committed
Breathe version and formatting
1 parent 15248e1 commit 61ac598

File tree

9 files changed

+84
-85
lines changed

9 files changed

+84
-85
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ install:
9595
# Useful for debugging any issues with conda
9696
- conda info -a
9797
- conda install xtensor==0.10.2 pytest numpy pybind11==2.1.1 -c conda-forge
98-
- cd test
99-
- conda env create -f ./test-environment.yml
100-
- source activate test-xtensor-python
101-
- cd ..
98+
- conda install cmake gtest -c conda-forge
10299
- cmake -D BUILD_TESTS=ON -D CMAKE_INSTALL_PREFIX=$HOME/miniconda .
103100
- make -j2 test_xtensor_python
104101
- make install

docs/environment.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,4 @@ channels:
44
- conda-forge
55

66
dependencies:
7-
- python=3.5
8-
- sphinx_rtd_theme
9-
- pip:
10-
- breathe
11-
- sphinx==1.5.6
7+
- breathe

docs/source/basic_usage.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ Example 1: Use an algorithm of the C++ library on a numpy array inplace
4040

4141
.. code::
4242
43-
Python Code
44-
4543
import numpy as np
4644
import xtensor_python_test as xt
4745
@@ -56,8 +54,8 @@ Example 1: Use an algorithm of the C++ library on a numpy array inplace
5654
1.2853996391883833
5755
5856
59-
Example 2: Create a universal function from a C++ scalar function
60-
-----------------------------------------------------------------
57+
Example 2: Create a numpy-style universal function from a C++ scalar function
58+
-----------------------------------------------------------------------------
6159

6260
**C++ code**
6361

include/xtensor-python/pyarray.hpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#ifndef PY_ARRAY_HPP
1010
#define PY_ARRAY_HPP
1111

12+
#include <algorithm>
1213
#include <cstddef>
1314
#include <vector>
14-
#include <algorithm>
1515

16-
#include "xtensor/xsemantic.hpp"
17-
#include "xtensor/xiterator.hpp"
1816
#include "xtensor/xbuffer_adaptor.hpp"
17+
#include "xtensor/xiterator.hpp"
18+
#include "xtensor/xsemantic.hpp"
1919

2020
#include "pycontainer.hpp"
2121
#include "pystrides_adaptor.hpp"
@@ -62,7 +62,7 @@ namespace pybind11
6262
return static_cast<bool>(value);
6363
}
6464

65-
static handle cast(const handle &src, return_value_policy, handle)
65+
static handle cast(const handle& src, return_value_policy, handle)
6666
{
6767
return src.inc_ref();
6868
}
@@ -135,9 +135,9 @@ namespace xt
135135
using semantic_base = xcontainer_semantic<self_type>;
136136
using base_type = pycontainer<self_type>;
137137
using container_type = typename base_type::container_type;
138-
using value_type = typename base_type::value_type;
139-
using reference = typename base_type::reference;
140-
using const_reference = typename base_type::const_reference;
138+
using value_type = typename base_type::value_type;
139+
using reference = typename base_type::reference;
140+
using const_reference = typename base_type::const_reference;
141141
using pointer = typename base_type::pointer;
142142
using size_type = typename base_type::size_type;
143143
using shape_type = typename base_type::shape_type;
@@ -157,8 +157,8 @@ namespace xt
157157

158158
pyarray(pybind11::handle h, pybind11::object::borrowed_t);
159159
pyarray(pybind11::handle h, pybind11::object::stolen_t);
160-
pyarray(const pybind11::object &o);
161-
160+
pyarray(const pybind11::object& o);
161+
162162
explicit pyarray(const shape_type& shape, layout_type l = layout_type::row_major);
163163
explicit pyarray(const shape_type& shape, const_reference value, layout_type l = layout_type::row_major);
164164
explicit pyarray(const shape_type& shape, const strides_type& strides, const_reference value);
@@ -201,7 +201,7 @@ namespace xt
201201

202202
friend class xcontainer<pyarray<T>>;
203203
};
204-
204+
205205
/**************************************
206206
* pyarray_backstrides implementation *
207207
**************************************/
@@ -223,7 +223,7 @@ namespace xt
223223
{
224224
value_type sh = p_a->shape()[i];
225225
value_type res = sh == 1 ? 0 : (sh - 1) * p_a->strides()[i];
226-
return res;
226+
return res;
227227
}
228228

229229
/**************************
@@ -311,7 +311,7 @@ namespace xt
311311
}
312312

313313
template <class T>
314-
inline pyarray<T>::pyarray(const pybind11::object &o)
314+
inline pyarray<T>::pyarray(const pybind11::object& o)
315315
: base_type(o)
316316
{
317317
init_from_python();
@@ -348,7 +348,7 @@ namespace xt
348348
init_array(shape, strides);
349349
std::fill(m_data.begin(), m_data.end(), value);
350350
}
351-
351+
352352
/**
353353
* Allocates an uninitialized pyarray with the specified shape and strides.
354354
* Elements are initialized to the specified value.
@@ -389,8 +389,7 @@ namespace xt
389389
: base_type()
390390
{
391391
auto tmp = pybind11::reinterpret_steal<pybind11::object>(
392-
PyArray_NewLikeArray(rhs.python_array(), NPY_KEEPORDER, nullptr, 1)
393-
);
392+
PyArray_NewLikeArray(rhs.python_array(), NPY_KEEPORDER, nullptr, 1));
394393

395394
if (!tmp)
396395
{
@@ -464,22 +463,21 @@ namespace xt
464463
strides_type adapted_strides(strides);
465464

466465
std::transform(strides.begin(), strides.end(), adapted_strides.begin(),
467-
[](auto v) { return sizeof(T) * v; });
466+
[](auto v) { return sizeof(T) * v; });
468467

469468
int flags = NPY_ARRAY_ALIGNED;
470469
if (!std::is_const<T>::value)
471470
{
472471
flags |= NPY_ARRAY_WRITEABLE;
473472
}
474473
int type_num = detail::numpy_traits<T>::type_num;
475-
474+
476475
npy_intp* shape_data = reinterpret_cast<npy_intp*>(const_cast<size_type*>(shape.data()));
477476
npy_intp* strides_data = reinterpret_cast<npy_intp*>(adapted_strides.data());
478477
auto tmp = pybind11::reinterpret_steal<pybind11::object>(
479-
PyArray_New(&PyArray_Type, static_cast<int>(shape.size()), shape_data, type_num, strides_data,
480-
nullptr, static_cast<int>(sizeof(T)), flags, nullptr)
481-
);
482-
478+
PyArray_New(&PyArray_Type, static_cast<int>(shape.size()), shape_data, type_num, strides_data,
479+
nullptr, static_cast<int>(sizeof(T)), flags, nullptr));
480+
483481
if (!tmp)
484482
{
485483
throw std::runtime_error("NumPy: unable to create ndarray");
@@ -537,5 +535,3 @@ namespace xt
537535
}
538536

539537
#endif
540-
541-

include/xtensor-python/pycontainer.hpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#ifndef PY_CONTAINER_HPP
1010
#define PY_CONTAINER_HPP
1111

12+
#include <cmath>
1213
#include <functional>
1314
#include <numeric>
14-
#include <cmath>
1515

16-
#include "pybind11/pybind11.h"
1716
#include "pybind11/common.h"
1817
#include "pybind11/complex.h"
18+
#include "pybind11/pybind11.h"
1919

2020
#ifndef FORCE_IMPORT_ARRAY
2121
#define NO_IMPORT_ARRAY
@@ -123,11 +123,10 @@ namespace xt
123123

124124
constexpr static const int value_list[15] = {
125125
NPY_BOOL,
126-
NPY_BYTE, NPY_UBYTE, NPY_SHORT, NPY_USHORT,
127-
NPY_INT, NPY_UINT, NPY_LONGLONG, NPY_ULONGLONG,
128-
NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE,
129-
NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE
130-
};
126+
NPY_BYTE, NPY_UBYTE, NPY_SHORT, NPY_USHORT,
127+
NPY_INT, NPY_UINT, NPY_LONGLONG, NPY_ULONGLONG,
128+
NPY_FLOAT, NPY_DOUBLE, NPY_LONGDOUBLE,
129+
NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE};
131130

132131
public:
133132

@@ -158,7 +157,7 @@ namespace xt
158157
: pybind11::object(h, s)
159158
{
160159
}
161-
160+
162161
template <class D>
163162
inline pycontainer<D>::pycontainer(const pybind11::object& o)
164163
: pybind11::object(raw_array_t(o.ptr()), pybind11::object::stolen_t{})
@@ -196,7 +195,7 @@ namespace xt
196195
return nullptr;
197196
}
198197
int type_num = detail::numpy_traits<value_type>::type_num;
199-
auto res = PyArray_FromAny(ptr, PyArray_DescrFromType(type_num), 0, 0,
198+
auto res = PyArray_FromAny(ptr, PyArray_DescrFromType(type_num), 0, 0,
200199
NPY_ARRAY_ENSUREARRAY | NPY_ARRAY_FORCECAST, nullptr);
201200
return res;
202201
}
@@ -210,7 +209,7 @@ namespace xt
210209
template <class D>
211210
inline auto pycontainer<D>::get_min_stride() const -> size_type
212211
{
213-
const size_type & (*min) (const size_type&, const size_type&) = std::min<size_type>;
212+
const size_type& (*min)(const size_type&, const size_type&) = std::min<size_type>;
214213
return std::max(size_type(1), std::accumulate(this->strides().cbegin(), this->strides().cend(), std::numeric_limits<size_type>::max(), min));
215214
}
216215

@@ -272,15 +271,14 @@ namespace xt
272271
*/
273272
inline void import_numpy()
274273
{
275-
#ifdef FORCE_IMPORT_ARRAY
274+
#ifdef FORCE_IMPORT_ARRAY
276275
if (_import_array() < 0)
277276
{
278277
PyErr_Print();
279278
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
280279
}
281-
#endif
280+
#endif
282281
}
283282
}
284283

285284
#endif
286-

include/xtensor-python/pystrides_adaptor.hpp

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ namespace xt
2121
template <std::size_t N>
2222
class pystrides_adaptor
2323
{
24-
2524
public:
2625

2726
using value_type = std::size_t;
@@ -82,14 +81,40 @@ namespace xt
8281

8382
inline reference operator[](difference_type n) { return *(p_current + n) / N; }
8483

85-
inline self_type& operator++() { ++p_current; return *this; }
86-
inline self_type& operator--() { --p_current; return *this; }
84+
inline self_type& operator++()
85+
{
86+
++p_current;
87+
return *this;
88+
}
89+
inline self_type& operator--()
90+
{
91+
--p_current;
92+
return *this;
93+
}
8794

88-
inline self_type operator++(int) { self_type tmp(*this); ++p_current; return tmp; }
89-
inline self_type operator--(int) { self_type tmp(*this); --p_current; return tmp; }
95+
inline self_type operator++(int)
96+
{
97+
self_type tmp(*this);
98+
++p_current;
99+
return tmp;
100+
}
101+
inline self_type operator--(int)
102+
{
103+
self_type tmp(*this);
104+
--p_current;
105+
return tmp;
106+
}
90107

91-
inline self_type& operator+=(difference_type n) { p_current += n; return *this; }
92-
inline self_type& operator-=(difference_type n) { p_current -= n; return *this; }
108+
inline self_type& operator+=(difference_type n)
109+
{
110+
p_current += n;
111+
return *this;
112+
}
113+
inline self_type& operator-=(difference_type n)
114+
{
115+
p_current -= n;
116+
return *this;
117+
}
93118

94119
inline self_type operator+(difference_type n) const { return self_type(p_current + n); }
95120
inline self_type operator-(difference_type n) const { return self_type(p_current - n); }
@@ -212,8 +237,6 @@ namespace xt
212237
{
213238
return end();
214239
}
215-
216240
}
217241

218242
#endif
219-

0 commit comments

Comments
 (0)