idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
247,800 | def tpictr ( sample , lenout = _default_len_out , lenerr = _default_len_out ) : sample = stypes . stringToCharP ( sample ) pictur = stypes . stringToCharP ( lenout ) errmsg = stypes . stringToCharP ( lenerr ) lenout = ctypes . c_int ( lenout ) lenerr = ctypes . c_int ( lenerr ) ok = ctypes . c_int ( ) libspice . tpictr_c ( sample , lenout , lenerr , pictur , ctypes . byref ( ok ) , errmsg ) return stypes . toPythonString ( pictur ) , ok . value , stypes . toPythonString ( errmsg ) | Given a sample time string create a time format picture suitable for use by the routine timout . |
247,801 | def trcdep ( ) : depth = ctypes . c_int ( ) libspice . trcdep_c ( ctypes . byref ( depth ) ) return depth . value | Return the number of modules in the traceback representation . |
247,802 | def trcnam ( index , namlen = _default_len_out ) : index = ctypes . c_int ( index ) name = stypes . stringToCharP ( namlen ) namlen = ctypes . c_int ( namlen ) libspice . trcnam_c ( index , namlen , name ) return stypes . toPythonString ( name ) | Return the name of the module having the specified position in the trace representation . The first module to check in is at index 0 . |
247,803 | def twovec ( axdef , indexa , plndef , indexp ) : axdef = stypes . toDoubleVector ( axdef ) indexa = ctypes . c_int ( indexa ) plndef = stypes . toDoubleVector ( plndef ) indexp = ctypes . c_int ( indexp ) mout = stypes . emptyDoubleMatrix ( ) libspice . twovec_c ( axdef , indexa , plndef , indexp , mout ) return stypes . cMatrixToNumpy ( mout ) | Find the transformation to the right - handed frame having a given vector as a specified axis and having a second given vector lying in a specified coordinate plane . |
247,804 | def txtopn ( fname ) : fnameP = stypes . stringToCharP ( fname ) unit_out = ctypes . c_int ( ) fname_len = ctypes . c_int ( len ( fname ) ) libspice . txtopn_ ( fnameP , ctypes . byref ( unit_out ) , fname_len ) return unit_out . value | Internal undocumented command for opening a new text file for subsequent write access . |
247,805 | def ucase ( inchar , lenout = None ) : if lenout is None : lenout = len ( inchar ) + 1 inchar = stypes . stringToCharP ( inchar ) outchar = stypes . stringToCharP ( " " * lenout ) lenout = ctypes . c_int ( lenout ) libspice . ucase_c ( inchar , lenout , outchar ) return stypes . toPythonString ( outchar ) | Convert the characters in a string to uppercase . |
247,806 | def ucrss ( v1 , v2 ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) vout = stypes . emptyDoubleVector ( 3 ) libspice . ucrss_c ( v1 , v2 , vout ) return stypes . cVectorToPython ( vout ) | Compute the normalized cross product of two 3 - vectors . |
247,807 | def uddc ( udfunc , x , dx ) : x = ctypes . c_double ( x ) dx = ctypes . c_double ( dx ) isdescr = ctypes . c_int ( ) libspice . uddc_c ( udfunc , x , dx , ctypes . byref ( isdescr ) ) return bool ( isdescr . value ) | SPICE private routine intended solely for the support of SPICE routines . Users should not call this routine directly due to the volatile nature of this routine . |
247,808 | def uddf ( udfunc , x , dx ) : x = ctypes . c_double ( x ) dx = ctypes . c_double ( dx ) deriv = ctypes . c_double ( ) libspice . uddf_c ( udfunc , x , dx , ctypes . byref ( deriv ) ) return deriv . value | Routine to calculate the first derivative of a caller - specified function using a three - point estimation . |
247,809 | def udf ( x ) : x = ctypes . c_double ( x ) value = ctypes . c_double ( ) libspice . udf_c ( x , ctypes . byref ( value ) ) return value . value | No - op routine for with an argument signature matching udfuns . Allways returns 0 . 0 . |
247,810 | def unitim ( epoch , insys , outsys ) : epoch = ctypes . c_double ( epoch ) insys = stypes . stringToCharP ( insys ) outsys = stypes . stringToCharP ( outsys ) return libspice . unitim_c ( epoch , insys , outsys ) | Transform time from one uniform scale to another . The uniform time scales are TAI TDT TDB ET JED JDTDB JDTDT . |
247,811 | def unload ( filename ) : if isinstance ( filename , list ) : for f in filename : libspice . unload_c ( stypes . stringToCharP ( f ) ) return filename = stypes . stringToCharP ( filename ) libspice . unload_c ( filename ) | Unload a SPICE kernel . |
247,812 | def unorm ( v1 ) : v1 = stypes . toDoubleVector ( v1 ) vout = stypes . emptyDoubleVector ( 3 ) vmag = ctypes . c_double ( ) libspice . unorm_c ( v1 , vout , ctypes . byref ( vmag ) ) return stypes . cVectorToPython ( vout ) , vmag . value | Normalize a double precision 3 - vector and return its magnitude . |
247,813 | def unormg ( v1 , ndim ) : v1 = stypes . toDoubleVector ( v1 ) vout = stypes . emptyDoubleVector ( ndim ) vmag = ctypes . c_double ( ) ndim = ctypes . c_int ( ndim ) libspice . unormg_c ( v1 , ndim , vout , ctypes . byref ( vmag ) ) return stypes . cVectorToPython ( vout ) , vmag . value | Normalize a double precision vector of arbitrary dimension and return its magnitude . |
247,814 | def utc2et ( utcstr ) : utcstr = stypes . stringToCharP ( utcstr ) et = ctypes . c_double ( ) libspice . utc2et_c ( utcstr , ctypes . byref ( et ) ) return et . value | Convert an input time from Calendar or Julian Date format UTC to ephemeris seconds past J2000 . |
247,815 | def valid ( insize , n , inset ) : assert isinstance ( inset , stypes . SpiceCell ) insize = ctypes . c_int ( insize ) n = ctypes . c_int ( n ) libspice . valid_c ( insize , n , inset ) return inset | Create a valid CSPICE set from a CSPICE Cell of any data type . |
247,816 | def vcrss ( v1 , v2 ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) vout = stypes . emptyDoubleVector ( 3 ) libspice . vcrss_c ( v1 , v2 , vout ) return stypes . cVectorToPython ( vout ) | Compute the cross product of two 3 - dimensional vectors . |
247,817 | def vdist ( v1 , v2 ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) return libspice . vdist_c ( v1 , v2 ) | Return the distance between two three - dimensional vectors . |
247,818 | def vdistg ( v1 , v2 , ndim ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) ndim = ctypes . c_int ( ndim ) return libspice . vdistg_c ( v1 , v2 , ndim ) | Return the distance between two vectors of arbitrary dimension . |
247,819 | def vdot ( v1 , v2 ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) return libspice . vdot_c ( v1 , v2 ) | Compute the dot product of two double precision 3 - dimensional vectors . |
247,820 | def vdotg ( v1 , v2 , ndim ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) ndim = ctypes . c_int ( ndim ) return libspice . vdotg_c ( v1 , v2 , ndim ) | Compute the dot product of two double precision vectors of arbitrary dimension . |
247,821 | def vequ ( v1 ) : v1 = stypes . toDoubleVector ( v1 ) vout = stypes . emptyDoubleVector ( 3 ) libspice . vequ_c ( v1 , vout ) return stypes . cVectorToPython ( vout ) | Make one double precision 3 - dimensional vector equal to another . |
247,822 | def vequg ( v1 , ndim ) : v1 = stypes . toDoubleVector ( v1 ) vout = stypes . emptyDoubleVector ( ndim ) ndim = ctypes . c_int ( ndim ) libspice . vequg_c ( v1 , ndim , vout ) return stypes . cVectorToPython ( vout ) | Make one double precision vector of arbitrary dimension equal to another . |
247,823 | def vhat ( v1 ) : v1 = stypes . toDoubleVector ( v1 ) vout = stypes . emptyDoubleVector ( 3 ) libspice . vhat_c ( v1 , vout ) return stypes . cVectorToPython ( vout ) | Find the unit vector along a double precision 3 - dimensional vector . |
247,824 | def vhatg ( v1 , ndim ) : v1 = stypes . toDoubleVector ( v1 ) vout = stypes . emptyDoubleVector ( ndim ) ndim = ctypes . c_int ( ndim ) libspice . vhatg_c ( v1 , ndim , vout ) return stypes . cVectorToPython ( vout ) | Find the unit vector along a double precision vector of arbitrary dimension . |
247,825 | def vlcom ( a , v1 , b , v2 ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) sumv = stypes . emptyDoubleVector ( 3 ) a = ctypes . c_double ( a ) b = ctypes . c_double ( b ) libspice . vlcom_c ( a , v1 , b , v2 , sumv ) return stypes . cVectorToPython ( sumv ) | Compute a vector linear combination of two double precision 3 - dimensional vectors . |
247,826 | def vlcomg ( n , a , v1 , b , v2 ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) sumv = stypes . emptyDoubleVector ( n ) a = ctypes . c_double ( a ) b = ctypes . c_double ( b ) n = ctypes . c_int ( n ) libspice . vlcomg_c ( n , a , v1 , b , v2 , sumv ) return stypes . cVectorToPython ( sumv ) | Compute a vector linear combination of two double precision vectors of arbitrary dimension . |
247,827 | def vminug ( vin , ndim ) : vin = stypes . toDoubleVector ( vin ) vout = stypes . emptyDoubleVector ( ndim ) ndim = ctypes . c_int ( ndim ) libspice . vminug_c ( vin , ndim , vout ) return stypes . cVectorToPython ( vout ) | Negate a double precision vector of arbitrary dimension . |
247,828 | def vminus ( vin ) : vin = stypes . toDoubleVector ( vin ) vout = stypes . emptyDoubleVector ( 3 ) libspice . vminus_c ( vin , vout ) return stypes . cVectorToPython ( vout ) | Negate a double precision 3 - dimensional vector . |
247,829 | def vnormg ( v , ndim ) : v = stypes . toDoubleVector ( v ) ndim = ctypes . c_int ( ndim ) return libspice . vnormg_c ( v , ndim ) | Compute the magnitude of a double precision vector of arbitrary dimension . |
247,830 | def vpack ( x , y , z ) : x = ctypes . c_double ( x ) y = ctypes . c_double ( y ) z = ctypes . c_double ( z ) vout = stypes . emptyDoubleVector ( 3 ) libspice . vpack_c ( x , y , z , vout ) return stypes . cVectorToPython ( vout ) | Pack three scalar components into a vector . |
247,831 | def vperp ( a , b ) : a = stypes . toDoubleVector ( a ) b = stypes . toDoubleVector ( b ) vout = stypes . emptyDoubleVector ( 3 ) libspice . vperp_c ( a , b , vout ) return stypes . cVectorToPython ( vout ) | Find the component of a vector that is perpendicular to a second vector . All vectors are 3 - dimensional . |
247,832 | def vprjp ( vin , plane ) : vin = stypes . toDoubleVector ( vin ) vout = stypes . emptyDoubleVector ( 3 ) libspice . vprjp_c ( vin , ctypes . byref ( plane ) , vout ) return stypes . cVectorToPython ( vout ) | Project a vector onto a specified plane orthogonally . |
247,833 | def vprjpi ( vin , projpl , invpl ) : vin = stypes . toDoubleVector ( vin ) vout = stypes . emptyDoubleVector ( 3 ) found = ctypes . c_int ( ) libspice . vprjpi_c ( vin , ctypes . byref ( projpl ) , ctypes . byref ( invpl ) , vout , ctypes . byref ( found ) ) return stypes . cVectorToPython ( vout ) , bool ( found . value ) | Find the vector in a specified plane that maps to a specified vector in another plane under orthogonal projection . |
247,834 | def vproj ( a , b ) : a = stypes . toDoubleVector ( a ) b = stypes . toDoubleVector ( b ) vout = stypes . emptyDoubleVector ( 3 ) libspice . vproj_c ( a , b , vout ) return stypes . cVectorToPython ( vout ) | Find the projection of one vector onto another vector . |
247,835 | def vrel ( v1 , v2 ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) return libspice . vrel_c ( v1 , v2 ) | Return the relative difference between two 3 - dimensional vectors . |
247,836 | def vrelg ( v1 , v2 , ndim ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) ndim = ctypes . c_int ( ndim ) return libspice . vrelg_c ( v1 , v2 , ndim ) | Return the relative difference between two vectors of general dimension . |
247,837 | def vrotv ( v , axis , theta ) : v = stypes . toDoubleVector ( v ) axis = stypes . toDoubleVector ( axis ) theta = ctypes . c_double ( theta ) r = stypes . emptyDoubleVector ( 3 ) libspice . vrotv_c ( v , axis , theta , r ) return stypes . cVectorToPython ( r ) | Rotate a vector about a specified axis vector by a specified angle and return the rotated vector . |
247,838 | def vscl ( s , v1 ) : s = ctypes . c_double ( s ) v1 = stypes . toDoubleVector ( v1 ) vout = stypes . emptyDoubleVector ( 3 ) libspice . vscl_c ( s , v1 , vout ) return stypes . cVectorToPython ( vout ) | Multiply a scalar and a 3 - dimensional double precision vector . |
247,839 | def vsclg ( s , v1 , ndim ) : s = ctypes . c_double ( s ) v1 = stypes . toDoubleVector ( v1 ) vout = stypes . emptyDoubleVector ( ndim ) ndim = ctypes . c_int ( ndim ) libspice . vsclg_c ( s , v1 , ndim , vout ) return stypes . cVectorToPython ( vout ) | Multiply a scalar and a double precision vector of arbitrary dimension . |
247,840 | def vsep ( v1 , v2 ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) return libspice . vsep_c ( v1 , v2 ) | Find the separation angle in radians between two double precision 3 - dimensional vectors . This angle is defined as zero if either vector is zero . |
247,841 | def vsepg ( v1 , v2 , ndim ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) ndim = ctypes . c_int ( ndim ) return libspice . vsepg_c ( v1 , v2 , ndim ) | Find the separation angle in radians between two double precision vectors of arbitrary dimension . This angle is defined as zero if either vector is zero . |
247,842 | def vsub ( v1 , v2 ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) vout = stypes . emptyDoubleVector ( 3 ) libspice . vsub_c ( v1 , v2 , vout ) return stypes . cVectorToPython ( vout ) | Compute the difference between two 3 - dimensional double precision vectors . |
247,843 | def vsubg ( v1 , v2 , ndim ) : v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) vout = stypes . emptyDoubleVector ( ndim ) ndim = ctypes . c_int ( ndim ) libspice . vsubg_c ( v1 , v2 , ndim , vout ) return stypes . cVectorToPython ( vout ) | Compute the difference between two double precision vectors of arbitrary dimension . |
247,844 | def vtmv ( v1 , matrix , v2 ) : v1 = stypes . toDoubleVector ( v1 ) matrix = stypes . toDoubleMatrix ( matrix ) v2 = stypes . toDoubleVector ( v2 ) return libspice . vtmv_c ( v1 , matrix , v2 ) | Multiply the transpose of a 3 - dimensional column vector a 3x3 matrix and a 3 - dimensional column vector . |
247,845 | def vtmvg ( v1 , matrix , v2 , nrow , ncol ) : v1 = stypes . toDoubleVector ( v1 ) matrix = stypes . toDoubleMatrix ( matrix ) v2 = stypes . toDoubleVector ( v2 ) nrow = ctypes . c_int ( nrow ) ncol = ctypes . c_int ( ncol ) return libspice . vtmvg_c ( v1 , matrix , v2 , nrow , ncol ) | Multiply the transpose of a n - dimensional column vector a nxm matrix and a m - dimensional column vector . |
247,846 | def vupack ( v ) : v1 = stypes . toDoubleVector ( v ) x = ctypes . c_double ( ) y = ctypes . c_double ( ) z = ctypes . c_double ( ) libspice . vupack_c ( v1 , ctypes . byref ( x ) , ctypes . byref ( y ) , ctypes . byref ( z ) ) return x . value , y . value , z . value | Unpack three scalar components from a vector . |
247,847 | def vzero ( v ) : v = stypes . toDoubleVector ( v ) return bool ( libspice . vzero_c ( v ) ) | Indicate whether a 3 - vector is the zero vector . |
247,848 | def vzerog ( v , ndim ) : v = stypes . toDoubleVector ( v ) ndim = ctypes . c_int ( ndim ) return bool ( libspice . vzerog_c ( v , ndim ) ) | Indicate whether a general - dimensional vector is the zero vector . |
247,849 | def wncomd ( left , right , window ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 left = ctypes . c_double ( left ) right = ctypes . c_double ( right ) result = stypes . SpiceCell . double ( window . size ) libspice . wncomd_c ( left , right , ctypes . byref ( window ) , result ) return result | Determine the complement of a double precision window with respect to a specified interval . |
247,850 | def wncond ( left , right , window ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 left = ctypes . c_double ( left ) right = ctypes . c_double ( right ) libspice . wncond_c ( left , right , ctypes . byref ( window ) ) return window | Contract each of the intervals of a double precision window . |
247,851 | def wndifd ( a , b ) : assert isinstance ( a , stypes . SpiceCell ) assert isinstance ( b , stypes . SpiceCell ) assert a . dtype == 1 assert b . dtype == 1 c = stypes . SpiceCell . double ( a . size + b . size ) libspice . wndifd_c ( ctypes . byref ( a ) , ctypes . byref ( b ) , ctypes . byref ( c ) ) return c | Place the difference of two double precision windows into a third window . |
247,852 | def wnelmd ( point , window ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 point = ctypes . c_double ( point ) return bool ( libspice . wnelmd_c ( point , ctypes . byref ( window ) ) ) | Determine whether a point is an element of a double precision window . |
247,853 | def wnexpd ( left , right , window ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 left = ctypes . c_double ( left ) right = ctypes . c_double ( right ) libspice . wnexpd_c ( left , right , ctypes . byref ( window ) ) return window | Expand each of the intervals of a double precision window . |
247,854 | def wnextd ( side , window ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 assert side == 'L' or side == 'R' side = ctypes . c_char ( side . encode ( encoding = 'UTF-8' ) ) libspice . wnextd_c ( side , ctypes . byref ( window ) ) return window | Extract the left or right endpoints from a double precision window . |
247,855 | def wnfetd ( window , n ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 n = ctypes . c_int ( n ) left = ctypes . c_double ( ) right = ctypes . c_double ( ) libspice . wnfetd_c ( ctypes . byref ( window ) , n , ctypes . byref ( left ) , ctypes . byref ( right ) ) return left . value , right . value | Fetch a particular interval from a double precision window . |
247,856 | def wnfild ( small , window ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 small = ctypes . c_double ( small ) libspice . wnfild_c ( small , ctypes . byref ( window ) ) return window | Fill small gaps between adjacent intervals of a double precision window . |
247,857 | def wnincd ( left , right , window ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 left = ctypes . c_double ( left ) right = ctypes . c_double ( right ) return bool ( libspice . wnincd_c ( left , right , ctypes . byref ( window ) ) ) | Determine whether an interval is included in a double precision window . |
247,858 | def wninsd ( left , right , window ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 left = ctypes . c_double ( left ) right = ctypes . c_double ( right ) libspice . wninsd_c ( left , right , ctypes . byref ( window ) ) | Insert an interval into a double precision window . |
247,859 | def wnintd ( a , b ) : assert isinstance ( a , stypes . SpiceCell ) assert b . dtype == 1 assert isinstance ( b , stypes . SpiceCell ) assert a . dtype == 1 c = stypes . SpiceCell . double ( b . size + a . size ) libspice . wnintd_c ( ctypes . byref ( a ) , ctypes . byref ( b ) , ctypes . byref ( c ) ) return c | Place the intersection of two double precision windows into a third window . |
247,860 | def wnreld ( a , op , b ) : assert isinstance ( a , stypes . SpiceCell ) assert b . dtype == 1 assert isinstance ( b , stypes . SpiceCell ) assert a . dtype == 1 assert isinstance ( op , str ) op = stypes . stringToCharP ( op . encode ( encoding = 'UTF-8' ) ) return bool ( libspice . wnreld_c ( ctypes . byref ( a ) , op , ctypes . byref ( b ) ) ) | Compare two double precision windows . |
247,861 | def wnsumd ( window ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 meas = ctypes . c_double ( ) avg = ctypes . c_double ( ) stddev = ctypes . c_double ( ) shortest = ctypes . c_int ( ) longest = ctypes . c_int ( ) libspice . wnsumd_c ( ctypes . byref ( window ) , ctypes . byref ( meas ) , ctypes . byref ( avg ) , ctypes . byref ( stddev ) , ctypes . byref ( shortest ) , ctypes . byref ( longest ) ) return meas . value , avg . value , stddev . value , shortest . value , longest . value | Summarize the contents of a double precision window . |
247,862 | def wnunid ( a , b ) : assert isinstance ( a , stypes . SpiceCell ) assert b . dtype == 1 assert isinstance ( b , stypes . SpiceCell ) assert a . dtype == 1 c = stypes . SpiceCell . double ( b . size + a . size ) libspice . wnunid_c ( ctypes . byref ( a ) , ctypes . byref ( b ) , ctypes . byref ( c ) ) return c | Place the union of two double precision windows into a third window . |
247,863 | def wnvald ( insize , n , window ) : assert isinstance ( window , stypes . SpiceCell ) assert window . dtype == 1 insize = ctypes . c_int ( insize ) n = ctypes . c_int ( n ) libspice . wnvald_c ( insize , n , ctypes . byref ( window ) ) return window | Form a valid double precision window from the contents of a window array . |
247,864 | def writln ( line , unit ) : lineP = stypes . stringToCharP ( line ) unit = ctypes . c_int ( unit ) line_len = ctypes . c_int ( len ( line ) ) libspice . writln_ ( lineP , ctypes . byref ( unit ) , line_len ) | Internal undocumented command for writing a text line to a logical unit |
247,865 | def xfmsta ( input_state , input_coord_sys , output_coord_sys , body ) : input_state = stypes . toDoubleVector ( input_state ) input_coord_sys = stypes . stringToCharP ( input_coord_sys ) output_coord_sys = stypes . stringToCharP ( output_coord_sys ) body = stypes . stringToCharP ( body ) output_state = stypes . emptyDoubleVector ( 6 ) libspice . xfmsta_c ( input_state , input_coord_sys , output_coord_sys , body , output_state ) return stypes . cVectorToPython ( output_state ) | Transform a state between coordinate systems . |
247,866 | def xpose ( m ) : m = stypes . toDoubleMatrix ( m ) mout = stypes . emptyDoubleMatrix ( x = 3 , y = 3 ) libspice . xpose_c ( m , mout ) return stypes . cMatrixToNumpy ( mout ) | Transpose a 3x3 matrix |
247,867 | def xpose6 ( m ) : m = stypes . toDoubleMatrix ( m ) mout = stypes . emptyDoubleMatrix ( x = 6 , y = 6 ) libspice . xpose6_c ( m , mout ) return stypes . cMatrixToNumpy ( mout ) | Transpose a 6x6 matrix |
247,868 | def xposeg ( matrix , nrow , ncol ) : matrix = stypes . toDoubleMatrix ( matrix ) mout = stypes . emptyDoubleMatrix ( x = ncol , y = nrow ) ncol = ctypes . c_int ( ncol ) nrow = ctypes . c_int ( nrow ) libspice . xposeg_c ( matrix , nrow , ncol , mout ) return stypes . cMatrixToNumpy ( mout ) | Transpose a matrix of arbitrary size in place the matrix need not be square . |
247,869 | def CallUDFUNS ( f , x ) : value = c_double ( ) f ( x , byref ( value ) ) return value . value | We are given a UDF CFUNCTYPE and want to call it in python |
247,870 | def updateD_G ( self , x ) : self . precompute ( x ) g = zeros ( len ( x ) ) Ai = zeros ( self . A . shape [ 0 ] ) for i in range ( len ( g ) ) : Ai = self . A [ : , i ] g [ i ] = ( self . E * ( dot ( self . AD , outer ( self . R [ : , i ] , Ai ) ) + dot ( outer ( Ai , self . R [ i , : ] ) , self . ADt ) ) ) . sum ( ) return - 2 * g | Compute Gradient for update of D |
247,871 | def updateD_H ( self , x ) : self . precompute ( x ) H = zeros ( ( len ( x ) , len ( x ) ) ) Ai = zeros ( self . A . shape [ 0 ] ) Aj = zeros ( Ai . shape ) for i in range ( len ( x ) ) : Ai = self . A [ : , i ] ti = dot ( self . AD , outer ( self . R [ : , i ] , Ai ) ) + dot ( outer ( Ai , self . R [ i , : ] ) , self . ADt ) for j in range ( i , len ( x ) ) : Aj = self . A [ : , j ] tj = outer ( Ai , Aj ) H [ i , j ] = ( self . E * ( self . R [ i , j ] * tj + self . R [ j , i ] * tj . T ) - ti * ( dot ( self . AD , outer ( self . R [ : , j ] , Aj ) ) + dot ( outer ( Aj , self . R [ j , : ] ) , self . ADt ) ) ) . sum ( ) H [ j , i ] = H [ i , j ] H *= - 2 e = eigvals ( H ) . min ( ) H = H + ( eye ( H . shape [ 0 ] ) * e ) return H | Compute Hessian for update of D |
247,872 | def is_sequence ( obj ) : try : from collections import Sequence except ImportError : from operator import isSequenceType return isSequenceType ( obj ) else : return isinstance ( obj , Sequence ) | Helper function to determine sequences across Python 2 . x and 3 . x |
247,873 | def is_number ( obj ) : try : from numbers import Number except ImportError : from operator import isNumberType return isNumberType ( obj ) else : return isinstance ( obj , Number ) | Helper function to determine numbers across Python 2 . x and 3 . x |
247,874 | def func_attr ( f , attr ) : if hasattr ( f , 'func_%s' % attr ) : return getattr ( f , 'func_%s' % attr ) elif hasattr ( f , '__%s__' % attr ) : return getattr ( f , '__%s__' % attr ) else : raise ValueError ( 'Object %s has no attr' % ( str ( f ) , attr ) ) | Helper function to get the attribute of a function like name code defaults across Python 2 . x and 3 . x |
247,875 | def from_to_without ( frm , to , without , step = 1 , skip = 1 , reverse = False , separate = False ) : if reverse : frm , to = ( to - 1 ) , ( frm - 1 ) step *= - 1 skip *= - 1 a = list ( range ( frm , without , step ) ) b = list ( range ( without + skip , to , step ) ) if separate : return a , b else : return a + b | Helper function to create ranges with missing entries |
247,876 | def unfold ( self , mode ) : sz = array ( self . shape ) N = len ( sz ) order = ( [ mode ] , from_to_without ( N - 1 , - 1 , mode , step = - 1 , skip = - 1 ) ) newsz = ( sz [ order [ 0 ] ] [ 0 ] , prod ( sz [ order [ 1 ] ] ) ) arr = self . transpose ( axes = ( order [ 0 ] + order [ 1 ] ) ) arr = arr . reshape ( newsz ) return unfolded_dtensor ( arr , mode , self . shape ) | Unfolds a dense tensor in mode n . |
247,877 | def accum ( subs , vals , func = np . sum , issorted = False , with_subs = False ) : if not issorted : sidx = lexsort ( subs , axis = 0 ) subs = [ sub [ sidx ] for sub in subs ] vals = vals [ sidx ] idx = np . where ( np . diff ( subs ) . any ( axis = 0 ) ) [ 0 ] + 1 idx = np . concatenate ( ( [ 0 ] , idx , [ subs [ 0 ] . shape [ 0 ] ] ) ) nvals = np . zeros ( len ( idx ) - 1 ) for i in range ( len ( idx ) - 1 ) : nvals [ i ] = func ( vals [ idx [ i ] : idx [ i + 1 ] ] ) if with_subs : return nvals , tuple ( sub [ idx [ : - 1 ] ] for sub in subs ) else : return nvals | NumPy implementation for Matlab s accumarray |
247,878 | def hooi ( X , rank , ** kwargs ) : ainit = kwargs . pop ( 'init' , __DEF_INIT ) maxIter = kwargs . pop ( 'maxIter' , __DEF_MAXITER ) conv = kwargs . pop ( 'conv' , __DEF_CONV ) dtype = kwargs . pop ( 'dtype' , X . dtype ) if not len ( kwargs ) == 0 : raise ValueError ( 'Unknown keywords (%s)' % ( kwargs . keys ( ) ) ) ndims = X . ndim if is_number ( rank ) : rank = rank * ones ( ndims ) normX = norm ( X ) U = __init ( ainit , X , ndims , rank , dtype ) fit = 0 exectimes = [ ] for itr in range ( maxIter ) : tic = time . clock ( ) fitold = fit for n in range ( ndims ) : Utilde = ttm ( X , U , n , transp = True , without = True ) U [ n ] = nvecs ( Utilde , n , rank [ n ] ) core = ttm ( Utilde , U , n , transp = True ) normresidual = sqrt ( normX ** 2 - norm ( core ) ** 2 ) fit = 1 - ( normresidual / normX ) fitchange = abs ( fitold - fit ) exectimes . append ( time . clock ( ) - tic ) _log . debug ( '[%3d] fit: %.5f | delta: %7.1e | secs: %.5f' % ( itr , fit , fitchange , exectimes [ - 1 ] ) ) if itr > 1 and fitchange < conv : break return core , U | Compute Tucker decomposition of a tensor using Higher - Order Orthogonal Iterations . |
247,879 | def uttkrp ( self , U , mode ) : N = self . ndim if mode == 1 : R = U [ 1 ] . shape [ 1 ] else : R = U [ 0 ] . shape [ 1 ] W = np . tile ( self . lmbda , 1 , R ) for i in range ( mode ) + range ( mode + 1 , N ) : W = W * dot ( self . U [ i ] . T , U [ i ] ) return dot ( self . U [ mode ] , W ) | Unfolded tensor times Khatri - Rao product for Kruskal tensors |
247,880 | def norm ( self ) : N = len ( self . shape ) coef = outer ( self . lmbda , self . lmbda ) for i in range ( N ) : coef = coef * dot ( self . U [ i ] . T , self . U [ i ] ) return np . sqrt ( coef . sum ( ) ) | Efficient computation of the Frobenius norm for ktensors |
247,881 | def innerprod ( self , X ) : N = len ( self . shape ) R = len ( self . lmbda ) res = 0 for r in range ( R ) : vecs = [ ] for n in range ( N ) : vecs . append ( self . U [ n ] [ : , r ] ) res += self . lmbda [ r ] * X . ttv ( tuple ( vecs ) ) return res | Efficient computation of the inner product of a ktensor with another tensor |
247,882 | def toarray ( self ) : A = dot ( self . lmbda , khatrirao ( tuple ( self . U ) ) . T ) return A . reshape ( self . shape ) | Converts a ktensor into a dense multidimensional ndarray |
247,883 | def fromarray ( A ) : subs = np . nonzero ( A ) vals = A [ subs ] return sptensor ( subs , vals , shape = A . shape , dtype = A . dtype ) | Create a sptensor from a dense numpy array |
247,884 | def _ttm_me_compute ( self , V , edims , sdims , transp ) : shapeY = np . copy ( self . shape ) for n in np . union1d ( edims , sdims ) : shapeY [ n ] = V [ n ] . shape [ 1 ] if transp else V [ n ] . shape [ 0 ] Y = zeros ( shapeY ) shapeY = array ( shapeY ) v = [ None for _ in range ( len ( edims ) ) ] for i in range ( np . prod ( shapeY [ edims ] ) ) : rsubs = unravel_index ( shapeY [ edims ] , i ) | Assume Y = T x_i V_i for i = 1 ... n can fit into memory |
247,885 | def transpose ( self , axes = None ) : if axes is None : raise NotImplementedError ( 'Sparse tensor transposition without axes argument is not supported' ) nsubs = tuple ( [ self . subs [ idx ] for idx in axes ] ) nshape = [ self . shape [ idx ] for idx in axes ] return sptensor ( nsubs , self . vals , nshape ) | Compute transpose of sparse tensors . |
247,886 | def concatenate ( self , tpl , axis = None ) : if axis is None : raise NotImplementedError ( 'Sparse tensor concatenation without axis argument is not supported' ) T = self for i in range ( 1 , len ( tpl ) ) : T = _single_concatenate ( T , tpl [ i ] , axis = axis ) return T | Concatenates sparse tensors . |
247,887 | def fold ( self ) : nsubs = zeros ( ( len ( self . data ) , len ( self . ten_shape ) ) , dtype = np . int ) if len ( self . rdims ) > 0 : nidx = unravel_index ( self . row , self . ten_shape [ self . rdims ] ) for i in range ( len ( self . rdims ) ) : nsubs [ : , self . rdims [ i ] ] = nidx [ i ] if len ( self . cdims ) > 0 : nidx = unravel_index ( self . col , self . ten_shape [ self . cdims ] ) for i in range ( len ( self . cdims ) ) : nsubs [ : , self . cdims [ i ] ] = nidx [ i ] nsubs = [ z . flatten ( ) for z in hsplit ( nsubs , len ( self . ten_shape ) ) ] return sptensor ( tuple ( nsubs ) , self . data , self . ten_shape ) | Recreate original tensor by folding unfolded_sptensor according toc ten_shape . |
247,888 | def _updateA ( X , A , R , P , Z , lmbdaA , orthogonalize ) : n , rank = A . shape F = zeros ( ( n , rank ) , dtype = A . dtype ) E = zeros ( ( rank , rank ) , dtype = A . dtype ) AtA = dot ( A . T , A ) for i in range ( len ( X ) ) : F += X [ i ] . dot ( dot ( A , R [ i ] . T ) ) + X [ i ] . T . dot ( dot ( A , R [ i ] ) ) E += dot ( R [ i ] , dot ( AtA , R [ i ] . T ) ) + dot ( R [ i ] . T , dot ( AtA , R [ i ] ) ) I = lmbdaA * eye ( rank , dtype = A . dtype ) for i in range ( len ( Z ) ) : F += P [ i ] . dot ( Z [ i ] . T ) E += dot ( Z [ i ] , Z [ i ] . T ) A = solve ( I + E . T , F . T ) . T return orth ( A ) if orthogonalize else A | Update step for A |
247,889 | def _compute_fval ( X , A , R , P , Z , lmbdaA , lmbdaR , lmbdaZ , normX ) : f = lmbdaA * norm ( A ) ** 2 for i in range ( len ( X ) ) : ARAt = dot ( A , dot ( R [ i ] , A . T ) ) f += ( norm ( X [ i ] - ARAt ) ** 2 ) / normX [ i ] + lmbdaR * norm ( R [ i ] ) ** 2 return f | Compute fit for full slices |
247,890 | def als ( X , rank , ** kwargs ) : ainit = kwargs . pop ( 'init' , _DEF_INIT ) maxiter = kwargs . pop ( 'max_iter' , _DEF_MAXITER ) fit_method = kwargs . pop ( 'fit_method' , _DEF_FIT_METHOD ) conv = kwargs . pop ( 'conv' , _DEF_CONV ) dtype = kwargs . pop ( 'dtype' , _DEF_TYPE ) if not len ( kwargs ) == 0 : raise ValueError ( 'Unknown keywords (%s)' % ( kwargs . keys ( ) ) ) N = X . ndim normX = norm ( X ) U = _init ( ainit , X , N , rank , dtype ) fit = 0 exectimes = [ ] for itr in range ( maxiter ) : tic = time . clock ( ) fitold = fit for n in range ( N ) : Unew = X . uttkrp ( U , n ) Y = ones ( ( rank , rank ) , dtype = dtype ) for i in ( list ( range ( n ) ) + list ( range ( n + 1 , N ) ) ) : Y = Y * dot ( U [ i ] . T , U [ i ] ) Unew = Unew . dot ( pinv ( Y ) ) if itr == 0 : lmbda = sqrt ( ( Unew ** 2 ) . sum ( axis = 0 ) ) else : lmbda = Unew . max ( axis = 0 ) lmbda [ lmbda < 1 ] = 1 U [ n ] = Unew / lmbda P = ktensor ( U , lmbda ) if fit_method == 'full' : normresidual = normX ** 2 + P . norm ( ) ** 2 - 2 * P . innerprod ( X ) fit = 1 - ( normresidual / normX ** 2 ) else : fit = itr fitchange = abs ( fitold - fit ) exectimes . append ( time . clock ( ) - tic ) _log . debug ( '[%3d] fit: %.5f | delta: %7.1e | secs: %.5f' % ( itr , fit , fitchange , exectimes [ - 1 ] ) ) if itr > 0 and fitchange < conv : break return P , fit , itr , array ( exectimes ) | Alternating least - sqaures algorithm to compute the CP decomposition . |
247,891 | def _init ( init , X , N , rank , dtype ) : Uinit = [ None for _ in range ( N ) ] if isinstance ( init , list ) : Uinit = init elif init == 'random' : for n in range ( 1 , N ) : Uinit [ n ] = array ( rand ( X . shape [ n ] , rank ) , dtype = dtype ) elif init == 'nvecs' : for n in range ( 1 , N ) : Uinit [ n ] = array ( nvecs ( X , n , rank ) , dtype = dtype ) else : raise 'Unknown option (init=%s)' % str ( init ) return Uinit | Initialization for CP models |
247,892 | def nvecs ( X , n , rank , do_flipsign = True , dtype = np . float ) : Xn = X . unfold ( n ) if issparse_mat ( Xn ) : Xn = csr_matrix ( Xn , dtype = dtype ) Y = Xn . dot ( Xn . T ) _ , U = eigsh ( Y , rank , which = 'LM' ) else : Y = Xn . dot ( Xn . T ) N = Y . shape [ 0 ] _ , U = eigh ( Y , eigvals = ( N - rank , N - 1 ) ) U = array ( U [ : , : : - 1 ] ) if do_flipsign : U = flipsign ( U ) return U | Eigendecomposition of mode - n unfolding of a tensor |
247,893 | def flipsign ( U ) : midx = abs ( U ) . argmax ( axis = 0 ) for i in range ( U . shape [ 1 ] ) : if U [ midx [ i ] , i ] < 0 : U [ : , i ] = - U [ : , i ] return U | Flip sign of factor matrices such that largest magnitude element will be positive |
247,894 | def khatrirao ( A , reverse = False ) : if not isinstance ( A , tuple ) : raise ValueError ( 'A must be a tuple of array likes' ) N = A [ 0 ] . shape [ 1 ] M = 1 for i in range ( len ( A ) ) : if A [ i ] . ndim != 2 : raise ValueError ( 'A must be a tuple of matrices (A[%d].ndim = %d)' % ( i , A [ i ] . ndim ) ) elif N != A [ i ] . shape [ 1 ] : raise ValueError ( 'All matrices must have same number of columns' ) M *= A [ i ] . shape [ 0 ] matorder = arange ( len ( A ) ) if reverse : matorder = matorder [ : : - 1 ] P = np . zeros ( ( M , N ) , dtype = A [ 0 ] . dtype ) for n in range ( N ) : ab = A [ matorder [ 0 ] ] [ : , n ] for j in range ( 1 , len ( matorder ) ) : ab = np . kron ( ab , A [ matorder [ j ] ] [ : , n ] ) P [ : , n ] = ab return P | Compute the columnwise Khatri - Rao product . |
247,895 | def teneye ( dim , order ) : I = zeros ( dim ** order ) for f in range ( dim ) : idd = f for i in range ( 1 , order ) : idd = idd + dim ** ( i - 1 ) * ( f - 1 ) I [ idd ] = 1 return I . reshape ( ones ( order ) * dim ) | Create tensor with superdiagonal all one rest zeros |
247,896 | def ttm ( self , V , mode = None , transp = False , without = False ) : if mode is None : mode = range ( self . ndim ) if isinstance ( V , np . ndarray ) : Y = self . _ttm_compute ( V , mode , transp ) elif is_sequence ( V ) : dims , vidx = check_multiplication_dims ( mode , self . ndim , len ( V ) , vidx = True , without = without ) Y = self . _ttm_compute ( V [ vidx [ 0 ] ] , dims [ 0 ] , transp ) for i in xrange ( 1 , len ( dims ) ) : Y = Y . _ttm_compute ( V [ vidx [ i ] ] , dims [ i ] , transp ) return Y | Tensor times matrix product |
247,897 | def _process_registry ( registry , call_func ) : from django . core . exceptions import ImproperlyConfigured from django . apps import apps for key , value in list ( registry . items ( ) ) : model = apps . get_model ( * key . split ( '.' ) ) if model is None : raise ImproperlyConfigured ( _ ( '%(key)s is not a model' ) % { 'key' : key } ) if isinstance ( value , ( tuple , list ) ) : for item in value : if isinstance ( item , str ) : call_func ( model , item ) elif isinstance ( item , dict ) : field_name = item . pop ( 'name' ) call_func ( model , field_name , extra_params = item ) else : raise ImproperlyConfigured ( _ ( "%(settings)s doesn't recognize the value of %(key)s" ) % { 'settings' : 'CATEGORY_SETTINGS' , 'key' : key } ) elif isinstance ( value , str ) : call_func ( model , value ) elif isinstance ( value , dict ) : field_name = value . pop ( 'name' ) call_func ( model , field_name , extra_params = value ) else : raise ImproperlyConfigured ( _ ( "%(settings)s doesn't recognize the value of %(key)s" ) % { 'settings' : 'CATEGORY_SETTINGS' , 'key' : key } ) | Given a dictionary and a registration function process the registry |
247,898 | def field_exists ( app_name , model_name , field_name ) : model = apps . get_model ( app_name , model_name ) table_name = model . _meta . db_table cursor = connection . cursor ( ) field_info = connection . introspection . get_table_description ( cursor , table_name ) field_names = [ f . name for f in field_info ] return field_name in field_names | Does the FK or M2M table exist in the database already? |
247,899 | def drop_field ( app_name , model_name , field_name ) : app_config = apps . get_app_config ( app_name ) model = app_config . get_model ( model_name ) field = model . _meta . get_field ( field_name ) with connection . schema_editor ( ) as schema_editor : schema_editor . remove_field ( model , field ) | Drop the given field from the app s model |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.