def to_host(self, begin = 0, end = -1): elem_cls = self.name_elem_cls() if elem_cls=='int8_t': nptype = np.int8 elif elem_cls=='uint8_t': nptype = np.uint8 elif elem_cls=='int16_t': nptype = np.int16 elif elem_cls=='uint16_t': nptype = np.uint16 elif elem_cls=='int32_t': nptype = np.int32 elif elem_cls=='uint32_t': nptype = np.uint32 elif elem_cls=='int64_t': nptype = np.int64 elif elem_cls=='uint64_t': nptype = np.uint64 elif elem_cls=='float': nptype = np.float32 elif elem_cls=='double': nptype = np.float64 elif elem_cls=='bool': nptype = np.bool if end == -1: end = self.size() ret = np.empty(end - begin, dtype=nptype) native.n_dvvector_to_host(self.m_cptr, ret.__array_interface__['data'][0], begin, end) return ret
def Sequence(vec, value_init=None, value_step=None): cptr_init = None if value_init != None: cptr_init = value_init.m_cptr cptr_step = None if value_step != None: cptr_step = value_step.m_cptr native.n_sequence(vec.m_cptr, cptr_init, cptr_step)
def Sort( vec, comp=None, ): cptr_comp = None if comp != None: cptr_comp = comp.m_cptr native.n_sort(vec.m_cptr, cptr_comp)
def Adjacent_Difference(vec_in, vec_out, binary_op=None): cptr_binary_op = None if binary_op != None: cptr_binary_op = binary_op.m_cptr native.n_adjacent_difference( vec_in.m_cptr, vec_out.m_cptr, cptr_binary_op, )
def Exclusive_Scan(vec_in, vec_out, value_init=None, binary_op=None): cptr_init = None if value_init != None: cptr_init = value_init.m_cptr cptr_binary_op = None if binary_op != None: cptr_binary_op = binary_op.m_cptr native.n_exclusive_scan(vec_in.m_cptr, vec_out.m_cptr, cptr_init, cptr_binary_op)
def Inclusive_Scan_By_Key(vec_key, vec_value, vec_out, binary_pred=None, binary_op=None): cptr_binary_pred = None if binary_pred != None: cptr_binary_pred = binary_pred.m_cptr cptr_binary_op = None if binary_op != None: cptr_binary_op = binary_op.m_cptr native.n_inclusive_scan_by_key(vec_key.m_cptr, vec_value.m_cptr, vec_out.m_cptr, cptr_binary_pred, cptr_binary_op)
def __init__(self, nbarr): self.nbarr = nbarr if nbarr.dtype == np.int8: elem_cls = 'int8_t' elif nbarr.dtype == np.uint8: elem_cls = 'uint8_t' elif nbarr.dtype == np.int16: elem_cls = 'int16_t' elif nbarr.dtype == np.uint16: elem_cls = 'uint16_t' elif nbarr.dtype == np.int32: elem_cls = 'int32_t' elif nbarr.dtype == np.uint32: elem_cls = 'uint32_t' elif nbarr.dtype == np.int64: elem_cls = 'int64_t' elif nbarr.dtype == np.uint64: elem_cls = 'uint64_t' elif nbarr.dtype == np.int64: elem_cls = 'int64_t' elif nbarr.dtype == np.uint64: elem_cls = 'uint64_t' elif nbarr.dtype == np.float32: elem_cls = 'float' elif nbarr.dtype == np.float64: elem_cls = 'double' elif nbarr.dtype == np.bool: elem_cls = 'bool' size = nbarr.size ptr_device_data = nbarr.device_ctypes_pointer.value self.m_cptr = native.n_dvvectoradaptor_create(elem_cls, size, ptr_device_data)
def Exclusive_Scan_By_Key(vec_key, vec_value, vec_out, value_init=None, binary_pred=None, binary_op=None): cptr_init = None if value_init != None: cptr_init = value_init.m_cptr cptr_binary_pred = None if binary_pred != None: cptr_binary_pred = binary_pred.m_cptr cptr_binary_op = None if binary_op != None: cptr_binary_op = binary_op.m_cptr native.n_exclusive_scan_by_key(vec_key.m_cptr, vec_value.m_cptr, vec_out.m_cptr, cptr_init, cptr_binary_pred, cptr_binary_op)
def Unique_By_Key_Copy(keys_in, values_in, keys_out, values_out, binary_pred=None): cptr_binary_pred = None if binary_pred != None: cptr_binary_pred = binary_pred.m_cptr return native.n_unique_by_key_copy(keys_in.m_cptr, values_in.m_cptr, keys_out.m_cptr, values_out.m_cptr, cptr_binary_pred)
def Unique_By_Key(keys, values, binary_pred=None): cptr_binary_pred = None if binary_pred != None: cptr_binary_pred = binary_pred.m_cptr return native.n_unique_by_key(keys.m_cptr, values.m_cptr, cptr_binary_pred)
def Transform_Binary_If_Stencil(vec_in1, vec_in2, vec_stencil, vec_out, op, pred): native.n_transform_binary_if_stencil(vec_in1.m_cptr, vec_in2.m_cptr, vec_stencil.m_cptr, vec_out.m_cptr, op.m_cptr, pred.m_cptr)
def Unique(vec, binary_pred=None): cptr_binary_pred = None if binary_pred != None: cptr_binary_pred = binary_pred.m_cptr return native.n_unique(vec.m_cptr, cptr_binary_pred)
def Unique_Copy(vec_in, vec_out, binary_pred=None): cptr_binary_pred = None if binary_pred != None: cptr_binary_pred = binary_pred.m_cptr return native.n_unique_copy(vec_in.m_cptr, vec_out.m_cptr, cptr_binary_pred)
def Copy_If(vec_in, vec_out, pred): return native.n_copy_if(vec_in.m_cptr, vec_out.m_cptr, pred.m_cptr)
def Remove_Copy_If_Stencil(vec_in, stencil, vec_out, pred): return native.n_remove_copy_if_stencil(vec_in.m_cptr, stencil.m_cptr, vec_out.m_cptr, pred.m_cptr)
def Remove_Copy_If(vec_in, vec_out, pred): return native.n_remove_copy_if(vec_in.m_cptr, vec_out.m_cptr, pred.m_cptr)
def Remove_If_Stencil(vec, stencil, pred): return native.n_remove_if_stencil(vec.m_cptr, stencil.m_cptr, pred.m_cptr)
def Partition_Copy_Stencil(vec_in, stencil, vec_true, vec_false, pred): return native.n_partition_copy_stencil(vec_in.m_cptr, stencil.m_cptr, vec_true.m_cptr, vec_false.m_cptr, pred.m_cptr)
def Transform_Binary(vec_in1, vec_in2, vec_out, op): native.n_transform_binary(vec_in1.m_cptr, vec_in2.m_cptr, vec_out.m_cptr, op.m_cptr)
def Partition_Stencil(vec, stencil, pred): return native.n_partition_stencil(vec.m_cptr, stencil.m_cptr, pred.m_cptr)
def Copy_If_Stencil(vec_in, vec_stencil, vec_out, pred): return native.n_copy_if_stencil(vec_in.m_cptr, vec_stencil.m_cptr, vec_out.m_cptr, pred.m_cptr)
def For_Each(vec, f): native.n_for_each(vec.m_cptr, f.m_cptr)
def Transform_If_Stencil(vec_in, vec_stencil, vec_out, op, pred): native.n_transform_if_stencil(vec_in.m_cptr, vec_stencil.m_cptr, vec_out.m_cptr, op.m_cptr, pred.m_cptr)
def Transform_If(vec_in, vec_out, op, pred): native.n_transform_if(vec_in.m_cptr, vec_out.m_cptr, op.m_cptr, pred.m_cptr)
def Partition(vec, pred): return native.n_partition(vec.m_cptr, pred.m_cptr)
def Remove(vec, value): return native.n_remove(vec.m_cptr, value.m_cptr)
def Partition_Copy(vec_in, vec_true, vec_false, pred): return native.n_partition_copy(vec_in.m_cptr, vec_true.m_cptr, vec_false.m_cptr, pred.m_cptr)
def Remove_Copy(vec_in, vec_out, value): return native.n_remove_copy(vec_in.m_cptr, vec_out.m_cptr, value.m_cptr)
def __init__(self, elem_map): self.m_elem_map = elem_map self.m_cptr = native.n_dvtuple_create([ (param_name, elem.m_cptr) for param_name, elem in elem_map.items() ])
def Remove_If(vec, pred): return native.n_remove_if(vec.m_cptr, pred.m_cptr)