@@ -134,8 +134,6 @@ namespace xt
134134 using inner_backstrides_type = typename base_type::inner_backstrides_type;
135135
136136 pyarray ();
137- pyarray (const self_type&) = default ;
138- pyarray (self_type&&) = default ;
139137 pyarray (const value_type& t);
140138 pyarray (nested_initializer_list_t <T, 1 > t);
141139 pyarray (nested_initializer_list_t <T, 2 > t);
@@ -152,12 +150,15 @@ namespace xt
152150 explicit pyarray (const shape_type& shape, const strides_type& strides, const_reference value);
153151 explicit pyarray (const shape_type& shape, const strides_type& strides);
154152
155- template < class E >
156- pyarray (const xexpression<E>& e );
153+ pyarray ( const self_type& rhs);
154+ self_type& operator = (const self_type& rhs );
157155
158- self_type& operator =( const self_type& e ) = default ;
156+ pyarray ( self_type&& ) = default ;
159157 self_type& operator =(self_type&& e) = default ;
160158
159+ template <class E >
160+ pyarray (const xexpression<E>& e);
161+
161162 template <class E >
162163 self_type& operator =(const xexpression<E>& e);
163164
@@ -221,6 +222,7 @@ namespace xt
221222 // @{
222223 template <class T >
223224 inline pyarray<T>::pyarray()
225+ : base_type()
224226 {
225227 // TODO: avoid allocation
226228 shape_type shape = make_sequence<shape_type>(0 , size_type (1 ));
@@ -234,41 +236,47 @@ namespace xt
234236 */
235237 template <class T >
236238 inline pyarray<T>::pyarray(const value_type& t)
239+ : base_type()
237240 {
238241 base_type::reshape (xt::shape<shape_type>(t), layout::row_major);
239242 nested_copy (m_data.begin (), t);
240243 }
241244
242245 template <class T >
243246 inline pyarray<T>::pyarray(nested_initializer_list_t <T, 1 > t)
247+ : base_type()
244248 {
245249 base_type::reshape (xt::shape<shape_type>(t), layout::row_major);
246250 nested_copy (m_data.begin (), t);
247251 }
248252
249253 template <class T >
250254 inline pyarray<T>::pyarray(nested_initializer_list_t <T, 2 > t)
255+ : base_type()
251256 {
252257 base_type::reshape (xt::shape<shape_type>(t), layout::row_major);
253258 nested_copy (m_data.begin (), t);
254259 }
255260
256261 template <class T >
257262 inline pyarray<T>::pyarray(nested_initializer_list_t <T, 3 > t)
263+ : base_type()
258264 {
259265 base_type::reshape (xt::shape<shape_type>(t), layout::row_major);
260266 nested_copy (m_data.begin (), t);
261267 }
262268
263269 template <class T >
264270 inline pyarray<T>::pyarray(nested_initializer_list_t <T, 4 > t)
271+ : base_type()
265272 {
266273 base_type::reshape (xt::shape<shape_type>(t), layout::row_major);
267274 nested_copy (m_data.begin (), t);
268275 }
269276
270277 template <class T >
271278 inline pyarray<T>::pyarray(nested_initializer_list_t <T, 5 > t)
279+ : base_type()
272280 {
273281 base_type::reshape (xt::shape<shape_type>(t), layout::row_major);
274282 nested_copy (m_data.begin (), t);
@@ -303,6 +311,7 @@ namespace xt
303311 */
304312 template <class T >
305313 inline pyarray<T>::pyarray(const shape_type& shape, layout l)
314+ : base_type()
306315 {
307316 strides_type strides (shape.size ());
308317 compute_strides (shape, l, strides);
@@ -318,6 +327,7 @@ namespace xt
318327 */
319328 template <class T >
320329 inline pyarray<T>::pyarray(const shape_type& shape, const_reference value, layout l)
330+ : base_type()
321331 {
322332 strides_type strides (shape.size ());
323333 compute_strides (shape, l, strides);
@@ -334,6 +344,7 @@ namespace xt
334344 */
335345 template <class T >
336346 inline pyarray<T>::pyarray(const shape_type& shape, const strides_type& strides, const_reference value)
347+ : base_type()
337348 {
338349 init_array (shape, strides);
339350 std::fill (m_data.begin (), m_data.end (), value);
@@ -346,11 +357,50 @@ namespace xt
346357 */
347358 template <class T >
348359 inline pyarray<T>::pyarray(const shape_type& shape, const strides_type& strides)
360+ : base_type()
349361 {
350362 init_array (shape, strides);
351363 }
352364 // @}
353365
366+ /* *
367+ * @name Copy semantic
368+ */
369+ // @{
370+ /* *
371+ * The copy constructor.
372+ */
373+ template <class T >
374+ inline pyarray<T>::pyarray(const self_type& rhs)
375+ : base_type()
376+ {
377+ auto tmp = pybind11::reinterpret_steal<pybind11::object>(
378+ PyArray_NewLikeArray (rhs.python_array (), NPY_KEEPORDER, nullptr , 1 )
379+ );
380+
381+ if (!tmp)
382+ {
383+ throw std::runtime_error (" NumPy: unable to create ndarray" );
384+ }
385+
386+ this ->m_ptr = tmp.release ().ptr ();
387+ init_from_python ();
388+ std::copy (rhs.data ().begin (), rhs.data ().end (), this ->data ().begin ());
389+ }
390+
391+ /* *
392+ * The assignment operator.
393+ */
394+ template <class T >
395+ inline auto pyarray<T>::operator =(const self_type& rhs) -> self_type&
396+ {
397+ self_type tmp (rhs);
398+ *this = std::move (tmp);
399+ return *this ;
400+ }
401+
402+ // @}
403+
354404 /* *
355405 * @name Extended copy semantic
356406 */
@@ -361,6 +411,7 @@ namespace xt
361411 template <class T >
362412 template <class E >
363413 inline pyarray<T>::pyarray(const xexpression<E>& e)
414+ : base_type()
364415 {
365416 semantic_base::assign (e);
366417 }
0 commit comments