Changeset 7a54b37


Ignore:
Timestamp:
Oct 31, 2018, 7:36:31 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
Children:
088760e, 2410f57a
Parents:
07382d8
Message:

Merge branch 'fix/pyfvec'

Location:
python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/lib/aubio/__init__.py

    r07382d8 r7a54b37  
    3131
    3232class fvec(numpy.ndarray):
    33     """fvec(input_arg=1024, **kwargs)
     33    """fvec(input_arg=1024)
    3434    A vector holding float samples.
    3535
     
    4444        Can be a positive integer, or any object that can be converted to
    4545        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,)`.
    5646
    5747    Examples
     
    8171    numpy.array : create a numpy array from an existing object
    8272    """
    83     def __new__(cls, input_arg=1024, **kwargs):
     73    def __new__(cls, input_arg=1024):
    8474        if isinstance(input_arg, int):
    8575            if input_arg == 0:
    8676                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')
    8878        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

    r07382d8 r7a54b37  
    6060        self.assertRaises(IndexError, a.__getitem__, 3)
    6161        self.assertRaises(IndexError, a.__getitem__, 2)
     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)
    6270
    6371class aubio_wrong_fvec_input(TestCase):
Note: See TracChangeset for help on using the changeset viewer.