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

Diff of /trunk/escript/py_src/generateutil

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

revision 550 by gross, Wed Feb 22 02:14:38 2006 UTC revision 587 by gross, Fri Mar 10 02:26:50 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    for case in ["constData","taggedData","expandedData"]:
573       n=0
574       while n<len(alltests):
575          text="   #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
576          tname="test_eigenvalues_and_eigenvectors_%s_dim%s_%s"%(case,dim,alltests[n][0])
577          text+="   def %s(self):\n"%tname
578          a_0=numarray.array(alltests[n][1],numarray.Float64)
579          ev_0=numarray.array(alltests[n][2],numarray.Float64)
580          if case in ["taggedData", "expandedData"]:
581             a1_0=numarray.array(alltests[n+1][1],numarray.Float64)
582             ev1_0=numarray.array(alltests[n+1][2],numarray.Float64)
583             n+=2
584          else:
585             a1_0=a_0                  
586             ev1_0=ev_0
587             n+=1
588          text+=mkText(case,"arg",a_0,a1_0)
589          text+="      res=eigenvalues_and_eigenvectors(arg)\n"
590          text+=mkText(case,"ref_ev",ev_0,ev1_0)
591          text+=mkTypeAndShapeTest(case,(dim,),"res[0]"," for eigenvalues")
592          text+=mkTypeAndShapeTest(case,(dim,dim),"res[1]"," for eigenvectors")
593          text+="      self.failUnless(Lsup(res[0]-ref_ev)<=self.RES_TOL*Lsup(ref_ev),\"wrong eigenvalues\")\n"
594          for i in range(dim):
595              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)
596          text+="      self.failUnless(Lsup(matrixmult(transpose(res[1]),res[1])-kronecker(%s))<=self.RES_TOL,\"eigenvectors are not orthonormal\")\n"%dim
597          if case == "taggedData" :
598               t_prog_with_tags+=text
599          else:              
600               t_prog+=text
601    print test_header
602    print t_prog
603    print t_prog_with_tags
604    print test_tail          
605    1/0
606  #=======================================================================================================  #=======================================================================================================
607  # get slices  # get slices
608  #=======================================================================================================  #=======================================================================================================

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

  ViewVC Help
Powered by ViewVC 1.1.26