Changeset 7e923c2 in sasmodels for sasmodels/generate.py
- Timestamp:
- Aug 7, 2018 10:45:52 PM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 1a7ddc9
- Parents:
- c036ddb (diff), e9b17b18 (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
rd86f0fc rc036ddb 671 671 672 672 673 # type in IQXY pattern could be single, float, double, long double, ... 674 _IQXY_PATTERN = re.compile(r"(^|\s)double\s+I(?P<mode>q(ab?c|xy))\s*[(]", 673 _IQXY_PATTERN = re.compile(r"(^|\s)double\s+I(?P<mode>q(ac|abc|xy))\s*[(]", 675 674 flags=re.MULTILINE) 676 675 def find_xy_mode(source): … … 701 700 return 'qa' 702 701 702 # Note: not presently used. Need to know whether Fq is available before 703 # trying to compile the source. Leave the code here in case we decide that 704 # define have_Fq for each form factor is too tedious and error prone. 705 _FQ_PATTERN = re.compile(r"(^|\s)void\s+Fq[(]", flags=re.MULTILINE) 706 def contains_Fq(source): 707 # type: (List[str]) -> bool 708 """ 709 Return True if C source defines "void Fq(". 710 """ 711 for code in source: 712 m = _FQ_PATTERN.search(code) 713 if m is not None: 714 return True 715 return False 703 716 704 717 def _add_source(source, code, path, lineno=1): … … 730 743 # dispersion. Need to be careful that necessary parameters are available 731 744 # for computing volume even if we allow non-disperse volume parameters. 732 733 745 partable = model_info.parameters 734 746 … … 743 755 for path, code in user_code: 744 756 _add_source(source, code, path) 745 746 757 if model_info.c_code: 747 758 _add_source(source, model_info.c_code, model_info.filename, … … 751 762 q, qx, qy, qab, qa, qb, qc \ 752 763 = [Parameter(name=v) for v in 'q qx qy qab qa qb qc'.split()] 764 753 765 # Generate form_volume function, etc. from body only 754 766 if isinstance(model_info.form_volume, str): … … 789 801 source.append("\\\n".join(p.as_definition() 790 802 for p in partable.kernel_parameters)) 791 792 803 # Define the function calls 793 804 if partable.form_volume_parameters: … … 800 811 call_volume = "#define CALL_VOLUME(v) 1.0" 801 812 source.append(call_volume) 802 803 813 model_refs = _call_pars("_v.", partable.iq_parameters) 804 pars = ",".join(["_q"] + model_refs) 805 call_iq = "#define CALL_IQ(_q, _v) Iq(%s)" % pars 814 815 if model_info.have_Fq: 816 pars = ",".join(["_q", "&_F1", "&_F2",] + model_refs) 817 call_iq = "#define CALL_FQ(_q, _F1, _F2, _v) Fq(%s)" % pars 818 clear_iq = "#undef CALL_FQ" 819 else: 820 pars = ",".join(["_q"] + model_refs) 821 call_iq = "#define CALL_IQ(_q, _v) Iq(%s)" % pars 822 clear_iq = "#undef CALL_IQ" 806 823 if xy_mode == 'qabc': 807 824 pars = ",".join(["_qa", "_qb", "_qc"] + model_refs) … … 812 829 call_iqxy = "#define CALL_IQ_AC(_qa,_qc,_v) Iqac(%s)" % pars 813 830 clear_iqxy = "#undef CALL_IQ_AC" 814 elif xy_mode == 'qa' :831 elif xy_mode == 'qa' and not model_info.have_Fq: 815 832 pars = ",".join(["_qa"] + model_refs) 816 833 call_iqxy = "#define CALL_IQ_A(_qa,_v) Iq(%s)" % pars 817 834 clear_iqxy = "#undef CALL_IQ_A" 835 elif xy_mode == 'qa' and model_info.have_Fq: 836 pars = ",".join(["_qa", "&_F1", "&_F2",] + model_refs) 837 # Note: uses rare C construction (expr1, expr2) which computes 838 # expr1 then expr2 and evaluates to expr2. This allows us to 839 # leave it looking like a function even though it is returning 840 # its values by reference. 841 call_iqxy = "#define CALL_FQ_A(_qa,_F1,_F2,_v) (Fq(%s),_F2)" % pars 842 clear_iqxy = "#undef CALL_FQ_A" 818 843 elif xy_mode == 'qxy': 819 844 orientation_refs = _call_pars("_v.", partable.orientation_parameters) … … 831 856 magpars = [k-2 for k, p in enumerate(partable.call_parameters) 832 857 if p.type == 'sld'] 833 834 858 # Fill in definitions for numbers of parameters 835 859 source.append("#define MAX_PD %s"%partable.max_pd) … … 839 863 source.append("#define MAGNETIC_PARS %s"%",".join(str(k) for k in magpars)) 840 864 source.append("#define PROJECTION %d"%PROJECTION) 841 842 865 # TODO: allow mixed python/opencl kernels? 843 844 ocl = _kernels(kernel_code, call_iq, call_iqxy, clear_iqxy, model_info.name)845 dll = _kernels(kernel_code, call_iq, call_iqxy, clear_iqxy, model_info.name) 866 ocl = _kernels(kernel_code, call_iq, clear_iq, call_iqxy, clear_iqxy, model_info.name) 867 dll = _kernels(kernel_code, call_iq, clear_iq, call_iqxy, clear_iqxy, model_info.name) 868 846 869 result = { 847 870 'dll': '\n'.join(source+dll[0]+dll[1]+dll[2]), 848 871 'opencl': '\n'.join(source+ocl[0]+ocl[1]+ocl[2]), 849 872 } 850 851 873 return result 852 874 853 875 854 def _kernels(kernel, call_iq, c all_iqxy, clear_iqxy, name):876 def _kernels(kernel, call_iq, clear_iq, call_iqxy, clear_iqxy, name): 855 877 # type: ([str,str], str, str, str) -> List[str] 856 878 code = kernel[0] … … 862 884 '#line 1 "%s Iq"' % path, 863 885 code, 864 "#undef CALL_IQ",886 clear_iq, 865 887 "#undef KERNEL_NAME", 866 888 ]
Note: See TracChangeset
for help on using the changeset viewer.