shithub: aubio

Download patch

ref: 7a54b37160fa859f8decb918aebbea14dec4c31b
parent: 07382d8c0476840e5a86b3807577c988cc52e28a
author: Paul Brossier <piem@piem.org>
date: Wed Oct 31 15:36:31 EDT 2018

Merge branch 'fix/pyfvec'

--- a/python/lib/aubio/__init__.py
+++ b/python/lib/aubio/__init__.py
@@ -30,7 +30,7 @@
 from .slicing import *
 
 class fvec(numpy.ndarray):
-    """fvec(input_arg=1024, **kwargs)
+    """fvec(input_arg=1024)
     A vector holding float samples.
 
     If `input_arg` is an `int`, a 1-dimensional vector of length `input_arg`
@@ -43,17 +43,7 @@
     input_arg : `int` or `array_like`
         Can be a positive integer, or any object that can be converted to
         a numpy array with :func:`numpy.array`.
-    **kwargs
-        Additional keyword arguments passed to :func:`numpy.zeros`, if
-        `input_arg` is an integer, or to :func:`numpy.array`. Should not
-        include `dtype`, which is already specified as
-        :data:`aubio.float_type`.
 
-    Returns
-    -------
-    numpy.ndarray
-        Array of shape `(length,)`.
-
     Examples
     --------
     >>> aubio.fvec(10)
@@ -80,10 +70,15 @@
     numpy.zeros : create a numpy array filled with zeros
     numpy.array : create a numpy array from an existing object
     """
-    def __new__(cls, input_arg=1024, **kwargs):
+    def __new__(cls, input_arg=1024):
         if isinstance(input_arg, int):
             if input_arg == 0:
                 raise ValueError("vector length of 1 or more expected")
-            return numpy.zeros(input_arg, dtype=float_type, **kwargs)
+            return numpy.zeros(input_arg, dtype=float_type, order='C')
         else:
-            return numpy.array(input_arg, dtype=float_type, **kwargs)
+            np_input = numpy.array(input_arg, dtype=float_type, order='C')
+            if len(np_input.shape) != 1:
+                raise ValueError("input_arg should have shape (n,)")
+            if np_input.shape[0] == 0:
+                raise ValueError("vector length of 1 or more expected")
+            return np_input
--- a/python/tests/test_fvec.py
+++ b/python/tests/test_fvec.py
@@ -60,6 +60,14 @@
         self.assertRaises(IndexError, a.__getitem__, 3)
         self.assertRaises(IndexError, a.__getitem__, 2)
 
+    def test_wrong_dimensions(self):
+        a = np.array([[[1, 2], [3, 4]]], dtype=float_type)
+        self.assertRaises(ValueError, fvec, a)
+
+    def test_wrong_size(self):
+        a = np.ndarray([0,], dtype=float_type)
+        self.assertRaises(ValueError, fvec, a)
+
 class aubio_wrong_fvec_input(TestCase):
     """ uses min_removal to test PyAubio_IsValidVector """