Skip to content

Commit c79ad0c

Browse files
authored
move dparray from algo.pxd (#855)
1 parent 6badbb5 commit c79ad0c

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

dpnp/dparray.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ from dpnp.dpnp_iface import *
4242
# to avoid interference with Python internal functions
4343
from dpnp.dpnp_iface import sum as iface_sum
4444
from dpnp.dpnp_iface import prod as iface_prod
45+
from dpnp.dpnp_iface import get_dpnp_descriptor as iface_get_dpnp_descriptor
4546

4647
from dpnp.dpnp_algo cimport *
4748
from dpnp.dpnp_iface_statistics import min, max # TODO do the same as for iface_sum
@@ -514,7 +515,8 @@ cdef class dparray:
514515
if order == 'F':
515516
return self.transpose().reshape(self.size)
516517
517-
return dpnp_flatten(self)
518+
self_desc = iface_get_dpnp_descriptor(self)
519+
return dpnp_flatten(self_desc).get_pyobj()
518520
519521
result = utils.dp2nd_array(self).flatten(order=order)
520522
@@ -799,7 +801,8 @@ cdef class dparray:
799801
elif self.dtype == numpy.complex64 or dtype == numpy.complex64:
800802
pass
801803
else:
802-
return dpnp_astype(self, dtype)
804+
self_desc = iface_get_dpnp_descriptor(self)
805+
return dpnp_astype(self_desc, dtype).get_pyobj()
803806
804807
result = utils.dp2nd_array(self).astype(dtype=dtype, order=order, casting=casting, subok=subok, copy=copy)
805808

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from libcpp.vector cimport vector
2929
from libcpp cimport bool as cpp_bool
30-
from dpnp.dparray cimport dparray
30+
3131
from dpnp.dpnp_utils.dpnp_algo_utils cimport dpnp_descriptor
3232

3333

@@ -235,8 +235,8 @@ ctypedef void(*fptr_2in_1out_t)(void * , const void * , const size_t, const long
235235
ctypedef void(*fptr_blas_gemm_2in_1out_t)(void *, void * , void * , size_t, size_t, size_t)
236236
ctypedef void(*dpnp_reduction_c_t)(void *, const void * , const size_t*, const size_t, const long*, const size_t, const void * , const long*)
237237

238-
cpdef dparray dpnp_astype(dparray array1, dtype_target)
239-
cpdef dparray dpnp_flatten(dparray array1)
238+
cpdef dpnp_descriptor dpnp_astype(dpnp_descriptor array1, dtype)
239+
cpdef dpnp_descriptor dpnp_flatten(dpnp_descriptor array1)
240240

241241

242242
"""

dpnp/dpnp_algo/dpnp_algo.pyx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import dpnp.dpnp_utils as utils_py
3939
import numpy
4040

4141
cimport cpython
42+
from dpnp.dparray cimport dparray
4243
cimport dpnp.dpnp_utils as utils
4344
cimport numpy
4445

@@ -123,28 +124,30 @@ cpdef utils.dpnp_descriptor dpnp_array(object obj, object dtype=None):
123124
return result
124125

125126

126-
cpdef dparray dpnp_astype(dparray array1, dtype_target):
127+
cpdef utils.dpnp_descriptor dpnp_astype(utils.dpnp_descriptor array1, dtype):
127128
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(array1.dtype)
128-
cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(dtype_target)
129+
cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(dtype)
129130

130131
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_ASTYPE, param1_type, param2_type)
131132

132-
result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
133-
cdef dparray result = dparray(array1.shape, dtype=result_type)
133+
# ceate result array with type given by FPTR data
134+
cdef shape_type_c result_shape = array1.shape
135+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None)
134136

135137
cdef fptr_dpnp_astype_t func = <fptr_dpnp_astype_t > kernel_data.ptr
136138
func(array1.get_data(), result.get_data(), array1.size)
137139

138140
return result
139141

140142

141-
cpdef dparray dpnp_flatten(dparray array_):
143+
cpdef utils.dpnp_descriptor dpnp_flatten(utils.dpnp_descriptor array_):
142144
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(array_.dtype)
143145

144146
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_FLATTEN, param1_type, param1_type)
145147

146-
result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
147-
cdef dparray result = dparray(array_.size, dtype=result_type)
148+
# ceate result array with type given by FPTR data
149+
cdef shape_type_c result_shape = (array_.size,)
150+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None)
148151

149152
cdef fptr_dpnp_flatten_t func = <fptr_dpnp_flatten_t > kernel_data.ptr
150153
func(array_.get_data(), result.get_data(), array_.size)

dpnp/dpnp_iface_manipulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def ravel(x1, order='C'):
419419

420420
x1_desc = dpnp.get_dpnp_descriptor(x1)
421421
if x1_desc:
422-
return dpnp_flatten(x1)
422+
return dpnp_flatten(x1_desc).get_pyobj()
423423

424424
return call_origin(numpy.ravel, x1, order=order)
425425

0 commit comments

Comments
 (0)