mirror of
https://github.com/mborgerding/kissfft.git
synced 2025-05-27 21:20:27 -04:00
no longer use deprecated popen2 module
This commit is contained in:
parent
bc6a534c7b
commit
e931ae3d4b
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# Copyright (c) 2003-2010, Mark Borgerding. All rights reserved.
|
# Copyright (c) 2003-2019, Mark Borgerding. All rights reserved.
|
||||||
# This file is part of KISS FFT - https://github.com/mborgerding/kissfft
|
# This file is part of KISS FFT - https://github.com/mborgerding/kissfft
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: BSD-3-Clause
|
# SPDX-License-Identifier: BSD-3-Clause
|
||||||
@ -10,13 +10,11 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import struct
|
import struct
|
||||||
import popen2
|
|
||||||
import getopt
|
import getopt
|
||||||
import numpy
|
import numpy
|
||||||
|
|
||||||
pi=math.pi
|
pi=math.pi
|
||||||
e=math.e
|
e=math.e
|
||||||
j=complex(0,1)
|
|
||||||
|
|
||||||
doreal=0
|
doreal=0
|
||||||
|
|
||||||
@ -55,7 +53,7 @@ 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] )*j
|
return numpy.array(s[::2]) + numpy.array( s[1::2] )*1j
|
||||||
else:
|
else:
|
||||||
return numpy.array(s )
|
return numpy.array(s )
|
||||||
|
|
||||||
@ -89,14 +87,11 @@ def randmat( ndims ):
|
|||||||
def test_fft(ndims):
|
def test_fft(ndims):
|
||||||
x=randmat( ndims )
|
x=randmat( ndims )
|
||||||
|
|
||||||
|
|
||||||
if doreal:
|
if doreal:
|
||||||
xver = numpy.fft.rfftn(x)
|
xver = numpy.fft.rfftn(x)
|
||||||
else:
|
else:
|
||||||
xver = numpy.fft.fftn(x)
|
xver = numpy.fft.fftn(x)
|
||||||
|
|
||||||
open('/tmp/fftexp.dat','w').write(dopack( flatten(xver) , True ) )
|
|
||||||
|
|
||||||
x2=dofft(x,doreal)
|
x2=dofft(x,doreal)
|
||||||
err = xver - x2
|
err = xver - x2
|
||||||
errf = flatten(err)
|
errf = flatten(err)
|
||||||
@ -130,15 +125,14 @@ def dofft(x,isreal):
|
|||||||
cmd += ' -R '
|
cmd += ' -R '
|
||||||
|
|
||||||
print cmd
|
print cmd
|
||||||
p = popen2.Popen3(cmd )
|
|
||||||
|
|
||||||
open('/tmp/fftin.dat','w').write(dopack( x , isreal==False ) )
|
from subprocess import Popen,PIPE
|
||||||
|
p = Popen(cmd,shell=True,stdin=PIPE,stdout=PIPE )
|
||||||
|
|
||||||
p.tochild.write( dopack( x , isreal==False ) )
|
p.stdin.write( dopack( x , isreal==False ) )
|
||||||
p.tochild.close()
|
p.stdin.close()
|
||||||
|
|
||||||
res = dounpack( p.fromchild.read() , 1 )
|
res = dounpack( p.stdout.read() , 1 )
|
||||||
open('/tmp/fftout.dat','w').write(dopack( flatten(res) , True ) )
|
|
||||||
if doreal:
|
if doreal:
|
||||||
dims[-1] = int( dims[-1]/2 ) + 1
|
dims[-1] = int( dims[-1]/2 ) + 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user