Skip to content

Commit 7266bee

Browse files
authored
dpnp_full() to desc (#804)
1 parent f799ac1 commit 7266bee

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ Array creation routines
282282
cpdef dpnp_descriptor dpnp_arange(start, stop, step, dtype)
283283
cpdef dparray dpnp_array(object obj, object dtype=*)
284284
cpdef dparray dpnp_init_val(shape, dtype, value)
285-
285+
cpdef dpnp_descriptor dpnp_full(result_shape, value_in, result_dtype) # same as dpnp_init_val
286286

287287
"""
288288
Mathematical functions

dpnp/dpnp_algo/dpnp_algo.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ cpdef dparray dpnp_flatten(dparray array_):
154154

155155

156156
cpdef dparray dpnp_init_val(shape, dtype, value):
157+
"""
158+
same as dpnp_full(). TODO remove code dumplication
159+
"""
157160
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype)
158161

159162
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_INITVAL, param1_type, param1_type)

dpnp/dpnp_algo/dpnp_algo_arraycreation.pyx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,29 @@ cpdef utils.dpnp_descriptor dpnp_diag(utils.dpnp_descriptor v, int k):
9797
return result
9898

9999

100-
cpdef dparray dpnp_full(result_shape, value_in, result_dtype):
100+
cpdef utils.dpnp_descriptor dpnp_full(result_shape, value_in, result_dtype):
101101
# Convert string type names (dparray.dtype) to C enum DPNPFuncType
102102
cdef DPNPFuncType dtype_in = dpnp_dtype_to_DPNPFuncType(result_dtype)
103103

104104
# get the FPTR data structure
105105
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_FULL, dtype_in, DPNP_FT_NONE)
106106

107-
result_type = dpnp_DPNPFuncType_to_dtype(< size_t > kernel_data.return_type)
108-
# Create single-element input array with type given by FPTR data
109-
cdef dparray_shape_type shape_in = (1,)
110-
cdef dparray array_in = dparray(shape_in, dtype=result_type)
111-
array_in[0] = value_in
112-
# Create result array with type given by FPTR data
113-
cdef dparray result = dparray(result_shape, dtype=result_type)
107+
# Create single-element input fill array with type given by FPTR data
108+
cdef dparray_shape_type shape_in = (1,)
109+
cdef utils.dpnp_descriptor array_fill = utils.create_output_descriptor(shape_in, kernel_data.return_type, None)
110+
array_fill.get_pyobj()[0] = value_in
111+
112+
# ceate result array with type given by FPTR data
113+
cdef dparray_shape_type result_shape_c = utils._object_to_tuple(result_shape)
114+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(result_shape_c, kernel_data.return_type, None)
114115

115116
cdef fptr_1in_1out_t func = <fptr_1in_1out_t > kernel_data.ptr
116117
# Call FPTR function
117-
func(array_in.get_data(), result.get_data(), result.size)
118+
func(array_fill.get_data(), result.get_data(), result.size)
118119

119120
return result
120121

121-
122+
# TODO we don't need this function because it is the same as dpnp_full()
122123
cpdef dparray dpnp_full_like(result_shape, value_in, result_dtype):
123124
# Convert string type names (dparray.dtype) to C enum DPNPFuncType
124125
cdef DPNPFuncType dtype_in = dpnp_dtype_to_DPNPFuncType(result_dtype)

dpnp/dpnp_iface_arraycreation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ def fromstring(string, **kwargs):
625625
return call_origin(numpy.fromstring, string, **kwargs)
626626

627627

628-
# numpy.full(shape, fill_value, dtype=None, order='C')
629628
def full(shape, fill_value, dtype=None, order='C'):
630629
"""
631630
Return a new array of given shape and type, filled with `fill_value`.
@@ -656,9 +655,9 @@ def full(shape, fill_value, dtype=None, order='C'):
656655
pass
657656
else:
658657
if dtype is None:
659-
dtype = numpy.array(fill_value).dtype.type
658+
dtype = numpy.array(fill_value).dtype.type #TODO simplify
660659

661-
return dpnp_full(shape, fill_value, dtype)
660+
return dpnp_full(shape, fill_value, dtype).get_pyobj()
662661

663662
return call_origin(numpy.full, shape, fill_value, dtype, order)
664663

0 commit comments

Comments
 (0)