more modern python

This commit is contained in:
Mark Borgerding 2019-02-01 07:38:42 -05:00
parent e931ae3d4b
commit a7ea65edb1

View File

@ -4,7 +4,7 @@
# #
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# See COPYING file for more information. # See COPYING file for more information.
from __future__ import division,print_function
import math import math
import sys import sys
import os import os
@ -50,7 +50,7 @@ def dopack(x,cpx=1):
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 numpy.array(s[::2]) + numpy.array( s[1::2] )*1j return numpy.array(s[::2]) + numpy.array( s[1::2] )*1j
@ -99,12 +99,12 @@ def test_fft(ndims):
errpow = numpy.vdot(errf,errf)+1e-10 errpow = numpy.vdot(errf,errf)+1e-10
sigpow = numpy.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) : {0:.1f}dB'.format( float(snr) ) )
if snr<minsnr: if snr<minsnr:
print 'xver=',xver print( 'xver=',xver )
print 'x2=',x2 print( 'x2=',x2)
print 'err',err print( 'err',err)
sys.exit(1) sys.exit(1)
def dofft(x,isreal): def dofft(x,isreal):
@ -124,7 +124,7 @@ def dofft(x,isreal):
if doreal: if doreal:
cmd += ' -R ' cmd += ' -R '
print cmd print( cmd)
from subprocess import Popen,PIPE from subprocess import Popen,PIPE
p = Popen(cmd,shell=True,stdin=PIPE,stdout=PIPE ) p = Popen(cmd,shell=True,stdin=PIPE,stdout=PIPE )
@ -149,9 +149,9 @@ def main():
doreal = opts.has_key('-r') doreal = opts.has_key('-r')
if doreal: if doreal:
print 'Testing multi-dimensional real FFTs' print( 'Testing multi-dimensional real FFTs')
else: else:
print 'Testing multi-dimensional FFTs' print( 'Testing multi-dimensional FFTs')
for dim in range(1,4): for dim in range(1,4):
test_fft( dim ) test_fft( dim )