@@ -73,7 +73,7 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
73
73
public:
74
74
CIndexer_vector (int dim) : nd(dim) {}
75
75
76
- template <class ShapeTy > indT size (ShapeTy shape) const
76
+ template <class ShapeTy > indT size (const ShapeTy & shape) const
77
77
{
78
78
indT s = static_cast <indT>(1 );
79
79
for (int i = 0 ; i < nd; ++i) {
@@ -83,8 +83,10 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
83
83
}
84
84
85
85
template <class ShapeTy , class StridesTy >
86
- void
87
- get_displacement (indT i, ShapeTy shape, StridesTy stride, indT &disp) const
86
+ void get_displacement (const indT i,
87
+ const ShapeTy &shape,
88
+ const StridesTy &stride,
89
+ indT &disp) const
88
90
{
89
91
if (nd == 1 ) {
90
92
disp = i * stride[0 ];
@@ -104,10 +106,10 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
104
106
}
105
107
106
108
template <class ShapeTy , class StridesTy >
107
- void get_displacement (indT i,
108
- ShapeTy shape,
109
- StridesTy stride1,
110
- StridesTy stride2,
109
+ void get_displacement (const indT i,
110
+ const ShapeTy & shape,
111
+ const StridesTy & stride1,
112
+ const StridesTy & stride2,
111
113
indT &disp1,
112
114
indT &disp2) const
113
115
{
@@ -133,11 +135,11 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
133
135
}
134
136
135
137
template <class ShapeTy , class StridesTy >
136
- void get_displacement (indT i,
137
- ShapeTy shape,
138
- StridesTy stride1,
139
- StridesTy stride2,
140
- StridesTy stride3,
138
+ void get_displacement (const indT i,
139
+ const ShapeTy & shape,
140
+ const StridesTy & stride1,
141
+ const StridesTy & stride2,
142
+ const StridesTy & stride3,
141
143
indT &disp1,
142
144
indT &disp2,
143
145
indT &disp3) const
@@ -167,12 +169,12 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
167
169
}
168
170
169
171
template <class ShapeTy , class StridesTy >
170
- void get_displacement (indT i,
171
- ShapeTy shape,
172
- StridesTy stride1,
173
- StridesTy stride2,
174
- StridesTy stride3,
175
- StridesTy stride4,
172
+ void get_displacement (const indT i,
173
+ const ShapeTy & shape,
174
+ const StridesTy & stride1,
175
+ const StridesTy & stride2,
176
+ const StridesTy & stride3,
177
+ const StridesTy & stride4,
176
178
indT &disp1,
177
179
indT &disp2,
178
180
indT &disp3,
@@ -206,9 +208,9 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
206
208
}
207
209
208
210
template <class ShapeTy , class StridesTy , int nstrides>
209
- void get_displacement (indT i,
210
- ShapeTy shape,
211
- const std::array<StridesTy, nstrides> strides,
211
+ void get_displacement (const indT i,
212
+ const ShapeTy & shape,
213
+ const std::array<StridesTy, nstrides> & strides,
212
214
std::array<indT, nstrides> &disps) const
213
215
{
214
216
if (nd == 1 ) {
@@ -240,14 +242,14 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
240
242
}
241
243
242
244
template <class ShapeTy , class StridesTy >
243
- void get_left_rolled_displacement (indT i,
244
- ShapeTy shape,
245
- StridesTy stride,
246
- StridesTy shifts,
245
+ void get_left_rolled_displacement (const indT i,
246
+ const ShapeTy & shape,
247
+ const StridesTy & stride,
248
+ const StridesTy & shifts,
247
249
indT &disp) const
248
250
{
249
251
indT i_ = i;
250
- indT d = 0 ;
252
+ indT d ( 0 ) ;
251
253
for (int dim = nd; --dim > 0 ;) {
252
254
const indT si = shape[dim];
253
255
const indT q = i_ / si;
@@ -275,7 +277,7 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
275
277
276
278
template <int _ndim, typename indT = std::ptrdiff_t > class CIndexer_array
277
279
{
278
- static const int ndim = _ndim;
280
+ static constexpr int ndim = _ndim;
279
281
280
282
static_assert (std::is_integral<indT>::value, " Integral type is required" );
281
283
static_assert (std::is_signed<indT>::value,
@@ -295,7 +297,7 @@ template <int _ndim, typename indT = std::ptrdiff_t> class CIndexer_array
295
297
explicit CIndexer_array (const index_t &input_shape)
296
298
: elem_count(0 ), shape{}, multi_index{}
297
299
{
298
- indT s = static_cast <std:: ptrdiff_t > (1 );
300
+ indT s (1 );
299
301
for (int i = 0 ; i < ndim; ++i) {
300
302
shape[i] = input_shape[i];
301
303
s *= input_shape[i];
@@ -312,7 +314,7 @@ template <int _ndim, typename indT = std::ptrdiff_t> class CIndexer_array
312
314
return ndim;
313
315
}
314
316
315
- void set (indT i)
317
+ void set (const indT i)
316
318
{
317
319
if (ndim == 1 ) {
318
320
multi_index[0 ] = i;
@@ -366,7 +368,7 @@ int simplify_iteration_stride(const int nd,
366
368
StridesTy *strides,
367
369
StridesTy &disp)
368
370
{
369
- disp = std::ptrdiff_t (0 );
371
+ disp = StridesTy (0 );
370
372
if (nd < 2 )
371
373
return nd;
372
374
@@ -451,8 +453,8 @@ int simplify_iteration_two_strides(const int nd,
451
453
StridesTy &disp1,
452
454
StridesTy &disp2)
453
455
{
454
- disp1 = std::ptrdiff_t (0 );
455
- disp2 = std::ptrdiff_t (0 );
456
+ disp1 = StridesTy (0 );
457
+ disp2 = StridesTy (0 );
456
458
if (nd < 2 )
457
459
return nd;
458
460
@@ -603,8 +605,8 @@ int simplify_iteration_three_strides(const int nd,
603
605
StridesTy &disp2,
604
606
StridesTy &disp3)
605
607
{
606
- disp1 = std::ptrdiff_t (0 );
607
- disp2 = std::ptrdiff_t (0 );
608
+ disp1 = StridesTy (0 );
609
+ disp2 = StridesTy (0 );
608
610
if (nd < 2 )
609
611
return nd;
610
612
@@ -768,8 +770,8 @@ int simplify_iteration_four_strides(const int nd,
768
770
StridesTy &disp3,
769
771
StridesTy &disp4)
770
772
{
771
- disp1 = std::ptrdiff_t (0 );
772
- disp2 = std::ptrdiff_t (0 );
773
+ disp1 = StridesTy (0 );
774
+ disp2 = StridesTy (0 );
773
775
if (nd < 2 )
774
776
return nd;
775
777
0 commit comments