コード例 #1
0
 def __init__(self,param):
     c=param['c']
     Dsens = param['Dsens']
     Nsens = param['Nsens']
     Nts = param['Nts']
     Fs = param['Fs']
     row=vsip.VSIP_ROW
     mem=vsip.VSIP_MEM_NONE
     state=vsip.VSIP_STATE_SAVE
     sym=vsip.VSIP_NONSYM
     rng=vsip.VSIP_PRNG
     L          = int(2 * Fs/(Nsens * Dsens/c) + Nts + 1)
     self.Nsim_freqs = param['Nsim_freqs']
     self.Nsens = Nsens
     self.Nsim_noise=param['Nsim_noise']
     self.Nts = Nts
     self.Fs = Fs
     kernel     = vsip.create('kaiser_d',(6,1,0))
     self.fir   = vsip.create('fir_d',(kernel, sym, 2*L, 2, state, 0,0))
     self.noise = vsip.create('vview_d',(2*L,mem))
     self.bl_noise = vsip.create('vview_d',(L,mem))
     self.rand  = vsip.create('randstate',(7,1,1,rng))
     self.t = vsip.create('vview_d',(Nts,mem))
     vsip.ramp(0,1.0/Fs,self.t) #vector of sample times
     self.t_dt = vsip.create('vview_d',(Nts,mem))    
     self.m_data = vsip.create('mview_d',(Nsens,Nts,row,mem))
     self.v_data = vsip.rowview(self.m_data,0)
     self.d_t = param['Dsens']/param['c'] #travel time at end-fire between sensors
     self.sim_freqs = param['sim_freqs']
     self.sim_bearings = param['sim_bearings']
     vsip.allDestroy(kernel)
コード例 #2
0
ファイル: kw.py プロジェクト: rrjudd/jvsip
 def __init__(self,param):
     mem=vsip.VSIP_MEM_NONE
     col=vsip.VSIP_COL
     row=vsip.VSIP_ROW
     fftfwd=vsip.VSIP_FFT_FWD
     vsip.init()
     Nsens=param['Nsens']
     Nts=param['Nts']
     Nfreq=int(Nts/2) + 1
     self.Navg=param['Navg']
     self.Nfreq=Nfreq
     self.cm_freq=vsip.create('cmview_d',(Nsens,Nfreq,col,mem)) 
     self.rm_freq=vsip.realview(self.cm_freq)
     self.m_gram=vsip.create('mview_d',(Nsens,Nfreq,col,mem))
     self.rcfftm=vsip.create('rcfftmop_d',(Nsens,Nts,1,row,0,0))
     self.ccfftm=vsip.create('ccfftmip_d',(Nsens,Nfreq,fftfwd,1,col,0,0))
     self.ts_taper=vsip.create('hanning_d',(Nts,0))
     self.array_taper=vsip.create('hanning_d',(Nsens,0));
コード例 #3
0
ファイル: kw.py プロジェクト: rrjudd/jvsip
 def __init__(self, param):
     mem = vsip.VSIP_MEM_NONE
     col = vsip.VSIP_COL
     row = vsip.VSIP_ROW
     fftfwd = vsip.VSIP_FFT_FWD
     vsip.init()
     Nsens = param['Nsens']
     Nts = param['Nts']
     Nfreq = int(Nts / 2) + 1
     self.Navg = param['Navg']
     self.Nfreq = Nfreq
     self.cm_freq = vsip.create('cmview_d', (Nsens, Nfreq, col, mem))
     self.rm_freq = vsip.realview(self.cm_freq)
     self.m_gram = vsip.create('mview_d', (Nsens, Nfreq, col, mem))
     self.rcfftm = vsip.create('rcfftmop_d', (Nsens, Nts, 1, row, 0, 0))
     self.ccfftm = vsip.create('ccfftmip_d',
                               (Nsens, Nfreq, fftfwd, 1, col, 0, 0))
     self.ts_taper = vsip.create('hanning_d', (Nts, 0))
     self.array_taper = vsip.create('hanning_d', (Nsens, 0))
