From 0dad503c37b1147955aaec08e1b478754e1171db Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 29 Jan 2019 01:14:21 +0100 Subject: [PATCH] [tensor] add copy --- src/ai/tensor.c | 12 ++++++++++++ src/ai/tensor.h | 15 +++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/ai/tensor.c b/src/ai/tensor.c index ca134599..8f196a39 100644 --- a/src/ai/tensor.c +++ b/src/ai/tensor.c @@ -234,3 +234,15 @@ void aubio_tensor_matmul(aubio_tensor_t *a, aubio_tensor_t *b, b->size/b->shape[0], 0.F, c->buffer, b->size/b->shape[0]); #endif } + +void aubio_tensor_copy(aubio_tensor_t *s, aubio_tensor_t *t) +{ + if (!aubio_tensor_have_same_shape(s, t)) { + AUBIO_ERR("tensor: not copying source tensor %s", + aubio_tensor_get_shape_string(s)); + AUBIO_ERR(" to destination tensor %s", + aubio_tensor_get_shape_string(t)); + return; + } + AUBIO_MEMCPY(t->buffer, s->buffer, s->size); +} diff --git a/src/ai/tensor.h b/src/ai/tensor.h index a6fe03b2..3eae33c9 100644 --- a/src/ai/tensor.h +++ b/src/ai/tensor.h @@ -159,9 +159,24 @@ void aubio_tensor_print(aubio_tensor_t *t); */ const char_t *aubio_tensor_get_shape_string(aubio_tensor_t *t); +/** compute matrix multiplication A x B = C + + \param a left tensor + \param b right tensor + \param c output tensor + +*/ void aubio_tensor_matmul(aubio_tensor_t *a, aubio_tensor_t *b, aubio_tensor_t *c); +/** copy tensor + + \param s source tensor + \param d destination tensor + +*/ +void aubio_tensor_copy(aubio_tensor_t *s, aubio_tensor_t *d); + #ifdef __cplusplus } #endif -- 2.11.0