Changeset 1b5e020 in sasmodels for sasmodels/models/tabulated.py


Ignore:
Timestamp:
Aug 27, 2017 11:11:41 AM (5 years ago)
Author:
Jose Borreguero <borreguero@…>
Children:
41917b8
Parents:
df30106
Message:

decorator to numpyze positional arguments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/tabulated.py

    rdf30106 r1b5e020  
    7373 
    7474 
     75def numpyze(calc_I): 
     76    """ 
     77    Transform positional arguments into numpy arrays 
     78    :param calc_I: Intensities calculator 
     79    :return: function acting on the transformed positional arguments 
     80    """ 
     81    def wrapper(*args, **kwargs): 
     82        numpy_args = [np.array(arg, dtype=np.float) for arg in args] 
     83        return calc_I(*numpy_args, **kwargs) 
     84 
     85 
     86@numpyze 
    7587def Iq(q, scale=1.0): 
    7688    """ 
     
    7991    :return:      calculated intensities 
    8092    """ 
    81     q_a = np.array(q, dtype='float') 
    82     return scale * _attr['itp'](q_a) 
     93    return scale * _attr['itp'](q) 
    8394 
    8495Iq.vectorized = True  # Iq accepts an array of q values 
    8596 
    8697 
     98@numpyze 
    8799def Iqxy(qx, qy, scale=1.0): 
    88100    """ 
     
    92104    :return:      calculated intensities 
    93105    """ 
    94     qx_a = np.array(qx, dtype='float') 
    95     qy_a = np.array(qy, dtype='float') 
    96     return scale * _attr['itp'](qx_a, qy_a) 
     106    return scale * _attr['itp'](qx, qy) 
    97107    pass 
    98108 
Note: See TracChangeset for help on using the changeset viewer.