Exemple #1
0
 def _gen(a):
     N=int(vsip.getlength(a))
     npm=N/2
     c=pi/float(N)
     vsip.put(a,0,(float(N) - 1.0)/2.0)
     indx=0;
     if N % 2:
         for i in range(npm):
             indx = i+1
             x = c * float(i) + c
             x = -0.5j * ccos(x)/ssin(x)  - 0.5
             vsip.put(a,indx,x)
         for i in range(npm,0,-1):
             indx +=1
             x=vsip.get(a,i)
             x.i=-x.i
             vsip.put(a,indx,x)
     else:
         npm -= 1
         for i in range(npm):
            indx = i+1
            x = c * float(i) + c
            x = -0.5j * ccos(x)/ssin(x)  - 0.5
            vsip.put(a,indx,x)
         x=-0.5
         indx +=1
         vsip.put(a,indx,x)
         for i in range(npm,0,-1):
             indx +=1
             x=vsip.get(a,i)
             x.i=-x.i
             vsip.put(a,indx,x)
Exemple #2
0
 def _gen(a):
     N = int(vsip.getlength(a))
     npm = N / 2
     c = pi / float(N)
     vsip.put(a, 0, (float(N) - 1.0) / 2.0)
     indx = 0
     if N % 2:
         for i in range(npm):
             indx = i + 1
             x = c * float(i) + c
             x = -0.5j * ccos(x) / ssin(x) - 0.5
             vsip.put(a, indx, x)
         for i in range(npm, 0, -1):
             indx += 1
             x = vsip.get(a, i)
             x.i = -x.i
             vsip.put(a, indx, x)
     else:
         npm -= 1
         for i in range(npm):
             indx = i + 1
             x = c * float(i) + c
             x = -0.5j * ccos(x) / ssin(x) - 0.5
             vsip.put(a, indx, x)
         x = -0.5
         indx += 1
         vsip.put(a, indx, x)
         for i in range(npm, 0, -1):
             indx += 1
             x = vsip.get(a, i)
             x.i = -x.i
             vsip.put(a, indx, x)
Exemple #3
0
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')
Exemple #4
0
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')