@@ -54,6 +54,7 @@ __all__ = [
5454 " checker_throw_type_error" ,
5555 " checker_throw_value_error" ,
5656 " dp2nd_array" ,
57+ " dpnp_descriptor" ,
5758 " get_axis_indeces" ,
5859 " get_axis_offsets" ,
5960 " _get_linear_index" ,
@@ -71,6 +72,8 @@ def call_origin(function, *args, **kwargs):
7172 Call fallback function for unsupported cases
7273 """
7374
75+ # print(f"DPNP call_origin(): Fallback called")
76+
7477 kwargs_out = kwargs.get(" out" , None )
7578 if (kwargs_out is not None ):
7679 kwargs[" out" ] = dpnp.asnumpy(kwargs_out) if isinstance (kwargs_out, dparray) else kwargs_out
@@ -431,3 +434,77 @@ cpdef cpp_bool use_origin_backend(input1=None, size_t compute_size=0):
431434 return True
432435
433436 return False
437+
438+
439+ cdef class dpnp_descriptor:
440+ def __init__ (self , obj ):
441+ """ Initialze variables """
442+ self .descriptor = None
443+ self .dpnp_descriptor_data_size = 0
444+ self .dpnp_descriptor_is_scalar = True
445+
446+ """ Accure main data storage """
447+ self .descriptor = getattr (obj, " __array_interface__" , None )
448+ if self .descriptor is None :
449+ return
450+
451+ if self .descriptor[" version" ] != 3 :
452+ return
453+
454+ """ array size calculation """
455+ cdef Py_ssize_t shape_it = 0
456+ self .dpnp_descriptor_data_size = 1
457+ for shape_it in self .shape:
458+ # TODO need to use common procedure from utils to calculate array size by shape
459+ if shape_it < 0 :
460+ raise ValueError (f" {ERROR_PREFIX} dpnp_descriptor::__init__() invalid value {shape_it} in 'shape'" )
461+ self .dpnp_descriptor_data_size *= shape_it
462+
463+ """ set scalar propery """
464+ self .dpnp_descriptor_is_scalar = False
465+
466+ @property
467+ def is_valid (self ):
468+ if self .descriptor is None :
469+ return False
470+ return True
471+
472+ @property
473+ def shape (self ):
474+ if self .is_valid:
475+ return self .descriptor[" shape" ]
476+ return None
477+
478+ @property
479+ def size (self ):
480+ if self .is_valid:
481+ return self .dpnp_descriptor_data_size
482+ return 0
483+
484+ @property
485+ def dtype (self ):
486+ if self .is_valid:
487+ type_str = self .descriptor[" typestr" ]
488+ return dpnp.dtype(type_str)
489+ return None
490+
491+ @property
492+ def is_scalar (self ):
493+ return self .dpnp_descriptor_is_scalar
494+
495+ @property
496+ def data (self ):
497+ if self .is_valid:
498+ data_tuple = self .descriptor[" data" ]
499+ return data_tuple[0 ]
500+ return None
501+
502+ cdef void * get_data(self ):
503+ cdef long val = self .data
504+ return < void * > val
505+
506+ def __bool__ (self ):
507+ return self .is_valid
508+
509+ def __str__ (self ):
510+ return str (self .descriptor)
0 commit comments