Changeset 4bfd277 in sasmodels for sasmodels/kernelpy.py


Ignore:
Timestamp:
Apr 8, 2016 12:11:16 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:
2afc26d
Parents:
d2fc9a4
Message:

support ER/VR calls with vector parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernelpy.py

    r6d6508e r4bfd277  
    1010from numpy import pi, cos 
    1111 
     12from . import details 
    1213from .generate import F64 
    1314 
     
    145146 
    146147    def __call__(self, call_details, weights, values, cutoff): 
    147         # type: (.generate.CallDetails, np.ndarray, np.ndarray, float) -> np.ndarray 
     148        assert isinstance(call_details, details.CallDetails) 
    148149        res = _loops(self._parameter_vector, self._form, self._volume, 
    149150                     self.q_input.nq, call_details, weights, values, cutoff) 
     
    160161           form_volume, # type: Callable[[], float] 
    161162           nq,          # type: int 
    162            call_details,# type: .generate.CallDetails 
     163           call_details,# type: details.CallDetails 
    163164           weights,     # type: np.ndarray 
    164165           values,      # type: np.ndarray 
     
    205206                this_offset = call_details.par_offset[par] 
    206207                block_size = 1 
    207                 for bit in xrange(32): 
     208                for bit in range(len(pd_offset)): 
    208209                    if coord&1: 
    209210                        this_offset += block_size * pd_index[bit] 
     
    245246 
    246247 
     248def _create_default_functions(model_info): 
     249    """ 
     250    Autogenerate missing functions, such as Iqxy from Iq. 
     251 
     252    This only works for Iqxy when Iq is written in python. :func:`make_source` 
     253    performs a similar role for Iq written in C.  This also vectorizes 
     254    any functions that are not already marked as vectorized. 
     255    """ 
     256    _create_vector_Iq(model_info) 
     257    _create_vector_Iqxy(model_info)  # call create_vector_Iq() first 
     258 
    247259 
    248260def _create_vector_Iq(model_info): 
     
    252264    Iq = model_info.Iq 
    253265    if callable(Iq) and not getattr(Iq, 'vectorized', False): 
     266        #print("vectorizing Iq") 
    254267        def vector_Iq(q, *args): 
    255268            """ 
     
    265278    """ 
    266279    Iq, Iqxy = model_info.Iq, model_info.Iqxy 
    267     if callable(Iqxy) and not getattr(Iqxy, 'vectorized', False): 
    268         def vector_Iqxy(qx, qy, *args): 
    269             """ 
    270             Vectorized 2D kernel. 
    271             """ 
    272             return np.array([Iqxy(qxi, qyi, *args) for qxi, qyi in zip(qx, qy)]) 
    273         vector_Iqxy.vectorized = True 
    274         model_info.Iqxy = vector_Iqxy 
     280    if callable(Iqxy): 
     281        if not getattr(Iqxy, 'vectorized', False): 
     282            #print("vectorizing Iqxy") 
     283            def vector_Iqxy(qx, qy, *args): 
     284                """ 
     285                Vectorized 2D kernel. 
     286                """ 
     287                return np.array([Iqxy(qxi, qyi, *args) for qxi, qyi in zip(qx, qy)]) 
     288            vector_Iqxy.vectorized = True 
     289            model_info.Iqxy = vector_Iqxy 
    275290    elif callable(Iq): 
     291        #print("defaulting Iqxy") 
    276292        # Iq is vectorized because create_vector_Iq was already called. 
    277293        def default_Iqxy(qx, qy, *args): 
     
    283299        model_info.Iqxy = default_Iqxy 
    284300 
    285 def _create_default_functions(model_info): 
    286     """ 
    287     Autogenerate missing functions, such as Iqxy from Iq. 
    288  
    289     This only works for Iqxy when Iq is written in python. :func:`make_source` 
    290     performs a similar role for Iq written in C.  This also vectorizes 
    291     any functions that are not already marked as vectorized. 
    292     """ 
    293     _create_vector_Iq(model_info) 
    294     _create_vector_Iqxy(model_info)  # call create_vector_Iq() first 
    295  
Note: See TracChangeset for help on using the changeset viewer.