Skip to content

Commit 36ae9e6

Browse files
authored
linalg module to descriptor completed (#865)
1 parent 540d1ad commit 36ae9e6

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

dpnp/dpnp_algo/dpnp_algo_linearalgebra.pyx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ cpdef utils.dpnp_descriptor dpnp_dot(utils.dpnp_descriptor in_array1, utils.dpnp
7777
if size1 != size2:
7878
utils.checker_throw_runtime_error("dpnp_dot", "input vectors must be of equal size")
7979

80-
# convert string type names (dparray.dtype) to C enum DPNPFuncType
80+
# convert string type names (array.dtype) to C enum DPNPFuncType
8181
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(in_array1.dtype)
8282
cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(in_array2.dtype)
8383

@@ -104,7 +104,7 @@ cpdef utils.dpnp_descriptor dpnp_dot(utils.dpnp_descriptor in_array1, utils.dpnp
104104
return result
105105

106106

107-
cpdef dparray dpnp_inner(dpnp_descriptor array1, dpnp_descriptor array2):
107+
cpdef utils.dpnp_descriptor dpnp_inner(dpnp_descriptor array1, dpnp_descriptor array2):
108108
result_type = numpy.promote_types(array1.dtype, array1.dtype)
109109

110110
assert(len(array1.shape) == len(array2.shape))
@@ -115,7 +115,8 @@ cpdef dparray dpnp_inner(dpnp_descriptor array1, dpnp_descriptor array2):
115115
cdef shape_type_c result_shape = array1_no_last_axes
116116
result_shape.insert(result_shape.end(), array2_no_last_axes.begin(), array2_no_last_axes.end())
117117

118-
cdef dparray result = dparray(result_shape, dtype=result_type)
118+
# ceate result array with type given by FPTR data
119+
cdef utils.dpnp_descriptor result = utils_py.create_output_descriptor_py(result_shape, result_type, None)
119120

120121
# calculate input arrays offsets
121122
cdef shape_type_c array1_offsets = [1] * len(array1.shape)
@@ -157,14 +158,14 @@ cpdef dparray dpnp_inner(dpnp_descriptor array1, dpnp_descriptor array2):
157158
array2_lin_index_base += array2_offsets[axis] * xyz[axis2]
158159

159160
# do inner product
160-
result[idx1] = 0
161+
result.get_pyobj()[idx1] = 0
161162
for idx2 in range(array1.shape[-1]):
162-
result[idx1] += array1[array1_lin_index_base + idx2] * array2[array2_lin_index_base + idx2]
163+
result.get_pyobj()[idx1] += array1.get_pyobj()[array1_lin_index_base + idx2] * array2.get_pyobj()[array2_lin_index_base + idx2]
163164

164165
return result
165166

166167

167-
cpdef dparray dpnp_kron(dpnp_descriptor in_array1, dpnp_descriptor in_array2):
168+
cpdef utils.dpnp_descriptor dpnp_kron(dpnp_descriptor in_array1, dpnp_descriptor in_array2):
168169
cdef size_t ndim = max(in_array1.ndim, in_array2.ndim)
169170

170171
cdef shape_type_c in_array1_shape
@@ -185,16 +186,15 @@ cpdef dparray dpnp_kron(dpnp_descriptor in_array1, dpnp_descriptor in_array2):
185186
for i in range(ndim):
186187
result_shape.push_back(in_array1_shape[i] * in_array2_shape[i])
187188

188-
# convert string type names (dparray.dtype) to C enum DPNPFuncType
189+
# convert string type names (array.dtype) to C enum DPNPFuncType
189190
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(in_array1.dtype)
190191
cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(in_array2.dtype)
191192

192193
# get the FPTR data structure
193194
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_KRON, param1_type, param2_type)
194195

195-
result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type)
196196
# ceate result array with type given by FPTR data
197-
cdef dparray result = dparray(result_shape, dtype=result_type)
197+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape, kernel_data.return_type, None)
198198

199199
cdef fptr_2in_1out_shapes_t func = <fptr_2in_1out_shapes_t > kernel_data.ptr
200200
# call FPTR function
@@ -257,7 +257,7 @@ cpdef utils.dpnp_descriptor dpnp_matmul(utils.dpnp_descriptor in_array1, utils.d
257257
"""
258258
shape_result = shape1[:-1] + shape2[1:]
259259

260-
# convert string type names (dparray.dtype) to C enum DPNPFuncType
260+
# convert string type names (array.dtype) to C enum DPNPFuncType
261261
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(in_array1.dtype)
262262
cdef DPNPFuncType param2_type = dpnp_dtype_to_DPNPFuncType(in_array2.dtype)
263263

@@ -276,14 +276,14 @@ cpdef utils.dpnp_descriptor dpnp_matmul(utils.dpnp_descriptor in_array1, utils.d
276276
return result
277277

278278

279-
cpdef dparray dpnp_outer(dpnp_descriptor array1, dpnp_descriptor array2):
279+
cpdef utils.dpnp_descriptor dpnp_outer(utils.dpnp_descriptor array1, utils.dpnp_descriptor array2):
280280
cdef shape_type_c result_shape = (array1.size, array2.size)
281281
result_type = numpy.promote_types(array1.dtype, array1.dtype)
282282

283-
cdef dparray result = dparray(result_shape, dtype=result_type)
283+
cdef utils.dpnp_descriptor result = utils_py.create_output_descriptor_py(result_shape, result_type, None)
284284

285285
for idx1 in range(array1.size):
286286
for idx2 in range(array2.size):
287-
result[idx1 * array2.size + idx2] = array1[idx1] * array2[idx2]
287+
result.get_pyobj()[idx1 * array2.size + idx2] = array1.get_pyobj()[idx1] * array2.get_pyobj()[idx2]
288288

289289
return result

dpnp/dpnp_iface_linearalgebra.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ def inner(x1, x2, **kwargs):
183183

184184
x1_desc = dpnp.get_dpnp_descriptor(x1)
185185
x2_desc = dpnp.get_dpnp_descriptor(x2)
186-
if 0 and x1_desc and x2_desc and not kwargs:
187-
return dpnp_inner(x1_desc, x2_desc)
186+
if x1_desc and x2_desc and not kwargs:
187+
return dpnp_inner(x1_desc, x2_desc).get_pyobj()
188188

189189
return call_origin(numpy.inner, x1, x2, **kwargs)
190190

@@ -202,7 +202,7 @@ def kron(x1, x2):
202202
x1_desc = dpnp.get_dpnp_descriptor(x1)
203203
x2_desc = dpnp.get_dpnp_descriptor(x2)
204204
if x1_desc and x2_desc:
205-
return dpnp_kron(x1_desc, x2_desc)
205+
return dpnp_kron(x1_desc, x2_desc).get_pyobj()
206206

207207
return call_origin(numpy.kron, x1, x2)
208208

@@ -312,8 +312,8 @@ def outer(x1, x2, **kwargs):
312312

313313
x1_desc = dpnp.get_dpnp_descriptor(x1)
314314
x2_desc = dpnp.get_dpnp_descriptor(x2)
315-
if 0 and x1_desc and x2_desc and not kwargs:
316-
return dpnp_outer(x1_desc, x2_desc)
315+
if x1_desc and x2_desc and not kwargs:
316+
return dpnp_outer(x1_desc, x2_desc).get_pyobj()
317317

318318
return call_origin(numpy.outer, x1, x2, **kwargs)
319319

0 commit comments

Comments
 (0)