Changeset c4b2183


Ignore:
Timestamp:
Apr 25, 2016, 12:53:03 AM (8 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, pitchshift, sampler, timestretch, yinfft+
Children:
8bffcff
Parents:
fbcee4f
Message:

python/tests: use aubio.float_type

Location:
python/tests
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_filterbank.py

    rfbcee4f rc4b2183  
    66from math import pi
    77from numpy import array
    8 from aubio import cvec, filterbank
     8from aubio import cvec, filterbank, float_type
    99from utils import array_from_text_file
    1010
     
    1717  def test_set_coeffs(self):
    1818    f = filterbank(40, 512)
    19     r = random.random([40, int(512 / 2) + 1]).astype('float32')
     19    r = random.random([40, int(512 / 2) + 1]).astype(float_type)
    2020    f.set_coeffs(r)
    2121    assert_equal (r, f.get_coeffs())
     
    3636    f = filterbank(40, 512)
    3737    c = cvec(512)
    38     c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32')
     38    c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type)
    3939    assert_equal( f(c), 0)
    4040
     
    4242    f = filterbank(40, 512)
    4343    c = cvec(512)
    44     r = random.random([40, int(512 / 2) + 1]).astype('float32')
     44    r = random.random([40, int(512 / 2) + 1]).astype(float_type)
    4545    r /= r.sum()
    4646    f.set_coeffs(r)
    47     c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32')
     47    c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type)
    4848    assert_equal ( f(c) < 1., True )
    4949    assert_equal ( f(c) > 0., True )
     
    5353    c = cvec(512)
    5454    f.set_mel_coeffs_slaney(44100)
    55     c.norm[:] = random.random((int(512 / 2) + 1,)).astype('float32')
     55    c.norm[:] = random.random((int(512 / 2) + 1,)).astype(float_type)
    5656    assert_equal ( f(c) < 1., True )
    5757    assert_equal ( f(c) > 0., True )
  • python/tests/test_filterbank_mel.py

    rfbcee4f rc4b2183  
    44from numpy.testing import assert_equal, assert_almost_equal
    55from numpy import array, shape
    6 from aubio import cvec, filterbank
     6from aubio import cvec, filterbank, float_type
    77
    88class aubio_filterbank_mel_test_case(TestCase):
     
    2828    f = filterbank(9, 1024)
    2929    freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
    30     freqs = array(freq_list, dtype = 'float32')
     30    freqs = array(freq_list, dtype = float_type)
    3131    f.set_triangle_bands(freqs, 48000)
    3232    f.get_coeffs().T
     
    3636    f = filterbank(9, 1024)
    3737    freq_list = [40, 80, 200, 400, 800, 1600, 3200, 6400, 12800, 15000, 24000]
    38     freqs = array(freq_list, dtype = 'float32')
     38    freqs = array(freq_list, dtype = float_type)
    3939    f.set_triangle_bands(freqs, 48000)
    4040    f.get_coeffs().T
  • python/tests/test_fvec.py

    rfbcee4f rc4b2183  
    44from numpy.testing import assert_equal, assert_almost_equal
    55from aubio import fvec, zero_crossing_rate, alpha_norm, min_removal
     6from aubio import float_type
    67from numpy import array, shape
     8
     9wrong_type = 'float32' if float_type == 'float64' else 'float64'
    710
    811default_size = 512
     
    1215    def test_vector_created_with_zeroes(self):
    1316        a = fvec(10)
    14         assert a.dtype == 'float32'
     17        assert a.dtype == float_type
    1518        assert a.shape == (10,)
    1619        assert_equal (a, 0)
     
    1821    def test_vector_create_with_list(self):
    1922        a = fvec([0,1,2,3])
    20         assert a.dtype == 'float32'
     23        assert a.dtype == float_type
    2124        assert a.shape == (4,)
    2225        assert_equal (list(range(4)), a)
     
    5861        a[1] = 1
    5962        self.assertEqual (alpha_norm(a, 1), 1)
    60         a = array([0, 1], dtype='float32')
     63        a = array([0, 1], dtype=float_type)
    6164        from math import sqrt
    6265        assert_almost_equal (alpha_norm(a, 2), sqrt(2)/2.)
     
    6770    def test_alpha_norm_of_array_of_float32(self):
    6871        # check scalar fails
    69         a = array(1, dtype = 'float32')
     72        a = array(1, dtype = float_type)
    7073        self.assertRaises (ValueError, alpha_norm, a, 1)
    7174        # check 2d array fails
    72         a = array([[2],[4]], dtype = 'float32')
     75        a = array([[2],[4]], dtype = float_type)
    7376        self.assertRaises (ValueError, alpha_norm, a, 1)
    7477        # check 1d array
    75         a = array(range(10), dtype = 'float32')
     78        a = array(range(10), dtype = float_type)
    7679        self.assertEqual (alpha_norm(a, 1), 4.5)
    7780
     
    8992
    9093    def test_zero_crossing_rate(self):
    91         a = array([0,1,-1], dtype='float32')
     94        a = array([0,1,-1], dtype=float_type)
    9295        assert_almost_equal (zero_crossing_rate(a), 1./3. )
    93         a = array([0.]*100, dtype='float32')
     96        a = array([0.]*100, dtype=float_type)
    9497        self.assertEqual (zero_crossing_rate(a), 0 )
    95         a = array([-1.]*100, dtype='float32')
     98        a = array([-1.]*100, dtype=float_type)
    9699        self.assertEqual (zero_crossing_rate(a), 0 )
    97         a = array([1.]*100, dtype='float32')
     100        a = array([1.]*100, dtype=float_type)
    98101        self.assertEqual (zero_crossing_rate(a), 0 )
    99102
    100103    def test_alpha_norm_of_array_of_float64(self):
    101104        # check scalar fail
    102         a = array(1, dtype = 'float64')
     105        a = array(1, dtype = wrong_type)
    103106        self.assertRaises (ValueError, alpha_norm, a, 1)
    104107        # check 3d array fail
    105         a = array([[[1,2],[3,4]]], dtype = 'float64')
     108        a = array([[[1,2],[3,4]]], dtype = wrong_type)
    106109        self.assertRaises (ValueError, alpha_norm, a, 1)
    107110        # check float64 1d array fail
    108         a = array(list(range(10)), dtype = 'float64')
     111        a = array(list(range(10)), dtype = wrong_type)
    109112        self.assertRaises (ValueError, alpha_norm, a, 1)
    110113        # check float64 2d array fail
    111         a = array([list(range(10)), list(range(10))], dtype = 'float64')
     114        a = array([list(range(10)), list(range(10))], dtype = wrong_type)
    112115        self.assertRaises (ValueError, alpha_norm, a, 1)
    113116
    114117    def test_fvec_min_removal_of_array(self):
    115         a = array([20,1,19], dtype='float32')
     118        a = array([20,1,19], dtype=float_type)
    116119        b = min_removal(a)
    117120        assert_equal (array(b), [19, 0, 18])
     
    122125
    123126    def test_fvec_min_removal_of_array_float64(self):
    124         a = array([20,1,19], dtype='float64')
     127        a = array([20,1,19], dtype=wrong_type)
    125128        self.assertRaises (ValueError, min_removal, a)
    126129
    127130    def test_fvec_min_removal_of_fvec(self):
    128131        a = fvec(3)
    129         a = array([20, 1, 19], dtype = 'float32')
     132        a = array([20, 1, 19], dtype = float_type)
    130133        b = min_removal(a)
    131134        assert_equal (array(b), [19, 0, 18])
  • python/tests/test_musicutils.py

    rfbcee4f rc4b2183  
    88from aubio import window, level_lin, db_spl, silence_detection, level_detection
    99
    10 from aubio import fvec
     10from aubio import fvec, float_type
    1111
    1212class aubio_window(TestCase):
     
    5454    def test_minus_ones_is_one(self):
    5555        from numpy import ones
    56         assert_equal(level_lin(-ones(1024, dtype="float32")), 1.)
     56        assert_equal(level_lin(-ones(1024, dtype = float_type)), 1.)
    5757
    5858class aubio_db_spl(TestCase):
     
    7474    def test_minus_ones_is_zero(self):
    7575        from numpy import ones
    76         assert_equal(db_spl(-ones(1024, dtype="float32")), 0.)
     76        assert_equal(db_spl(-ones(1024, dtype = float_type)), 0.)
    7777
    7878class aubio_silence_detection(TestCase):
     
    9494    def test_minus_ones_is_zero(self):
    9595        from numpy import ones
    96         assert silence_detection(ones(1024, dtype="float32"), -70) == 0
     96        assert silence_detection(ones(1024, dtype = float_type), -70) == 0
    9797
    9898class aubio_level_detection(TestCase):
     
    114114    def test_minus_ones_is_zero(self):
    115115        from numpy import ones
    116         assert level_detection(ones(1024, dtype="float32"), -70) == 0
     116        assert level_detection(ones(1024, dtype = float_type), -70) == 0
    117117
    118118if __name__ == '__main__':
  • python/tests/test_pitch.py

    rfbcee4f rc4b2183  
    55from numpy import random, sin, arange, mean, median, isnan
    66from math import pi
    7 from aubio import fvec, pitch, freqtomidi
     7from aubio import fvec, pitch, freqtomidi, float_type
    88
    99class aubio_pitch_Good_Values(TestCase):
     
    5151
    5252    def build_sinusoid(self, length, freq, samplerate):
    53         return sin( 2. * pi * arange(length).astype('float32') * freq / samplerate)
     53        return sin( 2. * pi * arange(length).astype(float_type) * freq / samplerate)
    5454
    5555    def run_pitch(self, p, input_vec, freq):
  • python/tests/test_specdesc.py

    rfbcee4f rc4b2183  
    33from numpy.testing import TestCase, assert_equal, assert_almost_equal
    44from numpy import random, arange, log, zeros
    5 from aubio import specdesc, cvec
     5from aubio import specdesc, cvec, float_type
    66from math import pi
    77
     
    3838          #print "%20s" % method, str(o(spec))
    3939          o(spec)
    40           spec.norm = random.random_sample((len(spec.norm),)).astype('float32')
    41           spec.phas = random.random_sample((len(spec.phas),)).astype('float32')
     40          spec.norm = random.random_sample((len(spec.norm),)).astype(float_type)
     41          spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
    4242          #print "%20s" % method, str(o(spec))
    4343          assert (o(spec) != 0.)
     
    6161        # phase of zeros is zero
    6262        assert_equal (o(spec), 0.)
    63         spec.phas = random.random_sample((len(spec.phas),)).astype('float32')
     63        spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
    6464        # phase of random is not zero
    6565        spec.norm[:] = 1
     
    7171        # specdiff of zeros is zero
    7272        assert_equal (o(spec), 0.)
    73         spec.phas = random.random_sample((len(spec.phas),)).astype('float32')
     73        spec.phas = random.random_sample((len(spec.phas),)).astype(float_type)
    7474        # phase of random is not zero
    7575        spec.norm[:] = 1
     
    8080        c = cvec()
    8181        assert_equal( 0., o(c))
    82         a = arange(c.length, dtype='float32')
     82        a = arange(c.length, dtype=float_type)
    8383        c.norm = a
    8484        assert_equal (a, c.norm)
     
    8989        c = cvec()
    9090        assert_equal( 0., o(c))
    91         a = arange(c.length, dtype='float32')
     91        a = arange(c.length, dtype=float_type)
    9292        c.norm = a
    9393        assert_equal (a, c.norm)
     
    102102        c = cvec()
    103103        assert_equal( 0., o(c))
    104         a = arange(c.length, dtype='float32')
     104        a = arange(c.length, dtype=float_type)
    105105        c.norm = a
    106106        assert_almost_equal( sum(a * log(1.+ a/1.e-1 ) ) / o(c), 1., decimal=6)
     
    110110        c = cvec()
    111111        assert_equal( 0., o(c))
    112         a = arange(c.length, dtype='float32')
     112        a = arange(c.length, dtype=float_type)
    113113        c.norm = a
    114114        assert_almost_equal( sum(log(1.+ a/1.e-1 ) ) / o(c), 1, decimal=6)
     
    118118        c = cvec()
    119119        assert_equal( 0., o(c))
    120         a = arange(c.length, dtype='float32')
     120        a = arange(c.length, dtype=float_type)
    121121        c.norm = a
    122122        assert_equal( sum(a), o(c))
    123123        assert_equal( 0, o(c))
    124         c.norm = zeros(c.length, dtype='float32')
     124        c.norm = zeros(c.length, dtype=float_type)
    125125        assert_equal( 0, o(c))
    126126
     
    130130        # make sure centroid of zeros is zero
    131131        assert_equal( 0., o(c))
    132         a = arange(c.length, dtype='float32')
     132        a = arange(c.length, dtype=float_type)
    133133        c.norm = a
    134134        centroid = sum(a*a) / sum(a)
     
    141141        o = specdesc("spread")
    142142        c = cvec(2048)
    143         ramp = arange(c.length, dtype='float32')
     143        ramp = arange(c.length, dtype=float_type)
    144144        assert_equal( 0., o(c))
    145145
     
    154154        c = cvec()
    155155        assert_equal( 0., o(c))
    156         a = arange(c.length, dtype='float32')
     156        a = arange(c.length, dtype=float_type)
    157157        c.norm = a
    158158        centroid = sum(a*a) / sum(a)
     
    168168        c = cvec()
    169169        assert_equal( 0., o(c))
    170         a = arange(c.length, dtype='float32')
     170        a = arange(c.length, dtype=float_type)
    171171        c.norm = a
    172172        centroid = sum(a*a) / sum(a)
     
    179179        c = cvec()
    180180        assert_equal( 0., o(c))
    181         a = arange(c.length * 2, 0, -2, dtype='float32')
    182         k = arange(c.length, dtype='float32')
     181        a = arange(c.length * 2, 0, -2, dtype=float_type)
     182        k = arange(c.length, dtype=float_type)
    183183        c.norm = a
    184184        num = len(a) * sum(k*a) - sum(k)*sum(a)
     
    187187        assert_almost_equal (slope, o(c), decimal = 5)
    188188
    189         a = arange(0, c.length * 2, +2, dtype='float32')
     189        a = arange(0, c.length * 2, +2, dtype=float_type)
    190190        c.norm = a
    191191        num = len(a) * sum(k*a) - sum(k)*sum(a)
     
    194194        assert_almost_equal (slope, o(c), decimal = 5)
    195195
    196         a = arange(0, c.length * 2, +2, dtype='float32')
     196        a = arange(0, c.length * 2, +2, dtype=float_type)
    197197        c.norm = a * 2
    198198        assert_almost_equal (slope, o(c), decimal = 5)
     
    202202        c = cvec()
    203203        assert_equal( 0., o(c))
    204         a = arange(c.length * 2, 0, -2, dtype='float32')
    205         k = arange(c.length, dtype='float32')
     204        a = arange(c.length * 2, 0, -2, dtype=float_type)
     205        k = arange(c.length, dtype=float_type)
    206206        c.norm = a
    207207        decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:])
    208208        assert_almost_equal (decrease, o(c), decimal = 5)
    209209
    210         a = arange(0, c.length * 2, +2, dtype='float32')
     210        a = arange(0, c.length * 2, +2, dtype=float_type)
    211211        c.norm = a
    212212        decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:])
    213213        assert_almost_equal (decrease, o(c), decimal = 5)
    214214
    215         a = arange(0, c.length * 2, +2, dtype='float32')
     215        a = arange(0, c.length * 2, +2, dtype=float_type)
    216216        c.norm = a * 2
    217217        decrease = sum((a[1:] - a [0]) / k[1:]) / sum(a[1:])
     
    222222        c = cvec()
    223223        assert_equal( 0., o(c))
    224         a = arange(c.length * 2, 0, -2, dtype='float32')
    225         k = arange(c.length, dtype='float32')
     224        a = arange(c.length * 2, 0, -2, dtype=float_type)
     225        k = arange(c.length, dtype=float_type)
    226226        c.norm = a
    227227        cumsum = .95*sum(a*a)
Note: See TracChangeset for help on using the changeset viewer.