Skip to content

Commit 408ffed

Browse files
authored
add array_interface to desc to allow copy itself (#756)
1 parent b7b6404 commit 408ffed

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ This module contains differnt helpers and utilities
3131
3232
"""
3333

34+
import numpy
35+
import dpnp.config as config
36+
import dpnp
37+
from dpnp.dpnp_algo cimport dpnp_DPNPFuncType_to_dtype, dpnp_dtype_to_DPNPFuncType, get_dpnp_function_ptr
3438
from libcpp cimport bool as cpp_bool
3539
from libcpp.complex cimport complex as cpp_complex
3640

3741
cimport cpython
3842
cimport cython
3943
cimport numpy
40-
from dpnp.dpnp_algo cimport dpnp_DPNPFuncType_to_dtype, dpnp_dtype_to_DPNPFuncType, get_dpnp_function_ptr
41-
42-
import dpnp
43-
import dpnp.config as config
44-
import numpy
4544

4645

4746
"""
@@ -476,6 +475,12 @@ cdef class dpnp_descriptor:
476475
return self.descriptor["shape"]
477476
return None
478477

478+
@property
479+
def strides(self):
480+
if self.is_valid:
481+
return self.descriptor["strides"]
482+
return None
483+
479484
@property
480485
def ndim(self):
481486
if self.is_valid:
@@ -506,6 +511,30 @@ cdef class dpnp_descriptor:
506511
return data_tuple[0]
507512
return None
508513

514+
@property
515+
def descr(self):
516+
if self.is_valid:
517+
return self.descriptor["descr"]
518+
return None
519+
520+
@property
521+
def __array_interface__(self):
522+
# print(f"====dpnp_descriptor::__array_interface__====self.descriptor={ < size_t > self.descriptor}")
523+
if self.descriptor is None:
524+
return None
525+
526+
# TODO need to think about feature compatibility
527+
interface_dict = {
528+
"data": self.descriptor["data"],
529+
"strides": self.descriptor["strides"],
530+
"descr": self.descriptor["descr"],
531+
"typestr": self.descriptor["typestr"],
532+
"shape": self.descriptor["shape"],
533+
"version": self.descriptor["version"]
534+
}
535+
536+
return interface_dict
537+
509538
cdef void * get_data(self):
510539
cdef long val = self.data
511540
return < void * > val

0 commit comments

Comments
 (0)