Changeset 4c72117 in sasmodels


Ignore:
Timestamp:
Dec 18, 2017 10:14:18 AM (6 years ago)
Author:
Omer Eisenberg <omereis@…>
Children:
ddfdb16
Parents:
5c2a0f2
Message:

Comparison running: fixed bug in 'visit_Return', deleted commented statements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/py2c.py

    r5c2a0f2 r4c72117  
    575712/15/2017, OE: Precedence maintained by writing opening and closing 
    5858                parenthesesm '(',')', in procedure 'visit_BinOp'. 
     5912/18/2017, OE: Added call to 'add_current_line()' at the beginning 
     60                of visit_Return 
     61 
    5962""" 
    6063import ast 
     
    99102 
    100103 
    101 #def to_source(node, indent_with=' ' * 4, add_line_information=False): 
    102104def to_source(node, func_name, constants=None): 
    103105    """This function can convert a node tree back into python sourcecode. 
     
    119121    """ 
    120122    generator = SourceGenerator(' ' * 4, False, constants) 
    121 #    generator.required_functions = func_name 
    122123    generator.visit(node) 
    123124 
    124 #    return ''.join(generator.result) 
    125125    return ''.join(generator.c_proc) 
    126126 
     
    253253                        " = " + str(default.n) + "'" 
    254254                self.warnings.append(w_str) 
    255 #                self.write_python('=') 
    256 #                self.visit(default) 
    257255 
    258256    def decorators(self, node): 
     
    312310        self.visit(node.value) 
    313311        self.add_semi_colon() 
    314 #        self.write_c(';') 
    315312        self.add_current_line() 
    316313        for n, item in enumerate(self.Tuples): 
     
    338335        self.visit(node.value) 
    339336        self.add_semi_colon() 
    340 #        self.write_c(';') 
    341337        self.add_current_line() 
    342338 
     
    399395            fLine = True 
    400396            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 = True 
    405 #            start_var += 1 
    406397        if(len(self.C_Vectors) > 0): 
    407398            s = self.listToDeclare(self.C_Vectors) 
     
    443434 
    444435    def getMethodSignature(self): 
    445 #        args_str = ListToString(self.arguments) 
    446436        args_str = '' 
    447437        for n in range(len(self.arguments)): 
     
    450440                args_str += ", " 
    451441        return(args_str) 
    452 #        self.strMethodSignature = 'double ' + self.name + '(' + args_str + ")" 
    453442 
    454443    def InsertSignature(self): 
     
    470459        self.arguments = [] 
    471460        self.name = node.name 
    472 #        if self.name not in self.required_functions[0]: 
    473 #           return 
    474461        print("Parsing '" + self.name + "'") 
    475462        args_str = "" 
    476463 
    477464        self.visit(node.args) 
    478 # for C 
    479 #        self.writeInclude() 
    480465        self.getMethodSignature() 
    481 # for C 
    482466        self.signature_line = len(self.c_proc) 
    483 #        self.add_c_line(self.strMethodSignature) 
    484467        self.add_c_line("\n{") 
    485468        start_vars = len(self.c_proc) + 1 
     
    598581# Iterator name is in node.target.id. 
    599582        self.add_current_line() 
    600 #        if(len(self.current_statement) > 0): 
    601 #            self.add_c_line(self.current_statement) 
    602 #            self.current_statement = '' 
    603583        fForDone = False 
    604584        self.current_statement = '' 
     
    700680 
    701681    def visit_Return(self, node): 
    702         self.newline(node) 
     682        self.add_current_line() 
    703683        if node.value is None: 
    704684            self.write_c('return') 
     
    10481028                self.visit(if_) 
    10491029 
    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  
    10611030    def visit_arguments(self, node): 
    10621031        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_length 
    1066     if(q > p): 
    1067         q = p + 17 
    1068         p = q - 5 
    1069     z3 = -8 
    1070     inten = (porod_scale / q ** porod_exp 
    1071                 + lorentz_scale /(1 + z ** lorentz_exp)) 
    1072     return inten 
    1073  
    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_length 
    1076     if(q > p): 
    1077         q = p + 17 
    1078         p = q - 5 
    1079     elif(q == p): 
    1080         q = p * q 
    1081         q *= z1 
    1082         p = z1 
    1083     elif(q == 17): 
    1084         q = p * q - 17 
    1085     else: 
    1086         q += 7 
    1087     z3 = -8 
    1088     inten = (porod_scale / q ** porod_exp 
    1089                 + lorentz_scale /(1 + z ** lorentz_exp)) 
    1090     return inten 
    10911032 
    10921033def print_function(f=None): 
     
    11271068def translate(functions, constants=0): 
    11281069    sniplets = [] 
    1129 #    sniplets.append("#include <math.h>") 
    1130 #    sniplets.append("static double pi = 3.14159265359;") 
    11311070    add_constants (sniplets, constants) 
    11321071    for source,fname,line_no in functions: 
Note: See TracChangeset for help on using the changeset viewer.