History

Merge branch 'fix/pyfvec'

Paul Brossier committed 8 years ago

Commit 7a54b371 parent 07382d82 files · +17 −14Browse files

Showing the changes to python (2 of 2 files). Show all

Unified · Split

2 files
  1. python/lib/aubio/__init__.py +9 −14
  2. python/tests/test_fvec.py +8 −0
python/lib/aubio/__init__.py+9−14
@@ -30,7 +30,7 @@ from .midiconv import * · 29 unmodified lines
30from .slicing import *30from .slicing import *
31 31
32class fvec(numpy.ndarray):32class fvec(numpy.ndarray):
33 """fvec(input_arg=1024, **kwargs)33 """fvec(input_arg=1024)
34 A vector holding float samples.34 A vector holding float samples.
35 35
36 If `input_arg` is an `int`, a 1-dimensional vector of length `input_arg`36 If `input_arg` is an `int`, a 1-dimensional vector of length `input_arg`
@@ -43,16 +43,6 @@ class fvec(numpy.ndarray): · 6 unmodified lines
43 input_arg : `int` or `array_like`43 input_arg : `int` or `array_like`
44 Can be a positive integer, or any object that can be converted to44 Can be a positive integer, or any object that can be converted to
45 a numpy array with :func:`numpy.array`.45 a numpy array with :func:`numpy.array`.
46 **kwargs
47 Additional keyword arguments passed to :func:`numpy.zeros`, if
48 `input_arg` is an integer, or to :func:`numpy.array`. Should not
49 include `dtype`, which is already specified as
50 :data:`aubio.float_type`.
51
52 Returns
53 -------
54 numpy.ndarray
55 Array of shape `(length,)`.
56 46
57 Examples47 Examples
58 --------48 --------
@@ -80,10 +70,15 @@ class fvec(numpy.ndarray): · 21 unmodified lines
80 numpy.zeros : create a numpy array filled with zeros70 numpy.zeros : create a numpy array filled with zeros
81 numpy.array : create a numpy array from an existing object71 numpy.array : create a numpy array from an existing object
82 """72 """
83 def __new__(cls, input_arg=1024, **kwargs):73 def __new__(cls, input_arg=1024):
84 if isinstance(input_arg, int):74 if isinstance(input_arg, int):
85 if input_arg == 0:75 if input_arg == 0:
86 raise ValueError("vector length of 1 or more expected")76 raise ValueError("vector length of 1 or more expected")
87 return numpy.zeros(input_arg, dtype=float_type, **kwargs)77 return numpy.zeros(input_arg, dtype=float_type, order='C')
88 else:78 else:
89 return numpy.array(input_arg, dtype=float_type, **kwargs)79 np_input = numpy.array(input_arg, dtype=float_type, order='C')
80 if len(np_input.shape) != 1:
81 raise ValueError("input_arg should have shape (n,)")
82 if np_input.shape[0] == 0:
83 raise ValueError("vector length of 1 or more expected")
84 return np_input
python/tests/test_fvec.py+8−0
@@ -60,6 +60,14 @@ class aubio_fvec_wrong_values(TestCase): · 59 unmodified lines
60 self.assertRaises(IndexError, a.__getitem__, 3)60 self.assertRaises(IndexError, a.__getitem__, 3)
61 self.assertRaises(IndexError, a.__getitem__, 2)61 self.assertRaises(IndexError, a.__getitem__, 2)
62 62
63 def test_wrong_dimensions(self):
64 a = np.array([[[1, 2], [3, 4]]], dtype=float_type)
65 self.assertRaises(ValueError, fvec, a)
66
67 def test_wrong_size(self):
68 a = np.ndarray([0,], dtype=float_type)
69 self.assertRaises(ValueError, fvec, a)
70
63class aubio_wrong_fvec_input(TestCase):71class aubio_wrong_fvec_input(TestCase):
64 """ uses min_removal to test PyAubio_IsValidVector """72 """ uses min_removal to test PyAubio_IsValidVector """
65 73

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t