Return a new handle with specified storage type, shape, dtype and context.

    Empty handle is only used to hold results

    Returns
    -------
    handle
        A new empty ndarray handle
505503
def _new_alloc_handle(stype, shape, ctx, delay_alloc, dtype, aux_types, aux_shapes=None):
    
    hdl = NDArrayHandle()
    for aux_t in aux_types:
        if np.dtype(aux_t) != np.dtype("int64"):
            raise NotImplementedError("only int64 is supported for aux types")
    aux_type_ids = [int(_DTYPE_NP_TO_MX[np.dtype(aux_t).type]) for aux_t in aux_types]
    aux_shapes = [(0,) for aux_t in aux_types] if aux_shapes is None else aux_shapes
    aux_shape_lens = [len(aux_shape) for aux_shape in aux_shapes]
    aux_shapes = py_sum(aux_shapes, ())
    num_aux = mx_uint(len(aux_types))
    check_call(_LIB.MXNDArrayCreateSparseEx(
        ctypes.c_int(int(_STORAGE_TYPE_STR_TO_ID[stype])),
        c_array_buf(mx_uint, native_array('I', shape)),
        mx_uint(len(shape)),
        ctypes.c_int(ctx.device_typeid),
        ctypes.c_int(ctx.device_id),
        ctypes.c_int(int(delay_alloc)),
        ctypes.c_int(int(_DTYPE_NP_TO_MX[np.dtype(dtype).type])),
        num_aux,
        c_array_buf(ctypes.c_int, native_array('i', aux_type_ids)),
        c_array_buf(mx_uint, native_array('I', aux_shape_lens)),
        c_array_buf(mx_uint, native_array('I', aux_shapes)),
        ctypes.byref(hdl)))
    return hdl
333513
def make_empty(self, axes=None):
        
        if axes is None:
            axes = [ensure_index([])] + [ensure_index(a)
                                         for a in self.axes[1:]]

        # preserve dtype if possible
        if self.ndim == 1:
            blocks = np.array([], dtype=self.array_dtype)
        else:
            blocks = []
        return self.__class__(blocks, axes)
1188024
def _dispatchNextType(self,reader):
        
        
        # Need to check endianess here!
        endianness = reader.unpack_byte()
        if endianness == 0:
            reader.setEndianness('XDR')
        elif endianness == 1:
            reader.setEndianness('NDR')
        else:
            raise ExceptionWKBParser("Invalid endianness in WKB format.\n"\
                                     "The parser can only cope with XDR/big endian WKB format.\n"\
                                     "To force the WKB format to be in XDR use AsBinary(<fieldname>,'XDR'")
            
        
        geotype = reader.unpack_uint32() 

        mask = geotype & 0x80000000 # This is used to mask of the dimension flag.

        srid = geotype & 0x20000000
        # ignore srid ...
        if srid != 0:
            reader.unpack_uint32()

        dimensions = 2
        if mask == 0:
            dimensions = 2
        else:
            dimensions = 3
       
        geotype = geotype & 0x1FFFFFFF
        # Despatch to a method on the type id.
        if self._typemap.has_key(geotype):
            self._typemap[geotype](reader, dimensions)
        else:
            raise ExceptionWKBParser('Error type to dispatch with geotype = %s \n'\
                                     'Invalid geometry in WKB string: %s' % (str(geotype),
                                                                             str(self._current_string),))
532860
def default_empty(shape, dtype):
    
    default = numpy.zeros(shape, dtype=dtype)
    set_default_empty(default)
    return default
76827
def _free_array(self, handle: int):
        
        with self._lock:
            if self._arrays[handle] is not None:
                self._arrays[handle] = None
                self._count -= 1
113787
def create(self, type_, **kwargs):
        
        obj = self.factory.create("ns0:%s" % type_)
        for key, value in kwargs.items():
            setattr(obj, key, value)
        return obj
43733
def serialize_ndarray_readable(o):
    
    return dict(
        _type='np.ndarray',
        dtype=o.dtype,
        value=hint_tuples(o.tolist()))
1315782
def _gzip_open_handle(handle):
    """""""
    import gzip
    if sys.version_info[0] > 2:
        import io
        handle = io.TextIOWrapper(gzip.GzipFile(fileobj=handle), encoding="UTF-8")
    else:
        handle = gzip.GzipFile(fileobj=handle)
    return handle
