Changeset ddfdb16 in sasmodels
- Timestamp:
- Dec 18, 2017 12:46:31 PM (7 years ago)
- Children:
- 2694cb8, 8224d24
- Parents:
- 4c72117
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/py2c.py
r4c72117 rddfdb16 539 539 if(hasattr(node,'value')): 540 540 line_number = node.value.lineno 541 elif hasattr(node, 'iter'):542 if hasattr(node.iter, 'lineno'):541 elif hasattr(node, 'iter'): 542 if hasattr(node.iter, 'lineno'): 543 543 line_number = node.iter.lineno 544 544 return(line_number) … … 1043 1043 print(tree_source) 1044 1044 1045 def add_constants 1045 def add_constants(sniplets, c_constants): 1046 1046 sniplets.append("#include <math.h>") 1047 1047 sniplets.append("") … … 1049 1049 for c_var in vars: 1050 1050 c_values = c_constants[c_var] 1051 declare_values = str(c_values) 1052 str_dcl = "double " + c_var 1053 if (hasattr(c_values,'__len__')): 1054 str_dcl += "[]" 1055 len_prev = len(declare_values) 1056 len_after = len_prev - 1 1057 declare_values = declare_values.replace ('[','') 1058 declare_values = declare_values.replace (']','').strip() 1059 while (len_after < len_prev): 1060 len_prev = len_after 1061 declare_values = declare_values.replace (' ',' ') 1062 len_after = len(declare_values) 1063 declare_values = "{" + declare_values.replace (' ',',') + "}" 1064 str_dcl += " = " + declare_values + ";" 1065 sniplets.append (str_dcl) 1066 sniplets.append("") 1051 if isinstance(c_values, (int, float)): 1052 parts = ["double ", c_var, " = ", "%.15g"%c_values, ";"] 1053 else: 1054 elements = ["%.15g"%v for v in c_values] 1055 parts = ["double ", c_var, "[]", " = ", "{\n ", ", ".join(elements), "\n};"] 1056 sniplets.append("".join(parts)) 1067 1057 1068 1058 def translate(functions, constants=0):
Note: See TracChangeset
for help on using the changeset viewer.