Skip to content

Commit 2a38192

Browse files
committed
rework implementation of diag, diagflat, vander, and ptp
1 parent 247a266 commit 2a38192

11 files changed

+405
-334
lines changed

dpnp/backend/include/dpnp_iface_fptr.hpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ enum class DPNPFuncName : size_t
132132
DPNP_FN_DET_EXT, /**< Used in numpy.linalg.det() impl, requires extra
133133
parameters */
134134
DPNP_FN_DIAG, /**< Used in numpy.diag() impl */
135-
DPNP_FN_DIAG_EXT, /**< Used in numpy.diag() impl, requires extra parameters
136-
*/
137135
DPNP_FN_DIAG_INDICES, /**< Used in numpy.diag_indices() impl */
138136
DPNP_FN_DIAG_INDICES_EXT, /**< Used in numpy.diag_indices() impl, requires
139137
extra parameters */
@@ -243,7 +241,6 @@ enum class DPNPFuncName : size_t
243241
DPNP_FN_POWER, /**< Used in numpy.power() impl */
244242
DPNP_FN_PROD, /**< Used in numpy.prod() impl */
245243
DPNP_FN_PTP, /**< Used in numpy.ptp() impl */
246-
DPNP_FN_PTP_EXT, /**< Used in numpy.ptp() impl, requires extra parameters */
247244
DPNP_FN_PUT, /**< Used in numpy.put() impl */
248245
DPNP_FN_PUT_ALONG_AXIS, /**< Used in numpy.put_along_axis() impl */
249246
DPNP_FN_PUT_ALONG_AXIS_EXT, /**< Used in numpy.put_along_axis() impl,
@@ -405,21 +402,19 @@ enum class DPNPFuncName : size_t
405402
DPNP_FN_TAKE, /**< Used in numpy.take() impl */
406403
DPNP_FN_TAN, /**< Used in numpy.tan() impl */
407404
DPNP_FN_TANH, /**< Used in numpy.tanh() impl */
408-
DPNP_FN_TRANSPOSE, /**< Used in numpy.transpose() impl */
409-
DPNP_FN_TRACE, /**< Used in numpy.trace() impl */
410-
DPNP_FN_TRACE_EXT, /**< Used in numpy.trace() impl, requires extra
411-
parameters */
412-
DPNP_FN_TRAPZ, /**< Used in numpy.trapz() impl */
413-
DPNP_FN_TRAPZ_EXT, /**< Used in numpy.trapz() impl, requires extra
414-
parameters */
415-
DPNP_FN_TRI, /**< Used in numpy.tri() impl */
416-
DPNP_FN_TRIL, /**< Used in numpy.tril() impl */
417-
DPNP_FN_TRIU, /**< Used in numpy.triu() impl */
418-
DPNP_FN_TRUNC, /**< Used in numpy.trunc() impl */
419-
DPNP_FN_VANDER, /**< Used in numpy.vander() impl */
420-
DPNP_FN_VANDER_EXT, /**< Used in numpy.vander() impl, requires extra
421-
parameters */
422-
DPNP_FN_VAR, /**< Used in numpy.var() impl */
405+
DPNP_FN_TRANSPOSE, /**< Used in numpy.transpose() impl */
406+
DPNP_FN_TRACE, /**< Used in numpy.trace() impl */
407+
DPNP_FN_TRACE_EXT, /**< Used in numpy.trace() impl, requires extra
408+
parameters */
409+
DPNP_FN_TRAPZ, /**< Used in numpy.trapz() impl */
410+
DPNP_FN_TRAPZ_EXT, /**< Used in numpy.trapz() impl, requires extra
411+
parameters */
412+
DPNP_FN_TRI, /**< Used in numpy.tri() impl */
413+
DPNP_FN_TRIL, /**< Used in numpy.tril() impl */
414+
DPNP_FN_TRIU, /**< Used in numpy.triu() impl */
415+
DPNP_FN_TRUNC, /**< Used in numpy.trunc() impl */
416+
DPNP_FN_VANDER, /**< Used in numpy.vander() impl */
417+
DPNP_FN_VAR, /**< Used in numpy.var() impl */
423418
DPNP_FN_VAR_EXT, /**< Used in numpy.var() impl, requires extra parameters */
424419
DPNP_FN_ZEROS, /**< Used in numpy.zeros() impl */
425420
DPNP_FN_ZEROS_LIKE, /**< Used in numpy.zeros_like() impl */

