/[escript]/trunk/escript/py_src/generatediff
ViewVC logotype

Diff of /trunk/escript/py_src/generatediff

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 550 by gross, Wed Feb 22 02:14:38 2006 UTC revision 588 by gross, Fri Mar 10 04:45:04 2006 UTC
# Line 522  def mkText(case,name,a,a1=None,use_taggi Line 522  def mkText(case,name,a,a1=None,use_taggi
522    
523           return t_out           return t_out
524    
525  def mkTypeAndShapeTest(case,sh,argstr):  def mkTypeAndShapeTest(case,sh,argstr,name=""):
526      text=""      text=""
527      if case=="float":      if case=="float":
528           text+="      self.failUnless(isinstance(%s,float),\"wrong type of result.\")\n"%argstr           text+="      self.failUnless(isinstance(%s,float),\"wrong type of result%s.\")\n"%(argstr,name)
529      elif case=="array":      elif case=="array":
530           text+="      self.failUnless(isinstance(%s,numarray.NumArray),\"wrong type of result.\")\n"%argstr           text+="      self.failUnless(isinstance(%s,numarray.NumArray),\"wrong type of result%s.\")\n"%(argstr,name)
531           text+="      self.failUnlessEqual(%s.shape,%s,\"wrong shape of result.\")\n"%(argstr,str(sh))           text+="      self.failUnlessEqual(%s.shape,%s,\"wrong shape of result%s.\")\n"%(argstr,str(sh),name)
532      elif case in ["constData","taggedData","expandedData"]:          elif case in ["constData","taggedData","expandedData"]:    
533           text+="      self.failUnless(isinstance(%s,Data),\"wrong type of result.\")\n"%argstr           text+="      self.failUnless(isinstance(%s,Data),\"wrong type of result%s.\")\n"%(argstr,name)
534           text+="      self.failUnlessEqual(%s.getShape(),%s,\"wrong shape of result.\")\n"%(argstr,str(sh))           text+="      self.failUnlessEqual(%s.getShape(),%s,\"wrong shape of result%s.\")\n"%(argstr,str(sh),name)
535      elif case=="Symbol":      elif case=="Symbol":
536           text+="      self.failUnless(isinstance(%s,Symbol),\"wrong type of result.\")\n"%argstr           text+="      self.failUnless(isinstance(%s,Symbol),\"wrong type of result%s.\")\n"%(argstr,name)
537           text+="      self.failUnlessEqual(%s.getShape(),%s,\"wrong shape of result.\")\n"%(argstr,str(sh))           text+="      self.failUnlessEqual(%s.getShape(),%s,\"wrong shape of result%s.\")\n"%(argstr,str(sh),name)
538      return text      return text
539    
540  def mkCode(txt,args=[],intend=""):  def mkCode(txt,args=[],intend=""):
# Line 549  def mkCode(txt,args=[],intend=""): Line 549  def mkCode(txt,args=[],intend=""):
549      for r in args:      for r in args:
550        out=out.replace("%%a%s%%"%c,r)        out=out.replace("%%a%s%%"%c,r)
551      return out        return out  
552    
553    
554    #=======================================================================================================
555    # eigenvalues and eigen vectors 2D:
556    #=======================================================================================================
557    alltests= \
558      [ ("case0",[[0.0, 0.0], [0.0, 0.0]],[0.0, 0.0]) \
559       , ("case3",[[-1.0, 0.0], [0.0, -1.0]],[-1.0, -1.0]) \
560       , ("case5",[[-0.99999999999999967, -6.4606252205695602e-16], [-6.4606252205695602e-16, -0.99999999999999967]],[-1.0, -1.0]) \
561       , ("case6",[[0.0, 0.0], [0.0, 0.0001]],[0.0, 0.0001]) \
562       , ("case7",[[0.0001, 0.0], [0.0, 0.0]],[0.0, 0.0001]) \
563       , ("case8",[[6.0598371831785722e-06, 2.3859213977648625e-05], [2.3859213977648629e-05, 9.3940162816821425e-05]],[0.0, 0.0001]) \
564       , ("case9",[[1.0, 0.0], [0.0, 2.0]],[1.0, 2.0]) \
565       , ("case10",[[2.0, 0.0], [0.0, 1.0]],[1.0, 2.0]) \
566       , ("case11",[[1.0605983718317855, 0.23859213977648688], [0.23859213977648688, 1.9394016281682138]],[1.0, 2.0]) \
567       , ("case12",[[1.0, 0.0], [0.0, 1000000.0]],[1.0, 1000000.0]) \
568       , ("case13",[[1000000.0, 0.0], [0.0, 1.0]],[1.0, 1000000.0]) \
569       , ("case14",[[60599.311233413886, 238591.90118434647], [238591.90118434647, 939401.68876658613]],[1.0, 1000000.0]) \
570       ]
571    dim=2
572    
573    
574    alltests= \
575    [ ("case0",[[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],[0.0, 0.0, 0.0]) \
576    , ("case5",[[10.0, 0.0, 0.0], [0.0, 10.0, 0.0], [0.0, 0.0, 10.0]],[10.0, 10.0, 10.0]) \
577    , ("case10",[[0.9, 0.0, 0.0], [0.0, 0.9, 0.0], [0.0, 0.0, 1.0]],[0.9, 0.9, 1.0]) \
578    , ("case11",[[0.9, 0.0, 0.0], [0.0, 0.97060899725040983, -0.045555123008643325], [0.0, -0.045555123008643339, 0.92939100274959041]],[0.9, 0.9, 1.0]) \
579    , ("case12",[[0.92694799760252555, 0.0, 0.044368966468320177], [0.0, 0.9, 0.0], [0.044368966468320184, 0.0, 0.97305200239747425]],[0.9, 0.9, 1.0]) \
580    , ("case13",[[1.0, 0.0, 0.0], [0.0, 0.9, 0.], [0.0, 0., 0.9]],[0.9, 0.9, 1.0]) \
581    , ("case14",[[0.92379770619813639, 0.041031106298491521, -0.011396846732439278], [0.041031106298491535, 0.97074428392640366, -0.019650012730342326], [-0.011396846732439236, -0.019650012730342337, 0.90545800987545966]],[0.9, 0.9, 1.0]) \
582    , ("case15",[[1.0, 0.0, 0.0], [0.0, 1.1, 0.0], [0.0, 0.0, 1.1]],[1.0, 1.1, 1.1]) \
583    , ("case17",[[1.0269479976025255, 0.0, 0.044368966468320309], [0.0, 1.1, 0.0], [0.044368966468320295, 0.0, 1.0730520023974743]],[1.0, 1.1, 1.1]) \
584    , ("case18",[[1.1, 0.0, 0.0], [0.0, 1.0153410887977139, -0.036038311201720394], [0.0, -0.036038311201720373, 1.084658911202286]],[1.0, 1.1, 1.1]) \
585    , ("case19",[[1.035487967756175, 0.026317079185831614, -0.039960133424212368], [0.026317079185831618, 1.0892641940924184, 0.016301362071911414], [-0.039960133424212355, 0.016301362071911431, 1.0752478381514063]],[1.0, 1.1, 1.1]) \
586    , ("case20",[[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]],[1.0, 2.0, 3.0]) \
587    , ("case21",[[1.0, 0.0, 0.0], [0.0, 2.7060899725040968, -0.45555123008643206], [0.0, -0.45555123008643228, 2.2939100274959037]],[1.0, 2.0, 3.0]) \
588    , ("case22",[[1.5389599520505153, 0.0, 0.88737932936638753], [0.0, 2.0, 0.0], [0.88737932936638753, 0.0, 2.4610400479494858]],[1.0, 2.0, 3.0]) \
589    , ("case23",[[3.0, 0.0, 0.0], [0.0, 1.153410887977139, -0.36038311201720391], [0.0, -0.36038311201720391, 1.8465891120228608]],[1.0, 2.0, 3.0]) \
590    , ("case24",[[1.5928567395431172, 0.67348185484323142, -0.51356980156651744], [0.67348185484323153, 2.6000847801882254, -0.033486506584313548], [-0.51356980156651744, -0.033486506584313541, 1.8070584802686565]],[1.0, 2.0, 3.0]) \
591    , ("case25",[[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 30000.0]],[1.0, 2.0, 30000.0]) \
592    , ("case26",[[1.0, 0.0, 0.0], [0.0, 21183.286995177881, -13665.625800132779], [0.0, -13665.625800132779, 8818.7130048221279]],[1.0, 2.0, 30000.0]) \
593    , ("case27",[[8085.1298007817086, 0.0, 13310.246250831115], [0.0, 2.0, 0.0], [13310.246250831115, 0.0, 21915.870199218316]],[1.0, 2.0, 30000.0]) \
594    , ("case28",[[30000.0, 0.0, 0.0], [0.0, 1.153410887977139, -0.36038311201720391], [0.0, -0.36038311201720391, 1.8465891120228608]],[1.0, 2.0, 30000.0]) \
595    , ("case29",[[7140.1907849945546, 12308.774438213351, -3419.2256841313947], [12308.774438213351, 21223.762934183575, -5894.4478052274408], [-3419.2256841313947, -5894.4478052274408, 1639.0462808218595]],[1.0, 2.0, 30000.0]) \
596    ]
597    
598    dim=3
599    
600    alltests= \
601    [ ("case0",[[0.0]],[0.0]) \
602    , ("case1",[[1.0]],[1.0]) \
603    ]
604    dim=1
605    
606    for case in ["constData","taggedData","expandedData"]:
607       n=0
608       while n<len(alltests):
609          text="   #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
610          tname="test_eigenvalues_and_eigenvectors_%s_dim%s_%s"%(case,dim,alltests[n][0])
611          text+="   def %s(self):\n"%tname
612          a_0=numarray.array(alltests[n][1],numarray.Float64)
613          ev_0=numarray.array(alltests[n][2],numarray.Float64)
614          if case in ["taggedData", "expandedData"]:
615             if n+1<len(alltests):
616               a1_0=numarray.array(alltests[n+1][1],numarray.Float64)
617               ev1_0=numarray.array(alltests[n+1][2],numarray.Float64)
618             else:
619               a1_0=numarray.array(alltests[0][1],numarray.Float64)
620               ev1_0=numarray.array(alltests[0][2],numarray.Float64)
621             n+=2
622          else:
623             a1_0=a_0                  
624             ev1_0=ev_0
625             n+=1
626          text+=mkText(case,"arg",a_0,a1_0)
627          text+="      res=eigenvalues_and_eigenvectors(arg)\n"
628          text+=mkText(case,"ref_ev",ev_0,ev1_0)
629          text+=mkTypeAndShapeTest(case,(dim,),"res[0]"," for eigenvalues")
630          text+=mkTypeAndShapeTest(case,(dim,dim),"res[1]"," for eigenvectors")
631          text+="      self.failUnless(Lsup(res[0]-ref_ev)<=self.RES_TOL*Lsup(ref_ev),\"wrong eigenvalues\")\n"
632          for i in range(dim):
633              text+="      self.failUnless(Lsup(matrixmult(arg,res[1][:,%s])-res[0][%s]*res[1][:,%s])<=self.RES_TOL*Lsup(res[0]),\"wrong eigenvector %s\")\n"%(i,i,i,i)
634          text+="      self.failUnless(Lsup(matrixmult(transpose(res[1]),res[1])-kronecker(%s))<=self.RES_TOL,\"eigenvectors are not orthonormal\")\n"%dim
635          if case == "taggedData" :
636               t_prog_with_tags+=text
637          else:              
638               t_prog+=text
639    print test_header
640    print t_prog
641    print t_prog_with_tags
642    print test_tail          
643    1/0
644  #=======================================================================================================  #=======================================================================================================
645  # get slices  # get slices
646  #=======================================================================================================  #=======================================================================================================

Legend:
Removed from v.550  
changed lines
  Added in v.588

  ViewVC Help
Powered by ViewVC 1.1.26