From: Paul Brossier Date: Sat, 5 Sep 2015 09:05:43 +0000 (+0200) Subject: src/fvec.{c,h}: add fvec_weighted_copy X-Git-Tag: 0.4.4~300^2~375 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=7166ef8f3c2c07ea2fe4a6b6b540aac96509e56d;p=aubio.git src/fvec.{c,h}: add fvec_weighted_copy --- diff --git a/src/fvec.c b/src/fvec.c index e2361cc2..619e542d 100644 --- a/src/fvec.c +++ b/src/fvec.c @@ -121,6 +121,18 @@ void fvec_weight(fvec_t *s, fvec_t *weight) { #endif /* HAVE_ACCELERATE */ } +void fvec_weighted_copy(fvec_t *in, fvec_t *weight, fvec_t *out) { +#ifndef HAVE_ACCELERATE + uint_t j; + uint_t length = MIN(s->length, weight->length); + for (j=0; j< length; j++) { + out->data[j] = in->data[j] * weight->data[j]; + } +#else + aubio_vDSP_vmul(in->data, 1, weight->data, 1, out->data, 1, out->length); +#endif /* HAVE_ACCELERATE */ +} + void fvec_copy(fvec_t *s, fvec_t *t) { if (s->length != t->length) { AUBIO_ERR("trying to copy %d elements to %d elements \n", diff --git a/src/fvec.h b/src/fvec.h index c79295de..ceaec224 100644 --- a/src/fvec.h +++ b/src/fvec.h @@ -162,6 +162,15 @@ void fvec_weight(fvec_t *s, fvec_t *weight); */ void fvec_copy(fvec_t *s, fvec_t *t); +/** make a copy of a vector, applying weights to each element + + \param in input vector + \param weight weights vector + \param out output vector + +*/ +void fvec_weighted_copy(fvec_t *in, fvec_t *weight, fvec_t *out); + #ifdef __cplusplus } #endif