Ignore:
Timestamp:
Oct 31, 2018, 10:26:52 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/constantq
Children:
c03d191
Parents:
45c2c5c (diff), 7a54b37 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feature/constantq

File:
1 edited

Legend:

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

    r45c2c5c r088760e  
    11#! /usr/bin/env python
     2# -*- coding: utf8 -*-
     3
     4"""
     5aubio
     6=====
     7
     8Provides a number of classes and functions for music and audio signal
     9analysis.
     10
     11How to use the documentation
     12----------------------------
     13
     14Documentation of the python module is available as docstrings provided
     15within the code, and a reference guide available online from `the
     16aubio homepage <https://aubio.org/documentation>`_.
     17
     18The docstrings examples are written assuming `aubio` and `numpy` have been
     19imported with:
     20
     21>>> import aubio
     22>>> import numpy as np
     23"""
    224
    325import numpy
     
    931
    1032class fvec(numpy.ndarray):
    11     """a numpy vector holding audio samples"""
     33    """fvec(input_arg=1024)
     34    A vector holding float samples.
    1235
    13     def __new__(cls, input_arg=1024, **kwargs):
     36    If `input_arg` is an `int`, a 1-dimensional vector of length `input_arg`
     37    will be created and filled with zeros. Otherwise, if `input_arg` is an
     38    `array_like` object, it will be converted to a 1-dimensional vector of
     39    type :data:`float_type`.
     40
     41    Parameters
     42    ----------
     43    input_arg : `int` or `array_like`
     44        Can be a positive integer, or any object that can be converted to
     45        a numpy array with :func:`numpy.array`.
     46
     47    Examples
     48    --------
     49    >>> aubio.fvec(10)
     50    array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32)
     51    >>> aubio.fvec([0,1,2])
     52    array([0., 1., 2.], dtype=float32)
     53    >>> a = np.arange(10); type(a), type(aubio.fvec(a))
     54    (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)
     55    >>> a.dtype, aubio.fvec(a).dtype
     56    (dtype('int64'), dtype('float32'))
     57
     58    Notes
     59    -----
     60
     61    In the Python world, `fvec` is simply a subclass of
     62    :class:`numpy.ndarray`. In practice, any 1-dimensional `numpy.ndarray` of
     63    `dtype` :data:`float_type` may be passed to methods accepting
     64    `fvec` as parameter. For instance, `sink()` or `pvoc()`.
     65
     66    See Also
     67    --------
     68    cvec : a container holding spectral data
     69    numpy.ndarray : parent class of :class:`fvec`
     70    numpy.zeros : create a numpy array filled with zeros
     71    numpy.array : create a numpy array from an existing object
     72    """
     73    def __new__(cls, input_arg=1024):
    1474        if isinstance(input_arg, int):
    1575            if input_arg == 0:
    1676                raise ValueError("vector length of 1 or more expected")
    17             return numpy.zeros(input_arg, dtype=float_type, **kwargs)
     77            return numpy.zeros(input_arg, dtype=float_type, order='C')
    1878        else:
    19             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
Note: See TracChangeset for help on using the changeset viewer.