[tensor] add copy
authorPaul Brossier <piem@piem.org>
Tue, 29 Jan 2019 00:14:21 +0000 (01:14 +0100)
committerPaul Brossier <piem@piem.org>
Wed, 29 Dec 2021 16:52:01 +0000 (11:52 -0500)
src/ai/tensor.c
src/ai/tensor.h

index ca13459..8f196a3 100644 (file)
@@ -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);
+}
index a6fe03b..3eae33c 100644 (file)
@@ -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