Skip to content

Commit 73445f6

Browse files
authored
dpnp.array() to desc (#852)
1 parent bb55ff9 commit 73445f6

File tree

4 files changed

+28
-60
lines changed

4 files changed

+28
-60
lines changed

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ cpdef dpnp_descriptor dpnp_matmul(dpnp_descriptor in_array1, dpnp_descriptor in_
305305
Array creation routines
306306
"""
307307
cpdef dpnp_descriptor dpnp_arange(start, stop, step, dtype)
308-
cpdef dparray dpnp_array(object obj, object dtype=*)
309-
cpdef dparray dpnp_init_val(shape, dtype, value)
308+
cpdef dpnp_descriptor dpnp_array(object obj, object dtype=*)
309+
cpdef dpnp_descriptor dpnp_init_val(shape, dtype, value)
310310
cpdef dpnp_descriptor dpnp_full(result_shape, value_in, result_dtype) # same as dpnp_init_val
311311
cpdef dpnp_descriptor dpnp_copy(dpnp_descriptor x1)
312312

dpnp/dpnp_algo/dpnp_algo.pyx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,30 +96,29 @@ cpdef utils.dpnp_descriptor dpnp_arange(start, stop, step, dtype):
9696
return result
9797

9898

99-
cpdef dparray dpnp_array(object obj, object dtype=None):
100-
cdef dparray result
101-
cdef elem_dtype
99+
cpdef utils.dpnp_descriptor dpnp_array(object obj, object dtype=None):
100+
cdef utils.dpnp_descriptor result
102101
cdef shape_type_c obj_shape
103102

104103
# convert scalar to tuple
105104
if dpnp.isscalar(obj):
106105
obj = (obj, )
107106

108107
if not cpython.PySequence_Check(obj):
109-
raise TypeError(f"DPNP array(): Unsupported non-sequence obj={type(obj)}")
108+
raise TypeError(f"DPNP dpnp_array(): Unsupported non-sequence obj={type(obj)}")
110109

111110
obj_shape, elem_dtype = utils.get_shape_dtype(obj)
112111
if dtype is not None:
113112
""" Set type from parameter. result might be empty array """
114-
result = dparray(obj_shape, dtype=dtype)
113+
result = utils_py.create_output_descriptor_py(obj_shape, dtype, None)
115114
else:
116115
if obj_shape.empty():
117116
""" Empty object (ex. empty list) and no type provided """
118-
result = dparray(obj_shape)
117+
result = utils_py.create_output_descriptor_py(obj_shape, None, None)
119118
else:
120-
result = dparray(obj_shape, dtype=elem_dtype)
119+
result = utils_py.create_output_descriptor_py(obj_shape, elem_dtype, None)
121120

122-
utils.copy_values_to_dparray(result, obj)
121+
utils.copy_values_to_dparray(result.get_pyobj(), obj)
123122

124123
return result
125124

@@ -153,20 +152,19 @@ cpdef dparray dpnp_flatten(dparray array_):
153152
return result
154153

155154

156-
cpdef dparray dpnp_init_val(shape, dtype, value):
155+
cpdef utils.dpnp_descriptor dpnp_init_val(shape, dtype, value):
157156
"""
158157
same as dpnp_full(). TODO remove code dumplication
159158
"""
160159
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(dtype)
161160

162161
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_INITVAL, param1_type, param1_type)
163162

164-
result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
165-
cdef dparray result = dparray(shape, dtype=dtype)
163+
cdef utils.dpnp_descriptor result = utils_py.create_output_descriptor_py(shape, dtype, None)
166164

167165
# TODO: find better way to pass single value with type conversion
168-
cdef dparray val_arr = dparray((1, ), dtype=dtype)
169-
val_arr[0] = value
166+
cdef utils.dpnp_descriptor val_arr = utils_py.create_output_descriptor_py((1, ), dtype, None)
167+
val_arr.get_pyobj()[0] = value
170168

171169
cdef fptr_dpnp_initval_t func = <fptr_dpnp_initval_t > kernel_data.ptr
172170
func(result.get_data(), val_arr.get_data(), result.size)

dpnp/dpnp_iface_arraycreation.py

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def arange(start, stop=None, step=1, dtype=None):
149149
return call_origin(numpy.arange, start, stop=stop, step=step, dtype=dtype)
150150

151151

152-
def array(obj, dtype=None, copy=True, order='C', subok=False, ndmin=0):
152+
def array(x1, dtype=None, copy=True, order='C', subok=False, ndmin=0, like=None):
153153
"""
154154
Creates an array.
155155
@@ -192,51 +192,20 @@ def array(obj, dtype=None, copy=True, order='C', subok=False, ndmin=0):
192192
193193
"""
194194

195-
# print("=======================")
196-
# print(f"x1={obj}")
197-
if (use_origin_backend(obj)):
198-
# print("=========numpy.array==============")
199-
return numpy.array(obj, dtype=dtype, copy=copy, order=order, subok=subok, ndmin=ndmin)
195+
if not dpnp.is_type_supported(dtype) and dtype is not None:
196+
pass
197+
elif subok is not False:
198+
pass
199+
elif copy is not True:
200+
pass
201+
elif order != 'C':
202+
pass
203+
elif ndmin != 0:
204+
pass
205+
else:
206+
return dpnp_array(x1, dtype).get_pyobj()
200207

201-
# if not isinstance(obj, collections.abc.Sequence):
202-
# return numpy.array(obj, dtype=dtype, copy=copy, order=order, subok=subok, ndmin=ndmin)
203-
204-
# if isinstance(obj, numpy.object):
205-
# return numpy.array(obj, dtype=dtype, copy=copy, order=order, subok=subok, ndmin=ndmin)
206-
207-
if subok is not False:
208-
checker_throw_value_error("array", "subok", subok, False)
209-
210-
if copy is not True:
211-
checker_throw_value_error("array", "copy", copy, True)
212-
213-
if order != 'C':
214-
checker_throw_value_error("array", "order", order, 'C')
215-
216-
if ndmin != 0:
217-
checker_throw_value_error("array", "ndmin", ndmin, 0)
218-
219-
# print("=========dpnp_array==============")
220-
return dpnp_array(obj, dtype)
221-
222-
223-
# def array(x1, dtype=None, copy=True, order='C', subok=False, ndmin=0):
224-
# print("=======================")
225-
# print(f"x1={x1}")
226-
# x1_desc = dpnp.get_dpnp_descriptor(x1)
227-
# if x1_desc:
228-
# if subok is not False:
229-
# pass
230-
# elif copy is not True:
231-
# pass
232-
# elif order != 'C':
233-
# pass
234-
# elif ndmin != 0:
235-
# pass
236-
# else:
237-
# return dpnp_array(x1, dtype)
238-
239-
# return call_origin(numpy.array, x1, dtype, copy=copy, order=order, subok=subok, ndmin=ndmin)
208+
return call_origin(numpy.array, x1, dtype=dtype, copy=copy, order=order, subok=subok, ndmin=ndmin)
240209

241210

242211
def asanyarray(a, dtype=None, order='C'):

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ cdef tuple get_shape_dtype(object input_obj):
256256
cdef shape_type_c return_shape # empty shape means scalar
257257
return_dtype = None
258258

259+
# TODO replace with checking "shape" and "dtype" attributes
259260
if issubclass(type(input_obj), (numpy.ndarray, dparray)):
260261
return (input_obj.shape, input_obj.dtype)
261262

0 commit comments

Comments
 (0)