def _build_range(rslice, stop_val): if rslice is None or \ (rslice.start is None and rslice.stop is None and rslice.step is None): return lib.GrB_ALL, 0, None start = rslice.start stop = rslice.stop step = rslice.step if start is None: start = 0 if stop is None: stop = stop_val if step is None: size = (stop - start) + 1 I = ffi.new('GrB_Index[2]', [start, stop]) ni = lib.GxB_RANGE elif step < 0: step = abs(step) if start < stop: size = 0 else: size = int((start - stop) / step) + 1 I = ffi.new('GrB_Index[3]', [start, stop, step]) ni = lib.GxB_BACKWARDS else: if start > stop or step == 0: size = 0 else: size = int((stop - start) / step) + 1 I = ffi.new('GrB_Index[3]', [start, stop, step]) ni = lib.GxB_STRIDE return I, ni, size
def options_set( nthreads=None, chunk=None, burble=None, hyper_switch=None, bitmap_switch=None, format=None, ): if nthreads is not None: nthreads = ffi.cast("int", nthreads) _check(lib.GxB_Global_Option_set(lib.GxB_GLOBAL_NTHREADS, nthreads)) if chunk is not None: chunk = ffi.cast("double", chunk) _check(lib.GxB_Global_Option_set(lib.GxB_GLOBAL_CHUNK, chunk)) if burble is not None: burble = ffi.cast("int", burble) _check(lib.GxB_Global_Option_set(lib.GxB_BURBLE, burble)) if hyper_switch is not None: hyper_switch = ffi.cast("double", hyper_switch) _check(lib.GxB_Global_Option_set(lib.GxB_HYPER_SWITCH, hyper_switch)) if bitmap_switch is not None: bitmap_switch = ffi.new("double[8]", bitmap_switch) _check(lib.GxB_Global_Option_set(lib.GxB_BITMAP_SWITCH, bitmap_switch)) if format is not None: format = ffi.cast("GxB_Format_Value*", format) _check(lib.GxB_Global_Option_set(lib.GxB_FORMAT, format))
def _get_descriptor(inp0_trans=False): desc = ffi.new('GrB_Descriptor*') if inp0_trans: # transpose input to get row _check(lib.GrB_Descriptor_new(desc)) _check(lib.GrB_Descriptor_set(desc[0], lib.GrB_INP0, lib.GrB_TRAN)) else: desc[0] = NULL return desc
def _build_range(rslice, stop_val): # if already a list, return it and its length if isinstance(rslice, list): return rslice, len(rslice), len(rslice) if isinstance(rslice, int): return ffi.new('GrB_Index[1]', [rslice]), 1, 1 if rslice is None or \ (rslice.start is None and rslice.stop is None and rslice.step is None): return lib.GrB_ALL, 0, None start = rslice.start stop = rslice.stop step = rslice.step if start is None: start = 0 if stop is None: stop = stop_val if step is None: size = (stop - start) + 1 I = ffi.new('GrB_Index[2]', [start, stop]) ni = lib.GxB_RANGE elif step < 0: step = abs(step) if start < stop: size = 0 else: size = int((start - stop) / step) + 1 I = ffi.new('GrB_Index[3]', [start, stop, step]) ni = lib.GxB_BACKWARDS else: if start > stop or step == 0: size = 0 else: size = int((stop - start) / step) + 1 I = ffi.new('GrB_Index[3]', [start, stop, step]) ni = lib.GxB_STRIDE return I, ni, size
def options_get(): nthreads = ffi.new("int*") _check(lib.GxB_Global_Option_get(lib.GxB_GLOBAL_NTHREADS, nthreads)) chunk = ffi.new("double*") _check(lib.GxB_Global_Option_get(lib.GxB_GLOBAL_CHUNK, chunk)) burble = ffi.new("int*") _check(lib.GxB_Global_Option_get(lib.GxB_BURBLE, burble)) hyper_switch = ffi.new("double*") _check(lib.GxB_Global_Option_get(lib.GxB_HYPER_SWITCH, hyper_switch)) bitmap_switch = ffi.new("double[8]") _check(lib.GxB_Global_Option_get(lib.GxB_BITMAP_SWITCH, bitmap_switch)) format = ffi.new("GxB_Format_Value*") _check(lib.GxB_Global_Option_get(lib.GxB_FORMAT, format)) return dict( nthreads=nthreads[0], chunk=chunk[0], burble=burble[0], hyper_switch=hyper_switch[0], bitmap_switch=list(bitmap_switch), format=format[0], )