- Timestamp:
- 11/13/2008 04:10:19 PM (8 weeks ago)
- Location:
- trunk/fipy
- Files:
-
- 3 modified
-
tools/inline/inline.py (modified) (5 diffs)
-
variables/operatorVariable.py (modified) (3 diffs)
-
variables/variable.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fipy/tools/inline/inline.py
r2611 r2817 1 import sys 1 import inspect 2 2 3 from fipy.tools import numerix 3 4 from fipy.tools.inline import inlineFlagOn … … 9 10 return pythonFn(*args) 10 11 11 def _runInline(code_in, converters=None, verbose=0, **args): 12 def _frameComment(code, level=2): 13 frame = inspect.getouterframes(inspect.currentframe())[level] 14 15 # note: 16 # don't use #line because it actually makes it harder 17 # to find the offending code in both the C++ source and in the Python 18 #line %d "%s" 19 20 return ''' 21 /* 22 %s:%d 23 24 %s 25 */ 26 ''' % (frame[1], frame[2] - len(code.splitlines()), frame[3]) 27 28 def _runInline(code_in, converters=None, verbose=0, comment=None, **args): 12 29 argsKeys = args.keys() 13 30 dimList = ['i', 'j', 'k'] … … 35 52 code = 'int ' + ','.join(declarations) + ';\n' + loops + "\t" * dimensions + code_in + enders 36 53 54 if comment is None: 55 comment = _frameComment(code_in) 56 57 code = "\n" + comment + "\n" + code 58 37 59 from scipy import weave 38 60 … … 50 72 extra_compile_args =['-O3']) 51 73 52 def _runIterateElementInline(code_in, converters=None, verbose=0, **args):74 def _runIterateElementInline(code_in, converters=None, verbose=0, comment=None, **args): 53 75 loops = """ 54 76 int i; … … 70 92 """ 71 93 94 indent = "\t" * rank 95 72 96 code = """ 73 97 #define ITEM(arr,i,vec) (arr[arrayIndex(arr##_array, i, vec)]) 74 98 75 99 int vec[%(rank)d]; 76 %(loops)s%(indent)s%(code )s%(enders)s100 %(loops)s%(indent)s%(code_in)s%(enders)s 77 101 78 102 #undef ITEM 79 """ % { 80 'rank': rank, 81 'loops': loops, 82 'indent': "\t" * rank, 83 'code': code_in, 84 'enders': enders 85 } 103 """ % locals() 104 105 if comment is None: 106 comment = _frameComment(code_in) 107 108 code = "\n" + comment + "\n" + code 86 109 87 110 from scipy import weave -
trunk/fipy/variables/operatorVariable.py
r2781 r2817 35 35 def _OperatorVariableClass(baseClass=None): 36 36 class _OperatorVariable(baseClass): 37 def __init__(self, op, var, opShape=(), canInline=True, unit=None, *args, **kwargs):37 def __init__(self, op, var, opShape=(), canInline=True, unit=None, inlineComment=None, *args, **kwargs): 38 38 self.op = op 39 39 self.var = var … … 53 53 self.dontCacheMe() 54 54 55 self.comment = inlineComment 56 55 57 def _calcValue(self): 56 58 if not self.canInline: … … 61 63 62 64 def _calcValueIn(self): 63 return self._execInline( )65 return self._execInline(comment=self.comment) 64 66 65 67 def _calcValuePy(self): -
trunk/fipy/variables/variable.py
r2781 r2817 37 37 import sys 38 38 import os 39 import inspect 39 40 40 41 from fipy.tools.dimensions import physicalField … … 667 668 return Variable 668 669 669 def _execInline(self ):670 def _execInline(self, comment=None): 670 671 """ 671 672 Gets the stack from _getCstring() which calls _getRepresentation() … … 750 751 argDict['result'] = numerix.reshape(argDict['result'], (1,)) 751 752 752 inline._runInline(string, converters=None, **argDict)753 inline._runInline(string, converters=None, comment=comment, **argDict) 753 754 754 755 if resultShape == (): … … 803 804 return operatorVariable._OperatorVariableClass(baseClass=baseClass) 804 805 806 def _inlineComment(self, level=3): 807 frame = inspect.getouterframes(inspect.currentframe())[level] 808 809 # note: 810 # don't use #line because it actually makes it harder 811 # to find the offending code in both the C++ source and in the Python 812 #line %d "%s" 813 814 if frame[4] is not None: 815 code = "\n".join(frame[4]) 816 else: 817 code = "" 818 819 return ''' 820 /* 821 %s:%d 822 823 %s 824 */ 825 ''' % (frame[1], frame[2], code) 826 827 805 828 def _UnaryOperatorVariable(self, op, operatorClass=None, opShape=None, canInline=True, unit=None): 806 829 """ … … 826 849 canInline = False 827 850 828 return unOp(op=op, var=[self], opShape=opShape, canInline=canInline, unit=unit) 851 var = unOp(op=op, var=[self], opShape=opShape, canInline=canInline, unit=unit, inlineComment=self._inlineComment()) 852 # var.comment = self._frameComment(level=7) 853 854 return var 829 855 830 856 def _shapeClassAndOther(self, opShape, operatorClass, other): … … 872 898 binOp = binaryOperatorVariable._BinaryOperatorVariable(operatorClass) 873 899 874 return binOp(op=op, var=[self, other], opShape=opShape, canInline=canInline, unit=unit) 900 var = binOp(op=op, var=[self, other], opShape=opShape, canInline=canInline, unit=unit, inlineComment=self._inlineComment()) 901 # var.comment = self._frameComment(level=7) 902 903 return var 875 904 876 905 def __add__(self, other):
FiPy: A Finite Volume PDE Solver Using Python