Changeset da63656 in sasmodels for sasmodels/generate.py
- Timestamp:
- May 4, 2016 11:37:42 PM (8 years ago)
- 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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/generate.py
rae2b6b5 rda63656 387 387 with open(path) as fid: 388 388 _template_cache[filename] = (mtime, fid.read(), path) 389 return _template_cache[filename][1] 389 return _template_cache[filename][1], path 390 390 391 391 … … 393 393 double %(name)s(%(pars)s); 394 394 double %(name)s(%(pars)s) { 395 #line %(line)d "%(filename)s" 395 396 %(body)s 396 397 } … … 398 399 """ 399 400 400 def _gen_fn(name, pars, body ):401 # type: (str, List[Parameter], str ) -> str401 def _gen_fn(name, pars, body, filename, line): 402 # type: (str, List[Parameter], str, str, int) -> str 402 403 """ 403 404 Generate a function given pars and body. … … 411 412 """ 412 413 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 } 414 418 415 419 def _call_pars(prefix, pars): … … 438 442 line instead. 439 443 """ 440 for code in sources:444 for code, path in sources: 441 445 if _IQXY_PATTERN.search(code): 442 446 return True 443 447 else: 444 448 return False 449 450 def _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) 445 457 446 458 def make_source(model_info): … … 474 486 ocl_code = load_template('kernel_iq.cl') 475 487 #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)] 477 489 478 490 # 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) 480 495 481 496 # Make parameters for q, qx, qy so that we can use them in declarations … … 484 499 if isinstance(model_info.form_volume, str): 485 500 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)) 487 503 if isinstance(model_info.Iq, str): 488 504 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)) 490 507 if isinstance(model_info.Iqxy, str): 491 508 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)) 493 511 494 512 # Define the parameter table … … 528 546 529 547 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)) 531 549 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)) 533 551 source.append("#endif /* !USE_OPENCL */") 534 552 return '\n'.join(source) … … 569 587 kernel_module = getattr(models, model_name, None) 570 588 return kernel_module 571 572 573 589 574 590 section_marker = re.compile(r'\A(?P<first>[%s])(?P=first)*\Z'
Note: See TracChangeset
for help on using the changeset viewer.