Changeset 3b2d32c for src/fvec.c


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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.