mirror of
https://github.com/mborgerding/kissfft.git
synced 2025-05-27 21:20:27 -04:00
converted testkiss.py from Numeric to numpy
This commit is contained in:
parent
8fedba4d91
commit
4faaa83075
1
Makefile
1
Makefile
@ -13,6 +13,7 @@ testall:
|
|||||||
make -C test DATATYPE=int16_t CFLAGADD="$(CFLAGADD)" test
|
make -C test DATATYPE=int16_t CFLAGADD="$(CFLAGADD)" test
|
||||||
make -C test DATATYPE=float CFLAGADD="$(CFLAGADD)" test
|
make -C test DATATYPE=float CFLAGADD="$(CFLAGADD)" test
|
||||||
make -C test DATATYPE=double CFLAGADD="$(CFLAGADD)" test
|
make -C test DATATYPE=double CFLAGADD="$(CFLAGADD)" test
|
||||||
|
echo "all tests passed"
|
||||||
|
|
||||||
tarball: clean
|
tarball: clean
|
||||||
hg archive -r v$(KFVER) -t tgz kiss_fft$(KFVER).tar.gz
|
hg archive -r v$(KFVER) -t tgz kiss_fft$(KFVER).tar.gz
|
||||||
|
@ -7,8 +7,7 @@ import random
|
|||||||
import struct
|
import struct
|
||||||
import popen2
|
import popen2
|
||||||
import getopt
|
import getopt
|
||||||
import Numeric
|
import numpy
|
||||||
import FFT
|
|
||||||
|
|
||||||
pi=math.pi
|
pi=math.pi
|
||||||
e=math.e
|
e=math.e
|
||||||
@ -26,7 +25,7 @@ elif datatype=='int16_t':
|
|||||||
fmt='h'
|
fmt='h'
|
||||||
minsnr=10
|
minsnr=10
|
||||||
elif datatype=='int32_t':
|
elif datatype=='int32_t':
|
||||||
fmt='l'
|
fmt='i'
|
||||||
elif datatype=='simd':
|
elif datatype=='simd':
|
||||||
fmt='4f'
|
fmt='4f'
|
||||||
sys.stderr.write('testkiss.py does not yet test simd')
|
sys.stderr.write('testkiss.py does not yet test simd')
|
||||||
@ -39,21 +38,21 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
def dopack(x,cpx=1):
|
def dopack(x,cpx=1):
|
||||||
x = Numeric.reshape( x, ( Numeric.size(x),) )
|
x = numpy.reshape( x, ( numpy.size(x),) )
|
||||||
|
|
||||||
if cpx:
|
if cpx:
|
||||||
s = ''.join( [ struct.pack(fmt*2,c.real,c.imag) for c in x ] )
|
s = ''.join( [ struct.pack(fmt*2,c.real,c.imag) for c in x ] )
|
||||||
else:
|
else:
|
||||||
s = ''.join( [ struct.pack(fmt,c) for c in x ] )
|
s = ''.join( [ struct.pack(fmt,c.real) for c in x ] )
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def dounpack(x,cpx):
|
def dounpack(x,cpx):
|
||||||
uf = fmt * ( len(x) / struct.calcsize(fmt) )
|
uf = fmt * ( len(x) / struct.calcsize(fmt) )
|
||||||
s = struct.unpack(uf,x)
|
s = struct.unpack(uf,x)
|
||||||
if cpx:
|
if cpx:
|
||||||
return Numeric.array(s[::2]) + Numeric.array( s[1::2] )*j
|
return numpy.array(s[::2]) + numpy.array( s[1::2] )*j
|
||||||
else:
|
else:
|
||||||
return Numeric.array(s )
|
return numpy.array(s )
|
||||||
|
|
||||||
def make_random(dims=[1]):
|
def make_random(dims=[1]):
|
||||||
res = []
|
res = []
|
||||||
@ -67,11 +66,11 @@ def make_random(dims=[1]):
|
|||||||
res.append( complex(r,i) )
|
res.append( complex(r,i) )
|
||||||
else:
|
else:
|
||||||
res.append( make_random( dims[1:] ) )
|
res.append( make_random( dims[1:] ) )
|
||||||
return Numeric.array(res)
|
return numpy.array(res)
|
||||||
|
|
||||||
def flatten(x):
|
def flatten(x):
|
||||||
ntotal = Numeric.product(Numeric.shape(x))
|
ntotal = numpy.size(x)
|
||||||
return Numeric.reshape(x,(ntotal,))
|
return numpy.reshape(x,(ntotal,))
|
||||||
|
|
||||||
def randmat( ndims ):
|
def randmat( ndims ):
|
||||||
dims=[]
|
dims=[]
|
||||||
@ -85,11 +84,11 @@ def randmat( ndims ):
|
|||||||
def test_fft(ndims):
|
def test_fft(ndims):
|
||||||
x=randmat( ndims )
|
x=randmat( ndims )
|
||||||
|
|
||||||
print 'dimensions=%s' % str( Numeric.shape(x) ),
|
|
||||||
if doreal:
|
if doreal:
|
||||||
xver = FFT.real_fftnd(x)
|
xver = numpy.fft.rfftn(x)
|
||||||
else:
|
else:
|
||||||
xver = FFT.fftnd(x)
|
xver = numpy.fft.fftn(x)
|
||||||
|
|
||||||
open('/tmp/fftexp.dat','w').write(dopack( flatten(xver) , True ) )
|
open('/tmp/fftexp.dat','w').write(dopack( flatten(xver) , True ) )
|
||||||
|
|
||||||
@ -97,8 +96,8 @@ def test_fft(ndims):
|
|||||||
err = xver - x2
|
err = xver - x2
|
||||||
errf = flatten(err)
|
errf = flatten(err)
|
||||||
xverf = flatten(xver)
|
xverf = flatten(xver)
|
||||||
errpow = Numeric.vdot(errf,errf)+1e-10
|
errpow = numpy.vdot(errf,errf)+1e-10
|
||||||
sigpow = Numeric.vdot(xverf,xverf)+1e-10
|
sigpow = numpy.vdot(xverf,xverf)+1e-10
|
||||||
snr = 10*math.log10(abs(sigpow/errpow) )
|
snr = 10*math.log10(abs(sigpow/errpow) )
|
||||||
print 'SNR (compared to NumPy) : %.1fdB' % float(snr)
|
print 'SNR (compared to NumPy) : %.1fdB' % float(snr)
|
||||||
|
|
||||||
@ -109,9 +108,9 @@ def test_fft(ndims):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def dofft(x):
|
def dofft(x):
|
||||||
dims=list( Numeric.shape(x) )
|
dims=list( numpy.shape(x) )
|
||||||
x = flatten(x)
|
x = flatten(x)
|
||||||
iscomp = (type(x[0]) == complex)
|
iscomp = (all(x.conj()==x)==False)
|
||||||
|
|
||||||
scale=1
|
scale=1
|
||||||
if datatype=='int16_t':
|
if datatype=='int16_t':
|
||||||
@ -126,6 +125,7 @@ def dofft(x):
|
|||||||
if doreal:
|
if doreal:
|
||||||
cmd += ' -R '
|
cmd += ' -R '
|
||||||
|
|
||||||
|
print cmd
|
||||||
p = popen2.Popen3(cmd )
|
p = popen2.Popen3(cmd )
|
||||||
|
|
||||||
open('/tmp/fftin.dat','w').write(dopack( x , iscomp ) )
|
open('/tmp/fftin.dat','w').write(dopack( x , iscomp ) )
|
||||||
@ -141,7 +141,7 @@ def dofft(x):
|
|||||||
res = scale * res
|
res = scale * res
|
||||||
|
|
||||||
p.wait()
|
p.wait()
|
||||||
return Numeric.reshape(res,dims)
|
return numpy.reshape(res,dims)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
opts,args = getopt.getopt(sys.argv[1:],'r')
|
opts,args = getopt.getopt(sys.argv[1:],'r')
|
||||||
|
Loading…
Reference in New Issue
Block a user