include/it/vec.h

Go to the documentation of this file.
00001 /*
00002   libit - Library for basic source and channel coding functions
00003   Copyright (C) 2005-2005 Vivien Chappelier, Herve Jegou
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Library General Public
00007   License as published by the Free Software Foundation; either
00008   version 2 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Library General Public License for more details.
00014 
00015   You should have received a copy of the GNU Library General Public
00016   License along with this library; if not, write to the Free
00017   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /*
00021   Vectors functions
00022   Copyright (C) 2005-2007 Vivien Chappelier, Herve Jegou
00023 */
00024 
00025 
00026 #ifndef __it_vec_h
00027 #define __it_vec_h
00028 
00029 #include <it/cplx.h>
00030 #include <it/types.h>
00031 #include <assert.h>
00032 #include <stddef.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 
00036 
00037 /*---------------------------------------------------------------------------*/
00038 /*! \defgroup vec Vectors                                                    */
00039 /* @{                                                                        */
00040 /*---------------------------------------------------------------------------*/
00041 /* Notes: the following structures are used to store some vectors values. 
00042    For a given vector v of type type_t (with type_t=int, double, byte or complex), 
00043    the memory storage is managed as follows (1b=1 byte):
00044 
00045    variable      type          memory pos               purpose
00046 
00047    none          none          _Vec_header[v]->ptr     start of the memory block allocated for the vector.
00048    This position is not always the one of the vector header, 
00049    because a word alignment is enforced while a vector is allocated. 
00050    Vec_header(v) _Vec_header_  v-sizeof(header) bytes  Vector header (see below)
00051    v[0]         type_t         v                       first element of the vector
00052    v[1]         type_t         v+sizeof(type_t) bytes  second element...
00053    v[length-1]  type_t         v+length*sizeof(type_t) last element of the vector
00054    v[length], ... v[max_length-1] pre-allocated but not currently unused.
00055 
00056    Thus, the amount of memory allocated is greater than the number of element by at least
00057    sizeof(_Vec_header_) bytes, i.e. about 16 bytes on a 32 bits machine. 
00058    Usually, vector creation functions allocate vectors such that length=length_max. 
00059    When the vector length decreases, the already allocated memory remains allocated. 
00060    When the vector length increases, a geometric reallocation strategy is used. 
00061 */ 
00062 
00063 /*---------------------------------------------------------------------------*/
00064 /*! @name Constant vectors                                                   */
00065 /*---------------------------------------------------------------------------*/
00066 
00067 typedef void * Vec;
00068 typedef double * vec;
00069 typedef int * ivec;
00070 typedef byte * bvec;
00071 typedef cplx * cvec;
00072 
00073 
00074 /*@{*/
00075 /*! void vector of length 0, i.e. with no element
00076   \warning this is a constant vector which is in essence used for comparison. 
00077   It has to be differentiate from an unallocated vector or from the NULL vector.
00078  */
00079 extern vec const vec_null;
00080 extern ivec const ivec_null;
00081 extern bvec const bvec_null;
00082 extern cvec const cvec_null;
00083 /*@}*/
00084 /*@}*/
00085 
00086 
00087 typedef struct _Vec_header_ {
00088   idx_t length;   /* effective length of the vector (<= max_length)     */
00089   idx_t length_max;   /* amount of memory allocated for the vector elements */
00090   void *ptr;      /* memory block associated to this vector             */
00091   size_t element_size;  /* size of the stored elements                        */
00092 } Vec_header_t;
00093 
00094 /* Return the header associated with a given vector v. For internal use. */
00095 #define Vec_header(v) (*(((Vec_header_t *) (v)) - 1))
00096 #define Vec_element_size(v) (Vec_header(v).element_size)
00097 
00098 
00099 
00100 /* We want to make sure the memory is always properly aligned on an 16-byte
00101    boundary. This is needed to guarantee pointer arithmetic works with cplx.
00102    Besides it provides faster memory access in case of MMX/SSE/.. optimizations.
00103 */
00104 #define IT_ALLOC_ALIGN (sizeof(cplx))
00105 
00106 
00107 /* The reallocation of memory for vectors is done here according to a geometric
00108    rule so that the complexity of the overall reallocation proccess remains
00109    linear. The following value define the ratio of the realloction procedure.
00110    Note that the value is a tradeoff between memory overhead and computing 
00111    cost
00112 */
00113 #define DYN_ALLOC_RULE(l) ((l)*4/3+1)
00114 
00115 /* Vector allocation functions */
00116 Vec  __Vec_new_alloc (size_t elem_size, idx_t length, idx_t length_max);
00117 Vec  __Vec_new_realloc (void *V, size_t elem_size, idx_t length,
00118       idx_t length_max);
00119 
00120 
00121 
00122 /*! @addtogroup vec                                                          */
00123 /* @{                                                                        */
00124 /*---------------------------------------------------------------------------*/
00125 /*! @name Basic vector allocation, initialization and deletion               */
00126 /*---------------------------------------------------------------------------*/
00127 
00128 /*@{*/
00129 /*! Vector allocation with explicit allocation of the maximum number of elements */
00130 #define Vec_new_alloc( type_t, N, length_max ) \
00131     ((type_t *) __Vec_new_alloc(sizeof(type_t), N, length_max ))
00132 
00133 vec vec_new_alloc (idx_t length, idx_t length_max);
00134 ivec ivec_new_alloc (idx_t length, idx_t length_max);
00135 bvec bvec_new_alloc (idx_t length, idx_t length_max);
00136 cvec cvec_new_alloc (idx_t length, idx_t length_max);
00137 /*@}*/
00138 
00139 
00140 /*@{*/
00141 /*! Allocate a vector */
00142 #define Vec_new( type_t, N ) ((type_t *) __Vec_new( sizeof(type_t), N ))
00143 Vec __Vec_new (size_t elem_size, idx_t N);
00144 
00145 vec vec_new (idx_t length);
00146 ivec ivec_new (idx_t length);
00147 bvec bvec_new (idx_t length);
00148 cvec cvec_new (idx_t length);
00149 /*@}*/
00150 
00151 
00152 /*@{*/
00153 /*! Free a vector */
00154 #define Vec_delete( v ) free( Vec_header(v).ptr )
00155 
00156 void vec_delete (vec v);
00157 void ivec_delete (ivec v);
00158 void bvec_delete (bvec v);
00159 void cvec_delete (cvec v);
00160 /*@}*/
00161 
00162 
00163 /*---------------------------------------------------------------------------*/
00164 /*! @name Length and max length vector operations                            */
00165 /*---------------------------------------------------------------------------*/
00166 
00167 /*@{*/
00168 /*! Return the length of the vector */
00169 #define Vec_length( v ) ( Vec_header(v).length )
00170 
00171 idx_t vec_length (vec v);
00172 idx_t ivec_length (ivec v);
00173 idx_t bvec_length (bvec v);
00174 idx_t cvec_length (cvec v);
00175 /*@}*/
00176 
00177 
00178 /* to use the entity end in a vec function, this macro is called */
00179 #define VEC_END_PARAM( v, param ) do { if( param == end ) param = Vec_length( v ) - 1; } while(0)
00180 
00181 /*@{*/
00182 /*! Return the maximum length of the vector (number of allocated elements) */
00183 #define Vec_length_max( v ) ( Vec_header(v).length_max )
00184 
00185 idx_t vec_length_max (vec v);
00186 idx_t ivec_length_max (ivec v);
00187 idx_t bvec_length_max (bvec v);
00188 idx_t cvec_length_max (cvec v);
00189 /*@}*/
00190 
00191 
00192 /*@{*/
00193 /*! Modify the maximum length of a vector
00194   \warning the function Vec_set_length_max may change the value of the pointer
00195   corresponding to vector v. Consequently, the functions calling this function
00196   must be handled with care, especially when vectors are passed as parameters   */
00197 #define Vec_set_length_max( v, N ) do {                         \
00198   int L = Vec_length(v);          \
00199   size_t elem_size = Vec_element_size(v);     \
00200                 \
00201   assert( N >= Vec_length(v) );         \
00202   if( N > Vec_length(v) ) {         \
00203     Vec new_Vec = __Vec_new_realloc(v, elem_size, L, N);  \
00204     (v) = (v) + ((byte *) new_Vec - (byte *) (v)) / elem_size;  \
00205   }               \
00206 } while(0)
00207 
00208 
00209 vec _vec_set_length_max (vec v, idx_t N);
00210 ivec _ivec_set_length_max (ivec v, idx_t N);
00211 bvec _bvec_set_length_max (bvec v, idx_t N);
00212 cvec _cvec_set_length_max (cvec v, idx_t N);
00213 
00214 #define vec_set_length_max( v, N )  do { v=_vec_set_length_max( v, N ); } while (0)
00215 #define ivec_set_length_max( v, N ) do { v=_ivec_set_length_max( v, N ); } while (0)
00216 #define bvec_set_length_max( v, N ) do { v=_bvec_set_length_max( v, N ); } while (0)
00217 #define cvec_set_length_max( v, N ) do { v=_cvec_set_length_max( v, N ); } while (0)
00218 /*@}*/
00219 
00220 
00221 /*@{*/
00222 /*! Modify the length of a vector
00223   \warning This function never decreases the max size of the vector 
00224   (explictly call Vec_set_length_max for that purpose) 
00225 */
00226 #define Vec_set_length( v, N )      do {                                    \
00227                                       if( N > Vec_length_max( v ) ) {       \
00228           Vec_set_length_max( v, N );         \
00229                                         Vec_length( v ) = (N);              \
00230                                       } else {                              \
00231                                       Vec_length( v ) = (N); }              \
00232                                      } while(0)
00233 
00234 vec _vec_set_length (vec v, idx_t N);
00235 ivec _ivec_set_length (ivec v, idx_t N);
00236 bvec _bvec_set_length (bvec v, idx_t N);
00237 cvec _cvec_set_length (cvec v, idx_t N);
00238 
00239 #define vec_set_length( v, N )  do { v=_vec_set_length( v, N ); } while (0)
00240 #define ivec_set_length( v, N ) do { v=_ivec_set_length( v, N ); } while (0)
00241 #define bvec_set_length( v, N ) do { v=_bvec_set_length( v, N ); } while (0)
00242 #define cvec_set_length( v, N ) do { v=_cvec_set_length( v, N ); } while (0)
00243 /*@}*/
00244 
00245 
00246 
00247 
00248 /*---------------------------------------------------------------------------*/
00249 /*! @name Basic vector initialization/modification                           */
00250 /*---------------------------------------------------------------------------*/
00251 
00252 /*@{*/
00253 /*! Initialize the vector from a buffer of the same type */
00254 #define Vec_init( v, buf, N ) memcpy( v, buf, Vec_element_size(v) * (N) );
00255 
00256 
00257 vec vec_init (vec v, double *buf, idx_t N);
00258 ivec ivec_init (ivec v, int *buf, idx_t N);
00259 bvec bvec_init (bvec v, byte * buf, idx_t N);
00260 cvec cvec_init (cvec v, cplx * buf, idx_t N);
00261 /*@}*/
00262 
00263 
00264 /*@{*/
00265 /*! Set all the elements of the vector to a given value */
00266 #define Vec_set( v, val ) do {                                              \
00267                             idx_t i;                                       \
00268                             assert( v );                                    \
00269                             for( i = 0 ; i < Vec_length( v ) ; i++ )        \
00270                               v[ i ] = val; } while( 0 )
00271 
00272 vec vec_set (vec v, double val);
00273 ivec ivec_set (ivec v, int val);
00274 bvec bvec_set (bvec v, byte val); 
00275 cvec cvec_set (cvec v, cplx val);
00276 /*@}*/
00277 
00278 
00279 /*@{*/
00280 /*! Constant vector */
00281 vec  vec_new_set (double val, idx_t N);
00282 ivec ivec_new_set (int val, idx_t N);
00283 bvec bvec_new_set (byte val, idx_t N);
00284 cvec cvec_new_set (cplx val, idx_t N);
00285 /*@}*/
00286 
00287 
00288 /*@{*/
00289 /*! Reduce a vector to length 0 */
00290 #define Vec_void(v) do {                                                  \
00291   assert( v );                                                            \
00292   Vec_length( v ) = 0;                                                    \
00293 } while(0)
00294 
00295 void vec_void (vec);
00296 void ivec_void (ivec);
00297 void bvec_void (bvec);
00298 void cvec_void (cvec);
00299 /*@}*/
00300 
00301 
00302 /*@{*/
00303 /*! Create a vector of length 0 */
00304 #define Vec_new_void( type_t ) Vec_new( type_t, 0 )
00305 
00306 vec  vec_new_void ();
00307 ivec ivec_new_void ();
00308 bvec bvec_new_void ();
00309 cvec cvec_new_void ();
00310 /*@}*/
00311 
00312 
00313 /*@{*/
00314 /*! Set all the elements of a vector to 0 */
00315 void vec_zeros (vec);
00316 void ivec_zeros (ivec);
00317 void bvec_zeros (bvec);
00318 void cvec_zeros (cvec);
00319 /*@}*/
00320 
00321 
00322 /*@{*/
00323 /*! Create a vectors of zeros */
00324 vec vec_new_zeros (idx_t N);
00325 ivec ivec_new_zeros (idx_t N);
00326 bvec bvec_new_zeros (idx_t N);
00327 cvec cvec_new_zeros (idx_t N);
00328 /*@}*/
00329 
00330 
00331 /*@{*/
00332 /*! Set all the vector elements to 1 */
00333 void vec_ones (vec);
00334 void ivec_ones (ivec);
00335 void bvec_ones (bvec);
00336 void cvec_ones (cvec);
00337 /*@}*/
00338 
00339 
00340 /*@{*/
00341 /*! New vectors of ones */
00342 vec vec_new_ones (idx_t N);
00343 ivec ivec_new_ones (idx_t N);
00344 bvec bvec_new_ones (idx_t N);
00345 cvec cvec_new_ones (idx_t N);
00346 /*@}*/
00347 
00348 
00349 
00350 /*@{*/
00351 /*! Set the elements of a subvector to a given value val */
00352 #define Vec_set_between( v, i1, i2, val ) do {                            \
00353                             idx_t ve = i2;                                 \
00354                             idx_t i;                                       \
00355                             VEC_END_PARAM( v,ve );                          \
00356                             assert( v );                                    \
00357                             for( i = i1 ; i <= ve ; i++ )                   \
00358                               v[ i ] = val; } while( 0 )
00359 
00360 vec vec_set_between (vec v, idx_t i1, idx_t i2, double val);
00361 ivec ivec_set_between (ivec v, idx_t i1, idx_t i2, int val);
00362 bvec bvec_set_between (bvec v, idx_t i1, idx_t i2, byte val);
00363 cvec cvec_set_between (cvec v, idx_t i1, idx_t i2, cplx val);
00364 
00365 /*@}*/
00366 
00367 
00368 /*@{*/
00369 /*! Modify a given element subset of a vector to another vector */
00370 #define Vec_set_subvector( v, s, index ) do {          \
00371                             idx_t i;             \
00372           assert(v);             \
00373           assert(s);             \
00374           assert(index + Vec_length(s) <= Vec_length(v)); \
00375           for(i = 0; i < Vec_length(s); i++)       \
00376             (v)[(index) + i] = (s)[i]; } while(0)
00377 
00378 
00379 void vec_set_subvector (vec v, vec s, idx_t idx);
00380 void ivec_set_subvector (ivec v, ivec s, idx_t idx);
00381 void bvec_set_subvector (bvec v, bvec s, idx_t idx);
00382 void cvec_set_subvector (cvec v, cvec s, idx_t idx);
00383 /*@}*/
00384 
00385 
00386 /*@{*/
00387 /*! allocate a new vector formed by a subset of a given vector */
00388 vec vec_get_subvector (vec v, idx_t i1, idx_t i2);
00389 ivec ivec_get_subvector (ivec v, idx_t i1, idx_t i2);
00390 bvec bvec_get_subvector (bvec v, idx_t i1, idx_t i2);
00391 cvec cvec_get_subvector (cvec v, idx_t i1, idx_t i2);
00392 /*@}*/
00393 
00394 
00395 /*------------------------------------------------------------------------------*/
00396 /*! @name Comparisons functions                                                 */
00397 /*------------------------------------------------------------------------------*/
00398 
00399 /*@{*/
00400 /*! Return true iff all the vectors v1 and v2 are equal component per component  */
00401 #define Vec_eq( v1, v2 ) ( Vec_length( v1 ) == Vec_length( v2 ) &&          \
00402                          !memcmp( v1, v2, Vec_element_size( v1 ) * Vec_length( v1 ) ) )
00403 
00404 int  vec_eq (vec v1, vec v2);
00405 int  ivec_eq (ivec v1, ivec v2);
00406 int  bvec_eq (bvec v1, bvec v2);
00407 int  cvec_eq (cvec v1, cvec v2);
00408 /*@}*/
00409 
00410 
00411 /*@{*/
00412 /* Return 1 if vector v1 is lexicographically greater or equal to vector v2, 
00413    0 otherwise. Note that if v1 is a prefix of v2, v1 is assumed to be smaller  */
00414 int  vec_geq (vec v1, vec v2);
00415 int  ivec_geq (ivec v1, ivec v2);
00416 int  bvec_geq (bvec v1, bvec v2);
00417 /*@}*/
00418 
00419 
00420 /*------------------------------------------------------------------------------*/
00421 /** @name Copy and Conversions Functions                                        */
00422 /*------------------------------------------------------------------------------*/
00423 
00424 /*@{*/
00425 /*! Copy the content of a vector into another vector                            
00426   \warning  Note that these functions do NOT allocate memory for the destination vectors. 
00427   Consequently, the amount of allocated elements vec_length_max(v) must be sufficient. 
00428   The function returns the number of elements that has really been copied      
00429   If the vectors have not the same size, the function returns an error         
00430 */
00431 Vec __Vec_copy (Vec v1, Vec v2);
00432 
00433 #define Vec_copy( v1, v2 ) __Vec_copy((Vec) v1, (Vec) v2)
00434 void vec_copy (vec dest, vec orig);
00435 void ivec_copy (ivec dest, ivec orig);
00436 void bvec_copy (bvec dest, bvec orig);
00437 void cvec_copy (cvec dest, cvec orig);
00438 /*@}*/
00439 
00440 
00441 /*@{*/
00442 /*! Clone a vector (allocate memory and copy data) */
00443 Vec Vec_clone (Vec v);
00444 vec vec_clone (vec v);
00445 ivec ivec_clone (ivec v);
00446 bvec bvec_clone (bvec v);
00447 cvec cvec_clone (cvec v);
00448 /*@}*/
00449 
00450 
00451 /*@{*/
00452 /*! Copy with conversion (lengths must match) */
00453 void vec_copy_from_ivec (vec dest, ivec orig);
00454 void vec_copy_from_bvec (vec dest, bvec orig);
00455 void vec_copy_from_cvec (vec dest, cvec orig);
00456 
00457 void ivec_copy_from_vec (ivec dest, vec orig);
00458 void ivec_copy_from_bvec (ivec dest, bvec orig);
00459 void ivec_copy_from_cvec (ivec dest, cvec orig);
00460 
00461 void bvec_copy_from_vec (bvec dest, vec orig);
00462 void bvec_copy_from_ivec (bvec dest, ivec orig);
00463 void bvec_copy_from_cvec (bvec dest, cvec orig);
00464 
00465 void cvec_copy_from_vec (cvec dest, vec orig);
00466 void cvec_copy_from_ivec (cvec dest, ivec orig);
00467 void cvec_copy_from_bvec (cvec dest, bvec orig);
00468 /*@}*/
00469 
00470 
00471 /*@{*/
00472 /*! Vector type conversion */
00473 bvec vec_to_bvec (vec v);
00474 ivec vec_to_ivec (vec v);
00475 cvec vec_to_cvec (vec v);
00476 
00477 vec  ivec_to_vec (ivec v);
00478 bvec ivec_to_bvec (ivec v);
00479 cvec ivec_to_cvec (ivec v);
00480 
00481 ivec bvec_to_ivec (bvec v);
00482 vec  bvec_to_vec (bvec v);
00483 cvec bvec_to_cvec (bvec v);
00484 /*@}*/
00485 
00486 
00487 /*@{*/
00488 /*! Copy the vector into a buffer (which must be a valid allocated pointer)      */
00489 void vec_copy_mem (double *buf, vec v);
00490 void ivec_copy_mem (int *buf, ivec v);
00491 void bvec_copy_mem (byte * buf, bvec v);
00492 void cvec_copy_mem (cplx * buf, cvec v);
00493 /*@}*/
00494 
00495 
00496 /*@{*/
00497 /*! Pack/unpack all bits of a binary vector together */
00498 void bvec_pack (byte * buf, bvec v);
00499 void bvec_unpack (bvec v, byte * buf);
00500 /*@}*/
00501 
00502 
00503 /*------------------------------------------------------------------------------*/
00504 /** @name Ordered set and stack operations                                      */
00505 /*------------------------------------------------------------------------------*/
00506 
00507 
00508 /*@{*/
00509 /*! Delete an element from the vector */
00510 #define Vec_del(v, pos) do {                                                \
00511                                idx_t l = Vec_length(v)-1;                   \
00512                                idx_t i;                                     \
00513                                assert(v);                                   \
00514                                assert((pos) <= l);                          \
00515                                for( i = (pos) + 1 ; i <= l ; i++ )          \
00516                                  (v)[ i - 1 ] = (v)[ i ];                   \
00517                                Vec_length(v)--;                             \
00518                              } while( 0 )
00519 
00520 vec vec_del (vec v, idx_t pos);
00521 ivec ivec_del (ivec v, idx_t pos);
00522 bvec bvec_del (bvec v, idx_t pos);
00523 cvec cvec_del (cvec v, idx_t pos);
00524 /*@}*/
00525 
00526 
00527 /*@{*/
00528 /*! insert an element in a given vector at the specified position
00529   \warning the function MAY modify the value of the pointer v
00530   The vector max length is increased according to a geometric allocation   
00531 */
00532 #define Vec_ins( v, pos, elt ) do {                                         \
00533                                idx_t l = Vec_length(v);                     \
00534                                idx_t i;                                     \
00535                                assert(v);                                   \
00536                                assert((pos) <= l);                          \
00537                                if( l+1 > Vec_length_max(v) )                \
00538                                  Vec_set_length_max( v, DYN_ALLOC_RULE( l ));\
00539                                for( i = l ; i >(pos) ; i-- )                \
00540                                  (v)[i] = (v)[ i-1 ];                       \
00541                                (v)[(pos)] = (elt);                          \
00542                                Vec_length(v)++;                             \
00543                              } while( 0 )
00544 
00545 /* To be used as v = ivec_ins( v, pos, elt ) */
00546 vec _vec_ins (vec v, idx_t pos, double elt);
00547 ivec _ivec_ins (ivec v, idx_t pos, int elt);
00548 bvec _bvec_ins (bvec v, idx_t pos, byte elt);
00549 cvec _cvec_ins (cvec v, idx_t pos, cplx elt);
00550 
00551 #define vec_ins( v, pos, elt )  do { v=_vec_ins( v, pos, elt ); } while (0)
00552 #define ivec_ins( v, pos, elt ) do { v=_ivec_ins( v, pos, elt ); } while (0)
00553 #define bvec_ins( v, pos, elt ) do { v=_bvec_ins( v, pos, elt ); } while (0)
00554 #define cvec_ins( v, pos, elt ) do { v=_cvec_ins( v, pos, elt ); } while (0)
00555 /*@}*/
00556 
00557 
00558 /*@{*/
00559 /*! Add an element at the end of the vector */
00560 #define Vec_push( v, elt ) Vec_ins( v, Vec_length(v), elt )
00561 
00562 vec _vec_push (vec v, double elt);
00563 ivec _ivec_push (ivec v, int elt);
00564 bvec _bvec_push (bvec v, byte elt);
00565 cvec _cvec_push (cvec v, cplx elt);
00566 
00567 #define vec_push( v, elt )  do { v=_vec_push( v, elt ); } while (0)
00568 #define ivec_push( v, elt ) do { v=_ivec_push( v, elt ); } while (0)
00569 #define bvec_push( v, elt ) do { v=_bvec_push( v, elt ); } while (0)
00570 #define cvec_push( v, elt ) do { v=_cvec_push( v, elt ); } while (0)
00571 
00572 /*@}*/
00573 
00574 
00575 /*@{*/
00576 /*! Retrieve the last element at the end of the vector (this removes it) */
00577 #define Vec_pop( v ) Vec_del( v, Vec_length(v)-1 )
00578 
00579 vec vec_pop (vec v);
00580 ivec ivec_pop (ivec v);
00581 bvec bvec_pop (bvec v);
00582 cvec cvec_pop (cvec v);
00583 /*@}*/
00584 
00585 
00586 /*@{*/
00587 /*! Return the last element of vector                                           */
00588 #define Vec_head( v ) ((v)[Vec_length(v)-1])
00589 
00590 double vec_head (vec v);
00591 int ivec_head (ivec v);
00592 byte bvec_head (bvec v);
00593 cplx cvec_head (const cvec v);
00594 /*@}*/
00595 
00596 
00597 /*------------------------------------------------------------------------------*/
00598 /** @name Safe vector access                                                    */
00599 /*------------------------------------------------------------------------------*/
00600 
00601 /*@{*/
00602 /*! Safe access to vector's elements */
00603 #define _vec(v, i) (*__vec(v, i))
00604 #define _ivec(v, i) (*__ivec(v, i))
00605 #define _bvec(v, i) (*__bvec(v, i))
00606 #define _cvec(v, i) (*__cvec(v, i))
00607 
00608 double *__vec (vec v, idx_t i);
00609 int *__ivec (ivec v, idx_t i);
00610 byte *__bvec (bvec v, idx_t i);
00611 cplx *__cvec (cvec v, idx_t i);
00612 /*@}*/
00613 
00614 
00615 /*------------------------------------------------------------------------------*/
00616 /** @name Mean, median, min, max, sum and elementary statistic indicators       */
00617 /*------------------------------------------------------------------------------*/
00618 
00619 /*@{*/
00620 /*! mean of the input vector */
00621 double vec_mean (vec v);
00622 double ivec_mean (ivec v);
00623 double vec_mean_robust (vec v);
00624 /*@}*/
00625 
00626 
00627 /*@{*/
00628 /*! median value of the input vector */
00629 double vec_median (vec v);
00630 int  ivec_median (ivec v);
00631 /*@}*/
00632 
00633 
00634 /*@{*/
00635 /*! vector sum */
00636 double vec_sum (vec v); /* The sum of all the elements          */
00637 int  ivec_sum (ivec v); /* use with care: may easily under/overflow */
00638 cplx cvec_sum (cvec v); /* The sum of all the elements          */
00639 double vec_sum_robust(vec v);
00640 /*@}*/
00641 
00642 
00643 /*@{*/
00644 /*! cumulative vector sum 
00645   \param v the input vector v
00646   \return a new vector of the cumulative sum of the input vector
00647 */
00648 vec  vec_cum_sum (vec v);
00649 ivec ivec_cum_sum (ivec v);
00650 cvec cvec_cum_sum (cvec v);
00651 /*@}*/
00652 
00653 
00654 /*@{*/
00655 /*! sum of a subset of the vector specified by an index interval */
00656 double vec_sum_between (vec v, idx_t i1, idx_t i2);
00657 int  ivec_sum_between (ivec v, idx_t i1, idx_t i2);
00658 cplx cvec_sum_between (cvec v, idx_t i1, idx_t i2);
00659 /*@}*/
00660 
00661 
00662 /*@{*/
00663 /*! The sum of the square components of a vector, i.e. the vector energy */
00664 double vec_sum_sqr (vec v); 
00665 /*@}*/
00666 
00667 
00668 /*@{*/
00669 /*! Mininum of a vector */
00670 double vec_min (vec v);
00671 int  ivec_min (ivec v);
00672 /*@}*/
00673 
00674 
00675 /*@{*/
00676 /*! Maxinum of a vector */
00677 double vec_max (vec v);
00678 int  ivec_max (ivec v);
00679 /*@}*/
00680 
00681 
00682 /*@{*/
00683 /*! Position where the vector minimum occurs */
00684 idx_t vec_min_index (vec v);
00685 idx_t ivec_min_index (ivec v);
00686 /*@}*/
00687 
00688 
00689 /*@{*/
00690 /*! Position where the vector maximum occurs */
00691 idx_t vec_max_index (vec v);
00692 idx_t ivec_max_index (ivec v);
00693 /*@}*/
00694 
00695 
00696 /*@{*/
00697 /*! Search the k smallest elements 
00698   \todo modify the algorithm and use the k-select algorithm
00699 */
00700 vec  vec_k_min (vec v, int k);
00701 ivec ivec_k_min (ivec v, int k);
00702 /*@}*/
00703 
00704 
00705 /*@{*/
00706 /*! Search the k greatest elements */
00707 vec  vec_k_max (vec v, int k);
00708 ivec ivec_k_max (ivec v, int k);
00709 /*@}*/
00710 
00711 
00712 /*@{*/
00713 /*! Search the k smallest elements between two positions */
00714 vec  vec_k_min_between (vec v, int k, idx_t a, idx_t b);
00715 ivec ivec_k_min_between (ivec v, int k, idx_t a, idx_t b);
00716 /*@}*/
00717 
00718 
00719 /*@{*/
00720 /*! Search the k greatest elements between two positions */
00721 vec  vec_k_max_between (vec v, int k, idx_t a, idx_t b);
00722 ivec ivec_k_max_between (ivec v, int k, idx_t a, idx_t b);
00723 /*@}*/
00724 
00725 
00726 /*@{*/
00727 /*! Search the indexes where the k smallest elements occur */
00728 ivec vec_k_min_index (vec v, int k);
00729 ivec ivec_k_min_index (ivec v, int k);
00730 /*@}*/
00731 
00732 
00733 /*@{*/
00734 /*! Search the indexes where the k greatest elements occur */
00735 ivec vec_k_max_index (vec v, int k);
00736 ivec ivec_k_max_index (ivec v, int k);
00737 /*@}*/
00738 
00739 
00740 /*@{*/
00741 /*! Search the indexes where the k smallest elements between two positions occur */
00742 ivec vec_k_min_index_between (vec v, int k, idx_t a, idx_t b);
00743 ivec ivec_k_min_index_between (ivec v, int k, idx_t a, idx_t b);
00744 /*@}*/
00745 
00746 
00747 /*@{*/
00748 /*! Search the indexes where the k greatest elements between two positions occur */
00749 ivec vec_k_max_index_between (vec v, int k, idx_t a, idx_t b);
00750 ivec ivec_k_max_index_between (ivec v, int k, idx_t a, idx_t b);
00751 /*@}*/
00752 
00753 
00754 /*@{*/
00755 /*! Unbiaised variance of the vector (obtained by dividing by N-1) */
00756 double vec_variance (vec v);  
00757 double vec_variance_robust (vec v); 
00758 /*@}*/
00759 
00760 /*@{*/
00761 /*! Covariance between two vectors */
00762 double vec_cov(vec v1, vec v2);
00763 /*@}*/
00764 
00765 /*@{*/
00766 /*! Norm of the input vector */
00767 double vec_norm (vec v, double nr);
00768 double ivec_norm (ivec v, int nr);
00769 /*@}*/
00770 
00771 
00772 /*@{*/
00773 /*! Normalize the vector for a specified norm, so that $sum(||v||_nr)=1$ */
00774 void vec_normalize (vec v, double nr); 
00775 /*@}*/
00776 
00777 
00778 /*@{*/
00779 /*! Return a normalized version of the input vector */
00780 vec vec_new_normalize (vec v, double nr);
00781 /*@}*/
00782 
00783 
00784 
00785 /*------------------------------------------------------------------------------*/
00786 /** @name Basic arithmetic operations                                           */
00787 /*------------------------------------------------------------------------------*/
00788 
00789 
00790 /*@{*/
00791 /*! Negate the vector */
00792 void vec_neg (vec v);
00793 void ivec_neg (ivec v);
00794 void cvec_neg (cvec v);
00795 /*@}*/
00796 
00797 
00798 /*@{*/
00799 /*! Complex conjugate */
00800 void cvec_conj (cvec v);
00801 /*@}*/
00802 
00803 
00804 /*@{*/
00805 /*! elementwise |v_i|^2 */
00806 void cvec_abssqr (cvec v);  
00807 /*@}*/
00808 
00809 
00810 /*@{*/
00811 /*! square the vector component per component */
00812 void vec_sqr (vec v);
00813 void ivec_sqr (ivec v);
00814 /*@}*/
00815 
00816 
00817 /*@{*/
00818 /*! root square of a vector component per component */
00819 void vec_sqrt (vec v);
00820 /*@}*/
00821 
00822 /*@{*/
00823 /*! logarithm of a vector component per component */
00824 void vec_log (vec v);
00825 void vec_log10 (vec v);
00826 /*@}*/
00827 
00828 
00829 /*@{*/
00830 /*! apply exponential */
00831 void vec_exp (vec v);   
00832 /*@}*/
00833 
00834 
00835 /*@{*/
00836 /*! set each component c to c^a */
00837 void vec_pow (vec v, double a); 
00838 /*@}*/
00839 
00840 
00841 /*@{*/
00842 /*! new vector: exponential values of the input vector */
00843 vec vec_new_pow (vec v, double a);
00844 /*@}*/
00845 
00846 
00847 /*@{*/
00848 /*! Apply absolute value */
00849 void vec_abs (vec v);   
00850 void ivec_abs (ivec v);
00851 /*@}*/
00852 
00853 
00854 /*@{*/
00855 /*! New vector generated with the absolute values of the input vector */
00856 vec  vec_new_abs (vec v);
00857 ivec ivec_new_abs (ivec v);
00858 vec  cvec_new_abs (cvec v);
00859 /*@}*/
00860 
00861 
00862 
00863 /*------------------------------------------------------------------------------*/
00864 /** @name Arithmetic operations with a scalar value                             */
00865 /*------------------------------------------------------------------------------*/
00866 
00867 /*@{*/
00868 /*! add a to the components */
00869 void vec_incr (vec v, double a);  
00870 void ivec_incr (ivec v, int a); 
00871 void cvec_incr (cvec v, cplx a);
00872 void cvec_incr_real (cvec v, double a); 
00873 /*@}*/
00874 
00875 
00876 /*@{*/
00877 /*! substract a specified value to the vector components */
00878 void vec_decr (vec v, double a);  
00879 void ivec_decr (ivec v, int a); 
00880 void cvec_decr (cvec v, cplx a); 
00881 /*@}*/
00882 
00883 
00884 /*@{*/
00885 /*! substract a specified real value to the complex components */
00886 void cvec_decr_real (cvec v, double a); 
00887 /*@}*/
00888 
00889 
00890 /*@{*/
00891 /*! multiply the components per a specified value */
00892 void vec_mul_by (vec v, double a);  
00893 void ivec_mul_by (ivec v, int a); /* multiply the components per a        */
00894 void cvec_mul_by (cvec v, cplx a);  /* multiply the components per a        */
00895 /*@}*/
00896 
00897 
00898 /*@{*/
00899 /*! multiply the components per a */
00900 void cvec_mul_by_real (cvec v, double a);
00901 /*@}*/
00902 
00903 
00904 /*@{*/
00905 /*! divide the components per a */
00906 void vec_div_by (vec v, double a);  
00907 void ivec_div_by (ivec v, int a);
00908 void cvec_div_by (cvec v, cplx a);
00909 /*@}*/
00910 
00911 
00912 /*@{*/
00913 void cvec_div_by_real (cvec v, double a);
00914 /*@}*/
00915 
00916 
00917 /*------------------------------------------------------------------------------*/
00918 /** @name Component per component operations                                    */
00919 /*------------------------------------------------------------------------------*/
00920 
00921 /*@{*/
00922 /*! addition */
00923 void vec_add (vec v1, vec v2);
00924 void ivec_add (ivec v1, ivec v2);
00925 void cvec_add (cvec v1, cvec v2);
00926 /*@}*/
00927 
00928 
00929 /*@{*/
00930 /*! addition stored in a new vector */
00931 vec  vec_new_add (vec v1, vec v2);
00932 ivec ivec_new_add (ivec v1, ivec v2);
00933 /*@}*/
00934 
00935 
00936 /*@{*/
00937 /*! Substraction */
00938 void vec_sub (vec v1, vec v2);
00939 void ivec_sub (ivec v1, ivec v2);
00940 void cvec_sub (cvec v1, cvec v2);
00941 /*@}*/
00942 
00943 
00944 /*@{*/
00945 /*! Substraction */
00946 vec  vec_new_sub (vec v1, vec v2);
00947 ivec ivec_new_sub (ivec v1, ivec v2);
00948 /*@}*/
00949 
00950 
00951 /*@{*/
00952 /*! Component per component multiplication 
00953 
00954 The result is stored in the vector which is the first parameter
00955 */
00956 void vec_mul (vec v1, vec v2);
00957 void ivec_mul (ivec v1, ivec v2);
00958 void cvec_mul (cvec v1, cvec v2);
00959 /*@}*/
00960 
00961 
00962 /*@{*/
00963 /*! Component per component multiplication */
00964 vec  vec_new_mul (vec v1, vec v2);
00965 ivec ivec_new_mul (ivec v1, ivec v2);
00966 /*@}*/
00967 
00968 
00969 
00970 /*@{*/
00971 /*! Component per component division */
00972 void vec_div (vec v1, vec v2);
00973 void ivec_div (ivec v1, ivec v2);
00974 void cvec_div (cvec v1, cvec v2);
00975 /*@}*/
00976 
00977 
00978 /*@{*/
00979 /*! Component per component division */
00980 vec  vec_new_div (vec v1, vec v2);
00981 ivec ivec_new_div (ivec v1, ivec v2);
00982 /*@}*/
00983 
00984 
00985 /*@{*/
00986 /*! Inner product of two vectors */
00987 double vec_inner_product (vec v1, vec v2);
00988 int  ivec_inner_product (ivec v1, ivec v2);
00989 double vecivec_inner_product (vec v1, ivec v2);
00990 int  bvecivec_inner_product (bvec v1, ivec v2);
00991 /*@}*/
00992 
00993 
00994 /*@{*/
00995 /*! Robustly computed inner product of two vectors */
00996 double vec_inner_product_robust (vec v1, vec v2);
00997 /*@}*/
00998 
00999 
01000 /*@{*/
01001 /*! Hermitian product of two complex vectors */
01002 void cvec_conj_mul (cvec v1, cvec v2);
01003 /*@}*/
01004 
01005 
01006 
01007 /*-----------------------------------------------------------------*/
01008 /** @name Component per component arbitrar function                */
01009 /*-----------------------------------------------------------------*/
01010 
01011 /*@{*/
01012 /*! Apply a function to all vector elements  */
01013 void  vec_apply_function (vec v, it_function_t function, it_args_t args);
01014 /*@}*/
01015 
01016 /*@{*/
01017 /*! Apply a function to all vector elements  */
01018 vec  vec_new_apply_function (vec v, it_function_t function, it_args_t args);
01019 /*@}*/
01020 
01021 #define vec_eval(v, f, a) vec_apply_function(v, f, a)
01022 #define vec_new_eval(v, f, a) vec_new_apply_function(v, f, a)
01023 
01024 
01025 /*@{*/
01026 /*! Apply a function to all vector elements  */
01027 ivec ivec_apply_function (ivec v, it_ifunction_t function, it_args_t args);
01028 /*@}*/
01029 
01030 /*@{*/
01031 /*! Apply a function to all vector elements  */
01032 ivec ivec_new_apply_function (ivec v, it_ifunction_t function,
01033 /*@}*/
01034             it_args_t args);
01035 #define ivec_eval(v, f, a) ivec_apply_function(v, f, a)
01036 #define ivec_new_eval(v, f, a) ivec_new_apply_function(v, f, a)
01037 
01038 
01039 /*-----------------------------------------------------------------*/
01040 /** @name Set, sorting and finding functions                       */
01041 /*-----------------------------------------------------------------*/
01042 
01043 /*@{*/
01044 /*! Reverse the vector */
01045 void vec_reverse (vec v);
01046 void ivec_reverse (ivec v);
01047 void bvec_reverse (bvec v);
01048 void cvec_reverse (cvec v);
01049 /*@}*/
01050 
01051 
01052 /*@{*/
01053 /*! Reverse the vector */
01054 vec  vec_new_reverse (vec v);
01055 ivec ivec_new_reverse (ivec v);
01056 bvec bvec_new_reverse (bvec v);
01057 cvec cvec_new_reverse (cvec v);
01058 /*@}*/
01059 
01060 
01061 /*@{*/
01062 /*! Count the number of elements equal to a given value a */
01063 idx_t vec_count (vec v, double a);
01064 idx_t ivec_count (ivec v, int a);
01065 idx_t bvec_count (bvec v, byte a);
01066 idx_t cvec_count (cvec v, cplx a);
01067 /*@}*/
01068 
01069 
01070 /*@{*/
01071 /*! Return the first position where the value a occurs, NULL_INDEX 
01072    if the research is not successful                               */
01073 idx_t vec_find_first (vec v, double a);
01074 idx_t ivec_find_first (ivec v, int a);
01075 idx_t bvec_find_first (bvec v, byte a);
01076 idx_t cvec_find_first (cvec v, cplx a);
01077 /*@}*/
01078 
01079 
01080 /*@{*/
01081 /*! Return the set of positions where a given value occurs */
01082 ivec vec_find (vec v, double a);
01083 ivec ivec_find (ivec v, int a);
01084 ivec bvec_find (bvec v, byte a);
01085 ivec cvec_find (cvec v, cplx a);
01086 /*@}*/
01087 
01088 
01089 /*@{*/
01090 /*! Return the set of positions where a given value occurs assuming a sorted set */
01091 idx_t vec_find_sorted (vec v, double a);
01092 idx_t ivec_find_sorted (ivec v, int a);
01093 idx_t bvec_find_sorted (bvec v, byte a);
01094 /*@}*/
01095 
01096 
01097 /*@{*/
01098 /*! Replace a given value by another for all vector components */
01099 ivec vec_replace (vec v, double a, double b);
01100 ivec ivec_replace (ivec v, int a, int b);
01101 ivec bvec_replace (bvec v, byte a, byte b);
01102 ivec cvec_replace (cvec v, cplx a, cplx b);
01103 /*@}*/
01104 
01105 
01106 /*@{*/
01107 /*! Concatenate two vectors */
01108 vec  vec_new_concat (vec v1, vec v2);
01109 ivec ivec_new_concat (ivec v1, ivec v2);
01110 bvec bvec_new_concat (bvec v1, bvec v2);
01111 cvec cvec_new_concat (cvec v1, cvec v2);
01112 /*@}*/
01113 
01114 
01115 /*@{*/
01116 /*! Vector created from the input vector by taking one occurences 
01117   of each possible value of the input vector */
01118 vec  vec_new_unique (vec v);
01119 ivec ivec_new_unique (ivec v);
01120 bvec bvec_new_unique (bvec v);
01121 /*@}*/
01122 
01123 
01124 /*@{*/
01125 /*! Union of two sets represented by the two input vectors */
01126 vec  vec_new_union (vec v1, vec v2);
01127 ivec ivec_new_union (ivec v1, ivec v2);
01128 bvec bvec_new_union (bvec v1, bvec v2);
01129 /*@}*/
01130 
01131 
01132 /*@{*/
01133 /*! Intersection of two sets represented by the two input vectors */
01134 vec  vec_new_intersection (vec v1, vec v2);
01135 ivec ivec_new_intersection (ivec v1, ivec v2);
01136 bvec bvec_new_intersection (bvec v1, bvec v2);
01137 /*@}*/
01138 
01139 
01140 /*@{*/
01141 /*! Return the vector composed of the elements of v indexed by idx */
01142 vec  vec_index_by (vec v, ivec idx);
01143 ivec ivec_index_by (ivec v, ivec idx);
01144 bvec bvec_index_by (bvec v, ivec idx);
01145 cvec cvec_index_by (cvec v, ivec idx);
01146 /*@}*/
01147 
01148 
01149 /*@{*/
01150 /*! Sort the vector by increasing values */
01151 void Vec_sort (Vec v, int (*elem_leq) (const void *, const void *));
01152 void vec_sort (vec v);
01153 void ivec_sort (ivec v);
01154 void bvec_sort (bvec v);
01155 /*@}*/
01156 
01157 
01158 /*@{*/
01159 /*! Return a vector of index corresponding to increasing values of the input vector */
01160 ivec Vec_sort_index (Vec v,
01161          int (*elem_leq_idx) (const void *, const void *));
01162 ivec vec_sort_index (vec v);
01163 ivec ivec_sort_index (ivec v);
01164 ivec bvec_sort_index (bvec v);
01165 /*@}*/
01166 
01167 
01168 
01169 /*-----------------------------------------------------------------*/
01170 /** @name Special vectors                                          */
01171 /*-----------------------------------------------------------------*/
01172 
01173 
01174 /*@{*/
01175 /*! Set the vector elements to 0,1, ... n-1 */
01176 void vec_range (vec);
01177 void ivec_range (ivec);
01178 void bvec_range (bvec);
01179 void cvec_range (cvec);
01180 /*@}*/
01181 
01182 
01183 /*@{*/
01184 /*! New vector 0, 1, ... N-1 */
01185 vec  vec_new_range (idx_t n);
01186 ivec ivec_new_range (idx_t n);
01187 bvec bvec_new_range (idx_t n);
01188 cvec cvec_new_range (idx_t n);
01189 /*@}*/
01190 
01191 
01192 /*@{*/
01193 /*! Set the vector elements to 1,2, ... n */
01194 void vec_1N (vec);
01195 void ivec_1N (ivec);
01196 void bvec_1N (bvec);
01197 void cvec_1N (cvec);
01198 /*@}*/
01199 
01200 
01201 /*@{*/
01202 /*! The sequence 1, 2.. N */
01203 vec  vec_new_1N (idx_t n);
01204 ivec ivec_new_1N (idx_t n);
01205 bvec bvec_new_1N (idx_t n);
01206 cvec cvec_new_1N (idx_t n);
01207 /*@}*/
01208 
01209 
01210 /*@{*/
01211 /*! Set the vector to an arithmetic sequence */
01212 void vec_arithm (vec, double start, double incr);
01213 void ivec_arithm (ivec, int start, int incr);
01214 void bvec_arithm (bvec, byte start, byte incr);
01215 void cvec_arithm (cvec, cplx start, cplx incr);
01216 /*@}*/
01217 
01218 
01219 /*@{*/
01220 /*! New arithmetic sequence */
01221 vec  vec_new_arithm (double start, double incr, idx_t N);
01222 ivec ivec_new_arithm (int start, int incr, idx_t N);
01223 bvec bvec_new_arithm (byte start, byte incr, idx_t N);
01224 cvec cvec_new_arithm (cplx start, cplx incr, idx_t N);
01225 /*@}*/
01226 
01227 
01228 /*@{*/
01229 /*! Set the vector to an geometric sequence */
01230 void vec_geom (vec, double start, double r);
01231 void ivec_geom (ivec, int start, int r);
01232 void bvec_geom (bvec, byte start, byte r);
01233 void cvec_geom (cvec, cplx start, cplx r);
01234 /*@}*/
01235 
01236 
01237 /*@{*/
01238 /*! Same but a geometric sequence of geometric factor r */
01239 vec  vec_new_geom (double start, double r, idx_t N);
01240 ivec ivec_new_geom (int start, int r, idx_t N);
01241 bvec bvec_new_geom (byte start, byte r, idx_t N);
01242 cvec cvec_new_geom (cplx start, cplx r, idx_t N);
01243 /*@}*/
01244 
01245 
01246 /*@{*/
01247 /*! generate $e^{2i Pi k / N} = cos(2 k Pi / N) + i sin(2 k Pi / N)$ */
01248 cvec cvec_new_unit_roots (idx_t N);
01249 /*@}*/
01250 
01251 
01252 /*-----------------------------------------------------------------*/
01253 /** @name Random vectors                                           */
01254 /*-----------------------------------------------------------------*/
01255 
01256 /*! Draw the component of a vector to uniformally random variable in [0,1[ */
01257 void vec_rand (vec v);
01258   
01259 /*! Generate a random vector, uniformally drawn in [0,1[ */
01260 vec  vec_new_rand (idx_t N);
01261 
01262 /*! Generate a random vector, uniformally drawn in [0,1[ */
01263 void vec_randn (vec v);
01264 
01265 /*! Generate a random vector with normal law */
01266 vec  vec_new_randn (idx_t N);
01267 
01268 /*! Generate a new vector representing a random permutation */
01269 ivec ivec_new_perm (size_t N);
01270 
01271 
01272 /*-----------------------------------------------------------------*/
01273 /** @name Convolution                                              */
01274 /*-----------------------------------------------------------------*/
01275 
01276 /*@{*/
01277 /*! Convolution of two vectors */
01278 vec  vec_conv (vec v1, vec v2);
01279 ivec ivec_conv (ivec v1, ivec v2);
01280 /*@}*/
01281 
01282 
01283 /*-----------------------------------------------------------------*/
01284 /** @name Vector <-> sparse vectors conversion                     */
01285 /*-----------------------------------------------------------------*/
01286 
01287 /*@{*/
01288 /*! convert a vector into a sparse vector */
01289 void vec_to_spvec (vec v, ivec * svi_out, vec * sv_out);
01290 void ivec_to_spivec (ivec v, ivec * svi_out, ivec * sv_out);
01291 /*@}*/
01292   
01293 
01294 /*@{*/
01295 /*! convert a sparse vector into a vector */
01296 vec spvec_to_vec (ivec svi, vec sv, int n);
01297 ivec spivec_to_ivec (ivec svi, ivec sv, int n);
01298 /*@}*/
01299 
01300 
01301 /*@{*/
01302 /*! Inner product between two sparse vectors */
01303 double spvec_inner_product (ivec svi1, vec sv1, ivec svi2, vec sv2);
01304 int spivec_inner_product (ivec svi1, ivec sv1, ivec svi2, ivec sv2);
01305 /*@}*/
01306 
01307 
01308 /*@}*/
01309 
01310 #endif

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau