Skip to content

Commit e69d268

Browse files
Merge pull request #1583 from IntelPython/technical-debt-changes
Technical debt changes
2 parents 786f7fc + b030a79 commit e69d268

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines changed

dpctl/tensor/libtensor/include/utils/strided_iters.hpp

+38-36
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
7373
public:
7474
CIndexer_vector(int dim) : nd(dim) {}
7575

76-
template <class ShapeTy> indT size(ShapeTy shape) const
76+
template <class ShapeTy> indT size(const ShapeTy &shape) const
7777
{
7878
indT s = static_cast<indT>(1);
7979
for (int i = 0; i < nd; ++i) {
@@ -83,8 +83,10 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
8383
}
8484

8585
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
8890
{
8991
if (nd == 1) {
9092
disp = i * stride[0];
@@ -104,10 +106,10 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
104106
}
105107

106108
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,
111113
indT &disp1,
112114
indT &disp2) const
113115
{
@@ -133,11 +135,11 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
133135
}
134136

135137
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,
141143
indT &disp1,
142144
indT &disp2,
143145
indT &disp3) const
@@ -167,12 +169,12 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
167169
}
168170

169171
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,
176178
indT &disp1,
177179
indT &disp2,
178180
indT &disp3,
@@ -206,9 +208,9 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
206208
}
207209

208210
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,
212214
std::array<indT, nstrides> &disps) const
213215
{
214216
if (nd == 1) {
@@ -240,14 +242,14 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
240242
}
241243

242244
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,
247249
indT &disp) const
248250
{
249251
indT i_ = i;
250-
indT d = 0;
252+
indT d(0);
251253
for (int dim = nd; --dim > 0;) {
252254
const indT si = shape[dim];
253255
const indT q = i_ / si;
@@ -275,7 +277,7 @@ template <typename indT = std::ptrdiff_t> class CIndexer_vector
275277

276278
template <int _ndim, typename indT = std::ptrdiff_t> class CIndexer_array
277279
{
278-
static const int ndim = _ndim;
280+
static constexpr int ndim = _ndim;
279281

280282
static_assert(std::is_integral<indT>::value, "Integral type is required");
281283
static_assert(std::is_signed<indT>::value,
@@ -295,7 +297,7 @@ template <int _ndim, typename indT = std::ptrdiff_t> class CIndexer_array
295297
explicit CIndexer_array(const index_t &input_shape)
296298
: elem_count(0), shape{}, multi_index{}
297299
{
298-
indT s = static_cast<std::ptrdiff_t>(1);
300+
indT s(1);
299301
for (int i = 0; i < ndim; ++i) {
300302
shape[i] = input_shape[i];
301303
s *= input_shape[i];
@@ -312,7 +314,7 @@ template <int _ndim, typename indT = std::ptrdiff_t> class CIndexer_array
312314
return ndim;
313315
}
314316

315-
void set(indT i)
317+
void set(const indT i)
316318
{
317319
if (ndim == 1) {
318320
multi_index[0] = i;
@@ -366,7 +368,7 @@ int simplify_iteration_stride(const int nd,
366368
StridesTy *strides,
367369
StridesTy &disp)
368370
{
369-
disp = std::ptrdiff_t(0);
371+
disp = StridesTy(0);
370372
if (nd < 2)
371373
return nd;
372374

@@ -451,8 +453,8 @@ int simplify_iteration_two_strides(const int nd,
451453
StridesTy &disp1,
452454
StridesTy &disp2)
453455
{
454-
disp1 = std::ptrdiff_t(0);
455-
disp2 = std::ptrdiff_t(0);
456+
disp1 = StridesTy(0);
457+
disp2 = StridesTy(0);
456458
if (nd < 2)
457459
return nd;
458460

@@ -603,8 +605,8 @@ int simplify_iteration_three_strides(const int nd,
603605
StridesTy &disp2,
604606
StridesTy &disp3)
605607
{
606-
disp1 = std::ptrdiff_t(0);
607-
disp2 = std::ptrdiff_t(0);
608+
disp1 = StridesTy(0);
609+
disp2 = StridesTy(0);
608610
if (nd < 2)
609611
return nd;
610612

@@ -768,8 +770,8 @@ int simplify_iteration_four_strides(const int nd,
768770
StridesTy &disp3,
769771
StridesTy &disp4)
770772
{
771-
disp1 = std::ptrdiff_t(0);
772-
disp2 = std::ptrdiff_t(0);
773+
disp1 = StridesTy(0);
774+
disp2 = StridesTy(0);
773775
if (nd < 2)
774776
return nd;
775777

dpctl/tensor/libtensor/source/clip.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ py_clip(const dpctl::tensor::usm_ndarray &src,
225225
simplified_shape, simplified_src_strides, simplified_min_strides,
226226
simplified_max_strides, simplified_dst_strides);
227227
py::ssize_t *packed_shape_strides = std::get<0>(ptr_size_event_tuple);
228+
if (!packed_shape_strides) {
229+
throw std::runtime_error("USM-host memory allocation failure");
230+
}
228231
sycl::event copy_shape_strides_ev = std::get<2>(ptr_size_event_tuple);
229232

230233
std::vector<sycl::event> all_deps;

dpctl/tensor/libtensor/source/where.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ py_where(const dpctl::tensor::usm_ndarray &condition,
203203
simplified_shape, simplified_cond_strides, simplified_x1_strides,
204204
simplified_x2_strides, simplified_dst_strides);
205205
py::ssize_t *packed_shape_strides = std::get<0>(ptr_size_event_tuple);
206+
if (!packed_shape_strides) {
207+
throw std::runtime_error("USM-host memory allocation failure");
208+
}
206209
sycl::event copy_shape_strides_ev = std::get<2>(ptr_size_event_tuple);
207210

208211
std::vector<sycl::event> all_deps;

0 commit comments

Comments
 (0)