Skip to content

Commit 1d53250

Browse files
committed
m_data -> m_storage
1 parent 2d42039 commit 1d53250

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

include/xtensor-python/pyarray.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ namespace xt
374374
inner_shape_type m_shape;
375375
inner_strides_type m_strides;
376376
mutable inner_backstrides_type m_backstrides;
377-
storage_type m_data;
377+
storage_type m_storage;
378378

379379
void init_array(const shape_type& shape, const strides_type& strides);
380380
void init_from_python();
@@ -477,7 +477,7 @@ namespace xt
477477
shape_type shape = xtl::make_sequence<shape_type>(0, size_type(1));
478478
strides_type strides = xtl::make_sequence<strides_type>(0, size_type(0));
479479
init_array(shape, strides);
480-
m_data[0] = T();
480+
m_storage[0] = T();
481481
}
482482

483483
/**
@@ -488,47 +488,47 @@ namespace xt
488488
: base_type()
489489
{
490490
base_type::resize(xt::shape<shape_type>(t), layout_type::row_major);
491-
nested_copy(m_data.begin(), t);
491+
nested_copy(m_storage.begin(), t);
492492
}
493493

494494
template <class T>
495495
inline pyarray<T>::pyarray(nested_initializer_list_t<T, 1> t)
496496
: base_type()
497497
{
498498
base_type::resize(xt::shape<shape_type>(t), layout_type::row_major);
499-
nested_copy(m_data.begin(), t);
499+
nested_copy(m_storage.begin(), t);
500500
}
501501

502502
template <class T>
503503
inline pyarray<T>::pyarray(nested_initializer_list_t<T, 2> t)
504504
: base_type()
505505
{
506506
base_type::resize(xt::shape<shape_type>(t), layout_type::row_major);
507-
nested_copy(m_data.begin(), t);
507+
nested_copy(m_storage.begin(), t);
508508
}
509509

510510
template <class T>
511511
inline pyarray<T>::pyarray(nested_initializer_list_t<T, 3> t)
512512
: base_type()
513513
{
514514
base_type::resize(xt::shape<shape_type>(t), layout_type::row_major);
515-
nested_copy(m_data.begin(), t);
515+
nested_copy(m_storage.begin(), t);
516516
}
517517

518518
template <class T>
519519
inline pyarray<T>::pyarray(nested_initializer_list_t<T, 4> t)
520520
: base_type()
521521
{
522522
base_type::resize(xt::shape<shape_type>(t), layout_type::row_major);
523-
nested_copy(m_data.begin(), t);
523+
nested_copy(m_storage.begin(), t);
524524
}
525525

526526
template <class T>
527527
inline pyarray<T>::pyarray(nested_initializer_list_t<T, 5> t)
528528
: base_type()
529529
{
530530
base_type::resize(xt::shape<shape_type>(t), layout_type::row_major);
531-
nested_copy(m_data.begin(), t);
531+
nested_copy(m_storage.begin(), t);
532532
}
533533

534534
template <class T>
@@ -581,7 +581,7 @@ namespace xt
581581
strides_type strides(shape.size());
582582
compute_strides(shape, l, strides);
583583
init_array(shape, strides);
584-
std::fill(m_data.begin(), m_data.end(), value);
584+
std::fill(m_storage.begin(), m_storage.end(), value);
585585
}
586586

587587
/**
@@ -596,7 +596,7 @@ namespace xt
596596
: base_type()
597597
{
598598
init_array(shape, strides);
599-
std::fill(m_data.begin(), m_data.end(), value);
599+
std::fill(m_storage.begin(), m_storage.end(), value);
600600
}
601601

602602
/**
@@ -730,8 +730,8 @@ namespace xt
730730
m_strides = inner_strides_type(reinterpret_cast<size_type*>(PyArray_STRIDES(this->python_array())),
731731
static_cast<size_type>(PyArray_NDIM(this->python_array())));
732732
m_backstrides = backstrides_type(*this);
733-
m_data = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
734-
this->get_min_stride() * static_cast<size_type>(PyArray_SIZE(this->python_array())));
733+
m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
734+
this->get_min_stride() * static_cast<size_type>(PyArray_SIZE(this->python_array())));
735735
}
736736

737737
template <class T>
@@ -759,13 +759,13 @@ namespace xt
759759
template <class T>
760760
inline auto pyarray<T>::storage_impl() noexcept -> storage_type&
761761
{
762-
return m_data;
762+
return m_storage;
763763
}
764764

765765
template <class T>
766766
inline auto pyarray<T>::storage_impl() const noexcept -> const storage_type&
767767
{
768-
return m_data;
768+
return m_storage;
769769
}
770770
}
771771

include/xtensor-python/pycontainer.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,17 @@ namespace xt
358358
inline layout_type pycontainer<D>::layout() const
359359
{
360360
if (PyArray_CHKFLAGS(python_array(), NPY_ARRAY_C_CONTIGUOUS))
361+
{
361362
return layout_type::row_major;
363+
}
362364
else if (PyArray_CHKFLAGS(python_array(), NPY_ARRAY_F_CONTIGUOUS))
365+
{
363366
return layout_type::column_major;
367+
}
364368
else
369+
{
365370
return layout_type::dynamic;
371+
}
366372
}
367373

368374
/**

include/xtensor-python/pytensor.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ namespace xt
191191
inner_shape_type m_shape;
192192
inner_strides_type m_strides;
193193
inner_backstrides_type m_backstrides;
194-
storage_type m_data;
194+
storage_type m_storage;
195195

196196
void init_tensor(const shape_type& shape, const strides_type& strides);
197197
void init_from_python();
@@ -228,7 +228,7 @@ namespace xt
228228
m_shape = xtl::make_sequence<shape_type>(N, size_type(1));
229229
m_strides = xtl::make_sequence<strides_type>(N, size_type(0));
230230
init_tensor(m_shape, m_strides);
231-
m_data[0] = T();
231+
m_storage[0] = T();
232232
}
233233

234234
/**
@@ -239,7 +239,7 @@ namespace xt
239239
: base_type()
240240
{
241241
base_type::resize(xt::shape<shape_type>(t), layout_type::row_major);
242-
nested_copy(m_data.begin(), t);
242+
nested_copy(m_storage.begin(), t);
243243
}
244244

245245
template <class T, std::size_t N>
@@ -290,7 +290,7 @@ namespace xt
290290
{
291291
compute_strides(shape, l, m_strides);
292292
init_tensor(shape, m_strides);
293-
std::fill(m_data.begin(), m_data.end(), value);
293+
std::fill(m_storage.begin(), m_storage.end(), value);
294294
}
295295

296296
/**
@@ -306,7 +306,7 @@ namespace xt
306306
const_reference value)
307307
{
308308
init_tensor(shape, strides);
309-
std::fill(m_data.begin(), m_data.end(), value);
309+
std::fill(m_storage.begin(), m_storage.end(), value);
310310
}
311311

312312
/**
@@ -417,8 +417,8 @@ namespace xt
417417
m_shape = shape;
418418
m_strides = strides;
419419
adapt_strides(m_shape, m_strides, m_backstrides);
420-
m_data = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
421-
static_cast<size_type>(PyArray_SIZE(this->python_array())));
420+
m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
421+
static_cast<size_type>(PyArray_SIZE(this->python_array())));
422422
}
423423

424424
template <class T, std::size_t N>
@@ -433,8 +433,8 @@ namespace xt
433433
std::transform(PyArray_STRIDES(this->python_array()), PyArray_STRIDES(this->python_array()) + N, m_strides.begin(),
434434
[](auto v) { return v / sizeof(T); });
435435
adapt_strides(m_shape, m_strides, m_backstrides);
436-
m_data = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
437-
this->get_min_stride() * static_cast<size_type>(PyArray_SIZE(this->python_array())));
436+
m_storage = storage_type(reinterpret_cast<pointer>(PyArray_DATA(this->python_array())),
437+
this->get_min_stride() * static_cast<size_type>(PyArray_SIZE(this->python_array())));
438438
}
439439

440440
template <class T, std::size_t N>
@@ -476,13 +476,13 @@ namespace xt
476476
template <class T, std::size_t N>
477477
inline auto pytensor<T, N>::storage_impl() noexcept -> storage_type&
478478
{
479-
return m_data;
479+
return m_storage;
480480
}
481481

482482
template <class T, std::size_t N>
483483
inline auto pytensor<T, N>::storage_impl() const noexcept -> const storage_type&
484484
{
485-
return m_data;
485+
return m_storage;
486486
}
487487
}
488488

include/xtensor-python/xtensor_type_caster_base.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#ifndef XTENSOR_TYPE_CASTER_HPP
1616
#define XTENSOR_TYPE_CASTER_HPP
1717

18+
#include <cstddef>
19+
#include <algorithm>
20+
#include <vector>
21+
1822
#include "xtensor/xtensor.hpp"
1923

2024
#include <pybind11/numpy.h>
@@ -24,17 +28,20 @@ namespace pybind11
2428
{
2529
namespace detail
2630
{
27-
// Casts an xtensor (or xarray) type to numpy array. If given a base, the numpy array references the src data,
28-
// otherwise it'll make a copy. writeable lets you turn off the writeable flag for the array.
31+
// Casts an xtensor (or xarray) type to numpy array.If given a base,
32+
// the numpy array references the src data, otherwise it'll make a copy.
33+
// The writeable attributes lets you specify writeable flag for the array.
2934
template <typename Type>
30-
handle xtensor_array_cast(Type const& src, handle base = handle(), bool writeable = true)
35+
handle xtensor_array_cast(const Type& src, handle base = handle(), bool writeable = true)
3136
{
3237
// TODO: make use of xt::pyarray instead of array.
33-
std::vector<size_t> python_strides(src.strides().size());
34-
std::transform(src.strides().begin(), src.strides().end(), python_strides.begin(),
35-
[](auto v) { return sizeof(typename Type::value_type) * v; });
38+
std::vector<std::size_t> python_strides(src.strides().size());
39+
std::transform(src.strides().begin(), src.strides().end(),
40+
python_strides.begin(), [](auto v) {
41+
return sizeof(typename Type::value_type) * v;
42+
});
3643

37-
std::vector<size_t> python_shape(src.shape().size());
44+
std::vector<std::size_t> python_shape(src.shape().size());
3845
std::copy(src.shape().begin(), src.shape().end(), python_shape.begin());
3946

4047
array a(python_shape, python_strides, src.begin(), base);

0 commit comments

Comments
 (0)