コード例 #4
0
def cchol(p):
      print("********\nTEST cchol"+p+"\n")
      ablock = vsip.create('cblock'+p,(200,vsip.VSIP_MEM_NONE))
      R = vsip.create('cmview'+p,(4,4,vsip.VSIP_ROW,vsip.VSIP_MEM_NONE))
      RH = vsip.create('cmview'+p,(4,4,vsip.VSIP_ROW,vsip.VSIP_MEM_NONE))
      A = vsip.bind(ablock,(40,-9,4,-2,4))
      B = vsip.bind(ablock,(100,10,4,3,3))
      chol = vsip.create('cchol'+p,(vsip.VSIP_TR_UPP,4))
      ans = vsip.create('cmview'+p,(4,3,vsip.VSIP_ROW,vsip.VSIP_MEM_NONE))
      data_R =     [ [1.0,  -2.0,  3.0,  1.0], 
                      [0.0,   2.0,  4.0, -1.0], 
                      [0.0,   0.0,  4.0,  3.0], 
                      [0.0,   0.0,  0.0,  6.0] ]
      data_I =     [ [0.0,  2.0,  2.0,  1.0], 
                       [0.0,  0.0,  2.0, -4.0], 
                       [0.0,  0.0,  0.0,  2.0], 
                       [0.0,  0.0,  0.0,  0.0] ]
      data_Br =    [ [1.0, 2.0, 3.0],  
                      [0.0, 1.0, 2.0], 
                      [3.0, 0.0, 1.0], 
                      [3.0, 4.0, 5.0]]
      data_Bi =    [ [1.0, 0.5, 3.2], 
                      [2.0, 0.0, 0.6], 
                      [0.6, 2.0, 0.0], 
                      [5.0, 7.0, 8.0]]
      data_ans_r = [ [13.6236, 27.5451, 43.1573],
                      [-0.1104,  5.2370,  3.3312],
                      [-0.8403, -1.9410, -2.9823],
                     [ 0.7000,  0.8125,  1.7375] ]
      data_ans_i = [ [19.4965,  5.3707, 40.9604],
                     [ 6.7292,  5.4896, 15.8781],
                     [-1.4021, -0.3776, -2.9688],
                     [0.3694, -0.1632,  0.4667] ]
      for i in range(4):
         for j in range(4):
            vsip.put(R,(i,j),vsip.complexToCscalar('cscalar'+p,(data_R[i][j] + 1j * data_I[i][j])))
      for i in range(4):
         for j in range(3):
            vsip.put(B,(i,j),vsip.complexToCscalar('cscalar'+p,(data_Br[i][j] + 1j * data_Bi[i][j])))
            vsip.put(ans,(i,j),vsip.complexToCscalar('cscalar'+p,(data_ans_r[i][j] + 1j * data_ans_i[i][j])))
      vsip.herm(R,RH)
      vsip.prod(RH,R,A)
      print("R = \n");VU.mprint(R,"%4.2f")
      print("RH = \n");VU.mprint(RH,"%4.2f")
      print("A = R * RH\n");VU.mprint(A,"%4.2f")
      print("B \n");VU.mprint(B,"%4.2f")
   
      vsip.chold(chol,A)
      vsip.cholsol(chol,B)
      print("Solve using cholesky AX = B\n X = \n");VU.mprint(B,"%4.2f")
      vsip.destroy(chol)
      print("right answer \n ans = \n");VU.mprint(ans,"%4.2f")
      vsip.sub(ans,B,B)
      chk =  vsip.meansqval(B)
      if chk > .001:
         print("error\n")
      else:
         print("correct\n")
      lu = vsip.create('clu'+p,4)
      Bans = vsip.create('cmview'+p,(4,3,vsip.VSIP_ROW,vsip.VSIP_MEM_NONE))
      vsip.prod(RH,R,A)
      for i in range(4):
         for j in range(3):
            vsip.put(B,(i,j),vsip.complexToCscalar('cscalar'+p,(data_Br[i][j] + 1j * data_Bi[i][j])))
      vsip.lud(lu,A)
      vsip.lusol(lu,vsip.VSIP_MAT_NTRANS,B)
      print("Solve using LUD AX = B\n X = \n");VU.mprint(B,"%4.2f")
      vsip.destroy(lu)
      vsip.prod(RH,R,A)
      vsip.prod(A,B,Bans)
      print("Bans = A X \n");VU.mprint(Bans,"%4.2f")
      vsip.sub(ans,B,B)
      chk =  vsip.meansqval(B)
      if chk > .001:
         print("error\n")
      else:
         print("correct\n")
      vsip.allDestroy(Bans)
      vsip.allDestroy(R)
      vsip.allDestroy(RH)
      vsip.destroy(B)
      vsip.allDestroy(A)
コード例 #5
0
def chol(p):
      print("********\nTEST chol"+p+"\n")
      ablock = vsip.create('block'+p,(200,vsip.VSIP_MEM_NONE))
      R = vsip.create('mview'+p,(4,4,vsip.VSIP_ROW,vsip.VSIP_MEM_NONE))
      RH = vsip.create('mview'+p,(4,4,vsip.VSIP_ROW,vsip.VSIP_MEM_NONE))
      A = vsip.bind(ablock,(99,-11,4,-2,4))
      B = vsip.bind(ablock,(100,20,4,2,3))
      ans = vsip.create('mview'+p,(4,3,vsip.VSIP_ROW,vsip.VSIP_MEM_NONE))
      chol = vsip.create('chol'+p,(vsip.VSIP_TR_UPP,4))
      data_R = [ [1.0,  -2.0,  3.0,  1.0], 
                       [0.0,   2.0,  4.0, -1.0], 
                       [0.0,   0.0,  4.0,  3.0], 
                       [0.0,   0.0,  0.0,  6.0] ]
      data_Br = [ [ 1.0, 2.0, 3.0],  
                  [ 0.0, 1.0, 2.0], 
                  [ 3.0, 0.0, 1.0], 
                  [ 3.0, 4.0, 5.0]]
      data_ans = [[  4.6250, 13.9062, 21.0000],
                  [  1.3333,  4.1667,  6.3333],
                  [ -0.3750, -1.3438, -2.0000],
                  [  0.1667,  0.4583,  0.6667]]
   
      for i in range(4):
         for j in range(4):
            vsip.put(R,(i,j),data_R[i][j])
      for i in range(4):
         for j in range(3):
            vsip.put(B,(i,j),data_Br[i][j])
            vsip.put(ans,(i,j),data_ans[i][j])
      vsip.trans(R,RH)
      vsip.prod(RH,R,A)
      print("R = \n");VU.mprint(R,"%4.2f")
      print("RH = \n");VU.mprint(RH,"%4.2f")
      print("A = R * RH\n");VU.mprint(A,"%4.2f")
      print("B \n");VU.mprint(B,"%4.2f")
      vsip.chold(chol,A)
      vsip.cholsol(chol,B)
      print("Solve using cholesky AX = B\n X = \n");VU.mprint(B,"%4.2f")
      vsip.destroy(chol)
      print("right answer \n ans = \n");VU.mprint(ans,"%4.2f")
   
      vsip.sub(ans,B,B)
      chk =  vsip.sumsqval(B)
      if chk > .001: 
         print("error\n")
      else:
         print("correct\n")
      lu = vsip.create('lu'+p,4)
      Bans = vsip.create('mview'+p,(4,3,vsip.VSIP_ROW,vsip.VSIP_MEM_NONE))
      vsip.prod(RH,R,A)
      for i in range(4):
         for j in range(3):
            vsip.put(B,(i,j),data_Br[i][j])
      vsip.lud(lu,A)
      vsip.lusol(lu,vsip.VSIP_MAT_NTRANS,B)
      print("Solve using LUD AX = B\n X = \n");VU.mprint(B,"%4.2f")
      vsip.destroy(lu)
      vsip.prod(RH,R,A)
      vsip.prod(A,B,Bans)
      print("Bans = A X\n");VU.mprint(Bans,"%4.2f")
      vsip.sub(ans,B,B)
      chk =  vsip.sumsqval(B)
      if chk > .001:
         print("error\n")
      else:
         print("correct\n")
      vsip.allDestroy(Bans)
      vsip.allDestroy(R)
      vsip.allDestroy(RH)
      vsip.destroy(B)
      vsip.allDestroy(A)
