Changeset 4c72117 in sasmodels
- Timestamp:
- Dec 18, 2017 12:14:18 PM (7 years ago)
- Children:
- ddfdb16
- Parents:
- 5c2a0f2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/py2c.py
r5c2a0f2 r4c72117 57 57 12/15/2017, OE: Precedence maintained by writing opening and closing 58 58 parenthesesm '(',')', in procedure 'visit_BinOp'. 59 12/18/2017, OE: Added call to 'add_current_line()' at the beginning 60 of visit_Return 61 59 62 """ 60 63 import ast … … 99 102 100 103 101 #def to_source(node, indent_with=' ' * 4, add_line_information=False):102 104 def to_source(node, func_name, constants=None): 103 105 """This function can convert a node tree back into python sourcecode. … … 119 121 """ 120 122 generator = SourceGenerator(' ' * 4, False, constants) 121 # generator.required_functions = func_name122 123 generator.visit(node) 123 124 124 # return ''.join(generator.result)125 125 return ''.join(generator.c_proc) 126 126 … … 253 253 " = " + str(default.n) + "'" 254 254 self.warnings.append(w_str) 255 # self.write_python('=')256 # self.visit(default)257 255 258 256 def decorators(self, node): … … 312 310 self.visit(node.value) 313 311 self.add_semi_colon() 314 # self.write_c(';')315 312 self.add_current_line() 316 313 for n, item in enumerate(self.Tuples): … … 338 335 self.visit(node.value) 339 336 self.add_semi_colon() 340 # self.write_c(';')341 337 self.add_current_line() 342 338 … … 399 395 fLine = True 400 396 start_var += 1 401 # if(len(self.C_IntVars) > 0):402 # s = self.listToDeclare(self.C_IntVars)403 # self.c_proc.insert(start_var, " int " + s + ";\n")404 # fLine = True405 # start_var += 1406 397 if(len(self.C_Vectors) > 0): 407 398 s = self.listToDeclare(self.C_Vectors) … … 443 434 444 435 def getMethodSignature(self): 445 # args_str = ListToString(self.arguments)446 436 args_str = '' 447 437 for n in range(len(self.arguments)): … … 450 440 args_str += ", " 451 441 return(args_str) 452 # self.strMethodSignature = 'double ' + self.name + '(' + args_str + ")"453 442 454 443 def InsertSignature(self): … … 470 459 self.arguments = [] 471 460 self.name = node.name 472 # if self.name not in self.required_functions[0]:473 # return474 461 print("Parsing '" + self.name + "'") 475 462 args_str = "" 476 463 477 464 self.visit(node.args) 478 # for C479 # self.writeInclude()480 465 self.getMethodSignature() 481 # for C482 466 self.signature_line = len(self.c_proc) 483 # self.add_c_line(self.strMethodSignature)484 467 self.add_c_line("\n{") 485 468 start_vars = len(self.c_proc) + 1 … … 598 581 # Iterator name is in node.target.id. 599 582 self.add_current_line() 600 # if(len(self.current_statement) > 0):601 # self.add_c_line(self.current_statement)602 # self.current_statement = ''603 583 fForDone = False 604 584 self.current_statement = '' … … 700 680 701 681 def visit_Return(self, node): 702 self. newline(node)682 self.add_current_line() 703 683 if node.value is None: 704 684 self.write_c('return') … … 1048 1028 self.visit(if_) 1049 1029 1050 # def visit_excepthandler(self, node):1051 # self.newline(node)1052 # self.write_python('except')1053 # if node.type is not None:1054 # self.write_python(' ')1055 # self.visit(node.type)1056 # if node.name is not None:1057 # self.write_python(' as ')1058 # self.visit(node.name)1059 # self.body(node.body)1060 1061 1030 def visit_arguments(self, node): 1062 1031 self.signature(node) 1063 1064 def Iq1(q, porod_scale, porod_exp, lorentz_scale, lorentz_length, peak_pos, lorentz_exp=17):1065 z1 = z2 = z = abs(q - peak_pos) * lorentz_length1066 if(q > p):1067 q = p + 171068 p = q - 51069 z3 = -81070 inten = (porod_scale / q ** porod_exp1071 + lorentz_scale /(1 + z ** lorentz_exp))1072 return inten1073 1074 def Iq(q, porod_scale, porod_exp, lorentz_scale, lorentz_length, peak_pos, lorentz_exp=17):1075 z1 = z2 = z = abs(q - peak_pos) * lorentz_length1076 if(q > p):1077 q = p + 171078 p = q - 51079 elif(q == p):1080 q = p * q1081 q *= z11082 p = z11083 elif(q == 17):1084 q = p * q - 171085 else:1086 q += 71087 z3 = -81088 inten = (porod_scale / q ** porod_exp1089 + lorentz_scale /(1 + z ** lorentz_exp))1090 return inten1091 1032 1092 1033 def print_function(f=None): … … 1127 1068 def translate(functions, constants=0): 1128 1069 sniplets = [] 1129 # sniplets.append("#include <math.h>")1130 # sniplets.append("static double pi = 3.14159265359;")1131 1070 add_constants (sniplets, constants) 1132 1071 for source,fname,line_no in functions:
Note: See TracChangeset
for help on using the changeset viewer.