Changeset da63656 in sasmodels for sasmodels/generate.py


Ignore:
Timestamp:
May 4, 2016 11:37:42 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
24d5b30
Parents:
13b99fd (diff), 47e498b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into polydisp

Conflicts:

sasmodels/generate.py
sasmodels/kerneldll.py

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    rae2b6b5 rda63656  
    387387        with open(path) as fid: 
    388388            _template_cache[filename] = (mtime, fid.read(), path) 
    389     return _template_cache[filename][1] 
     389    return _template_cache[filename][1], path 
    390390 
    391391 
     
    393393double %(name)s(%(pars)s); 
    394394double %(name)s(%(pars)s) { 
     395#line %(line)d "%(filename)s" 
    395396    %(body)s 
    396397} 
     
    398399""" 
    399400 
    400 def _gen_fn(name, pars, body): 
    401     # type: (str, List[Parameter], str) -> str 
     401def _gen_fn(name, pars, body, filename, line): 
     402    # type: (str, List[Parameter], str, str, int) -> str 
    402403    """ 
    403404    Generate a function given pars and body. 
     
    411412    """ 
    412413    par_decl = ', '.join(p.as_function_argument() for p in pars) if pars else 'void' 
    413     return _FN_TEMPLATE % {'name': name, 'body': body, 'pars': par_decl} 
     414    return _FN_TEMPLATE % { 
     415        'name': name, 'pars': par_decl, 'body': body, 
     416        'filename': filename.replace('\\', '\\\\'), 'line': line, 
     417    } 
    414418 
    415419def _call_pars(prefix, pars): 
     
    438442    line instead. 
    439443    """ 
    440     for code in sources: 
     444    for code, path in sources: 
    441445        if _IQXY_PATTERN.search(code): 
    442446            return True 
    443447    else: 
    444448        return False 
     449 
     450def _add_source(source, code, path): 
     451    """ 
     452    Add a file to the list of source code chunks, tagged with path and line. 
     453    """ 
     454    path = path.replace('\\','\\\\') 
     455    source.append('#line 1 "%s"'%path) 
     456    source.append(code) 
    445457 
    446458def make_source(model_info): 
     
    474486    ocl_code = load_template('kernel_iq.cl') 
    475487    #ocl_code = load_template('kernel_iq_local.cl') 
    476     user_code = [open(f).read() for f in model_sources(model_info)] 
     488    user_code = [(f, open(f).read()) for f in model_sources(model_info)] 
    477489 
    478490    # Build initial sources 
    479     source = [kernel_header] + user_code 
     491    source = [] 
     492    _add_source(source, *kernel_header) 
     493    for path, code in user_code: 
     494        _add_source(source, code, path) 
    480495 
    481496    # Make parameters for q, qx, qy so that we can use them in declarations 
     
    484499    if isinstance(model_info.form_volume, str): 
    485500        pars = partable.form_volume_parameters 
    486         source.append(_gen_fn('form_volume', pars, model_info.form_volume)) 
     501        source.append(_gen_fn('form_volume', pars, model_info.form_volume, 
     502                              model_info.filename, model_info._form_volume_line)) 
    487503    if isinstance(model_info.Iq, str): 
    488504        pars = [q] + partable.iq_parameters 
    489         source.append(_gen_fn('Iq', pars, model_info.Iq)) 
     505        source.append(_gen_fn('Iq', pars, model_info.Iq, 
     506                              model_info.filename, model_info._Iq_line)) 
    490507    if isinstance(model_info.Iqxy, str): 
    491508        pars = [qx, qy] + partable.iqxy_parameters 
    492         source.append(_gen_fn('Iqxy', pars, model_info.Iqxy)) 
     509        source.append(_gen_fn('Iqxy', pars, model_info.Iqxy, 
     510                              model_info.filename, model_info._Iqxy_line)) 
    493511 
    494512    # Define the parameter table 
     
    528546 
    529547    source.append("#if defined(USE_OPENCL)") 
    530     source.extend(_add_kernels(ocl_code, call_iq, call_iqxy, model_info.name)) 
     548    source.extend(_add_kernels(ocl_code[0], call_iq, call_iqxy, model_info.name)) 
    531549    source.append("#else /* !USE_OPENCL */") 
    532     source.extend(_add_kernels(dll_code, call_iq, call_iqxy, model_info.name)) 
     550    source.extend(_add_kernels(dll_code[0], call_iq, call_iqxy, model_info.name)) 
    533551    source.append("#endif /* !USE_OPENCL */") 
    534552    return '\n'.join(source) 
     
    569587        kernel_module = getattr(models, model_name, None) 
    570588    return kernel_module 
    571  
    572  
    573589 
    574590section_marker = re.compile(r'\A(?P<first>[%s])(?P=first)*\Z' 
Note: See TracChangeset for help on using the changeset viewer.