コード例 #6
0
def clud(p):
    def cmplx(p, re, im):
        return eval('vsip_cmplx' + p + '(re,im)')

    def csub(p, a, b):
        return eval('vsip_csub' + p + '(a,b)')

    def cmag(p, a):
        return eval('vsip_cmag' + p + '(a)')

    """
     Usage is clud(p) where p is a string of either '_d' or '_f' to denote precision.
     only works for complex data. 
   """
    print('********\nTEST clud' + p + '\n')
    block = vsip.create('cblock' + p, (600, vsip.VSIP_MEM_NONE))
    AC = vsip.bind(block, (0, 7, 7, 1, 7))
    AG = vsip.bind(block, (175, -2, 7, -18, 7))
    IC = vsip.bind(block, (176, 1, 7, 7, 7))
    IG = vsip.bind(block, (226, 2, 7, 15, 7))
    B = vsip.bind(block, (335, 7, 7, 1, 7))
    A = vsip.bind(block, (385, 7, 7, 1, 7))
    X = vsip.bind(block, (434, 5, 7, 1, 3))
    Y = vsip.bind(block, (475, 3, 7, 1, 3))
    ludC = vsip.create('clu' + p, 7)
    ludG = vsip.create('clu' + p, 7)
    data_r = [ \
           [0.5,  7.0, 10.0, 12.0, -3.0,  0.0,   0.05], \
           [2.0, 13.0, 18.0,  6.0,  0.0, 130.0,  8.0], \
           [3.0, -9.0,  2.0,  3.0,  2.0,  -9.0,  6.0], \
           [4.0,  2.0,  2.0,  4.0,  1.0,   2.0,  3.0], \
           [0.2,  2.0,  9.0,  4.0,  1.0,   2.0,  3.0], \
           [0.1,  2.0,  0.3,  4.0,  1.0,   2.0,  3.0], \
           [0.0,  0.2,  3.0,  4.0,  1.0,   2.0,  3.0]]
    data_i = [
          [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], \
         [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], \
         [0.1, 0.1, 0.1, 0.2, 0.2,-0.2, 0.2], \
         [0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2], \
         [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3], \
         [0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4], \
         [0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4]]

    ydata_r = [ \
         [77.85,   155.70,   311.40], \
        [942.00,  1884.00,  3768.00], \
          [1.00,     2.00,     4.00], \
         [68.00,   136.00,   272.00], \
         [85.20,   170.40,   340.80], \
         [59.00,   118.00,   236.00], \
          [5.00,    18.00,     6.00]]

    ydata_i = [ \
         [4.5,      1.70,   -3.40], \
         [3.7,    184.00,   -2.00], \
         [1.00,     3.00,    2.00], \
         [68.00,   16.00,  272.00], \
         [85.20, 1170.40,  340.80], \
         [59.00,   18.50,   62.00], \
         [59.00,   11.60,   26.00]]


    Ident = [    \
                   [1, 0, 0, 0, 0, 0, 0], \
                   [0, 1, 0, 0, 0, 0, 0], \
                   [0, 0, 1, 0, 0, 0, 0], \
                   [0, 0, 0, 1, 0, 0, 0], \
                   [0, 0, 0, 0, 1, 0, 0], \
                   [0, 0, 0, 0, 0, 1, 0], \
                   [0, 0, 0, 0, 0, 0, 1]]
    AH = vsip.create('cmview' + p, (7, 7, vsip.VSIP_ROW, vsip.VSIP_MEM_NONE))

    for i in range(7):
        for j in range(7):
            a = cmplx(p, data_r[i][j], data_i[i][j])
            e = cmplx(p, Ident[i][j], 0.0)
            vsip.put(A, (i, j), a)
            vsip.put(AC, (i, j), a)
            vsip.put(AG, (i, j), a)
            vsip.put(IC, (i, j), e)
            vsip.put(IG, (i, j), e)
    for i in range(7):
        for j in range(3):
            a = cmplx(p, ydata_r[i][j], ydata_i[i][j])
            vsip.put(X, (i, j), a)
    vsip.herm(A, AH)
    print("Matrix A = \n")
    VU.mprint(A, '%7.2f')
    vsip.lud(ludC, AC)
    vsip.lud(ludG, AG)
    print("vsip_clusol(lud,vsip.VSIP_MAT_NTRANS,X)\n")
    print("Solve A X = I \n")
    vsip.lusol(ludC, vsip.VSIP_MAT_NTRANS, IC)
    vsip.lusol(ludG, vsip.VSIP_MAT_NTRANS, IG)
    print("for compact case X = \n")
    VU.mprint(IC, '%8.4f')
    print("for general case X = \n")
    VU.mprint(IG, '%8.4f')
    chk = 0
    for i in range(7):
        for j in range(7):
            chk += cmag(p, csub(p, vsip.get(IC, (i, j)), vsip.get(IG, (i, j))))
    if chk > .01:
        print("error\n")
    else:
        print("agree\n")
    vsip.prod(A, IC, B)
    chk = 0
    for i in range(7):
        for j in range(7):
            chk += cmag(
                p, csub(p, vsip.get(B, (i, j)), cmplx(p, Ident[i][j], 0.0)))
    vsip.prod(A, IG, B)
    for i in range(7):
        for j in range(7):
            chk += cmag(
                p, csub(p, vsip.get(B, (i, j)), cmplx(p, Ident[i][j], 0.0)))
    print("mprod(A,X) = \n")
    VU.mprint(B, '%8.3f')
    if chk > .01:
        print("error\n")
    else:
        print("correct\n")
    # check case VSIP_MAT_HERM
    print("Matrix Hermitian A = \n")
    VU.mprint(AH, '%7.2f')
    for i in range(7):
        for j in range(7):
            vsip.put(IC, (i, j), cmplx(p, Ident[i][j], 0.0))
            vsip.put(IG, (i, j), cmplx(p, Ident[i][j], 0.0))
    print("vsip_clusol(lud,vsip.VSIP_MAT_HERM,X)\n")
    print("Solve herm(A) X = I \n")
    vsip.lusol(ludC, vsip.VSIP_MAT_HERM, IC)
    vsip.lusol(ludG, vsip.VSIP_MAT_HERM, IG)
    print("for compact case X = \n")
    VU.mprint(IC, '%8.4f')
    print("for general case X = \n")
    VU.mprint(IG, '%8.4f')
    chk = 0
    for i in range(7):
        for j in range(7):
            chk += cmag(p, csub(p, vsip.get(IC, (i, j)), vsip.get(IG, (i, j))))
            chk += cmag(p, csub(p, vsip.get(IC, (i, j)), vsip.get(IG, (i, j))))
    if chk > .01:
        print("error\n")
    else:
        print("agree\n")
    vsip.prod(AH, IC, B)
    chk = 0
    for i in range(7):
        for j in range(7):
            chk += cmag(
                p, csub(p, vsip.get(B, (i, j)), cmplx(p, Ident[i][j], 0.0)))
    vsip.prod(AH, IG, B)
    for i in range(7):
        for j in range(7):
            chk += cmag(
                p, csub(p, vsip.get(B, (i, j)), cmplx(p, Ident[i][j], 0.0)))
    print("mprod(trans(A),X) = \n")
    VU.mprint(B, '%8.3f')
    if chk > .01:
        print("error\n")
    else:
        print("correct\n")
    # check case A X = B for VSIP_MAT_NTRANS
    print("check A X = Y; VSIP_MAT_NTRANS\n")
    print("Y = \n")
    VU.mprint(X, "%8.4f")
    vsip.lusol(ludC, vsip.VSIP_MAT_NTRANS, X)
    print("X = \n")
    VU.mprint(X, "%8.4f")
    vsip.prod(A, X, Y)
    print(" Y = A X\n")
    VU.mprint(Y, "%8.4f")
    chk = 0
    for i in range(7):
        for j in range(3):
            chk += cmag(
                p,
                csub(p, vsip.get(Y, (i, j)),
                     cmplx(p, ydata_r[i][j], ydata_i[i][j])))
    if (chk > .01):
        print("error\n")
    else:
        print("agree\n")

    for i in range(7):
        for j in range(3):
            vsip.put(X, (i, j), cmplx(p, ydata_r[i][j], ydata_i[i][j]))
    print("Y = \n")
    VU.mprint(X, '%8.4f')
    vsip.lusol(ludG, vsip.VSIP_MAT_HERM, X)
    vsip.prod(AH, X, Y)
    print("X = \n")
    VU.mprint(X, '%8.4f')
    print("Y = trans(A) X\n")
    VU.mprint(Y, '%8.4f')
    chk = 0
    for i in range(7):
        for j in range(3):
            chk += cmag(
                p,
                csub(p, vsip.get(Y, (i, j)),
                     cmplx(p, ydata_r[i][j], ydata_i[i][j])))
    if (chk > .02):
        print("error\n")
    else:
        print("agree\n")
    vsip.destroy(AC)
    vsip.destroy(AG)
    vsip.destroy(IC)
    vsip.destroy(IG)
    vsip.destroy(B)
    vsip.destroy(A)
    vsip.destroy(X)
    vsip.destroy(Y)
    vsip.allDestroy(AH)
    vsip.destroy(ludC)
    vsip.destroy(ludG)
