Skip to content

Commit 915236e

Browse files
committed
Changes according to review
1 parent e2ffd62 commit 915236e

2 files changed

Lines changed: 20 additions & 22 deletions

File tree

include/xtensor/xchunked_array.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ namespace xt
184184
template<class E>
185185
constexpr bool is_chunked(const xexpression<E>& e);
186186

187+
template<class E>
188+
constexpr bool is_chunked();
189+
187190
/**
188191
* Creates an in-memory chunked array.
189192
* This function returns an uninitialized ``xchunked_array<xarray<T>>``.
@@ -286,6 +289,12 @@ namespace xt
286289

287290
template<class E>
288291
constexpr bool is_chunked(const xexpression<E>&)
292+
{
293+
return is_chunked<E>();
294+
}
295+
296+
template<class E>
297+
constexpr bool is_chunked()
289298
{
290299
using return_type = typename detail::chunk_helper<E>::is_chunked;
291300
return return_type::value;

include/xtensor/xchunked_view.hpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,11 @@
1515
#include "xnoalias.hpp"
1616
#include "xstorage.hpp"
1717
#include "xstrided_view.hpp"
18+
#include "xchunked_array.hpp"
1819

1920
namespace xt
2021
{
2122

22-
// SFINAE test if chunked
23-
template <typename T>
24-
class has_chunks
25-
{
26-
private:
27-
typedef char YesType[1];
28-
typedef char NoType[2];
29-
30-
template <typename C> static YesType& test(decltype(&C::chunk_shape));
31-
template <typename C> static NoType& test(...);
32-
33-
public:
34-
enum { value = sizeof(test<T>(0)) == sizeof(YesType) };
35-
};
36-
3723
/*****************
3824
* xchunked_view *
3925
*****************/
@@ -45,7 +31,7 @@ namespace xt
4531
class xchunked_view
4632
{
4733
public:
48-
34+
4935
using self_type = xchunked_view<E>;
5036
using expression_type = std::decay_t<E>;
5137
using value_type = typename expression_type::value_type;
@@ -63,10 +49,10 @@ namespace xt
6349
xchunked_view(OE&& e, S&& chunk_shape);
6450

6551
template <class OE>
66-
typename std::enable_if<!has_chunks<OE>::value, xchunked_view<E>&>::type operator=(const OE& e);
52+
typename std::enable_if<!is_chunked<OE>(), xchunked_view<E>&>::type operator=(const OE& e);
6753

6854
template <class OE>
69-
typename std::enable_if<has_chunks<OE>::value, xchunked_view<E>&>::type operator=(const OE& e);
55+
typename std::enable_if<is_chunked<OE>(), xchunked_view<E>&>::type operator=(const OE& e);
7056

7157
size_type dimension() const noexcept;
7258
const shape_type& shape() const noexcept;
@@ -132,9 +118,10 @@ namespace xt
132118

133119
template <class E>
134120
template <class OE>
135-
typename std::enable_if<!has_chunks<OE>::value, xchunked_view<E>&>::type xchunked_view<E>::operator=(const OE& e)
121+
typename std::enable_if<!is_chunked<OE>(), xchunked_view<E>&>::type xchunked_view<E>::operator=(const OE& e)
136122
{
137-
for (auto it = chunk_begin(); it != chunk_end(); it++)
123+
auto end = chunk_end();
124+
for (auto it = chunk_begin(); it != end; ++it)
138125
{
139126
auto el = *it;
140127
noalias(el) = strided_view(e, it.get_slice_vector());
@@ -144,9 +131,11 @@ namespace xt
144131

145132
template <class E>
146133
template <class OE>
147-
typename std::enable_if<has_chunks<OE>::value, xchunked_view<E>&>::type xchunked_view<E>::operator=(const OE& e)
134+
typename std::enable_if<is_chunked<OE>(), xchunked_view<E>&>::type xchunked_view<E>::operator=(const OE& e)
148135
{
149-
for (auto it1 = chunk_begin(), it2 = e.chunks().begin(); it1 != chunk_end(); it1++, it2++)
136+
auto it2 = e.chunks().begin();
137+
auto end1 = chunk_end();
138+
for (auto it1 = chunk_begin(); it1 != end1; ++it1, ++it2)
150139
{
151140
auto el1 = *it1;
152141
auto el2 = *it2;

0 commit comments

Comments
 (0)