Ignore:
Timestamp:
Apr 25, 2016, 12:53:03 AM (4 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
8bffcff
Parents:
fbcee4f
Message:

python/tests: use aubio.float_type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.