/[escript]/trunk/escript/py_src/symbolic/symbol.py
ViewVC logotype

Diff of /trunk/escript/py_src/symbolic/symbol.py

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

revision 3508 by caltinay, Wed May 11 06:04:52 2011 UTC revision 3509 by caltinay, Fri May 13 06:01:52 2011 UTC
# Line 70  class Symbol(object): Line 70  class Symbol(object):
70              shape=args[1]              shape=args[1]
71              if len(shape)>4:              if len(shape)>4:
72                  raise ValueError("Symbol only supports tensors up to order 4")                  raise ValueError("Symbol only supports tensors up to order 4")
73              self.__arr=sympy.symarray(shape, '['+name+']')              if len(shape)==0:
74                    self.__arr=numpy.array(sympy.Symbol(name, **kwargs))
75                else:
76                    self.__arr=sympy.symarray(shape, '['+name+']')
77          else:          else:
78              raise TypeError("Unsupported number of arguments")              raise TypeError("Unsupported number of arguments")
79          if self.__arr.ndim==0:          if self.__arr.ndim==0:
# Line 181  class Symbol(object): Line 184  class Symbol(object):
184      def swap_axes(self, axis0, axis1):      def swap_axes(self, axis0, axis1):
185          return Symbol(numpy.swapaxes(self.__arr, axis0, axis1))          return Symbol(numpy.swapaxes(self.__arr, axis0, axis1))
186    
187      def tensorproduct(self, other, axis_offset):      def tensorProduct(self, other, axis_offset):
188          arg0_c=self.__arr.copy()          arg0_c=self.__arr.copy()
189          sh0=self.__arr.shape          sh0=self.__arr.shape
190          if isinstance(other, Symbol):          if isinstance(other, Symbol):
# Line 203  class Symbol(object): Line 206  class Symbol(object):
206          out.resize(sh0[:self.__arr.ndim-axis_offset]+sh1[axis_offset:])          out.resize(sh0[:self.__arr.ndim-axis_offset]+sh1[axis_offset:])
207          return Symbol(out)          return Symbol(out)
208    
209        def transposedTensorProduct(self, other, axis_offset):
210            arg0_c=self.__arr.copy()
211            sh0=self.__arr.shape
212            if isinstance(other, Symbol):
213                arg1_c=other.__arr.copy()
214                sh1=other.getShape()
215            else:
216                arg1_c=other.copy()
217                sh1=other.shape
218            d0,d1,d01=1,1,1
219            for i in sh0[axis_offset:]: d0*=i
220            for i in sh1[axis_offset:]: d1*=i
221            for i in sh1[:axis_offset]: d01*=i
222            arg0_c.resize((d01,d0))
223            arg1_c.resize((d01,d1))
224            out=numpy.zeros((d0,d1),numpy.object)
225            for i0 in range(d0):
226                for i1 in range(d1):
227                    out[i0,i1]=numpy.sum(arg0_c[:,i0]*arg1_c[:,i1])
228            out.resize(sh0[axis_offset:]+sh1[axis_offset:])
229            return Symbol(out)
230    
231        def tensorTransposedProduct(self, other, axis_offset):
232            arg0_c=self.__arr.copy()
233            sh0=self.__arr.shape
234            if isinstance(other, Symbol):
235                arg1_c=other.__arr.copy()
236                sh1=other.getShape()
237                r1=other.getRank()
238            else:
239                arg1_c=other.copy()
240                sh1=other.shape
241                r1=other.ndim
242            d0,d1,d01=1,1,1
243            for i in sh0[:self.__arr.ndim-axis_offset]: d0*=i
244            for i in sh1[:r1-axis_offset]: d1*=i
245            for i in sh1[r1-axis_offset:]: d01*=i
246            arg0_c.resize((d0,d01))
247            arg1_c.resize((d1,d01))
248            out=numpy.zeros((d0,d1),numpy.object)
249            for i0 in range(d0):
250                for i1 in range(d1):
251                    out[i0,i1]=numpy.sum(arg0_c[i0,:]*arg1_c[i1,:])
252            out.resize(sh0[:self.__arr.ndim-axis_offset]+sh1[:r1-axis_offset])
253            return Symbol(out)
254    
255      def trace(self, axis_offset):      def trace(self, axis_offset):
256          sh=self.__arr.shape          sh=self.__arr.shape
257          s1=1          s1=1
# Line 403  def combineData(array, shape): Line 452  def combineData(array, shape):
452      if len(fs)>0:      if len(fs)>0:
453          d=Data(0., shape, fs.pop()) #FIXME: interpolate instead of using first?          d=Data(0., shape, fs.pop()) #FIXME: interpolate instead of using first?
454      else:      else:
455          d=0.          d=numpy.zeros(shape)
456      for idx in numpy.ndindex(shape):      for idx in numpy.ndindex(shape):
457          #z=numpy.zeros(shape)          #z=numpy.zeros(shape)
458          #z[idx]=1.          #z[idx]=1.

Legend:
Removed from v.3508  
changed lines
  Added in v.3509

  ViewVC Help
Powered by ViewVC 1.1.26