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`
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
--------
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
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 """