Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:09

0001 #pragma once
0002 /**
0003 qprop.h
0004 ========
0005 
0006 HMM: this relies on the prop arrays having last column integer 
0007 annotation as done by NP::combine but there is no naming 
0008 or anything that stresses that 
0009 
0010 **/
0011 
0012 
0013 
0014 #if defined(__CUDACC__) || defined(__CUDABE__)
0015    #define QPROP_METHOD __device__
0016 #else
0017    #define QPROP_METHOD 
0018 #endif 
0019 
0020 #include "sview.h"
0021 
0022 
0023 template<typename T>
0024 struct qprop
0025 {
0026     T* pp ; 
0027     unsigned width ; 
0028     unsigned height ; 
0029 
0030 #if defined(__CUDACC__) || defined(__CUDABE__) || defined( MOCK_CURAND )
0031     QPROP_METHOD T  interpolate( unsigned iprop, T x );  
0032 #else
0033     qprop()
0034         :
0035         pp(nullptr),
0036         width(0),
0037         height(0)
0038     {
0039     }
0040 #endif
0041 
0042 }; 
0043 
0044 
0045 #if defined(__CUDACC__) || defined(__CUDABE__) || defined(MOCK_CURAND) 
0046 
0047 /**
0048 qprop<T>::interpolate
0049 -----------------------
0050 
0051 1. access property data for index iprop
0052 2. interpret the last column to obtain the number of payload values
0053 3. binary search to find the bin relevant to domain argument x  
0054 4. linear interpolation to yield the y value at x
0055 
0056 **/
0057 
0058 template <typename T>
0059 inline QPROP_METHOD T qprop<T>::interpolate( unsigned iprop, T x )
0060 {
0061     const T* vv = pp + width*iprop ; 
0062 
0063     int ni = sview::int_from<T>( *(vv+width-1) ) ; 
0064 
0065     //printf("//qprop:interpolate iprop %d width %d height %d ni %d \n", iprop, width, height, ni ); 
0066 
0067     int lo = 0 ;
0068     int hi = ni-1 ;
0069 
0070     if( x <= vv[2*lo+0] ) return vv[2*lo+1] ; 
0071     if( x >= vv[2*hi+0] ) return vv[2*hi+1] ; 
0072 
0073     while (lo < hi-1)
0074     {    
0075         int mi = (lo+hi)/2;
0076         if (x < vv[2*mi+0]) hi = mi ; 
0077         else lo = mi;
0078     }    
0079 
0080     T dy = vv[2*hi+1] - vv[2*lo+1] ; 
0081     T dx = vv[2*hi+0] - vv[2*lo+0] ; 
0082     T  y = vv[2*lo+1] + dy*(x-vv[2*lo+0])/dx ; 
0083     return y ;  
0084 }
0085 
0086 
0087 #endif
0088