561577
def array(a, dtype:type=None, **kwargs)->np.ndarray:
    ""
    if not isinstance(a, collections.Sized) and not getattr(a,'__array_interface__',False):
        a = list(a)
    if np.int_==np.int32 and dtype is None and is_listy(a) and len(a) and isinstance(a[0],int):
        dtype=np.int64
    return np.array(a, dtype=dtype, **kwargs)
1021198
def recognize_ndarray(self, ndarray):
        
        if self._recognize_raw_image_func is None:
            raise RuntimeError('NumPy missing')
        height, width = ndarray.shape[:2]
        bpp = ndarray.shape[2] if len(ndarray.shape) > 2 else 1
        ptr = self._recognize_raw_image_func(self.alpr_pointer, ndarray.flatten(), bpp, width, height)
        json_data = ctypes.cast(ptr, ctypes.c_char_p).value
        json_data = _convert_from_charp(json_data)
        
        # there is a bug in the openalpr python bindings
        # sometimes there are real numbers with "," as the decimal point..!
        # print("openalpr_lib : recognize_ndarray : json_data =", json_data)
        p = re.compile('\d(\,)\d')
        json_data = p.subn(".", json_data)[0]
        
        response_obj = json.loads(json_data)
        self._free_json_mem_func(ctypes.c_void_p(ptr))
        return response_obj
457390
def wait(self, dwMilliseconds = None):
        
        if self.value is None:
            raise ValueError("Handle is already closed!")
        if dwMilliseconds is None:
            dwMilliseconds = INFINITE
        r = WaitForSingleObject(self.value, dwMilliseconds)
        if r != WAIT_OBJECT_0:
            raise ctypes.WinError(r)
1051015
def _simple_new(cls, values, name=None, dtype=None, **kwargs):
        
        if not hasattr(values, 'dtype'):
            if (values is None or not len(values)) and dtype is not None:
                values = np.empty(0, dtype=dtype)
            else:
                values = np.array(values, copy=False)
                if is_object_dtype(values):
                    values = cls(values, name=name, dtype=dtype,
                                 **kwargs)._ndarray_values

        if isinstance(values, (ABCSeries, ABCIndexClass)):
            # Index._data must always be an ndarray.
            # This is no-copy for when _values is an ndarray,
            # which should be always at this point.
            values = np.asarray(values._values)

        result = object.__new__(cls)
        result._data = values
        # _index_data is a (temporary?) fix to ensure that the direct data
        # manipulation we do in `_libs/reduction.pyx` continues to work.
        # We need access to the actual ndarray, since we're messing with
        # data buffers and strides. We don't re-use `_ndarray_values`, since
        # we actually set this value too.
        result._index_data = values
        result.name = name
        for k, v in kwargs.items():
            setattr(result, k, v)
        return result._reset_identity()
546320
def _coerce_dtype(self, other_dtype):
        
        if self._dtype is None:
            new_dtype = np.dtype(other_dtype)
        else:
            new_dtype = np.find_common_type([self._dtype, np.dtype(other_dtype)], [])
        if new_dtype != self.dtype:
            self.set_dtype(new_dtype)
300557
public final InternalFactHandle newFactHandle(int id,
                                                  Object object,
                                                  ObjectTypeConf conf,
                                                  InternalWorkingMemory workingMemory,
                                                  WorkingMemoryEntryPoint wmEntryPoint) {
        return newFactHandle( id,
                              object,
                              getNextRecency(),
                              conf,
                              workingMemory,
                              wmEntryPoint );
    }
1006848
public HandlerType<HandlerChainType<T>> getOrCreateHandler()
   {
      List<Node> nodeList = childNode.get("handler");
      if (nodeList != null &&  nodeList.size() > 0)
      {
         return new HandlerTypeImpl<HandlerChainType<T>>(this, "handler", childNode, nodeList.get(0));
      }
      return createHandler();
   }
190563
def get_stream_handle(stream=sys.stdout):
    
    handle = stream
    if os.name == "nt":
        from ctypes import windll

        handle_id = WIN_STDOUT_HANDLE_ID
        handle = windll.kernel32.GetStdHandle(handle_id)
    return handle
1313528
def get_object_handle(self, obj):
        
        if obj not in self._object_handles:
            self._object_handles[obj] = self._get_object_handle(obj=obj)

        return self._object_handles[obj]