/[escript]/trunk/escript/py_src/util.py
ViewVC logotype

Diff of /trunk/escript/py_src/util.py

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

revision 2188 by caltinay, Tue Dec 23 04:24:03 2008 UTC revision 2200 by jfenwick, Thu Jan 8 23:55:40 2009 UTC
# Line 3440  def trace(arg,axis_offset=0): Line 3440  def trace(arg,axis_offset=0):
3440        if len(sh)<2:        if len(sh)<2:
3441          raise ValueError,"rank of argument must be greater than 1"          raise ValueError,"rank of argument must be greater than 1"
3442        if axis_offset<0 or axis_offset>len(sh)-2:        if axis_offset<0 or axis_offset>len(sh)-2:
3443          raise ValueError,"axis_offset must be between 0 and %s"%len(sh)-2          raise ValueError,"axis_offset must be between 0 and %d"%(len(sh)-2)
3444        s1=1        s1=1
3445        for i in range(axis_offset): s1*=sh[i]        for i in range(axis_offset): s1*=sh[i]
3446        s2=1        s2=1
3447        for i in range(axis_offset+2,len(sh)): s2*=sh[i]        for i in range(axis_offset+2,len(sh)): s2*=sh[i]
3448        if not sh[axis_offset] == sh[axis_offset+1]:        if not sh[axis_offset] == sh[axis_offset+1]:
3449          raise ValueError,"dimensions of component %s and %s must match."%(axis_offset.axis_offset+1)          raise ValueError,"dimensions of component %d and %d must match."%(axis_offset,axis_offset+1)
3450        arg_reshaped=numarray.reshape(arg,(s1,sh[axis_offset],sh[axis_offset],s2))        arg_reshaped=numarray.reshape(arg,(s1,sh[axis_offset],sh[axis_offset],s2))
3451        out=numarray.zeros([s1,s2],numarray.Float64)        out=numarray.zeros([s1,s2],numarray.Float64)
3452        for i1 in range(s1):        for i1 in range(s1):
# Line 3458  def trace(arg,axis_offset=0): Line 3458  def trace(arg,axis_offset=0):
3458        if arg.getRank()<2:        if arg.getRank()<2:
3459          raise ValueError,"rank of argument must be greater than 1"          raise ValueError,"rank of argument must be greater than 1"
3460        if axis_offset<0 or axis_offset>arg.getRank()-2:        if axis_offset<0 or axis_offset>arg.getRank()-2:
3461          raise ValueError,"axis_offset must be between 0 and %s"%arg.getRank()-2          raise ValueError,"axis_offset must be between 0 and %d"%(arg.getRank()-2)
3462        s=list(arg.getShape())        s=list(arg.getShape())
3463        if not s[axis_offset] == s[axis_offset+1]:        if not s[axis_offset] == s[axis_offset+1]:
3464          raise ValueError,"dimensions of component %s and %s must match."%(axis_offset.axis_offset+1)          raise ValueError,"dimensions of component %d and %d must match."%(axis_offset,axis_offset+1)
3465        return arg._trace(axis_offset)        return arg._trace(axis_offset)
3466     elif isinstance(arg,float):     elif isinstance(arg,float):
3467        raise TypeError,"illegal argument type float."        raise TypeError,"illegal argument type float."
# Line 3491  class Trace_Symbol(DependendSymbol): Line 3491  class Trace_Symbol(DependendSymbol):
3491        if arg.getRank()<2:        if arg.getRank()<2:
3492          raise ValueError,"rank of argument must be greater than 1"          raise ValueError,"rank of argument must be greater than 1"
3493        if axis_offset<0 or axis_offset>arg.getRank()-2:        if axis_offset<0 or axis_offset>arg.getRank()-2:
3494          raise ValueError,"axis_offset must be between 0 and %s"%arg.getRank()-2          raise ValueError,"axis_offset must be between 0 and %d"%(arg.getRank()-2)
3495        s=list(arg.getShape())        s=list(arg.getShape())
3496        if not s[axis_offset] == s[axis_offset+1]:        if not s[axis_offset] == s[axis_offset+1]:
3497          raise ValueError,"dimensions of component %s and %s must match."%(axis_offset.axis_offset+1)          raise ValueError,"dimensions of component %d and %d must match."%(axis_offset,axis_offset+1)
3498        super(Trace_Symbol,self).__init__(args=[arg,axis_offset],shape=tuple(s[0:axis_offset]+s[axis_offset+2:]),dim=arg.getDim())        super(Trace_Symbol,self).__init__(args=[arg,axis_offset],shape=tuple(s[0:axis_offset]+s[axis_offset+2:]),dim=arg.getDim())
3499    
3500     def getMyCode(self,argstrs,format="escript"):     def getMyCode(self,argstrs,format="escript"):

Legend:
Removed from v.2188  
changed lines
  Added in v.2200

  ViewVC Help
Powered by ViewVC 1.1.26