コード例 #7
0
def lud(p):
    """
     Usage is lud(p) where p is a string of either '_d' or '_f' to denote precision.
     only works for real data. 
   """
    print('********\nTEST lud' + p + '\n')
    block = vsip.create('block' + p, (500, vsip.VSIP_MEM_NONE))
    AC = vsip.bind(block, (0, 6, 6, 1, 6))
    AG = vsip.bind(block, (36, 2, 6, 18, 6))
    IC = vsip.bind(block, (150, 1, 6, 6, 6))
    IG = vsip.bind(block, (200, 2, 6, 14, 6))
    B = vsip.bind(block, (300, 6, 6, 1, 6))
    A = vsip.bind(block, (350, 6, 6, 1, 6))
    X = vsip.bind(block, (400, 5, 6, 1, 3))
    Y = vsip.bind(block, (450, 3, 6, 1, 3))
    ludC = vsip.create('lu' + p, 6)
    ludG = vsip.create('lu' + p, 6)
    AT = vsip.transview(A)
    data = [[0.50, 7.00, 10.00, 12.00, -3.00, 0.00],
            [2.00, 13.00, 18.00, 6.00, 0.00, 130.00],
            [3.00, -9.00, 2.00, 3.00, 2.00, -9.00],
            [4.00, 2.00, 2.00, 4.00, 1.00, 2.00],
            [0.20, 2.00, 9.00, 4.00, 1.00, 2.00],
            [0.10, 2.00, 0.30, 4.00, 1.00, 2.00]]

    ydata = [[77.85, 155.70, 311.40], [942.00, 1884.00, 3768.00],
             [1.00, 2.00, 4.00], [68.00, 136.00, 272.00],
             [85.20, 170.40, 340.80], [59.00, 118.00, 236.00]]

    Ident = [[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0],
             [0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1]]

    for i in range(6):
        for j in range(6):
            vsip.put(A, (i, j), data[i][j])
            vsip.put(AC, (i, j), data[i][j])
            vsip.put(AG, (i, j), data[i][j])
            vsip.put(IC, (i, j), Ident[i][j])
            vsip.put(IG, (i, j), Ident[i][j])
    for i in range(6):
        for j in range(3):
            vsip.put(X, (i, j), ydata[i][j])

    print("Matrix A = \n")
    VU.mprint(A, '%7.2f')
    vsip.lud(ludC, AC)
    vsip.lud(ludG, AG)
    print("vsip_lusol(lud,vsip.VSIP_MAT_NTRANS,X)\n")
    print("Solve A X = I \n")
    vsip.lusol(ludC, vsip.VSIP_MAT_NTRANS, IC)
    vsip.lusol(ludG, vsip.VSIP_MAT_NTRANS, IG)
    print("for compact case X = \n")
    VU.mprint(IC, '%8.4f')
    print("for general case X = \n")
    VU.mprint(IG, '%8.4f')
    chk = 0
    for i in range(6):
        for j in range(6):
            chk += abs(vsip.get(IC, (i, j)) - vsip.get(IG, (i, j)))
    if chk > .01:
        print("error\n")
    else:
        print("agree\n")
    vsip.prod(A, IC, B)
    chk = 0
    for i in range(6):
        for j in range(6):
            chk += abs(vsip.get(B, (i, j)) - Ident[i][j])
    vsip.prod(A, IG, B)
    for i in range(6):
        for j in range(6):
            chk += abs(vsip.get(B, (i, j)) - Ident[i][j])
    print("mprod(A,X) = \n")
    VU.mprint(B, '%8.3f')
    if chk > .01:
        print("error\n")
    else:
        print("correct\n")
    print("Matrix Transpose A = \n")
    VU.mprint(AT, '%7.2f')
    for i in range(6):
        for j in range(6):
            vsip.put(IC, (i, j), Ident[i][j])
            vsip.put(IG, (i, j), Ident[i][j])
    print("vsip_lusol(lud,vsip.VSIP_MAT_TRANS,X)\n")
    print("Solve trans(A) X = I \n")
    vsip.lusol(ludC, vsip.VSIP_MAT_TRANS, IC)
    vsip.lusol(ludG, vsip.VSIP_MAT_TRANS, IG)
    print("for compact case X = \n")
    VU.mprint(IC, '%8.4f')
    print("for general case X = \n")
    VU.mprint(IG, '%8.4f')
    chk = 0
    for i in range(6):
        for j in range(6):
            chk += abs(vsip.get(IC, (i, j)) - vsip.get(IG, (i, j)))
    if chk > .01:
        print("error\n")
    else:
        print("agree\n")
    vsip.prod(AT, IC, B)
    chk = 0
    for i in range(6):
        for j in range(6):
            chk += abs(vsip.get(B, (i, j)) - Ident[i][j])
    vsip.prod(AT, IG, B)
    for i in range(6):
        for j in range(6):
            chk += abs(vsip.get(B, (i, j)) - Ident[i][j])
    print("mprod(trans(A),X) = \n")
    VU.mprint(B, '%8.3f')
    if chk > .01:
        print("error\n")
    else:
        print("correct\n")
    print("check A X = Y; vsip.VSIP_MAT_NTRANS\n")
    print("Y = \n")
    VU.mprint(X, '%8.4f')
    vsip.lusol(ludC, vsip.VSIP_MAT_NTRANS, X)
    print("X = \n")
    VU.mprint(X, '%8.4f')
    vsip.prod(A, X, Y)
    print(" Y = A X\n")
    VU.mprint(Y, '%8.4f')
    chk = 0
    for i in range(6):
        for j in range(3):
            chk += abs(vsip.get(Y, (i, j)) - ydata[i][j])
    if chk > .01:
        print("error\n")
    else:
        print("agree\n")
    for i in range(6):
        for j in range(3):
            vsip.put(X, (i, j), ydata[i][j])
    print("Y = \n")
    VU.mprint(X, '%8.4f')
    vsip.lusol(ludG, vsip.VSIP_MAT_TRANS, X)
    vsip.prod(AT, X, Y)
    print("X = \n")
    VU.mprint(X, '%8.4f')
    print("Y = trans(A) X\n")
    VU.mprint(Y, '%8.4f')
    chk = 0
    for i in range(6):
        for j in range(3):
            chk += abs(vsip.get(Y, (i, j)) - ydata[i][j])
    if (chk > .01):
        print("error\n")
    else:
        print("agree\n")
    vsip.destroy(AC)
    vsip.destroy(AG)
    vsip.destroy(IC)
    vsip.destroy(IG)
    vsip.destroy(B)
    vsip.destroy(A)
    vsip.destroy(X)
    vsip.destroy(Y)
    vsip.allDestroy(AT)
    vsip.destroy(ludC)
    vsip.destroy(ludG)
