@@ -33,7 +33,7 @@ and the rest of the library
33
33
"""
34
34
35
35
import dpnp
36
- from dpnp.dpnp_utils cimport *
36
+ cimport dpnp.dpnp_utils as utils
37
37
from dpnp.dpnp_algo cimport *
38
38
from dpnp.dparray cimport dparray, dparray_shape_type
39
39
import numpy
@@ -63,24 +63,19 @@ ctypedef void(*custom_linalg_1in_3out_shape_t)(void * , void * , void * , void *
63
63
ctypedef void (* custom_linalg_2in_1out_func_ptr_t)(void * , void * , void * , size_t )
64
64
65
65
66
- cpdef dparray dpnp_cholesky(dparray input ):
67
- if input .dtype == dpnp.int32 or input .dtype == dpnp.int64:
68
- input_ = input .astype(dpnp.float64)
69
- else :
70
- input_ = input
71
-
66
+ cpdef utils.dpnp_descriptor dpnp_cholesky(utils.dpnp_descriptor input_):
72
67
size_ = input_.shape[- 1 ]
73
68
74
69
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input_.dtype)
75
70
76
71
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_CHOLESKY, param1_type, param1_type)
77
72
78
- result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
79
- cdef dparray result = dparray (input_.shape, dtype = result_type )
73
+ # ceate result array with type given by FPTR data
74
+ cdef utils.dpnp_descriptor result = utils.create_output_descriptor (input_.shape, kernel_data.return_type, None )
80
75
81
76
cdef custom_linalg_1in_1out_with_2size_func_ptr_t_ func = < custom_linalg_1in_1out_with_2size_func_ptr_t_ > kernel_data.ptr
82
77
83
- func(input_.get_data(), result.get_data(), input .size, size_)
78
+ func(input_.get_data(), result.get_data(), input_ .size, size_)
84
79
85
80
return result
86
81
@@ -108,30 +103,31 @@ cpdef dparray dpnp_cond(dparray input, p):
108
103
return ret
109
104
110
105
111
- cpdef dparray dpnp_det(dparray input ):
106
+ cpdef utils.dpnp_descriptor dpnp_det(utils.dpnp_descriptor input ):
107
+ cdef dparray_shape_type input_shape = input .shape
112
108
cdef size_t n = input .shape[- 1 ]
113
109
cdef size_t size_out = 1
114
110
if input .ndim != 2 :
115
111
output_shape = tuple ((list (input .shape))[:- 2 ])
116
112
for i in range (len (output_shape)):
117
113
size_out *= output_shape[i]
118
114
115
+ cdef dparray_shape_type result_shape = (size_out,)
116
+ if size_out > 1 :
117
+ result_shape = output_shape
118
+
119
119
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input .dtype)
120
120
121
121
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_DET, param1_type, param1_type)
122
122
123
- result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
124
- cdef dparray result = dparray(size_out, dtype = result_type )
123
+ # ceate result array with type given by FPTR data
124
+ cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None )
125
125
126
126
cdef custom_linalg_1in_1out_func_ptr_t func = < custom_linalg_1in_1out_func_ptr_t > kernel_data.ptr
127
127
128
- func(input .get_data(), result.get_data(), < size_t * > input ._dparray_shape .data(), input .ndim)
128
+ func(input .get_data(), result.get_data(), < size_t * > input_shape .data(), input .ndim)
129
129
130
- if size_out > 1 :
131
- dpnp_result = result.reshape(output_shape)
132
- return dpnp_result
133
- else :
134
- return result
130
+ return result
135
131
136
132
137
133
cpdef tuple dpnp_eig(dparray x1):
@@ -154,17 +150,16 @@ cpdef tuple dpnp_eig(dparray x1):
154
150
return (res_val, res_vec)
155
151
156
152
157
- cpdef dparray dpnp_eigvals(dparray input ):
153
+ cpdef utils.dpnp_descriptor dpnp_eigvals(utils.dpnp_descriptor input ):
158
154
cdef dparray_shape_type input_shape = input .shape
159
155
160
156
cdef size_t size = 0 if input_shape.empty() else input_shape.front()
161
157
162
158
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input .dtype)
163
159
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_EIGVALS, param1_type, param1_type)
164
160
165
- result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
166
-
167
- cdef dparray res_val = dparray((size,), dtype = result_type)
161
+ # ceate result array with type given by FPTR data
162
+ cdef utils.dpnp_descriptor res_val = utils.create_output_descriptor((size,), kernel_data.return_type, None )
168
163
169
164
cdef custom_linalg_1in_1out_with_size_func_ptr_t_ func = < custom_linalg_1in_1out_with_size_func_ptr_t_ > kernel_data.ptr
170
165
# call FPTR function
@@ -175,6 +170,8 @@ cpdef dparray dpnp_eigvals(dparray input):
175
170
176
171
cpdef dparray dpnp_inv(dparray input_):
177
172
cdef dparray input = input_.astype(dpnp.float64)
173
+ cdef dparray_shape_type input_shape = input .shape
174
+
178
175
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input .dtype)
179
176
180
177
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_INV, param1_type, param1_type)
@@ -183,23 +180,24 @@ cpdef dparray dpnp_inv(dparray input_):
183
180
184
181
cdef custom_linalg_1in_1out_func_ptr_t func = < custom_linalg_1in_1out_func_ptr_t > kernel_data.ptr
185
182
186
- func(input .get_data(), result.get_data(), < size_t * > input ._dparray_shape .data(), input .ndim)
183
+ func(input .get_data(), result.get_data(), < size_t * > input_shape .data(), input .ndim)
187
184
188
185
dpnp_result = result.reshape(input .shape)
189
186
return dpnp_result
190
187
191
188
192
- cpdef dparray dpnp_matrix_rank(dparray input ):
189
+ cpdef utils.dpnp_descriptor dpnp_matrix_rank(utils.dpnp_descriptor input ):
190
+ cdef dparray_shape_type input_shape = input .shape
193
191
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input .dtype)
194
192
195
193
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_MATRIX_RANK, param1_type, param1_type)
196
194
197
- result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
198
- cdef dparray result = dparray ((1 ,), dtype = result_type )
195
+ # ceate result array with type given by FPTR data
196
+ cdef utils.dpnp_descriptor result = utils.create_output_descriptor ((1 ,), kernel_data.return_type, None )
199
197
200
198
cdef custom_linalg_1in_1out_func_ptr_t func = < custom_linalg_1in_1out_func_ptr_t > kernel_data.ptr
201
199
202
- func(input .get_data(), result.get_data(), < size_t * > input ._dparray_shape .data(), input .ndim)
200
+ func(input .get_data(), result.get_data(), < size_t * > input_shape .data(), input .ndim)
203
201
204
202
return result
205
203
0 commit comments