Changeset 3b2d32c for src


Ignore:
Timestamp:
Sep 12, 2009, 2:28:00 PM (15 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
6f1727f
Parents:
ae4d5de
Message:

src/fvec.{c,h}: add fvec_set _zeros _ones _rev _weight and _copy utilities functions

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/fvec.c

    rae4d5de r3b2d32c  
    6262}
    6363
     64/* helper functions */
     65
    6466void fvec_print(fvec_t *s) {
    6567  uint_t i,j;
     
    7173  }
    7274}
     75
     76void fvec_set(fvec_t *s, smpl_t val) {
     77  uint_t i,j;
     78  for (i=0; i< s->channels; i++) {
     79    for (j=0; j< s->length; j++) {
     80      s->data[i][j] = val;
     81    }
     82  }
     83}
     84
     85void fvec_zeros(fvec_t *s) {
     86  fvec_set(s, 0.);
     87}
     88
     89void fvec_ones(fvec_t *s) {
     90  fvec_set(s, 1.);
     91}
     92
     93void fvec_rev(fvec_t *s) {
     94  uint_t i,j;
     95  for (i=0; i< s->channels; i++) {
     96    for (j=0; j< FLOOR(s->length/2); j++) {
     97      ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
     98    }
     99  }
     100}
     101
     102void fvec_weight(fvec_t *s, fvec_t *weight) {
     103  uint_t i,j;
     104  uint_t length = MIN(s->length, weight->length);
     105  for (i=0; i< s->channels; i++) {
     106    for (j=0; j< length; j++) {
     107      s->data[i][j] *= weight->data[0][j];
     108    }
     109  }
     110}
     111
     112void fvec_copy(fvec_t *s, fvec_t *t) {
     113  uint_t i,j;
     114  uint_t channels = MIN(s->channels, t->channels);
     115  uint_t length = MIN(s->length, t->length);
     116  if (s->channels != t->channels) {
     117    AUBIO_ERR("warning, trying to copy %d channels to %d channels\n",
     118            s->channels, t->channels);
     119  }
     120  if (s->length != t->length) {
     121    AUBIO_ERR("warning, trying to copy %d elements to %d elements \n",
     122            s->length, t->length);
     123  }
     124  for (i=0; i< channels; i++) {
     125    for (j=0; j< length; j++) {
     126      t->data[i][j] = s->data[i][j];
     127    }
     128  }
     129}
     130
  • src/fvec.h

    rae4d5de r3b2d32c  
    121121void fvec_print(fvec_t *s);
    122122
     123/** set all elements to a given value
     124
     125  \param s vector to modify
     126  \param val value to set elements to
     127
     128*/
     129void fvec_set(fvec_t *s, smpl_t val);
     130
     131/** set all elements to zero
     132
     133  \param s vector to modify
     134
     135*/
     136void fvec_zeros(fvec_t *s);
     137
     138/** set all elements to ones
     139
     140  \param s vector to modify
     141
     142*/
     143void fvec_ones(fvec_t *s);
     144
     145/** revert order of vector elements
     146
     147  \param s vector to revert
     148
     149*/
     150void fvec_rev(fvec_t *s);
     151
     152/** apply weight to vector
     153
     154  If the weight vector is longer than s, only the first elements are used. If
     155  the weight vector is shorter than s, the last elements of s are not weighted.
     156
     157  \param s vector to weight
     158  \param weight weighting coefficients
     159
     160*/
     161void fvec_weight(fvec_t *s, fvec_t *weight);
     162
     163/** make a copy of a vector
     164
     165  \param s source vector
     166  \param t vector to copy to
     167
     168*/
     169void fvec_copy(fvec_t *s, fvec_t *t);
     170
    123171#ifdef __cplusplus
    124172}
Note: See TracChangeset for help on using the changeset viewer.