def mprint(m, fmt): """ This function will print a VSIPL matrix or vector suitable for pasting into Octave or Matlab. usage: mprint(<vsip matrix/vector>, fmt) fmt is a string corresponding to a simple fmt statement. For instance '%6.5f' prints as 6 characters wide with 5 decimal digits. Note format converts this statement to '% 6.5f' or '%+6.5f' so keep the input simple. """ def _fmt1(c): if c != '%': return c else: return '% ' def _fmt2(c): if c != '%': return c else: return '%+' def _fmtfunc(fmt1, fmt2, y): x = vsip.cscalarToComplex(y) if type(x) == complex: return fmt1 % x.real + fmt2 % x.imag + "i" else: return fmt % x tm = [ 'mview_d', 'mview_f', 'cmview_d', 'cmview_f', 'mview_i', 'mview_uc', 'mview_si', 'mview_bl' ] tv = [ 'vview_d', 'vview_f', 'cvview_d', 'cvview_f', 'vview_i', 'vview_uc', 'vview_si', 'vview_bl', 'vview_vi', 'vview_mi' ] t = vsip.getType(m)[1] tfmt = [_fmt1(c) for c in fmt] fmt1 = "".join(tfmt) tfmt = [_fmt2(c) for c in fmt] fmt2 = "".join(tfmt) if t in tm: cl = vsip.getcollength(m) rl = vsip.getrowlength(m) for i in range(cl): M = [] for j in range(rl): M.append(_fmtfunc(fmt1, fmt2, vsip.get(m, (i, j)))) if i == 0: print("[" + " ".join(M) + ";") elif i < cl - 1: print(" " + " ".join(M) + ";") else: print(" " + " ".join(M) + "]") elif t in tv: l = vsip.getlength(m) V = [_fmtfunc(fmt1, fmt2, vsip.get(m, i)) for i in range(l)] print("[" + " ".join(V) + "]") else: print('Object not VSIP vector or matrix')
def mToA(m): M=vsip.getcollength(m) N=vsip.getrowlength(m) a=np.empty((M,N),float,'C') for i in range(M): for j in range(N): a[i,j] = vsip.get(m,(i,j)) return a
def mstring(m,fmt): """ This function will print a VSIPL matrix or vector suitable for pasting into Octave or Matlab. usage: mprint(<vsip matrix/vector>, fmt) fmt is a string corresponding to a simple fmt statement. For instance '%6.5f' prints as 6 characters wide with 5 decimal digits. Note format converts this statement to '% 6.5f' or '%+6.5f' so keep the input simple. """ def _fmt1(c): if c != '%': return c else: return '% ' def _fmt2(c): if c != '%': return c else: return '%+' def _fmtfunc(fmt1,fmt2,y): x = vsip.cscalarToComplex(y) if type(x) == complex: s = fmt1 % x.real s += fmt2 % x.imag s += "i" return s else: return fmt1 % x tm=['mview_d','mview_f','cmview_d','cmview_f','mview_i','mview_uc','mview_si','mview_bl'] tv=['vview_d','vview_f','cvview_d','cvview_f','vview_i','vview_uc','vview_si','vview_bl','vview_vi','vview_mi'] t=vsip.getType(m)[1] tfmt=[_fmt1(c) for c in fmt] fmt1 = "".join(tfmt) tfmt=[_fmt2(c) for c in fmt] fmt2 = "".join(tfmt) if t in tm: cl=vsip.getcollength(m) rl=vsip.getrowlength(m) s=str() for i in range(cl): M=[] for j in range(rl): M.append(_fmtfunc(fmt1,fmt2,vsip.get(m,(i,j)))) if i == 0: s += "["+" ".join(M) + ";\n" elif i < cl-1: s += " "+" ".join(M) + ";\n" else: s += " "+" ".join(M) + "]\n" return s elif t in tv: l=vsip.getlength(m) V=[_fmtfunc(fmt1,fmt2,vsip.get(m,i)) for i in range(l)] return "[" + " ".join(V) + "]\n" else: print('Object not VSIP vector or matrix')