Changeset 50b5464 in sasmodels
- Timestamp:
- Dec 4, 2017 8:12:20 AM (7 years ago)
- Children:
- 7a40b08
- Parents:
- bf88ef1
- Location:
- sasmodels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/autoc.py
rbf88ef1 r50b5464 65 65 66 66 libs = [] # type: List[str] 67 snippets = [] # type: List[str] 68 constants = {} # type: Dict[str, Any] 67 69 code = {} # type: Dict[str, str] 68 70 depends = {} # type: Dict[str, List[str]] … … 90 92 translate.append((name, obj)) 91 93 elif isinstance(obj, float): 92 code[name] = "const double %s = %.15g\n"%(name, obj) 94 constants[name] = obj 95 snippets.append("const double %s = %.15g;"%(name, obj)) 93 96 elif isinstance(obj, int): 94 code[name] = "const int %s = %d\n"%(name, obj) 97 constants[name] = obj 98 snippets.append("const int %s = %d;"%(name, obj)) 95 99 elif isinstance(obj, (list, tuple, np.ndarray)): 100 constants[name] = obj 101 # extend constant arrays to a multiple of 4; not sure if this 102 # is necessary, but some OpenCL targets broke if the number 103 # of parameters in the parameter table was not a multiple of 4, 104 # so do it for all constant arrays to be safe. 105 if len(obj)%4 != 0: 106 obj = list(obj) + [0.]*(4-len(obj)) 96 107 vals = ", ".join("%.15g"%v for v in obj) 97 code[name] = "const double %s[] = {%s};\n" %(name, vals)108 snippets.append("const double %s[] = {%s};" %(name, vals)) 98 109 elif isinstance(obj, special.Gauss): 110 constants["GAUSS_N"] = obj.n 111 constants["GAUSS_Z"] = obj.z 112 constants["GAUSS_W"] = obj.w 99 113 libs.append('lib/gauss%d.c'%obj.n) 100 114 source = (source.replace(name+'.n', 'GAUSS_N') … … 105 119 % (name, str(type(obj)))) 106 120 107 tree = ast.parse(source) 108 snippet = codegen.to_source(tree) #, filename, offset) 109 code[function_name] = snippet 121 # add (possibly modified) source to set of functions to compile 122 code[function_name] = (source, filename, offset) 110 123 111 124 # remove duplicates from the dependecy list … … 115 128 unique_libs.append(filename) 116 129 130 # translate source 131 functions = codegen.translate( 132 [code[name] for name in ordered_dag(depends) if name in code], 133 constants) 134 135 # update model info 117 136 info.source = unique_libs 118 info.c_code = "\n".join(code[k] for k in ordered_dag(depends) if k in code) 119 137 info.c_code = "\n".join(snippets) + functions 120 138 info.Iq = info.Iqxy = info.form_volume = None 121 139 -
sasmodels/codegen.py
rdb03406 r50b5464 49 49 UNARYOP_SYMBOLS[ast.USub] = '-' 50 50 51 52 def translate(functions, constants): 53 # type: (List[Tuple[str, str, int]], Dict[str, Any]) -> str 54 snippets = [] 55 for source, filename, offset in functions: 56 tree = ast.parse(source) 57 snippet = to_source(tree) #, filename, offset) 58 snippets.append(snippet) 59 return "\n".join(snippets) 51 60 52 61 def to_source(node, indent_with=' ' * 4, add_line_information=False):
Note: See TracChangeset
for help on using the changeset viewer.