[tensor] rewrite and rename have_same_shape
authorPaul Brossier <piem@piem.org>
Mon, 28 Jan 2019 21:56:27 +0000 (22:56 +0100)
committerPaul Brossier <piem@piem.org>
Wed, 29 Dec 2021 16:52:00 +0000 (11:52 -0500)
src/ai/tensor.c
tests/src/ai/test-tensor.c

index cbf2af9..ca13459 100644 (file)
@@ -137,15 +137,15 @@ uint_t aubio_tensor_get_subtensor(aubio_tensor_t *t, uint_t i,
   return AUBIO_OK;
 }
 
-uint_t aubio_tensor_have_same_size(aubio_tensor_t *t, aubio_tensor_t *s)
+uint_t aubio_tensor_have_same_shape(aubio_tensor_t *a, aubio_tensor_t *b)
 {
   uint_t n;
-  if (!t || !s) return 0;
-  if (t->ndim != s->ndim) return 0;
-  if (t->size != s->size) return 0;
-  n = t->ndim;
-  while (n--) {
-    if (t->shape[n] != s->shape[n]) {
+  AUBIO_ASSERT(a && b);
+  if (a->ndim != b->ndim) {
+    return 0;
+  }
+  for (n = 0; n < a->ndim; n++) {
+    if (a->shape[n] != b->shape[n]) {
       return 0;
     }
   }
index b8b30b4..84d6943 100644 (file)
@@ -123,28 +123,28 @@ int test_sizes(void)
   aubio_tensor_t *a = new_aubio_tensor(4, dims);
   aubio_tensor_t *b = new_aubio_tensor(3, dims);
 
-  assert (!aubio_tensor_have_same_size(a, b));
+  assert (!aubio_tensor_have_same_shape(a, b));
 
   del_aubio_tensor(b);
   dims[2] += 1;
   b = new_aubio_tensor(4, dims);
-  assert (!aubio_tensor_have_same_size(a, b));
+  assert (!aubio_tensor_have_same_shape(a, b));
   del_aubio_tensor(b);
   dims[2] -= 1;
 
   dims[0] -= 1;
   dims[1] += 1;
   b = new_aubio_tensor(4, dims);
-  assert (!aubio_tensor_have_same_size(a, b));
+  assert (!aubio_tensor_have_same_shape(a, b));
   del_aubio_tensor(b);
 
   dims[0] += 1;
   dims[1] -= 1;
   b = new_aubio_tensor(4, dims);
-  assert (aubio_tensor_have_same_size(a, b));
+  assert (aubio_tensor_have_same_shape(a, b));
 
-  assert (!aubio_tensor_have_same_size(NULL, b));
-  assert (!aubio_tensor_have_same_size(a, NULL));
+  assert (!aubio_tensor_have_same_shape(NULL, b));
+  assert (!aubio_tensor_have_same_shape(a, NULL));
 
   del_aubio_tensor(a);
   del_aubio_tensor(b);
@@ -320,7 +320,7 @@ int main(void) {
   assert (test_3d() == 0);
   PRINT_MSG("testing 4d tensors\n");
   assert (test_4d() == 0);
-  PRINT_MSG("testing aubio_tensor_have_same_size\n");
+  PRINT_MSG("testing aubio_tensor_have_same_shape\n");
   assert (test_sizes() == 0);
   PRINT_MSG("testing new_aubio_tensor with wrong arguments\n");
   assert (test_wrong_args() == 0);