Changeset 1ddb794 in sasmodels
- Timestamp:
- Dec 18, 2017 10:48:16 AM (7 years ago)
- Children:
- 8224d24
- Parents:
- 98a4f14
- Location:
- sasmodels
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/autoc.py
r2badeca r1ddb794 72 72 function_name, function = translate.pop(0) 73 73 filename = function.__code__.co_filename 74 escaped_filename = filename.replace('\\', '\\\\') 74 75 offset = function.__code__.co_firstlineno 75 76 refs = function.__code__.co_names … … 93 94 elif isinstance(obj, float): 94 95 constants[name] = obj 96 snippets.append('#line 1 "%s"' % escaped_filename) 95 97 snippets.append("const double %s = %.15g;"%(name, obj)) 96 98 elif isinstance(obj, int): 97 99 constants[name] = obj 100 snippets.append('#line 1 "%s"' % escaped_filename) 98 101 snippets.append("const int %s = %d;"%(name, obj)) 99 102 elif isinstance(obj, (list, tuple, np.ndarray)): … … 106 109 obj = list(obj) + [0.]*(4-len(obj)) 107 110 vals = ", ".join("%.15g"%v for v in obj) 111 snippets.append('#line 1 "%s"' % escaped_filename) 108 112 snippets.append("const double %s[] = {%s};" %(name, vals)) 109 113 elif isinstance(obj, special.Gauss): … … 129 133 130 134 # translate source 131 functions = py2c.translate( 132 [code[name] for name in ordered_dag(depends) if name in code], 133 constants) 134 snippets.clear() 135 snippets.append(functions) 136 #print("source", info.source) 137 print("\n".join(snippets)) 138 try: 139 c_text = "\n".join(snippets) 140 translated = open ("_autoc.c", "a+") 141 translated.write (c_text) 142 translated.close() 143 except Exception as excp: 144 strErr = "Error:\n" + str(excp.args) 145 print(strErr) 146 #return 147 # raise RuntimeError("not yet converted...") 135 ordered_code = [code[name] for name in ordered_dag(depends) if name in code] 136 functions = py2c.translate(ordered_code, constants) 137 snippets.extend(functions) 148 138 149 139 # update model info -
sasmodels/kerneldll.py
r2d81cfe r1ddb794 185 185 subprocess.check_output(command, shell=shell, stderr=subprocess.STDOUT) 186 186 except subprocess.CalledProcessError as exc: 187 raise RuntimeError("compile failed.\n%s\n%s"%(command_str, exc.output)) 187 raise RuntimeError("compile failed.\n%s\n%s" 188 % (command_str, exc.output.decode())) 188 189 if not os.path.exists(output): 189 190 raise RuntimeError("compile failed. File is in %r"%source) -
sasmodels/py2c.py
r98a4f14 r1ddb794 243 243 # for C 244 244 for arg in node.args: 245 self.arguments.append(arg.arg) 245 # CRUFT: 2.7 uses arg.id, 3.x uses arg.arg 246 try: 247 arg_name = arg.arg 248 except AttributeError: 249 arg_name = arg.id 250 self.arguments.append(arg_name) 246 251 247 252 padding = [None] *(len(node.args) - len(node.defaults)) 248 253 for arg, default in zip(node.args, padding + node.defaults): 249 254 if default is not None: 250 self.warnings.append("Default Parameter unknown to C") 251 w_str = "Default Parameters are unknown to C: '" + arg.arg + \ 252 " = " + str(default.n) + "'" 255 # CRUFT: 2.7 uses arg.id, 3.x uses arg.arg 256 # CRUFT: 2.7 uses arg.id, 3.x uses arg.arg 257 try: 258 arg_name = arg.arg 259 except AttributeError: 260 arg_name = arg.id 261 w_str = ("Default Parameters are unknown to C: '%s = %s" 262 % arg_name, str(default.n)) 253 263 self.warnings.append(w_str) 254 264 # self.write_python('=') … … 305 315 if(len(self.Tuples) > 0): 306 316 tplTargets = list(self.Tuples) 307 self.Tuples.clear()317 del self.Tuples[:] 308 318 self.write_c(' = ') 309 319 self.is_sequence = False … … 410 420 self.c_proc.insert(start_var, c_dcl + "\n") 411 421 start_var += 1 412 self.C_Vars.clear()413 self.C_IntVars.clear()414 self.C_Vectors.clear()415 self.C_Pointers.clear()422 del self.C_Vars[:] 423 del self.C_IntVars[:] 424 del self.C_Vectors[:] 425 del self.C_Pointers[:] 416 426 self.C_DclPointers 417 427 if(fLine == True): … … 427 437 self.c_proc.insert(start_var + 1, "\n") 428 438 429 def writeInclude(self):430 if(self.MathIncludeed == False):431 self.add_c_line("#include <math.h>\n")432 self.add_c_line("static double pi = 3.14159265359;\n")433 self.MathIncludeed = True434 435 439 def ListToString(self, strings): 436 440 s = '' … … 475 479 476 480 self.visit(node.args) 477 # for C478 # self.writeInclude()479 481 self.getMethodSignature() 480 482 # for C … … 802 804 if((name not in self.C_Functions) and (name not in self.C_Vars) and \ 803 805 (name not in self.C_IntVars) and (name not in self.arguments) and \ 804 (name.is numeric() == False)):806 (name.isdigit() == False)): 805 807 if(self.InSubscript): 806 808 self.C_IntVars.append(node.id) … … 1101 1103 1102 1104 def translate(functions, constants=0): 1103 sniplets = [] 1104 sniplets.append("#include <math.h>") 1105 sniplets.append("static double pi = 3.14159265359;") 1106 for source,fname,line_no in functions: 1107 line_directive = '#line %d "%s"' %(line_no,fname) 1108 line_directive = line_directive.replace('\\','\\\\') 1109 # sniplets.append(line_directive) 1105 snippets = [] 1106 for source, fname, line_no in functions: 1107 line_directive = '#line %d "%s"'%(line_no, fname.replace('\\','\\\\')) 1108 snippets.append(line_directive) 1110 1109 tree = ast.parse(source) 1111 sniplet = to_source(tree, functions) # in the future add filename, offset, constants 1112 sniplets.append(sniplet) 1113 c_code = "\n".join(sniplets) 1114 f_out = open ("xlate.c", "w+") 1115 f_out.write (c_code) 1116 f_out.close() 1117 return("\n".join(sniplets)) 1110 # in the future add filename, offset, constants 1111 c_code = to_source(tree, functions) 1112 snippets.append(c_code) 1113 return snippets 1118 1114 1119 1115 def get_file_names():
Note: See TracChangeset
for help on using the changeset viewer.