int_frac.c

 
def lib_cut_sat(data_in, fix_info): “”“data fixed to specific fixed point”“” # % fix_p = [fix_en fix_mode sign data_width frac_width] # % fix_en: 0 disable, 1 enable # % fix_mode: # % 0 rnd + sat # % 1 prnd + sat # % 2 floor + sat # % 3 rnd # % 4 prnd # % 5 floor # % 6 sat # % 7 rnd + sym_sat # % 8 prnd + sym_sat # % 9 floor + sym_sat # % 10 sym_sat # % sign: 0 unsign, 1 sign import ctypes as C import numpy as np import os # load lib if os.name == ‘posix’: c_lib = C.cdll.LoadLibrary(‘./LIB/fix/lib_cut_sat.so’) else: # c_lib = C.cdll.LoadLibrary(‘./LIB/fix/lib_cut_sat.dll’) c_lib = C.cdll.LoadLibrary(r’D:\jiaoben\8911_sofdm_lite_toSDK\8911_sofdm_lite_toSDK\LIB\fix\lib_cut_sat.dll’) ## data type convert to np.array type if np.isrealobj(data_in): # real data data_type = np.float64 else: # complex data data_type = np.complex128 if not isinstance(data_in,np.ndarray): flg = type(data_in) if isinstance(data_in,(tuple, list)): data_in = np.asarray(data_in, dtype=data_type) else: data_in = np.asarray([data_in], dtype=data_type) else: flg = np.ndarray if data_in.dtype != data_type: data_in = data_in.astype(dtype=data_type) if not data_in.flags['C_CONTIGUOUS']: data_in = np.ascontiguousarray(data_in, dtype=data_in.dtype) ## call lib_cut sat c_fix_p = (C.c_int*len(fix_info))(*fix_info) if data_type == np.float64: # real data c_lib.libCutSatReal.argtypes = (np.ctypeslib.ndpointer(dtype=data_in.dtype,ndim=data_in.ndim,flags='C_CONTIGUOUS'), C.POINTER(C.c_int), C.c_uint) c_lib.libCutSatReal(data_in, c_fix_p, data_in.size) else: # complex data c_lib.libCutSatComp.argtypes = (np.ctypeslib.ndpointer(dtype=data_in.dtype,ndim=data_in.ndim,flags='C_CONTIGUOUS'), C.POINTER(C.c_int), C.c_uint) c_lib.libCutSatComp(data_in, c_fix_p, data_in.size) ## data type convert to input type if flg != np.ndarray: if flg == float: data_in = float(data_in) elif flg == int: data_in = int(data_in) elif flg == tuple: data_in = tuple(data_in) elif flg == list: data_in = list(data_in) return data_in解释代码
最新发布
08-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值