libcm is a C development framework with an emphasis on audio signal processing applications.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cmVectOpsRIHdr.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. //( { label:"Matrix ops" desc:"Common 2D matrix operations and accessors." kw:[vop] }
  2. // 2D matrix accessors
  3. VECT_OP_TYPE* VECT_OP_FUNC(Col)( VECT_OP_TYPE* m, unsigned ci, unsigned rn, unsigned cn );
  4. VECT_OP_TYPE* VECT_OP_FUNC(Row)( VECT_OP_TYPE* m, unsigned ri, unsigned rn, unsigned cn );
  5. VECT_OP_TYPE* VECT_OP_FUNC(ElePtr)( VECT_OP_TYPE* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn );
  6. VECT_OP_TYPE VECT_OP_FUNC(Ele)( VECT_OP_TYPE* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn );
  7. void VECT_OP_FUNC(Set)( VECT_OP_TYPE* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn, VECT_OP_TYPE v );
  8. const VECT_OP_TYPE* VECT_OP_FUNC(CCol)( const VECT_OP_TYPE* m, unsigned ci, unsigned rn, unsigned cn );
  9. const VECT_OP_TYPE* VECT_OP_FUNC(CRow)( const VECT_OP_TYPE* m, unsigned ri, unsigned rn, unsigned cn );
  10. const VECT_OP_TYPE* VECT_OP_FUNC(CElePtr)( const VECT_OP_TYPE* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn );
  11. VECT_OP_TYPE VECT_OP_FUNC(CEle)( const VECT_OP_TYPE* m, unsigned ri, unsigned ci, unsigned rn, unsigned cn );
  12. // Set only the diagonal of a square mtx to sbp.
  13. VECT_OP_TYPE* VECT_OP_FUNC(Diag)( VECT_OP_TYPE* dbp, unsigned n, const VECT_OP_TYPE* sbp );
  14. // Set the diagonal of a square mtx to db to sbp and set all other values to zero.
  15. VECT_OP_TYPE* VECT_OP_FUNC(DiagZ)( VECT_OP_TYPE* dbp, unsigned n, const VECT_OP_TYPE* sbp );
  16. // Create an identity matrix (only sets 1's not zeros).
  17. VECT_OP_TYPE* VECT_OP_FUNC(Identity)( VECT_OP_TYPE* dbp, unsigned rn, unsigned cn );
  18. // Zero the matrix and then fill it as an identity matrix.
  19. VECT_OP_TYPE* VECT_OP_FUNC(IdentityZ)( VECT_OP_TYPE* dbp, unsigned rn, unsigned cn );
  20. // Transpose the matrix sbp[srn,scn] into dbp[scn,srn]
  21. VECT_OP_TYPE* VECT_OP_FUNC(Transpose)( VECT_OP_TYPE* dbp, const VECT_OP_TYPE* sbp, unsigned srn, unsigned scn );
  22. //======================================================================================================================
  23. //)
  24. //( { label:"Fill,move,copy" desc:"Basic data movement and initialization." kw:[vop] }
  25. // Fill a vector with a value. If value is 0 then the function is accellerated via memset().
  26. VECT_OP_TYPE* VECT_OP_FUNC(Fill)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE value );
  27. // Fill a vector with zeros
  28. VECT_OP_TYPE* VECT_OP_FUNC(Zero)( VECT_OP_TYPE* dbp, unsigned dn );
  29. // Analogous to memmove()
  30. VECT_OP_TYPE* VECT_OP_FUNC(Move)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
  31. // Fill the vector from various sources
  32. VECT_OP_TYPE* VECT_OP_FUNC(Copy)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
  33. VECT_OP_TYPE* VECT_OP_FUNC(CopyN)( VECT_OP_TYPE* dbp, unsigned dn, unsigned d_stride, const VECT_OP_TYPE* sp, unsigned s_stride );
  34. VECT_OP_TYPE* VECT_OP_FUNC(CopyU)( VECT_OP_TYPE* dbp, unsigned dn, const unsigned* sp );
  35. VECT_OP_TYPE* VECT_OP_FUNC(CopyI)( VECT_OP_TYPE* dbp, unsigned dn, const int* sp );
  36. VECT_OP_TYPE* VECT_OP_FUNC(CopyF)( VECT_OP_TYPE* dbp, unsigned dn, const float* sp );
  37. VECT_OP_TYPE* VECT_OP_FUNC(CopyD)( VECT_OP_TYPE* dbp, unsigned dn, const double* sp );
  38. VECT_OP_TYPE* VECT_OP_FUNC(CopyS)( VECT_OP_TYPE* dbp, unsigned dn, const cmSample_t* sp );
  39. VECT_OP_TYPE* VECT_OP_FUNC(CopyR)( VECT_OP_TYPE* dbp, unsigned dn, const cmReal_t* sp );
  40. // Fill the the destination vector from a source vector where the source vector contains
  41. // srcStride interleaved elements to be ignored.
  42. VECT_OP_TYPE* VECT_OP_FUNC(CopyStride)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp, unsigned srcStride );
  43. //======================================================================================================================
  44. //)
  45. //( { label:"Shrink/Expand/Replace" desc:"Change the size of a vector." kw:[vop] }
  46. // Shrink the elemetns of dbp[dn] by copying all elements past t+tn to t.
  47. // This operation results in overwriting the elements in the range t[tn].
  48. // t[tn] must be entirely inside dbp[dn].
  49. VECT_OP_TYPE* VECT_OP_FUNC(Shrink)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* t, unsigned tn );
  50. // Expand dbp[[dn] by shifting all elements past t to t+tn.
  51. // This produces a set of empty elements in t[tn].
  52. // t must be inside or at the end of dbp[dn].
  53. // This results in a reallocation of dbp[]. Be sure to call cmMemFree(dbp)
  54. // to release the returned pointer.
  55. VECT_OP_TYPE* VECT_OP_FUNC(Expand)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* t, unsigned tn );
  56. // Replace the elements t[tn] with the elements in u[un].
  57. // t must be inside or at the end of dbp[dn].
  58. // This operation may result in a reallocation of dbp[]. Be sure to call cmMemFree(dbp)
  59. // to release the returned pointer.
  60. // IF dbp==NULL and tn==0 then the dbp[un] is allocated and returned
  61. // with the contents of u[un].
  62. VECT_OP_TYPE* VECT_OP_FUNC(Replace)(VECT_OP_TYPE* dbp, unsigned* dn, const VECT_OP_TYPE* t, unsigned tn, const VECT_OP_TYPE* u, unsigned un );
  63. //======================================================================================================================
  64. //)
  65. //( { label:"Rotate/Shift/Flip/Sequence" desc:"Modify/generate the vector sequence." kw:[vop] }
  66. // Assuming a row vector positive shiftCnt rotates right, negative shiftCnt rotates left.
  67. VECT_OP_TYPE* VECT_OP_FUNC(Rotate)( VECT_OP_TYPE* dbp, unsigned dn, int shiftCnt );
  68. // Equivalent to Matlab circshift().
  69. VECT_OP_TYPE* VECT_OP_FUNC(RotateM)( VECT_OP_TYPE* dbp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* sbp, int rShift, int cShift );
  70. // Assuming a row vector positive shiftCnt shifts right, negative shiftCnt shifts left.
  71. VECT_OP_TYPE* VECT_OP_FUNC(Shift)( VECT_OP_TYPE* dbp, unsigned dn, int shiftCnt, VECT_OP_TYPE fill );
  72. // Reverse the contents of the vector.
  73. VECT_OP_TYPE* VECT_OP_FUNC(Flip)( VECT_OP_TYPE* dbp, unsigned dn);
  74. // Fill dbp[] with a sequence of values. Returns next value.
  75. VECT_OP_TYPE VECT_OP_FUNC(Seq)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE beg, VECT_OP_TYPE incr );
  76. //======================================================================================================================
  77. //)
  78. //( { label:"Arithmetic" desc:"Add,Sub,Mult,Divde" kw:[vop] }
  79. VECT_OP_TYPE* VECT_OP_FUNC(SubVS)( VECT_OP_TYPE* dp, unsigned dn, VECT_OP_TYPE v );
  80. VECT_OP_TYPE* VECT_OP_FUNC(SubVV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* v );
  81. VECT_OP_TYPE* VECT_OP_FUNC(SubVVS)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* v, VECT_OP_TYPE s );
  82. VECT_OP_TYPE* VECT_OP_FUNC(SubVVNN)(VECT_OP_TYPE* dp, unsigned dn, unsigned dnn, const VECT_OP_TYPE* sp, unsigned snn );
  83. VECT_OP_TYPE* VECT_OP_FUNC(SubVVV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* sb0p, const VECT_OP_TYPE* sb1p );
  84. VECT_OP_TYPE* VECT_OP_FUNC(SubVSV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE s0, const VECT_OP_TYPE* sb1p );
  85. VECT_OP_TYPE* VECT_OP_FUNC(AddVS)( VECT_OP_TYPE* dp, unsigned dn, VECT_OP_TYPE v );
  86. VECT_OP_TYPE* VECT_OP_FUNC(AddVV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* v );
  87. VECT_OP_TYPE* VECT_OP_FUNC(AddVVS)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* v, VECT_OP_TYPE s );
  88. VECT_OP_TYPE* VECT_OP_FUNC(AddVVNN)(VECT_OP_TYPE* dp, unsigned dn, unsigned dnn, const VECT_OP_TYPE* sp, unsigned snn );
  89. VECT_OP_TYPE* VECT_OP_FUNC(AddVVV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* sb0p, const VECT_OP_TYPE* sb1p );
  90. VECT_OP_TYPE* VECT_OP_FUNC(MultVVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sb0p, const VECT_OP_TYPE* sb1p );
  91. VECT_OP_TYPE* VECT_OP_FUNC(MultVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp );
  92. VECT_OP_TYPE* VECT_OP_FUNC(MultVVNN)(VECT_OP_TYPE* dp, unsigned dn, unsigned dnn, const VECT_OP_TYPE* sp, unsigned snn );
  93. VECT_OP_TYPE* VECT_OP_FUNC(MultVS)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE s );
  94. VECT_OP_TYPE* VECT_OP_FUNC(MultVVS)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE s );
  95. VECT_OP_TYPE* VECT_OP_FUNC(MultVaVS)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE s );
  96. VECT_OP_TYPE* VECT_OP_FUNC(MultSumVVS)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sbp, VECT_OP_TYPE s );
  97. VECT_OP_TYPE* VECT_OP_FUNC(DivVVS)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sb0p, VECT_OP_TYPE sb1 );
  98. VECT_OP_TYPE* VECT_OP_FUNC(DivVVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sb0p, const VECT_OP_TYPE* sb1p );
  99. VECT_OP_TYPE* VECT_OP_FUNC(DivVV)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sb0p );
  100. VECT_OP_TYPE* VECT_OP_FUNC(DivVVNN)(VECT_OP_TYPE* dp, unsigned dn, unsigned dnn, const VECT_OP_TYPE* sp, unsigned snn );
  101. VECT_OP_TYPE* VECT_OP_FUNC(DivVS)( VECT_OP_TYPE* dbp, unsigned dn, VECT_OP_TYPE s );
  102. VECT_OP_TYPE* VECT_OP_FUNC(DivVSV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE s0, const VECT_OP_TYPE* sb1p );
  103. // Set dest to 0 if denominator is 0.
  104. VECT_OP_TYPE* VECT_OP_FUNC(DivVVVZ)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sb0p, const VECT_OP_TYPE* sb1p );
  105. VECT_OP_TYPE* VECT_OP_FUNC(DivVVZ)( VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sb0p );
  106. // Divide columns of dp[:,i] by each value in the source vector sp[i].
  107. VECT_OP_TYPE* VECT_OP_FUNC(DivMS)( VECT_OP_TYPE* dp, unsigned drn, unsigned dcn, const VECT_OP_TYPE* sp );
  108. //======================================================================================================================
  109. //)
  110. //( { label:"Sum vectors" desc:"Operations which take sum vector elements." kw:[vop] }
  111. VECT_OP_TYPE VECT_OP_FUNC(Sum)( const VECT_OP_TYPE* sp, unsigned sn );
  112. VECT_OP_TYPE VECT_OP_FUNC(SumN)( const VECT_OP_TYPE* sp, unsigned sn, unsigned stride );
  113. // Sum the columns of sp[srn,scn] into dp[scn].
  114. // dp[] is zeroed prior to computing the sum.
  115. VECT_OP_TYPE* VECT_OP_FUNC(SumM)( const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, VECT_OP_TYPE* dp );
  116. // Sum the rows of sp[srn,scn] into dp[srn]
  117. // dp[] is zeroed prior to computing the sum.
  118. VECT_OP_TYPE* VECT_OP_FUNC(SumMN)( const VECT_OP_TYPE* sp, unsigned srn, unsigned scn, VECT_OP_TYPE* dp );
  119. //======================================================================================================================
  120. //)
  121. //( { label:"Min/max/median/mode" desc:"Simple descriptive statistics." kw:[vop] }
  122. VECT_OP_TYPE VECT_OP_FUNC(Median)( const VECT_OP_TYPE* sp, unsigned sn );
  123. unsigned VECT_OP_FUNC(MinIndex)( const VECT_OP_TYPE* sp, unsigned sn, unsigned stride );
  124. unsigned VECT_OP_FUNC(MaxIndex)( const VECT_OP_TYPE* sp, unsigned sn, unsigned stride );
  125. VECT_OP_TYPE VECT_OP_FUNC(Min)( const VECT_OP_TYPE* sp, unsigned sn, unsigned stride );
  126. VECT_OP_TYPE VECT_OP_FUNC(Max)( const VECT_OP_TYPE* sp, unsigned sn, unsigned stride );
  127. VECT_OP_TYPE* VECT_OP_FUNC(MinVV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* sp );
  128. VECT_OP_TYPE* VECT_OP_FUNC(MaxVV)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* sp );
  129. // Return index of max/min value into dp[scn] of each column of sp[srn,scn]
  130. unsigned* VECT_OP_FUNC(MinIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn );
  131. unsigned* VECT_OP_FUNC(MaxIndexM)( unsigned* dp, const VECT_OP_TYPE* sp, unsigned srn, unsigned scn );
  132. // Return the most frequently occuring element in sp.
  133. VECT_OP_TYPE VECT_OP_FUNC(Mode)( const VECT_OP_TYPE* sp, unsigned sn );
  134. //======================================================================================================================
  135. //)
  136. //( { label:"Compare/Find" desc:"Compare, find, replace and count elements in a vector." kw:[vop] }
  137. // Return true if s0p[sn] is equal to s1p[sn]
  138. bool VECT_OP_FUNC(IsEqual)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn );
  139. // Return true if all elements of s0p[sn] are within 'eps' of s1p[sn].
  140. // This function is based on cmMath.h:cmIsCloseX()
  141. bool VECT_OP_FUNC(IsClose)( const VECT_OP_TYPE* s0p, const VECT_OP_TYPE* s1p, unsigned sn, double eps );
  142. // Replace all values <= lteKeyVal with replaceVal. sp==dp is legal.
  143. VECT_OP_TYPE* VECT_OP_FUNC(ReplaceLte)( VECT_OP_TYPE* dp, unsigned dn, const VECT_OP_TYPE* sp, VECT_OP_TYPE lteKeyVal, VECT_OP_TYPE replaceVal );
  144. // Return the index of 'key' in sp[sn] or cmInvalidIdx if 'key' does not exist.
  145. unsigned VECT_OP_FUNC(Find)( const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE key );
  146. // Count the number of times 'key' occurs in sp[sn].
  147. unsigned VECT_OP_FUNC(Count)(const VECT_OP_TYPE* sp, unsigned sn, VECT_OP_TYPE key );
  148. //======================================================================================================================
  149. //)
  150. //( { label:"Absolute value" desc:"Absolute value and signal rectification." kw:[vop] }
  151. VECT_OP_TYPE* VECT_OP_FUNC(Abs)( VECT_OP_TYPE* dbp, unsigned dn );
  152. // Half wave rectify the source vector.
  153. // dbp[] = sbp<0 .* sbp
  154. // Overlapping the source and dest is allowable as long as dbp <= sbp.
  155. VECT_OP_TYPE* VECT_OP_FUNC(HalfWaveRectify)(VECT_OP_TYPE* dbp, unsigned dn, const VECT_OP_TYPE* sp );
  156. //======================================================================================================================
  157. //)
  158. //( { label:"Filter" desc:"Apply filtering to a vector taking into account vector begin/end conditions." kw:[vop] }
  159. // Apply a median or other filter of order wndN to xV[xN] and store the result in yV[xN].
  160. // When the window goes off either side of the vector the window is shortened.
  161. // This algorithm produces the same result as the fn_thresh function in MATLAB fv codebase.
  162. void VECT_OP_FUNC(FnThresh)( const VECT_OP_TYPE* xV, unsigned xN, unsigned wndN, VECT_OP_TYPE* yV, unsigned yStride, VECT_OP_TYPE (*fnPtr)(const VECT_OP_TYPE*, unsigned) );
  163. // Apply a median filter of order wndN to xV[xN] and store the result in yV[xN].
  164. // When the window goes off either side of the vector the missing elements are considered
  165. // to be 0.
  166. // This algorithm produces the same result as the MATLAB medfilt1() function.
  167. void VECT_OP_FUNC(MedianFilt)( const VECT_OP_TYPE* xV, unsigned xN, unsigned wndN, VECT_OP_TYPE* yV, unsigned yStride );
  168. //======================================================================================================================
  169. //)
  170. //( { label:"Edit distance" desc:"Calculate the Levenshtein edit distance between vectors." kw:[vop] }
  171. // Allocate and initialize a matrix for use by LevEditDist().
  172. // This matrix can be released with a call to cmMemFree().
  173. unsigned* VECT_OP_FUNC(LevEditDistAllocMtx)(unsigned mtxMaxN);
  174. // Return the Levenshtein edit distance between two vectors.
  175. // m must point to a matrix pre-allocated by VECT_OP_FUNC(InitiLevEditDistMtx)(maxN).
  176. double VECT_OP_FUNC(LevEditDist)(unsigned mtxMaxN, unsigned* m, const VECT_OP_TYPE* s0, int n0, const VECT_OP_TYPE* s1, int n1, unsigned maxN );
  177. // Return the Levenshtein edit distance between two vectors.
  178. // Edit distance with a max cost threshold. This version of the algorithm
  179. // will run faster than LevEditDist() because it will stop execution as soon
  180. // as the distance exceeds 'maxCost'.
  181. // 'maxCost' must be between 0.0 and 1.0 or it is forced into this range.
  182. // The maximum distance returned will be 'maxCost'.
  183. // m must point to a matrix pre-allocated by VECT_OP_FUNC(InitiLevEditDistMtx)(maxN).
  184. double VECT_OP_FUNC(LevEditDistWithCostThresh)( int mtxMaxN, unsigned* m, const VECT_OP_TYPE* s0, int n0, const VECT_OP_TYPE* s1, int n1, double maxCost, unsigned maxN );
  185. //======================================================================================================================
  186. //)