コード例 #8
0
ファイル: vsipUser.py プロジェクト: rrjudd/jvsip
 def rcfn(t,s,f,l):
     a=vsip.create(t,l);
     s=vsip.create('rand',(s,1,1,f))
     vsip.randn(s,a)
     vsip.destroy(s)
     return a
コード例 #9
0
ファイル: test_create_destroy.py プロジェクト: rrjudd/jvsip
print('TEST vsiputils create and destroy routines')
print('this test just does a create and destroy for each supported VSIP type')
print('No \'additional\' output means the test passes')
import vsiputils as vsip
#block create/destroy
a = vsip.create('block_f', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('block_d', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('cblock_f', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('cblock_d', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('block_i', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('block_si', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('block_uc', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('block_vi', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('block_mi', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('block_bl', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
#vector view create/destroy
a = vsip.create('vview_d', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('vview_f', (100, vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a = vsip.create('vview_d', (100, vsip.VSIP_MEM_NONE))
コード例 #10
0
 def rcfu(t, s, f, l):
     a = vsip.create(t, l)
     s = vsip.create('rand', (s, 1, 1, f))
     vsip.randu(s, a)
     vsip.destroy(s)
     return a
コード例 #11
0
ファイル: test_create_destroy.py プロジェクト: rrjudd/jvsip
print('TEST vsiputils create and destroy routines')
print('this test just does a create and destroy for each supported VSIP type')
print('No \'additional\' output means the test passes')
import vsiputils as vsip
#block create/destroy
a=vsip.create('block_f',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('block_d',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('cblock_f',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('cblock_d',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('block_i',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('block_si',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('block_uc',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('block_vi',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('block_mi',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('block_bl',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
#vector view create/destroy
a=vsip.create('vview_d',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('vview_f',(100,vsip.VSIP_MEM_NONE))
vsip.destroy(a)
a=vsip.create('vview_d',(100,vsip.VSIP_MEM_NONE))
コード例 #12
0
ファイル: lud.py プロジェクト: rrjudd/jvsip
def clud(p):
   def cmplx(p,re,im):
      return eval('vsip_cmplx'+p+'(re,im)')
   def csub(p,a,b):
       return eval('vsip_csub'+p+'(a,b)')
   def cmag(p,a):
       return eval('vsip_cmag'+p+'(a)')
   """
     Usage is clud(p) where p is a string of either '_d' or '_f' to denote precision.
     only works for complex data. 
   """
   print('********\nTEST clud'+p+'\n')
   block = vsip.create('cblock'+p,(600,vsip.VSIP_MEM_NONE))
   AC = vsip.bind(block,(0,7,7,1,7))
   AG = vsip.bind(block,(175,-2,7,-18,7))
   IC = vsip.bind(block,(176,1,7,7,7))
   IG = vsip.bind(block,(226,2,7,15,7))
   B = vsip.bind(block,(335,7,7,1,7))
   A = vsip.bind(block,(385,7,7,1,7))
   X = vsip.bind(block,(434,5,7,1,3))
   Y = vsip.bind(block,(475,3,7,1,3))
   ludC = vsip.create('clu'+p,7)
   ludG = vsip.create('clu'+p,7)
   data_r = [ \
          [0.5,  7.0, 10.0, 12.0, -3.0,  0.0,   0.05], \
          [2.0, 13.0, 18.0,  6.0,  0.0, 130.0,  8.0], \
          [3.0, -9.0,  2.0,  3.0,  2.0,  -9.0,  6.0], \
          [4.0,  2.0,  2.0,  4.0,  1.0,   2.0,  3.0], \
          [0.2,  2.0,  9.0,  4.0,  1.0,   2.0,  3.0], \
          [0.1,  2.0,  0.3,  4.0,  1.0,   2.0,  3.0], \
          [0.0,  0.2,  3.0,  4.0,  1.0,   2.0,  3.0]];
   data_i = [
         [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], \
        [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], \
        [0.1, 0.1, 0.1, 0.2, 0.2,-0.2, 0.2], \
        [0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2], \
        [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3], \
        [0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4], \
        [0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4]];

   ydata_r = [ \
        [77.85,   155.70,   311.40], \
       [942.00,  1884.00,  3768.00], \
         [1.00,     2.00,     4.00], \
        [68.00,   136.00,   272.00], \
        [85.20,   170.40,   340.80], \
        [59.00,   118.00,   236.00], \
         [5.00,    18.00,     6.00]];

   ydata_i = [ \
        [4.5,      1.70,   -3.40], \
        [3.7,    184.00,   -2.00], \
        [1.00,     3.00,    2.00], \
        [68.00,   16.00,  272.00], \
        [85.20, 1170.40,  340.80], \
        [59.00,   18.50,   62.00], \
        [59.00,   11.60,   26.00]];

                  
   Ident = [    \
                  [1, 0, 0, 0, 0, 0, 0], \
                  [0, 1, 0, 0, 0, 0, 0], \
                  [0, 0, 1, 0, 0, 0, 0], \
                  [0, 0, 0, 1, 0, 0, 0], \
                  [0, 0, 0, 0, 1, 0, 0], \
                  [0, 0, 0, 0, 0, 1, 0], \
                  [0, 0, 0, 0, 0, 0, 1]];
   AH = vsip.create('cmview'+p,(7,7,vsip.VSIP_ROW,vsip.VSIP_MEM_NONE));

   for i in range(7):  
       for j in range(7):
           a=cmplx(p,data_r[i][j],data_i[i][j])
           e=cmplx(p,Ident[i][j],0.0)
           vsip.put(A, (i,j),a)
           vsip.put(AC,(i,j),a)
           vsip.put(AG,(i,j),a)
           vsip.put(IC,(i,j),e)
           vsip.put(IG,(i,j),e)
   for i in range(7):
       for j in range(3):
           a=cmplx(p,ydata_r[i][j],ydata_i[i][j])
           vsip.put(X,(i,j),a)
   vsip.herm(A,AH)
   print("Matrix A = \n");VU.mprint(A,'%7.2f')
   vsip.lud(ludC,AC); vsip.lud(ludG,AG)
   print("vsip_clusol(lud,vsip.VSIP_MAT_NTRANS,X)\n")
   print("Solve A X = I \n")
   vsip.lusol(ludC,vsip.VSIP_MAT_NTRANS,IC)
   vsip.lusol(ludG,vsip.VSIP_MAT_NTRANS,IG)
   print("for compact case X = \n");VU.mprint(IC,'%8.4f')
   print("for general case X = \n");VU.mprint(IG,'%8.4f')
   chk = 0
   for i in range(7):
       for j in range(7):
           chk += cmag(p,csub(p,vsip.get(IC,(i,j)),vsip.get(IG,(i,j))))
   if chk > .01: 
       print("error\n") 
   else:
       print("agree\n")
   vsip.prod(A,IC,B)
   chk = 0
   for i in range(7):   
       for j in range(7):
           chk += cmag(p,csub(p,vsip.get(B,(i,j)),cmplx(p,Ident[i][j],0.0)))
   vsip.prod(A,IG,B)
   for i in range(7):
       for j in range(7):
           chk += cmag(p,csub(p,vsip.get(B,(i,j)),cmplx(p,Ident[i][j],0.0)))
   print("mprod(A,X) = \n"); VU.mprint(B,'%8.3f')
   if chk > .01: 
       print("error\n") 
   else:
       print("correct\n")
   # check case VSIP_MAT_HERM
   print("Matrix Hermitian A = \n");VU.mprint(AH,'%7.2f')
   for i in range(7):
       for j in range(7):
         vsip.put(IC,(i,j),cmplx(p,Ident[i][j],0.0))
         vsip.put(IG,(i,j),cmplx(p,Ident[i][j],0.0))
   print("vsip_clusol(lud,vsip.VSIP_MAT_HERM,X)\n")
   print("Solve herm(A) X = I \n")
   vsip.lusol(ludC,vsip.VSIP_MAT_HERM,IC)
   vsip.lusol(ludG,vsip.VSIP_MAT_HERM,IG)
   print("for compact case X = \n");VU.mprint(IC,'%8.4f')
   print("for general case X = \n");VU.mprint(IG,'%8.4f')
   chk = 0
   for i in range(7):
       for j in range(7):
         chk += cmag(p,csub(p,vsip.get(IC,(i,j)),vsip.get(IG,(i,j))))
         chk += cmag(p,csub(p,vsip.get(IC,(i,j)),vsip.get(IG,(i,j))))
   if chk > .01:
       print("error\n") 
   else: 
       print("agree\n")
   vsip.prod(AH,IC,B)
   chk = 0
   for i in range(7):
       for j in range(7):
           chk += cmag(p,csub(p,vsip.get(B,(i,j)),cmplx(p,Ident[i][j],0.0)))
   vsip.prod(AH,IG,B)
   for i in range(7):
       for j in range(7):
           chk += cmag(p,csub(p,vsip.get(B,(i,j)),cmplx(p,Ident[i][j],0.0)))
   print("mprod(trans(A),X) = \n"); VU.mprint(B,'%8.3f')
   if chk > .01:
       print("error\n") 
   else: 
       print("correct\n")
   # check case A X = B for VSIP_MAT_NTRANS
   print("check A X = Y; VSIP_MAT_NTRANS\n")
   print("Y = \n");VU.mprint(X,"%8.4f")
   vsip.lusol(ludC,vsip.VSIP_MAT_NTRANS,X)
   print("X = \n"); VU.mprint(X,"%8.4f")
   vsip.prod(A,X,Y)
   print(" Y = A X\n");VU.mprint(Y,"%8.4f")
   chk = 0;
   for i in range(7):
       for j in range(3):
           chk += cmag(p,csub(p,vsip.get(Y,(i,j)),cmplx(p,ydata_r[i][j],ydata_i[i][j])))
   if (chk > .01):
       print("error\n") 
   else: 
       print("agree\n")

   for i in range(7):
       for j in range(3):
          vsip.put(X,(i,j),cmplx(p,ydata_r[i][j],ydata_i[i][j]))
   print("Y = \n");VU.mprint(X,'%8.4f')
   vsip.lusol(ludG,vsip.VSIP_MAT_HERM,X)
   vsip.prod(AH,X,Y)
   print("X = \n");VU.mprint(X,'%8.4f')
   print("Y = trans(A) X\n");VU.mprint(Y,'%8.4f')
   chk = 0
   for i in range(7):
       for j in range(3):
           chk += cmag(p,csub(p,vsip.get(Y,(i,j)),cmplx(p,ydata_r[i][j],ydata_i[i][j])))
   if (chk > .02):
       print("error\n") 
   else: 
       print("agree\n")
   vsip.destroy(AC)
   vsip.destroy(AG)
   vsip.destroy(IC)
   vsip.destroy(IG)
   vsip.destroy(B)
   vsip.destroy(A)
   vsip.destroy(X)
   vsip.destroy(Y)
   vsip.allDestroy(AH)
   vsip.destroy(ludC)
   vsip.destroy(ludG)
コード例 #13
0
ファイル: lud.py プロジェクト: rrjudd/jvsip
def lud(p):
   """
     Usage is lud(p) where p is a string of either '_d' or '_f' to denote precision.
     only works for real data. 
   """
   print('********\nTEST lud'+p+'\n')
   block = vsip.create('block'+p,(500,vsip.VSIP_MEM_NONE))
   AC = vsip.bind(block,(0,6,6,1,6))
   AG = vsip.bind(block,(36,2,6,18,6))
   IC = vsip.bind(block,(150,1,6,6,6))
   IG = vsip.bind(block,(200,2,6,14,6))
   B = vsip.bind(block,(300,6,6,1,6))
   A = vsip.bind(block,(350,6,6,1,6))
   X = vsip.bind(block,(400,5,6,1,3))
   Y = vsip.bind(block,(450,3,6,1,3))
   ludC = vsip.create('lu'+p,6)
   ludG = vsip.create('lu'+p,6)
   AT = vsip.transview(A)
   data= [ [0.50,     7.00,    10.00,    12.00,    -3.00,     0.00],
            [2.00,    13.00,    18.00,     6.00,     0.00,   130.00],
            [3.00,    -9.00,     2.00,     3.00,     2.00,    -9.00],
            [4.00,     2.00,     2.00,     4.00,     1.00,     2.00],
            [0.20,     2.00,     9.00,     4.00,     1.00,     2.00],
            [0.10,     2.00,     0.30,     4.00,     1.00,     2.00]]
              
   ydata= [[  77.85,   155.70,   311.40],
         [ 942.00,  1884.00,  3768.00],
         [   1.00,     2.00,     4.00],
         [  68.00,   136.00,   272.00],
         [  85.20,   170.40,   340.80],
         [  59.00,   118.00,   236.00]]

   Ident = [[1, 0, 0, 0, 0, 0],
                 [0, 1, 0, 0, 0, 0],
                 [0, 0, 1, 0, 0, 0],
                 [0, 0, 0, 1, 0, 0],
                 [0, 0, 0, 0, 1, 0],
                 [0, 0, 0, 0, 0, 1]]

   for i in range(6):  
       for j in range(6):
           vsip.put(A, (i,j),data[i][j])
           vsip.put(AC,(i,j),data[i][j])
           vsip.put(AG,(i,j),data[i][j])
           vsip.put(IC,(i,j),Ident[i][j])
           vsip.put(IG,(i,j),Ident[i][j])
   for i in range(6):
       for j in range(3):
           vsip.put(X,(i,j),ydata[i][j])

   print("Matrix A = \n");VU.mprint(A,'%7.2f')
   vsip.lud(ludC,AC); vsip.lud(ludG,AG)
   print("vsip_lusol(lud,vsip.VSIP_MAT_NTRANS,X)\n")
   print("Solve A X = I \n")
   vsip.lusol(ludC,vsip.VSIP_MAT_NTRANS,IC)
   vsip.lusol(ludG,vsip.VSIP_MAT_NTRANS,IG)
   print("for compact case X = \n");VU.mprint(IC,'%8.4f')
   print("for general case X = \n");VU.mprint(IG,'%8.4f')
   chk = 0
   for i in range(6):
       for j in range(6):
           chk += abs(vsip.get(IC,(i,j)) - vsip.get(IG,(i,j)))
   if chk > .01: 
       print("error\n") 
   else:
       print("agree\n")
   vsip.prod(A,IC,B)
   chk = 0
   for i in range(6):   
       for j in range(6):
           chk += abs(vsip.get(B,(i,j)) - Ident[i][j])
   vsip.prod(A,IG,B)
   for i in range(6):
       for j in range(6):
           chk += abs(vsip.get(B,(i,j)) - Ident[i][j])
   print("mprod(A,X) = \n"); VU.mprint(B,'%8.3f')
   if chk > .01: 
       print("error\n") 
   else:
       print("correct\n")
   print("Matrix Transpose A = \n");VU.mprint(AT,'%7.2f')
   for i in range(6):
       for j in range(6):
         vsip.put(IC,(i,j),Ident[i][j])
         vsip.put(IG,(i,j),Ident[i][j])
   print("vsip_lusol(lud,vsip.VSIP_MAT_TRANS,X)\n")
   print("Solve trans(A) X = I \n")
   vsip.lusol(ludC,vsip.VSIP_MAT_TRANS,IC)
   vsip.lusol(ludG,vsip.VSIP_MAT_TRANS,IG)
   print("for compact case X = \n");VU.mprint(IC,'%8.4f')
   print("for general case X = \n");VU.mprint(IG,'%8.4f')
   chk = 0
   for i in range(6):
       for j in range(6):
         chk += abs(vsip.get(IC,(i,j)) - vsip.get(IG,(i,j)))
   if chk > .01:
       print("error\n") 
   else: 
       print("agree\n")
   vsip.prod(AT,IC,B)
   chk = 0
   for i in range(6):
       for j in range(6):
          chk += abs(vsip.get(B,(i,j)) - Ident[i][j])
   vsip.prod(AT,IG,B)
   for i in range(6):
       for j in range(6):
          chk += abs(vsip.get(B,(i,j)) - Ident[i][j])
   print("mprod(trans(A),X) = \n"); VU.mprint(B,'%8.3f')
   if chk > .01:
       print("error\n") 
   else: 
       print("correct\n")
   print("check A X = Y; vsip.VSIP_MAT_NTRANS\n")
   print("Y = \n");VU.mprint(X,'%8.4f')
   vsip.lusol(ludC,vsip.VSIP_MAT_NTRANS,X)
   print("X = \n"); VU.mprint(X,'%8.4f')
   vsip.prod(A,X,Y)
   print(" Y = A X\n");VU.mprint(Y,'%8.4f')
   chk = 0
   for i in range(6):
       for j in range(3):
           chk += abs(vsip.get(Y,(i,j)) - ydata[i][j])
   if chk > .01:
       print("error\n") 
   else : 
       print("agree\n")
   for i in range(6):
       for j in range(3):
          vsip.put(X,(i,j),ydata[i][j])
   print("Y = \n");VU.mprint(X,'%8.4f')
   vsip.lusol(ludG,vsip.VSIP_MAT_TRANS,X)
   vsip.prod(AT,X,Y)
   print("X = \n");VU.mprint(X,'%8.4f')
   print("Y = trans(A) X\n");VU.mprint(Y,'%8.4f')
   chk = 0
   for i in range(6):
       for j in range(3):
           chk += abs(vsip.get(Y,(i,j)) - ydata[i][j])
   if (chk > .01):
       print("error\n") 
   else: 
       print("agree\n")
   vsip.destroy(AC)
   vsip.destroy(AG)
   vsip.destroy(IC)
   vsip.destroy(IG)
   vsip.destroy(B)
   vsip.destroy(A)
   vsip.destroy(X)
   vsip.destroy(Y)
   vsip.allDestroy(AT)
   vsip.destroy(ludC)
   vsip.destroy(ludG)