dpnp/backend/kernels/dpnp_krnl_arraycreation.cpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,6 @@ void (*dpnp_diag_default_c)(void *,
200200
const size_t,
201201
const size_t) = dpnp_diag_c<_DataType>;
202202

203-
template <typename _DataType>
204-
DPCTLSyclEventRef (*dpnp_diag_ext_c)(DPCTLSyclQueueRef,
205-
void *,
206-
void *,
207-
const int,
208-
shape_elem_type *,
209-
shape_elem_type *,
210-
const size_t,
211-
const size_t,
212-
const DPCTLEventVectorRef) =
213-
dpnp_diag_c<_DataType>;
214-
215203
template <typename _DataType>
216204
DPCTLSyclEventRef dpnp_eye_c(DPCTLSyclQueueRef q_ref,
217205
void *result1,
@@ -569,23 +557,6 @@ void (*dpnp_ptp_default_c)(void *,
569557
const shape_elem_type *,
570558
const size_t) = dpnp_ptp_c<_DataType>;
571559

572-
template <typename _DataType>
573-
DPCTLSyclEventRef (*dpnp_ptp_ext_c)(DPCTLSyclQueueRef,
574-
void *,
575-
const size_t,
576-
const size_t,
577-
const shape_elem_type *,
578-
const shape_elem_type *,
579-
const void *,
580-
const size_t,
581-
const size_t,
582-
const shape_elem_type *,
583-
const shape_elem_type *,
584-
const shape_elem_type *,
585-
const size_t,
586-
const DPCTLEventVectorRef) =
587-
dpnp_ptp_c<_DataType>;
588-
589560
template <typename _DataType_input, typename _DataType_output>
590561
DPCTLSyclEventRef dpnp_vander_c(DPCTLSyclQueueRef q_ref,
591562
const void *array1_in,
@@ -673,16 +644,6 @@ void (*dpnp_vander_default_c)(const void *,
673644
const int) =
674645
dpnp_vander_c<_DataType_input, _DataType_output>;
675646

676-
template <typename _DataType_input, typename _DataType_output>
677-
DPCTLSyclEventRef (*dpnp_vander_ext_c)(DPCTLSyclQueueRef,
678-
const void *,
679-
void *,
680-
const size_t,
681-
const size_t,
682-
const int,
683-
const DPCTLEventVectorRef) =
684-
dpnp_vander_c<_DataType_input, _DataType_output>;
685-
686647
template <typename _DataType, typename _ResultType>
687648
class dpnp_trace_c_kernel;
688649

@@ -1192,15 +1153,6 @@ void func_map_init_arraycreation(func_map_t &fmap)
11921153
fmap[DPNPFuncName::DPNP_FN_DIAG][eft_DBL][eft_DBL] = {
11931154
eft_DBL, (void *)dpnp_diag_default_c<double>};
11941155

1195-
fmap[DPNPFuncName::DPNP_FN_DIAG_EXT][eft_INT][eft_INT] = {
1196-
eft_INT, (void *)dpnp_diag_ext_c<int32_t>};
1197-
fmap[DPNPFuncName::DPNP_FN_DIAG_EXT][eft_LNG][eft_LNG] = {
1198-
eft_LNG, (void *)dpnp_diag_ext_c<int64_t>};
1199-
fmap[DPNPFuncName::DPNP_FN_DIAG_EXT][eft_FLT][eft_FLT] = {
1200-
eft_FLT, (void *)dpnp_diag_ext_c<float>};
1201-
fmap[DPNPFuncName::DPNP_FN_DIAG_EXT][eft_DBL][eft_DBL] = {
1202-
eft_DBL, (void *)dpnp_diag_ext_c<double>};
1203-
12041156
fmap[DPNPFuncName::DPNP_FN_EYE][eft_INT][eft_INT] = {
12051157
eft_INT, (void *)dpnp_eye_default_c<int32_t>};
12061158
fmap[DPNPFuncName::DPNP_FN_EYE][eft_LNG][eft_LNG] = {
@@ -1284,15 +1236,6 @@ void func_map_init_arraycreation(func_map_t &fmap)
12841236
fmap[DPNPFuncName::DPNP_FN_PTP][eft_DBL][eft_DBL] = {
12851237
eft_DBL, (void *)dpnp_ptp_default_c<double>};
12861238

1287-
fmap[DPNPFuncName::DPNP_FN_PTP_EXT][eft_INT][eft_INT] = {
1288-
eft_INT, (void *)dpnp_ptp_ext_c<int32_t>};
1289-
fmap[DPNPFuncName::DPNP_FN_PTP_EXT][eft_LNG][eft_LNG] = {
1290-
eft_LNG, (void *)dpnp_ptp_ext_c<int64_t>};
1291-
fmap[DPNPFuncName::DPNP_FN_PTP_EXT][eft_FLT][eft_FLT] = {
1292-
eft_FLT, (void *)dpnp_ptp_ext_c<float>};
1293-
fmap[DPNPFuncName::DPNP_FN_PTP_EXT][eft_DBL][eft_DBL] = {
1294-
eft_DBL, (void *)dpnp_ptp_ext_c<double>};
1295-
12961239
fmap[DPNPFuncName::DPNP_FN_VANDER][eft_INT][eft_INT] = {
12971240
eft_LNG, (void *)dpnp_vander_default_c<int32_t, int64_t>};
12981241
fmap[DPNPFuncName::DPNP_FN_VANDER][eft_LNG][eft_LNG] = {
@@ -1308,23 +1251,6 @@ void func_map_init_arraycreation(func_map_t &fmap)
13081251
(void *)
13091252
dpnp_vander_default_c<std::complex<double>, std::complex<double>>};
13101253

1311-
fmap[DPNPFuncName::DPNP_FN_VANDER_EXT][eft_INT][eft_INT] = {
1312-
eft_LNG, (void *)dpnp_vander_ext_c<int32_t, int64_t>};
1313-
fmap[DPNPFuncName::DPNP_FN_VANDER_EXT][eft_LNG][eft_LNG] = {
1314-
eft_LNG, (void *)dpnp_vander_ext_c<int64_t, int64_t>};
1315-
fmap[DPNPFuncName::DPNP_FN_VANDER_EXT][eft_FLT][eft_FLT] = {
1316-
eft_FLT, (void *)dpnp_vander_ext_c<float, float>};
1317-
fmap[DPNPFuncName::DPNP_FN_VANDER_EXT][eft_DBL][eft_DBL] = {
1318-
eft_DBL, (void *)dpnp_vander_ext_c<double, double>};
1319-
fmap[DPNPFuncName::DPNP_FN_VANDER_EXT][eft_BLN][eft_BLN] = {
1320-
eft_LNG, (void *)dpnp_vander_ext_c<bool, int64_t>};
1321-
fmap[DPNPFuncName::DPNP_FN_VANDER_EXT][eft_C64][eft_C64] = {
1322-
eft_C64,
1323-
(void *)dpnp_vander_ext_c<std::complex<float>, std::complex<float>>};
1324-
fmap[DPNPFuncName::DPNP_FN_VANDER_EXT][eft_C128][eft_C128] = {
1325-
eft_C128,
1326-
(void *)dpnp_vander_ext_c<std::complex<double>, std::complex<double>>};
1327-
13281254
fmap[DPNPFuncName::DPNP_FN_TRACE][eft_INT][eft_INT] = {
13291255
eft_INT, (void *)dpnp_trace_default_c<int32_t, int32_t>};
13301256
fmap[DPNPFuncName::DPNP_FN_TRACE][eft_LNG][eft_INT] = {

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
6464
DPNP_FN_DEGREES_EXT
6565
DPNP_FN_DET
6666
DPNP_FN_DET_EXT
67-
DPNP_FN_DIAG
68-
DPNP_FN_DIAG_EXT
6967
DPNP_FN_DIAG_INDICES
7068
DPNP_FN_DIAG_INDICES_EXT
7169
DPNP_FN_DIAGONAL
@@ -122,8 +120,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
122120
DPNP_FN_PARTITION
123121
DPNP_FN_PARTITION_EXT
124122
DPNP_FN_PLACE
125-
DPNP_FN_PTP
126-
DPNP_FN_PTP_EXT
127123
DPNP_FN_QR
128124
DPNP_FN_QR_EXT
129125
DPNP_FN_RADIANS
@@ -222,8 +218,6 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
222218
DPNP_FN_TRIL_EXT
223219
DPNP_FN_TRIU
224220
DPNP_FN_TRIU_EXT
225-
DPNP_FN_VANDER
226-
DPNP_FN_VANDER_EXT
227221
DPNP_FN_VAR
228222
DPNP_FN_VAR_EXT
229223
DPNP_FN_ZEROS

dpnp/dpnp_algo/dpnp_algo_arraycreation.pxi

Lines changed: 0 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ and the rest of the library
3737

3838
__all__ += [
3939
"dpnp_copy",
40-
"dpnp_diag",
41-
"dpnp_ptp",
4240
"dpnp_trace",
43-
"dpnp_vander",
4441
]
4542

4643

@@ -88,136 +85,6 @@ cpdef utils.dpnp_descriptor dpnp_copy(utils.dpnp_descriptor x1):
8885
return call_fptr_1in_1out_strides(DPNP_FN_COPY_EXT, x1)
8986

9087

91-
cpdef utils.dpnp_descriptor dpnp_diag(utils.dpnp_descriptor v, int k):
92-
cdef shape_type_c input_shape = v.shape
93-
cdef shape_type_c result_shape
94-
95-
if v.ndim == 1:
96-
n = v.shape[0] + abs(k)
97-
98-
result_shape = (n, n)
99-
else:
100-
n = min(v.shape[0], v.shape[0] + k, v.shape[1], v.shape[1] - k)
101-
if n < 0:
102-
n = 0
103-
104-
result_shape = (n, )
105-
106-
v_obj = v.get_array()
107-
108-
result_obj = dpnp_container.zeros(result_shape, dtype=v.dtype, device=v_obj.sycl_device)
109-
cdef utils.dpnp_descriptor result = dpnp_descriptor(result_obj)
110-
111-
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(v.dtype)
112-
113-
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_DIAG_EXT, param1_type, param1_type)
114-
115-
result_sycl_queue = result.get_array().sycl_queue
116-
117-
cdef c_dpctl.SyclQueue q = <c_dpctl.SyclQueue> result_sycl_queue
118-
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()
119-
120-
cdef custom_1in_1out_func_ptr_t func = <custom_1in_1out_func_ptr_t > kernel_data.ptr
121-
122-
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
123-
v.get_data(),
124-
result.get_data(),
125-
k,
126-
input_shape.data(),
127-
result_shape.data(),
128-
v.ndim,
129-
result.ndim,
130-
NULL) # dep_events_ref
131-
132-
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
133-
c_dpctl.DPCTLEvent_Delete(event_ref)
134-
135-
return result
136-
137-
138-
cpdef dpnp_ptp(utils.dpnp_descriptor arr, axis=None):
139-
cdef shape_type_c shape_arr = arr.shape
140-
cdef shape_type_c output_shape
141-
if axis is None:
142-
axis_ = axis
143-
output_shape = (1,)
144-
else:
145-
if isinstance(axis, int):
146-
if axis < 0:
147-
axis_ = tuple([arr.ndim - axis])
148-
else:
149-
axis_ = tuple([axis])
150-
else:
151-
_axis_ = []
152-
for i in range(len(axis)):
153-
if axis[i] < 0:
154-
_axis_.append(arr.ndim - axis[i])
155-
else:
156-
_axis_.append(axis[i])
157-
axis_ = tuple(_axis_)
158-
159-
out_shape = []
160-
ind = 0
161-
for id, shape_axis in enumerate(shape_arr):
162-
if id not in axis_:
163-
out_shape.append(shape_axis)
164-
output_shape = tuple(out_shape)
165-
166-
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(arr.dtype)
167-
168-
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_PTP_EXT, param1_type, param1_type)
169-
170-
arr_obj = arr.get_array()
171-
172-
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(output_shape,
173-
kernel_data.return_type,
174-
None,
175-
device=arr_obj.sycl_device,
176-
usm_type=arr_obj.usm_type,
177-
sycl_queue=arr_obj.sycl_queue)
178-
179-
cdef shape_type_c axis1
180-
cdef Py_ssize_t axis_size = 0
181-
cdef shape_type_c axis2 = axis1
182-
if axis_ is not None:
183-
axis1 = axis_
184-
axis2.reserve(len(axis1))
185-
for shape_it in axis1:
186-
if shape_it < 0:
187-
raise ValueError("DPNP dparray::__init__(): Negative values in 'shape' are not allowed")
188-
axis2.push_back(shape_it)
189-
axis_size = len(axis1)
190-
191-
cdef shape_type_c result_strides = utils.strides_to_vector(result.strides, result.shape)
192-
cdef shape_type_c arr_strides = utils.strides_to_vector(arr.strides, arr.shape)
193-
194-
result_sycl_queue = result.get_array().sycl_queue
195-
196-
cdef c_dpctl.SyclQueue q = <c_dpctl.SyclQueue> result_sycl_queue
197-
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()
198-
199-
cdef custom_arraycreation_1in_1out_func_ptr_t func = <custom_arraycreation_1in_1out_func_ptr_t > kernel_data.ptr
200-
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
201-
result.get_data(),
202-
result.size,
203-
result.ndim,
204-
output_shape.data(),
205-
result_strides.data(),
206-
arr.get_data(),
207-
arr.size,
208-
arr.ndim,
209-
shape_arr.data(),
210-
arr_strides.data(),
211-
axis2.data(),
212-
axis_size,
213-
NULL) # dep_events_ref
214-
215-
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
216-
c_dpctl.DPCTLEvent_Delete(event_ref)
217-
218-
return result
219-
220-
22188
cpdef utils.dpnp_descriptor dpnp_trace(utils.dpnp_descriptor arr, offset=0, axis1=0, axis2=1, dtype=None, out=None):
22289
if dtype is None:
22390
dtype_ = arr.dtype
@@ -262,38 +129,3 @@ cpdef utils.dpnp_descriptor dpnp_trace(utils.dpnp_descriptor arr, offset=0, axis
262129
c_dpctl.DPCTLEvent_Delete(event_ref)
263130

264131
return result
265-
266-
267-
cpdef utils.dpnp_descriptor dpnp_vander(utils.dpnp_descriptor x1, int N, int increasing):
268-
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
269-
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_VANDER_EXT, param1_type, DPNP_FT_NONE)
270-
271-
x1_obj = x1.get_array()
272-
273-
# create result array with type given by FPTR data
274-
cdef shape_type_c result_shape = (x1.size, N)
275-
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape,
276-
kernel_data.return_type,
277-
None,
278-
device=x1_obj.sycl_device,
279-
usm_type=x1_obj.usm_type,
280-
sycl_queue=x1_obj.sycl_queue)
281-
282-
result_sycl_queue = result.get_array().sycl_queue
283-
284-
cdef c_dpctl.SyclQueue q = <c_dpctl.SyclQueue> result_sycl_queue
285-
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()
286-
287-
cdef ftpr_custom_vander_1in_1out_t func = <ftpr_custom_vander_1in_1out_t > kernel_data.ptr
288-
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
289-
x1.get_data(),
290-
result.get_data(),
291-
x1.size,
292-
N,
293-
increasing,
294-
NULL) # dep_events_ref
295-
296-
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
297-
c_dpctl.DPCTLEvent_Delete(event_ref)
298-
299-
return result

0 commit comments

Comments
 (0)