Changeset f619de7 in sasmodels for sasmodels/generate.py
- Timestamp:
- Apr 11, 2016 11:14:50 AM (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:
- 7ae2b7f
- Parents:
- 9a943d0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/generate.py
r6d6508e rf619de7 164 164 from .modelinfo import Parameter 165 165 from .custom import load_custom_kernel_module 166 167 try: 168 from typing import Tuple, Sequence, Iterator 169 from .modelinfo import ModelInfo 170 except ImportError: 171 pass 166 172 167 173 TEMPLATE_ROOT = dirname(__file__) … … 220 226 221 227 def format_units(units): 228 # type: (str) -> str 222 229 """ 223 230 Convert units into ReStructured Text format. … … 226 233 227 234 def make_partable(pars): 235 # type: (List[Parameter]) -> str 228 236 """ 229 237 Generate the parameter table to include in the sphinx documentation. … … 256 264 257 265 def _search(search_path, filename): 266 # type: (List[str], str) -> str 258 267 """ 259 268 Find *filename* in *search_path*. … … 269 278 270 279 def model_sources(model_info): 280 # type: (ModelInfo) -> List[str] 271 281 """ 272 282 Return a list of the sources file paths for the module. … … 277 287 278 288 def timestamp(model_info): 289 # type: (ModelInfo) -> int 279 290 """ 280 291 Return a timestamp for the model corresponding to the most recently … … 288 299 289 300 def convert_type(source, dtype): 301 # type: (str, np.dtype) -> str 290 302 """ 291 303 Convert code from double precision to the desired type. … … 312 324 313 325 def _convert_type(source, type_name, constant_flag): 326 # type: (str, str, str) -> str 314 327 """ 315 328 Replace 'double' with *type_name* in *source*, tagging floating point … … 330 343 331 344 def kernel_name(model_info, is_2d): 345 # type: (ModelInfo, bool) -> str 332 346 """ 333 347 Name of the exported kernel symbol. … … 337 351 338 352 def indent(s, depth): 353 # type: (str, int) -> str 339 354 """ 340 355 Indent a string of text with *depth* additional spaces on each line. … … 345 360 346 361 347 _template_cache = {} 362 _template_cache = {} # type: Dict[str, Tuple[int, str, str]] 348 363 def load_template(filename): 364 # type: (str) -> str 349 365 path = joinpath(TEMPLATE_ROOT, filename) 350 366 mtime = getmtime(path) … … 355 371 356 372 def model_templates(): 373 # type: () -> List[str] 357 374 # TODO: fails DRY; templates are listed in two places. 358 375 # should instead have model_info contain a list of paths … … 371 388 372 389 def _gen_fn(name, pars, body): 390 # type: (str, List[Parameter], str) -> str 373 391 """ 374 392 Generate a function given pars and body. … … 385 403 386 404 def _call_pars(prefix, pars): 405 # type: (str, List[Parameter]) -> List[str] 387 406 """ 388 407 Return a list of *prefix.parameter* from parameter items. … … 393 412 flags=re.MULTILINE) 394 413 def _have_Iqxy(sources): 414 # type: (List[str]) -> bool 395 415 """ 396 416 Return true if any file defines Iqxy. … … 414 434 415 435 def make_source(model_info): 436 # type: (ModelInfo) -> str 416 437 """ 417 438 Generate the OpenCL/ctypes kernel from the module info. 418 439 419 Uses source files found in the given search path. 440 Uses source files found in the given search path. Returns None if this 441 is a pure python model, with no C source components. 420 442 """ 421 443 if callable(model_info.Iq): 422 r eturn None444 raise ValueError("can't compile python model") 423 445 424 446 # TODO: need something other than volume to indicate dispersion parameters … … 447 469 q, qx, qy = [Parameter(name=v) for v in ('q', 'qx', 'qy')] 448 470 # Generate form_volume function, etc. from body only 449 if model_info.form_volume is not None:471 if isinstance(model_info.form_volume, str): 450 472 pars = partable.form_volume_parameters 451 473 source.append(_gen_fn('form_volume', pars, model_info.form_volume)) 452 if model_info.Iq is not None:474 if isinstance(model_info.Iq, str): 453 475 pars = [q] + partable.iq_parameters 454 476 source.append(_gen_fn('Iq', pars, model_info.Iq)) 455 if model_info.Iqxy is not None:477 if isinstance(model_info.Iqxy, str): 456 478 pars = [qx, qy] + partable.iqxy_parameters 457 479 source.append(_gen_fn('Iqxy', pars, model_info.Iqxy)) … … 509 531 510 532 def load_kernel_module(model_name): 533 # type: (str) -> module 511 534 if model_name.endswith('.py'): 512 535 kernel_module = load_custom_kernel_module(model_name) … … 522 545 %re.escape(string.punctuation)) 523 546 def _convert_section_titles_to_boldface(lines): 547 # type: (Sequence[str]) -> Iterator[str] 524 548 """ 525 549 Do the actual work of identifying and converting section headings. … … 543 567 544 568 def convert_section_titles_to_boldface(s): 569 # type: (str) -> str 545 570 """ 546 571 Use explicit bold-face rather than section headings so that the table of … … 553 578 554 579 def make_doc(model_info): 580 # type: (ModelInfo) -> str 555 581 """ 556 582 Return the documentation for the model. … … 562 588 name=model_info.name, 563 589 title=model_info.title, 564 parameters=make_partable(model_info.parameters ),590 parameters=make_partable(model_info.parameters.kernel_parameters), 565 591 returns=Sq_units if model_info.structure_factor else Iq_units, 566 592 docs=docs) … … 569 595 570 596 def demo_time(): 597 # type: () -> None 571 598 """ 572 599 Show how long it takes to process a model. … … 582 609 583 610 def main(): 611 # type: () -> None 584 612 """ 585 613 Program which prints the source produced by the model.
Note: See TracChangeset
for help on using the changeset viewer.