Changes in / [d247047:5f1acda] in sasmodels


Ignore:
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • sascomp

    r424fe00 r6708a6a  
    1919 
    2020    import sasmodels.compare 
    21     sasmodels.compare.main(*sys.argv[1:]) 
     21    sasmodels.compare.main() 
    2222 
    2323if __name__ == "__main__": 
  • sasmodels/__init__.py

    r79906d1 rb2377b0  
    1414defining new models. 
    1515""" 
    16 __version__ = "0.94" 
     16__version__ = "0.93" 
    1717 
    1818def data_files(): 
  • sasmodels/compare.py

    r050c2c8 r050c2c8  
    789789 
    790790 
    791 def parse_opts(argv): 
    792     # type: (List[str]) -> Dict[str, Any] 
     791def parse_opts(): 
     792    # type: () -> Dict[str, Any] 
    793793    """ 
    794794    Parse command line options. 
    795795    """ 
    796796    MODELS = core.list_models() 
    797     flags = [arg for arg in argv 
     797    flags = [arg for arg in sys.argv[1:] 
    798798             if arg.startswith('-')] 
    799     values = [arg for arg in argv 
     799    values = [arg for arg in sys.argv[1:] 
    800800              if not arg.startswith('-') and '=' in arg] 
    801     positional_args = [arg for arg in argv 
     801    args = [arg for arg in sys.argv[1:] 
    802802            if not arg.startswith('-') and '=' not in arg] 
    803803    models = "\n    ".join("%-15s"%v for v in MODELS) 
    804     if len(positional_args) == 0: 
     804    if len(args) == 0: 
    805805        print(USAGE) 
    806806        print("\nAvailable models:") 
    807807        print(columnize(MODELS, indent="  ")) 
    808         return None 
    809     if len(positional_args) > 3: 
     808        sys.exit(1) 
     809    if len(args) > 3: 
    810810        print("expected parameters: model N1 N2") 
    811811 
    812     name = positional_args[0] 
     812    name = args[0] 
    813813    try: 
    814814        model_info = core.load_model_info(name) 
     
    816816        print(str(exc)) 
    817817        print("Could not find model; use one of:\n    " + models) 
    818         return None 
     818        sys.exit(1) 
    819819 
    820820    invalid = [o[1:] for o in flags 
     
    823823    if invalid: 
    824824        print("Invalid options: %s"%(", ".join(invalid))) 
    825         return None 
     825        sys.exit(1) 
    826826 
    827827 
     
    898898        del engines[2:] 
    899899 
    900     n1 = int(positional_args[1]) if len(positional_args) > 1 else 1 
    901     n2 = int(positional_args[2]) if len(positional_args) > 2 else 1 
     900    n1 = int(args[1]) if len(args) > 1 else 1 
     901    n2 = int(args[2]) if len(args) > 2 else 1 
    902902    use_sasview = any(engine == 'sasview' and count > 0 
    903903                      for engine, count in zip(engines, [n1, n2])) 
     
    916916            s = set(p.split('_pd')[0] for p in pars) 
    917917            print("%r invalid; parameters are: %s"%(k, ", ".join(sorted(s)))) 
    918             return None 
     918            sys.exit(1) 
    919919        presets[k] = float(v) if not k.endswith('type') else v 
    920920 
     
    970970    from bumps.gui.app_frame import AppFrame  # type: ignore 
    971971 
     972    problem = FitProblem(Explore(opts)) 
    972973    is_mac = "cocoa" in wx.version() 
    973     # Create an app if not running embedded 
    974     app = wx.App() if wx.GetApp() is None else None 
    975     problem = FitProblem(Explore(opts)) 
    976     frame = AppFrame(parent=None, title="explore", size=(1000,700)) 
     974    app = wx.App() 
     975    frame = AppFrame(parent=None, title="explore") 
    977976    if not is_mac: frame.Show() 
    978977    frame.panel.set_model(model=problem) 
     
    980979    frame.panel.aui.Split(0, wx.TOP) 
    981980    if is_mac: frame.Show() 
    982     # If running withing an app, start the main loop 
    983     if app: app.MainLoop() 
     981    app.MainLoop() 
    984982 
    985983class Explore(object): 
     
    10501048 
    10511049 
    1052 def main(*argv): 
    1053     # type: (*str) -> None 
     1050def main(): 
     1051    # type: () -> None 
    10541052    """ 
    10551053    Main program. 
    10561054    """ 
    1057     opts = parse_opts(argv) 
    1058     if opts is not None: 
    1059         if opts['explore']: 
    1060             explore(opts) 
    1061         else: 
    1062             compare(opts) 
     1055    opts = parse_opts() 
     1056    if opts['explore']: 
     1057        explore(opts) 
     1058    else: 
     1059        compare(opts) 
    10631060 
    10641061if __name__ == "__main__": 
    1065     main(*sys.argv[1:]) 
     1062    main() 
  • sasmodels/compare_many.py

    r424fe00 r40a87fa  
    229229    print_models() 
    230230 
    231 def main(argv): 
     231def main(): 
    232232    """ 
    233233    Main program. 
    234234    """ 
    235     if len(argv) not in (5, 6): 
     235    if len(sys.argv) not in (6, 7): 
    236236        print_help() 
    237         return 
    238  
    239     model = argv[0] 
     237        sys.exit(1) 
     238 
     239    model = sys.argv[1] 
    240240    if not (model in MODELS) and (model != "all"): 
    241241        print('Bad model %s.  Use "all" or one of:'%model) 
    242242        print_models() 
    243         return 
     243        sys.exit(1) 
    244244    try: 
    245         count = int(argv[1]) 
    246         is2D = argv[2].startswith('2d') 
    247         assert argv[2][1] == 'd' 
    248         Nq = int(argv[2][2:]) 
    249         mono = argv[3] == 'mono' 
    250         cutoff = float(argv[3]) if not mono else 0 
    251         base = argv[4] 
    252         comp = argv[5] if len(argv) > 5 else "sasview" 
     245        count = int(sys.argv[2]) 
     246        is2D = sys.argv[3].startswith('2d') 
     247        assert sys.argv[3][1] == 'd' 
     248        Nq = int(sys.argv[3][2:]) 
     249        mono = sys.argv[4] == 'mono' 
     250        cutoff = float(sys.argv[4]) if not mono else 0 
     251        base = sys.argv[5] 
     252        comp = sys.argv[6] if len(sys.argv) > 6 else "sasview" 
    253253    except Exception: 
    254254        traceback.print_exc() 
    255255        print_usage() 
    256         return 
     256        sys.exit(1) 
    257257 
    258258    data, index = make_data({'qmax':1.0, 'is2d':is2D, 'nq':Nq, 'res':0., 
     
    265265if __name__ == "__main__": 
    266266    #from .compare import push_seed 
    267     #with push_seed(1): main(sys.argv[1:]) 
    268     main(sys.argv[1:]) 
     267    #with push_seed(1): main() 
     268    main() 
  • sasmodels/custom/__init__.py

    r2a0c7a6 r40a87fa  
    1717    def load_module_from_path(fullname, path): 
    1818        """load module from *path* as *fullname*""" 
    19         spec = spec_from_file_location(fullname, os.path.expanduser(path)) 
     19        spec = spec_from_file_location(fullname, path) 
    2020        module = module_from_spec(spec) 
    2121        spec.loader.exec_module(module) 
     
    2626    def load_module_from_path(fullname, path): 
    2727        """load module from *path* as *fullname*""" 
    28         module = imp.load_source(fullname, os.path.expanduser(path)) 
     28        module = imp.load_source(fullname, path) 
    2929        #os.unlink(path+"c")  # remove the automatic pyc file 
    3030        return module 
     
    3535    name = basename(splitext(path)[0]) 
    3636    # Placing the model in the 'sasmodels.custom' name space. 
    37     kernel_module = load_module_from_path('sasmodels.custom.'+name, 
    38                                           os.path.expanduser(path)) 
     37    kernel_module = load_module_from_path('sasmodels.custom.'+name, path) 
    3938    return kernel_module 
  • sasmodels/direct_model.py

    r4cc161e rbde38b5  
    8585    if model_info.ER is None: 
    8686        return 1.0 
    87     elif not model_info.parameters.form_volume_parameters: 
    88         # handle the case where ER is provided but model is not polydisperse 
    89         return model_info.ER() 
    9087    else: 
    9188        value, weight = _vol_pars(model_info, pars) 
     
    104101    if model_info.VR is None: 
    105102        return 1.0 
    106     elif not model_info.parameters.form_volume_parameters: 
    107         # handle the case where ER is provided but model is not polydisperse 
    108         return model_info.VR() 
    109103    else: 
    110104        value, weight = _vol_pars(model_info, pars) 
     
    158152                for p in model_info.parameters.call_parameters 
    159153                if p.type == 'volume'] 
    160     #import pylab; pylab.plot(vol_pars[0][0],vol_pars[0][1]); pylab.show() 
    161154    value, weight = dispersion_mesh(model_info, vol_pars) 
    162155    return value, weight 
     
    402395    model = build_model(model_info) 
    403396    calculator = DirectModel(data, model) 
    404     pars = dict((k, (float(v) if not k.endswith("_pd_type") else v)) 
     397    pars = dict((k, float(v)) 
    405398                for pair in sys.argv[3:] 
    406399                for k, v in [pair.split('=')]) 
  • sasmodels/generate.py

    r2e49f9e r52ec91e  
    362362    for long double precision. 
    363363    """ 
    364     source = _fix_tgmath_int(source) 
    365364    if dtype == F16: 
    366365        fbytes = 2 
     
    392391    source = re.sub(r'(^|[^a-zA-Z0-9_]c?)double(([248]|16)?($|[^a-zA-Z0-9_]))', 
    393392                    r'\1%s\2'%type_name, source) 
    394     source = _tag_float(source, constant_flag) 
    395     return source 
    396  
    397 TGMATH_INT_RE = re.compile(r""" 
    398 (?: # Non-capturing match; not lookbehind since pattern length is variable 
    399   \b              # word boundary 
    400    # various math functions 
    401   (a?(sin|cos|tan)h? | atan2 
    402    | erfc? | tgamma 
    403    | exp(2|10|m1)? | log(2|10|1p)? | pow[nr]? | sqrt | rsqrt | rootn 
    404    | fabs | fmax | fmin 
    405    ) 
    406   \s*[(]\s*       # open parenthesis 
    407 ) 
    408 [+-]?(0|[1-9]\d*) # integer 
    409 (?=               # lookahead match: don't want to move from end of int 
    410   \s*[,)]         # comma or close parenthesis for end of argument 
    411 )                 # end lookahead 
    412 """, re.VERBOSE) 
    413 def _fix_tgmath_int(source): 
    414     # type: (str) -> str 
    415     """ 
    416     Replace f(integer) with f(integer.) for sin, cos, pow, etc. 
    417  
    418     OS X OpenCL complains that it can't resolve the type generic calls to 
    419     the standard math functions when they are called with integer constants, 
    420     but this does not happen with the Windows Intel driver for example. 
    421     To avoid confusion on the matrix marketplace, automatically promote 
    422     integers to floats if we recognize them in the source. 
    423  
    424     The specific functions we look for are: 
    425  
    426         trigonometric: sin, asin, sinh, asinh, etc., and atan2 
    427         exponential:   exp, exp2, exp10, expm1, log, log2, log10, logp1 
    428         power:         pow, pown, powr, sqrt, rsqrt, rootn 
    429         special:       erf, erfc, tgamma 
    430         float:         fabs, fmin, fmax 
    431  
    432     Note that we don't convert the second argument of dual argument 
    433     functions: atan2, fmax, fmin, pow, powr.  This could potentially 
    434     be a problem for pow(x, 2), but that case seems to work without change. 
    435     """ 
    436     out = TGMATH_INT_RE.sub(r'\g<0>.', source) 
    437     return out 
    438  
    439  
    440 # Floating point regular expression 
    441 # 
    442 # Define parts: 
    443 # 
    444 #    E = [eE][+-]?\d+    : Exponent 
    445 #    P = [.]             : Decimal separator 
    446 #    N = [1-9]\d*        : Natural number, no leading zeros 
    447 #    Z = 0               : Zero 
    448 #    F = \d+             : Fractional number, maybe leading zeros 
    449 #    F? = \d*            : Optional fractional number 
    450 # 
    451 # We want to reject bare natural numbers and bare decimal points, so we 
    452 # need to tediously outline the cases where we have either a fraction or 
    453 # an exponent: 
    454 # 
    455 #   ( ZP | ZPF | ZE | ZPE | ZPFE | NP | NPF | NE | NPE | NPFE | PF | PFE ) 
    456 # 
    457 # 
    458 # We can then join cases by making parts optional.  The following are 
    459 # some ways to do this: 
    460 # 
    461 #   ( (Z|N)(P|PF|E|PE|PFE) | PFE? )                   # Split on lead 
    462 #     => ( (Z|N)(PF?|(PF?)?E) | PFE? ) 
    463 #   ( ((Z|N)PF?|PF)E? | (Z|N)E)                       # Split on point 
    464 #   ( (ZP|ZPF|NP|NPF|PF) | (Z|ZP|ZPF|N|NP|NPF|PF)E )  # Split on E 
    465 #     => ( ((Z|N)PF?|PF) | ((Z|N)(PF?)? | PF) E ) 
    466 FLOAT_RE = re.compile(r""" 
    467     (?<!\w)  # use negative lookbehind since '.' confuses \b test 
    468     # use split on lead to match float ( (Z|N)(PF?|(PF?)?E) | PFE? ) 
    469     ( ( 0 | [1-9]\d* )                     # ( ( Z | N ) 
    470       ([.]\d* | ([.]\d*)? [eE][+-]?\d+ )   #   (PF? | (PF?)? E ) 
    471     | [.]\d+ ([eE][+-]?\d+)?               # | PF (E)? 
    472     )                                      # ) 
    473     (?!\w)  # use negative lookahead since '.' confuses \b test 
    474     """, re.VERBOSE) 
    475 def _tag_float(source, constant_flag): 
    476393    # Convert floating point constants to single by adding 'f' to the end, 
    477394    # or long double with an 'L' suffix.  OS/X complains if you don't do this. 
    478     out = FLOAT_RE.sub(r'\g<0>%s'%constant_flag, source) 
    479     #print("in",repr(source),"out",repr(out), constant_flag) 
    480     return out 
    481  
    482 def test_tag_float(): 
    483  
    484     cases=""" 
    485 ZP  : 0. 
    486 ZPF : 0.0,0.01,0.1 
    487 Z  E: 0e+001 
    488 ZP E: 0.E0 
    489 ZPFE: 0.13e-031 
    490 NP  : 1., 12. 
    491 NPF : 1.0001, 1.1, 1.0 
    492 N  E: 1e0, 37E-080 
    493 NP E: 1.e0, 37.E-080 
    494 NPFE: 845.017e+22 
    495  PF : .1, .0, .0100 
    496  PFE: .6e+9, .82E-004 
    497 # isolated cases 
    498 0. 
    499 1e0 
    500 0.13e-013 
    501 # untouched 
    502 struct3.e3, 03.05.67, 37 
    503 # expressions 
    504 3.75+-1.6e-7-27+13.2 
    505 a3.e2 - 0. 
    506 4*atan(1) 
    507 4.*atan(1.) 
    508 """ 
    509  
    510     output=""" 
    511 ZP  : 0.f 
    512 ZPF : 0.0f,0.01f,0.1f 
    513 Z  E: 0e+001f 
    514 ZP E: 0.E0f 
    515 ZPFE: 0.13e-031f 
    516 NP  : 1.f, 12.f 
    517 NPF : 1.0001f, 1.1f, 1.0f 
    518 N  E: 1e0f, 37E-080f 
    519 NP E: 1.e0f, 37.E-080f 
    520 NPFE: 845.017e+22f 
    521  PF : .1f, .0f, .0100f 
    522  PFE: .6e+9f, .82E-004f 
    523 # isolated cases 
    524 0.f 
    525 1e0f 
    526 0.13e-013f 
    527 # untouched 
    528 struct3.e3, 03.05.67, 37 
    529 # expressions 
    530 3.75f+-1.6e-7f-27+13.2f 
    531 a3.e2 - 0.f 
    532 4*atan(1) 
    533 4.f*atan(1.f) 
    534 """ 
    535  
    536     for case_in, case_out in zip(cases.split('\n'), output.split('\n')): 
    537         out = _tag_float(case_in, 'f') 
    538         assert case_out == out, "%r => %r"%(case_in, out) 
     395    source = re.sub(r'[^a-zA-Z_](\d*[.]\d+|\d+[.]\d*)([eE][+-]?\d+)?', 
     396                    r'\g<0>%s'%constant_flag, source) 
     397    return source 
    539398 
    540399 
     
    847706    Iq_units = "The returned value is scaled to units of |cm^-1| |sr^-1|, absolute scale." 
    848707    Sq_units = "The returned value is a dimensionless structure factor, $S(q)$." 
    849     docs = model_info.docs if model_info.docs is not None else "" 
    850     docs = convert_section_titles_to_boldface(docs) 
     708    docs = convert_section_titles_to_boldface(model_info.docs) 
    851709    pars = make_partable(model_info.parameters.COMMON 
    852710                         + model_info.parameters.kernel_parameters) 
     
    860718 
    861719 
    862 # TODO: need a single source for rst_prolog; it is also in doc/rst_prolog 
    863 RST_PROLOG = """\ 
    864 .. |Ang| unicode:: U+212B 
    865 .. |Ang^-1| replace:: |Ang|\ :sup:`-1` 
    866 .. |Ang^2| replace:: |Ang|\ :sup:`2` 
    867 .. |Ang^-2| replace:: |Ang|\ :sup:`-2` 
    868 .. |1e-6Ang^-2| replace:: 10\ :sup:`-6`\ |Ang|\ :sup:`-2` 
    869 .. |Ang^3| replace:: |Ang|\ :sup:`3` 
    870 .. |Ang^-3| replace:: |Ang|\ :sup:`-3` 
    871 .. |Ang^-4| replace:: |Ang|\ :sup:`-4` 
    872 .. |cm^-1| replace:: cm\ :sup:`-1` 
    873 .. |cm^2| replace:: cm\ :sup:`2` 
    874 .. |cm^-2| replace:: cm\ :sup:`-2` 
    875 .. |cm^3| replace:: cm\ :sup:`3` 
    876 .. |1e15cm^3| replace:: 10\ :sup:`15`\ cm\ :sup:`3` 
    877 .. |cm^-3| replace:: cm\ :sup:`-3` 
    878 .. |sr^-1| replace:: sr\ :sup:`-1` 
    879 .. |P0| replace:: P\ :sub:`0`\ 
    880  
    881 .. |equiv| unicode:: U+2261 
    882 .. |noteql| unicode:: U+2260 
    883 .. |TM| unicode:: U+2122 
    884  
    885 .. |cdot| unicode:: U+00B7 
    886 .. |deg| unicode:: U+00B0 
    887 .. |g/cm^3| replace:: g\ |cdot|\ cm\ :sup:`-3` 
    888 .. |mg/m^2| replace:: mg\ |cdot|\ m\ :sup:`-2` 
    889 .. |fm^2| replace:: fm\ :sup:`2` 
    890 .. |Ang*cm^-1| replace:: |Ang|\ |cdot|\ cm\ :sup:`-1` 
    891 """ 
    892  
    893 # TODO: make a better fake reference role 
    894 RST_ROLES = """\ 
    895 .. role:: ref 
    896  
    897 .. role:: numref 
    898  
    899 """ 
    900  
    901720def make_html(model_info): 
    902721    """ 
     
    904723    """ 
    905724    from . import rst2html 
    906  
    907     rst = make_doc(model_info) 
    908     return rst2html.rst2html("".join((RST_ROLES, RST_PROLOG, rst))) 
    909  
    910 def view_html(model_name): 
    911     from . import rst2html 
    912     from . import modelinfo 
    913     kernel_module = load_kernel_module(model_name) 
    914     info = modelinfo.make_model_info(kernel_module) 
    915     url = "file://"+dirname(info.filename)+"/" 
    916     rst2html.wxview(make_html(info), url=url) 
     725    return rst2html.convert(make_doc(model_info)) 
    917726 
    918727def demo_time(): 
  • sasmodels/kerneldll.py

    r3764ec1 r14a15a3  
    22DLL driver for C kernels 
    33 
    4 If the environment variable *SAS_OPENMP* is set, then sasmodels 
    5 will attempt to compile with OpenMP flags so that the model can use all 
    6 available kernels.  This may or may not be available on your compiler 
    7 toolchain.  Depending on operating system and environment. 
    8  
    9 Windows does not have provide a compiler with the operating system. 
    10 Instead, we assume that TinyCC is installed and available.  This can 
    11 be done with a simple pip command if it is not already available:: 
    12  
    13     pip install tinycc 
    14  
    15 If Microsoft Visual C++ is available (because VCINSTALLDIR is 
    16 defined in the environment), then that will be used instead. 
    17 Microsoft Visual C++ for Python is available from Microsoft: 
     4The global attribute *ALLOW_SINGLE_PRECISION_DLLS* should be set to *True* if 
     5you wish to allow single precision floating point evaluation for the compiled 
     6models, otherwise it defaults to *False*. 
     7 
     8The compiler command line is stored in the attribute *COMPILE*, with string 
     9substitutions for %(source)s and %(output)s indicating what to compile and 
     10where to store it.  The actual command is system dependent. 
     11 
     12On windows systems, you have a choice of compilers.  *MinGW* is the GNU 
     13compiler toolchain, available in packages such as anaconda and PythonXY, 
     14or available stand alone. This toolchain has had difficulties on some 
     15systems, and may or may not work for you.  In order to build DLLs, *gcc* 
     16must be on your path.  If the environment variable *SAS_OPENMP* is given 
     17then -fopenmp is added to the compiler flags.  This requires a version 
     18of MinGW compiled with OpenMP support. 
     19 
     20An alternative toolchain uses the Microsoft Visual C++ compiler, available 
     21free from microsoft: 
    1822 
    1923    `<http://www.microsoft.com/en-us/download/details.aspx?id=44266>`_ 
    2024 
    21 If neither compiler is available, sasmodels will check for *MinGW*, 
    22 the GNU compiler toolchain. This available in packages such as Anaconda 
    23 and PythonXY, or available stand alone. This toolchain has had 
    24 difficulties on some systems, and may or may not work for you. 
    25  
    26 You can control which compiler to use by setting SAS_COMPILER in the 
    27 environment: 
    28  
    29   - tinycc (Windows): use the TinyCC compiler shipped with SasView 
    30   - msvc (Windows): use the Microsoft Visual C++ compiler 
    31   - mingw (Windows): use the MinGW GNU cc compiler 
    32   - unix (Linux): use the system cc compiler. 
    33   - unix (Mac): use the clang compiler. You will need XCode installed, and 
    34     the XCode command line tools. Mac comes with OpenCL drivers, so generally 
    35     this will not be needed. 
    36  
    37 Both *msvc* and *mingw* require that the compiler is available on your path. 
    38 For *msvc*, this can done by running vcvarsall.bat in a windows terminal. 
    39 Install locations are system dependent, such as: 
     25Again, this requires that the compiler is available on your path.  This is 
     26done by running vcvarsall.bat in a windows terminal.  Install locations are 
     27system dependent, such as: 
    4028 
    4129    C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 
     
    4533    C:\Users\yourname\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 
    4634 
    47 OpenMP for *msvc* requires the Microsoft vcomp90.dll library, which doesn't 
    48 seem to be included with the compiler, nor does there appear to be a public 
    49 download location.  There may be one on your machine already in a location 
    50 such as: 
     35And again, the environment variable *SAS_OPENMP* controls whether OpenMP is 
     36used to compile the C code.  This requires the Microsoft vcomp90.dll library, 
     37which doesn't seem to be included with the compiler, nor does there appear 
     38to be a public download location.  There may be one on your machine already 
     39in a location such as: 
    5140 
    5241    C:\Windows\winsxs\x86_microsoft.vc90.openmp*\vcomp90.dll 
    5342 
    54 If you copy this to somewhere on your path, such as the python directory or 
    55 the install directory for this application, then OpenMP should be supported. 
    56  
    57 For full control of the compiler, define a function 
    58 *compile_command(source,output)* which takes the name of the source file 
    59 and the name of the output file and returns a compile command that can be 
    60 evaluated in the shell.  For even more control, replace the entire 
    61 *compile(source,output)* function. 
    62  
    63 The global attribute *ALLOW_SINGLE_PRECISION_DLLS* should be set to *False* if 
    64 you wish to prevent single precision floating point evaluation for the compiled 
    65 models, otherwise set it defaults to *True*. 
     43If you copy this onto your path, such as the python directory or the install 
     44directory for this application, then OpenMP should be supported. 
    6645""" 
    6746from __future__ import print_function 
     
    11190    compiler = "unix" 
    11291 
    113 ARCH = "" if ct.sizeof(c_void_p) > 4 else "x86"  # 4 byte pointers on x86 
     92ARCH = "" if sys.maxint > 2**32 else "x86"  # maxint=2**31-1 on 32 bit 
    11493if compiler == "unix": 
    11594    # Generic unix compile 
  • sasmodels/model_test.py

    r897ca7f r40a87fa  
    5050import numpy as np  # type: ignore 
    5151 
    52 from . import core 
    53 from .core import list_models, load_model_info, build_model 
     52from .core import list_models, load_model_info, build_model, HAVE_OPENCL 
    5453from .direct_model import call_kernel, call_ER, call_VR 
    5554from .exception import annotate_exception 
     
    9998        if is_py:  # kernel implemented in python 
    10099            test_name = "Model: %s, Kernel: python"%model_name 
    101             test_method_name = "test_%s_python" % model_info.id 
     100            test_method_name = "test_%s_python" % model_name 
    102101            test = ModelTestCase(test_name, model_info, 
    103102                                 test_method_name, 
     
    107106        else:   # kernel implemented in C 
    108107            # test using opencl if desired and available 
    109             if 'opencl' in loaders and core.HAVE_OPENCL: 
     108            if 'opencl' in loaders and HAVE_OPENCL: 
    110109                test_name = "Model: %s, Kernel: OpenCL"%model_name 
    111                 test_method_name = "test_%s_opencl" % model_info.id 
     110                test_method_name = "test_%s_opencl" % model_name 
    112111                # Using dtype=None so that the models that are only 
    113112                # correct for double precision are not tested using 
     
    123122            if 'dll' in loaders: 
    124123                test_name = "Model: %s, Kernel: dll"%model_name 
    125                 test_method_name = "test_%s_dll" % model_info.id 
     124                test_method_name = "test_%s_dll" % model_name 
    126125                test = ModelTestCase(test_name, model_info, 
    127126                                     test_method_name, 
     
    250249    return abs(target-actual)/shift < 1.5*10**-digits 
    251250 
    252 def run_one(model): 
    253     # type: (str) -> None 
    254     """ 
    255     Run the tests for a single model, printing the results to stdout. 
    256  
    257     *model* can by a python file, which is handy for checking user defined 
    258     plugin models. 
    259     """ 
    260     # Note that running main() directly did not work from within the 
    261     # wxPython pycrust console.  Instead of the results appearing in the 
    262     # window they were printed to the underlying console. 
    263     from unittest.runner import TextTestResult, _WritelnDecorator 
    264  
    265     # Build a object to capture and print the test results 
    266     stream = _WritelnDecorator(sys.stdout)  # Add writeln() method to stream 
    267     verbosity = 2 
    268     descriptions = True 
    269     result = TextTestResult(stream, descriptions, verbosity) 
    270  
    271     # Build a test suite containing just the model 
    272     loaders = ['opencl'] 
    273     models = [model] 
    274     try: 
    275         suite = make_suite(loaders, models) 
    276     except Exception: 
    277         import traceback 
    278         stream.writeln(traceback.format_exc()) 
    279         return 
    280  
    281     # Run the test suite 
    282     suite.run(result) 
    283  
    284     # Print the failures and errors 
    285     for _, tb in result.errors: 
    286         stream.writeln(tb) 
    287     for _, tb in result.failures: 
    288         stream.writeln(tb) 
    289  
    290     # Check if there are user defined tests. 
    291     # Yes, it is naughty to peek into the structure of the test suite, and 
    292     # to assume that it contains only one test. 
    293     if not suite._tests[0].info.tests: 
    294         stream.writeln("Note: %s has no user defined tests."%model) 
    295  
    296  
    297 def main(*models): 
    298     # type: (*str) -> int 
    299     """ 
    300     Run tests given is models. 
     251def main(): 
     252    # type: () -> int 
     253    """ 
     254    Run tests given is sys.argv. 
    301255 
    302256    Returns 0 if success or 1 if any tests fail. 
     
    309263        test_args = {} 
    310264 
     265    models = sys.argv[1:] 
    311266    if models and models[0] == '-v': 
    312267        verbosity = 2 
     
    315270        verbosity = 1 
    316271    if models and models[0] == 'opencl': 
    317         if not core.HAVE_OPENCL: 
     272        if not HAVE_OPENCL: 
    318273            print("opencl is not available") 
    319274            return 1 
     
    363318 
    364319if __name__ == "__main__": 
    365     sys.exit(main(*sys.argv[1:])) 
     320    sys.exit(main()) 
  • sasmodels/models/core_multi_shell.py

    r7b68dc5 r8c6fbbc  
    132132def ER(radius, n, thickness): 
    133133    """Effective radius""" 
    134     n = int(n[0])  # n cannot be polydisperse 
     134    n = n[0]  # n cannot be polydisperse 
    135135    return np.sum(thickness[:n], axis=0) + radius 
    136136 
  • sasmodels/models/onion.py

    r7b68dc5 r3cd1001  
    368368def ER(core_radius, n, thickness): 
    369369    """Effective radius""" 
    370     return np.sum(thickness[:int(n[0])], axis=0) + core_radius 
     370    return np.sum(thickness[:n[0]], axis=0) + core_radius 
    371371 
    372372demo = { 
  • sasmodels/models/sphere.py

    r7e6bea81 r9a4811a  
    22For information about polarised and magnetic scattering, see 
    33the :ref:`magnetism` documentation. 
     4documentation. 
    45 
    56Definition 
     
    1516 
    1617where *scale* is a volume fraction, $V$ is the volume of the scatterer, 
    17 $r$ is the radius of the sphere and *background* is the background level. 
     18$r$ is the radius of the sphere, *background* is the background level and 
    1819*sld* and *sld_solvent* are the scattering length densities (SLDs) of the 
    19 scatterer and the solvent respectively, whose difference is $\Delta\rho$. 
     20scatterer and the solvent respectively. 
    2021 
    2122Note that if your data is in absolute scale, the *scale* should represent 
     
    9091            radius=120, 
    9192            radius_pd=.2, radius_pd_n=45) 
    92  
    93 tests = [ 
    94     [{}, 0.2, 0.726362], 
    95     [{"scale": 1., "background": 0., "sld": 6., "sld_solvent": 1., 
    96       "radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, 
    97      0.2, 0.228843], 
    98     [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "ER", 120.], 
    99     [{"radius": 120., "radius_pd": 0.2, "radius_pd_n":45}, "VR", 1.], 
    100 ] 
    101  
    102  
  • sasmodels/rst2html.py

    rb217c71 r40a87fa  
    1010from contextlib import contextmanager 
    1111 
    12 # CRUFT: locale.getlocale() fails on some versions of OS X 
    13 # See https://bugs.python.org/issue18378 
    14 import locale 
    15 if hasattr(locale, '_parse_localename'): 
    16     try: 
    17         locale._parse_localename('UTF-8') 
    18     except ValueError: 
    19         _old_parse_localename = locale._parse_localename 
    20         def _parse_localename(localename): 
    21             code = locale.normalize(localename) 
    22             if code == 'UTF-8': 
    23                 return None, code 
    24             else: 
    25                 return _old_parse_localename(localename) 
    26         locale._parse_localename = _parse_localename 
    27  
    2812from docutils.core import publish_parts 
    2913from docutils.writers.html4css1 import HTMLTranslator 
    3014from docutils.nodes import SkipNode 
    3115 
    32 def wxview(html, url="", size=(850, 540)): 
    33     import wx 
    34     from wx.html2 import WebView 
    35     frame = wx.Frame(None, -1, size=size) 
    36     view = WebView.New(frame) 
    37     view.SetPage(html, url) 
    38     frame.Show() 
    39     return frame 
    4016 
    41 def view_rst(filename): 
    42     from os.path import expanduser 
    43     with open(expanduser(filename)) as fid: 
    44         rst = fid.read() 
    45     html = rst2html(rst) 
    46     wxview(html) 
    47  
    48 def rst2html(rst, part="whole", math_output="mathjax"): 
     17def rst2html(rst, part="whole", math_output="html"): 
    4918    r""" 
    5019    Convert restructured text into simple html. 
     
    7544    else: 
    7645        settings = {"math-output": math_output} 
    77  
    78     # TODO: support stylesheets 
    79     #html_root = "/full/path/to/_static/" 
    80     #sheets = [html_root+s for s in ["basic.css","classic.css"]] 
    81     #settings["embed_styesheet"] = True 
    82     #settings["stylesheet_path"] = sheets 
    8346 
    8447    # math2html and mathml do not support \frac12 
     
    141104    assert replace_dollar(u"and $mid$ too") == u"and :math:`mid` too" 
    142105    assert replace_dollar(u"$first$, $mid$, $last$") == u":math:`first`, :math:`mid`, :math:`last`" 
    143     assert replace_dollar(u"dollar\\$ escape") == u"dollar$ escape" 
    144     assert replace_dollar(u"dollar \\$escape\\$ too") == u"dollar $escape$ too" 
     106    assert replace_dollar(ur"dollar\$ escape") == u"dollar$ escape" 
     107    assert replace_dollar(ur"dollar \$escape\$ too") == u"dollar $escape$ too" 
    145108    assert replace_dollar(u"spaces $in the$ math") == u"spaces :math:`in the` math" 
    146     assert replace_dollar(u"emb\\ $ed$\\ ed") == u"emb\\ :math:`ed`\\ ed" 
     109    assert replace_dollar(ur"emb\ $ed$\ ed") == ur"emb\ :math:`ed`\ ed" 
    147110    assert replace_dollar(u"$first$a") == u"$first$a" 
    148111    assert replace_dollar(u"a$last$") == u"a$last$" 
  • sasmodels/weights.py

    rf1a8811 rf1a8811  
    1010import numpy as np  # type: ignore 
    1111from scipy.special import gammaln  # type: ignore 
    12  
    13 # TODO: include dispersion docs with the disperser models 
    1412 
    1513class Dispersion(object): 
Note: See TracChangeset for help on using the changeset viewer.