/[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 3531 by caltinay, Wed Jun 15 04:48:53 2011 UTC revision 3532 by caltinay, Mon Jun 20 04:14:42 2011 UTC
# Line 386  class Symbol(object): Line 386  class Symbol(object):
386          axes=range(axis_offset, self._arr.ndim)+range(0,axis_offset)          axes=range(axis_offset, self._arr.ndim)+range(0,axis_offset)
387          return Symbol(numpy.transpose(self._arr, axes=axes), dim=self.dim)          return Symbol(numpy.transpose(self._arr, axes=axes), dim=self.dim)
388    
389      def applyfunc(self, f):      def applyfunc(self, f, on_type=None):
390          assert callable(f)          assert callable(f)
391          if self._arr.ndim==0:          if self._arr.ndim==0:
392              el=f(self._arr.item())              if on_type is None or isinstance(self._arr.item(),on_type):
393                    el=f(self._arr.item())
394                else:
395                    el=self._arr.item()
396              if el is not None:              if el is not None:
397                  out=Symbol(el, dim=self.dim)                  out=Symbol(el, dim=self.dim)
398              else:              else:
# Line 397  class Symbol(object): Line 400  class Symbol(object):
400          else:          else:
401              out=numpy.empty(self.getShape(), dtype=object)              out=numpy.empty(self.getShape(), dtype=object)
402              for idx in numpy.ndindex(self.getShape()):              for idx in numpy.ndindex(self.getShape()):
403                  out[idx]=f(self._arr[idx])                  if on_type is None or isinstance(self._arr[idx],on_type):
404                        out[idx]=f(self._arr[idx])
405                    else:
406                        out[idx]=self._arr[idx]
407              out=Symbol(out, dim=self.dim)              out=Symbol(out, dim=self.dim)
408          return out          return out
409    
410        def simplify(self):
411            return self.applyfunc(sympy.simplify, sympy.Basic)
412    
413      def _sympy_(self):      def _sympy_(self):
414          return self.applyfunc(sympy.sympify)          return self.applyfunc(sympy.sympify)
415    

Legend:
Removed from v.3531  
changed lines
  Added in v.3532

  ViewVC Help
Powered by ViewVC 1.1.26