@@ -23,13 +23,15 @@ namespace xt
2323{
2424
2525 template <class D >
26- class pycontainer : public pybind11 ::object, public xiterable<D>
26+ class pycontainer : public pybind11 ::object,
27+ public xcontainer<D>
2728 {
2829
2930 public:
3031
3132 using derived_type = D;
3233
34+ using base_type = xcontainer<D>;
3335 using inner_types = xcontainer_inner_types<D>;
3436 using container_type = typename inner_types::container_type;
3537 using value_type = typename container_type::value_type;
@@ -57,58 +59,13 @@ namespace xt
5759 using broadcast_iterator = typename iterable_base::broadcast_iterator;
5860 using const_broadcast_iterator = typename iterable_base::broadcast_iterator;
5961
60- size_type size () const ;
61- size_type dimension () const ;
62-
63- const inner_shape_type& shape () const ;
64- const inner_strides_type& strides () const ;
65- const backstrides_type& backstrides () const ;
66-
6762 void reshape (const shape_type& shape);
6863 void reshape (const shape_type& shape, layout l);
6964 void reshape (const shape_type& shape, const strides_type& strides);
7065
71- template <class ... Args>
72- reference operator ()(Args... args);
73-
74- template <class ... Args>
75- const_reference operator ()(Args... args) const ;
76-
77- reference operator [](const xindex& index);
78- const_reference operator [](const xindex& index) const ;
79-
80- template <class It >
81- reference element (It first, It last);
82-
83- template <class It >
84- const_reference element (It first, It last) const ;
85-
86- container_type& data ();
87- const container_type& data () const ;
88-
89- template <class S >
90- bool broadcast_shape (S& shape) const ;
91-
92- template <class S >
93- bool is_trivial_broadcast (const S& strides) const ;
94-
95- iterator begin ();
96- iterator end ();
97-
98- const_iterator begin () const ;
99- const_iterator end () const ;
100- const_iterator cbegin () const ;
101- const_iterator cend () const ;
102-
103- template <class S >
104- stepper stepper_begin (const S& shape);
105- template <class S >
106- stepper stepper_end (const S& shape);
107-
108- template <class S >
109- const_stepper stepper_begin (const S& shape) const ;
110- template <class S >
111- const_stepper stepper_end (const S& shape) const ;
66+ using base_type::operator ();
67+ using base_type::begin;
68+ using base_type::end;
11269
11370 protected:
11471
@@ -132,17 +89,6 @@ namespace xt
13289 PyArrayObject* python_array ();
13390 };
13491
135- template <class D >
136- struct pycontainer_iterable_types
137- : xcontainer_iterable_types<D>
138- {
139- using stepper = xstepper<D>;
140- using const_stepper = xstepper<const D>;
141- using inner_shape_type = typename xcontainer_inner_types<D>::inner_shape_type;
142- using broadcast_iterator = xiterator<stepper, inner_shape_type*>;
143- using const_broadcast_iterator = xiterator<const_stepper, inner_shape_type*>;
144- };
145-
14692 namespace detail
14793 {
14894 // TODO : switch on pybind11::is_fmt_numeric when it is available
@@ -253,40 +199,10 @@ namespace xt
253199 return reinterpret_cast <PyArrayObject*>(this ->m_ptr );
254200 }
255201
256- template <class D >
257- inline auto pycontainer<D>::size() const -> size_type
258- {
259- return data ().size ();
260- }
261-
262- template <class D >
263- inline auto pycontainer<D>::dimension() const -> size_type
264- {
265- return shape ().size ();
266- }
267-
268- template <class D >
269- inline auto pycontainer<D>::shape() const -> const inner_shape_type&
270- {
271- return static_cast <const derived_type*>(this )->shape_impl ();
272- }
273-
274- template <class D >
275- inline auto pycontainer<D>::strides() const -> const inner_strides_type&
276- {
277- return static_cast <const derived_type*>(this )->strides_impl ();
278- }
279-
280- template <class D >
281- inline auto pycontainer<D>::backstrides() const -> const backstrides_type&
282- {
283- return static_cast <const derived_type*>(this )->backstrides_impl ();
284- }
285-
286202 template <class D >
287203 inline void pycontainer<D>::reshape(const shape_type& shape)
288204 {
289- if (shape.size () != dimension () || !std::equal (shape.begin (), shape.end (), this ->shape ().begin ()))
205+ if (shape.size () != this -> dimension () || !std::equal (shape.begin (), shape.end (), this ->shape ().begin ()))
290206 {
291207 reshape (shape, layout::row_major);
292208 }
@@ -307,143 +223,6 @@ namespace xt
307223 *static_cast <derived_type*>(this ) = std::move (tmp);
308224 }
309225
310- template <class D >
311- template <class ... Args>
312- inline auto pycontainer<D>::operator ()(Args... args) -> reference
313- {
314- size_type index = data_offset<size_type>(strides (), static_cast <size_type>(args)...);
315- return data ()[index];
316- }
317-
318- template <class D >
319- template <class ... Args>
320- inline auto pycontainer<D>::operator ()(Args... args) const -> const_reference
321- {
322- size_type index = data_offset<size_type>(strides (), static_cast <size_type>(args)...);
323- return data ()[index];
324- }
325-
326- template <class D >
327- inline auto pycontainer<D>::operator [](const xindex& index) -> reference
328- {
329- return element (index.cbegin (), index.cend ());
330- }
331-
332- template <class D >
333- inline auto pycontainer<D>::operator [](const xindex& index) const -> const_reference
334- {
335- return element (index.cbegin (), index.cend ());
336- }
337-
338- template <class D >
339- template <class It >
340- inline auto pycontainer<D>::element(It first, It last) -> reference
341- {
342- return data ()[element_offset<size_type>(strides (), first, last)];
343- }
344-
345- template <class D >
346- template <class It >
347- inline auto pycontainer<D>::element(It first, It last) const -> const_reference
348- {
349- return data ()[element_offset<size_type>(strides (), first, last)];
350- }
351-
352- template <class D >
353- inline auto pycontainer<D>::data() -> container_type&
354- {
355- return static_cast <derived_type*>(this )->data_impl ();
356- }
357-
358- template <class D >
359- inline auto pycontainer<D>::data() const -> const container_type&
360- {
361- return static_cast <const derived_type*>(this )->data_impl ();
362- }
363-
364- template <class D >
365- template <class S >
366- inline bool pycontainer<D>::broadcast_shape(S& shape) const
367- {
368- return xt::broadcast_shape (this ->shape (), shape);
369- }
370-
371- template <class D >
372- template <class S >
373- inline bool pycontainer<D>::is_trivial_broadcast(const S& strides) const
374- {
375- const inner_strides_type& str = this ->strides ();
376- return str.size () == strides.size () &&
377- std::equal (str.cbegin (), str.cend (), strides.begin ());
378- }
379-
380- template <class D >
381- inline auto pycontainer<D>::begin() -> iterator
382- {
383- return data ().begin ();
384- }
385-
386- template <class D >
387- inline auto pycontainer<D>::end() -> iterator
388- {
389- return data ().end ();
390- }
391-
392- template <class D >
393- inline auto pycontainer<D>::begin() const -> const_iterator
394- {
395- return cbegin ();
396- }
397-
398- template <class D >
399- inline auto pycontainer<D>::end() const -> const_iterator
400- {
401- return cend ();
402- }
403-
404- template <class D >
405- inline auto pycontainer<D>::cbegin() const -> const_iterator
406- {
407- return data ().cbegin ();
408- }
409-
410- template <class D >
411- inline auto pycontainer<D>::cend() const -> const_iterator
412- {
413- return data ().cend ();
414- }
415-
416- template <class D >
417- template <class S >
418- inline auto pycontainer<D>::stepper_begin(const S& shape) -> stepper
419- {
420- size_type offset = shape.size () - dimension ();
421- return stepper (static_cast <derived_type*>(this ), data ().begin (), offset);
422- }
423-
424- template <class D >
425- template <class S >
426- inline auto pycontainer<D>::stepper_end(const S& shape) -> stepper
427- {
428- size_type offset = shape.size () - dimension ();
429- return stepper (static_cast <derived_type*>(this ), data ().end (), offset);
430- }
431-
432- template <class D >
433- template <class S >
434- inline auto pycontainer<D>::stepper_begin(const S& shape) const -> const_stepper
435- {
436- size_type offset = shape.size () - dimension ();
437- return const_stepper (static_cast <const derived_type*>(this ), data ().begin (), offset);
438- }
439-
440- template <class D >
441- template <class S >
442- inline auto pycontainer<D>::stepper_end(const S& shape) const -> const_stepper
443- {
444- size_type offset = shape.size () - dimension ();
445- return const_stepper (static_cast <const derived_type*>(this ), data ().end (), offset);
446- }
447226}
448227
449228#endif
0 commit comments