Hi,
I am trying to access C Code in Python,for that I am using Ctypes built-in in Python.
A function in dll accepts 6 input parameters,Here is my Code.
Here ,input is a huge array which consists of Complex numbers.
buffer_size = c_int(len(input))
real_array = (c_float * buffer_size.value)()
for i in range(0,len(input)-1):
real_array[i] = input[i].real
imag_array = (c_float * buffer_size.value)()
for i in range(0,len(input)-1):
imag_array[i] = input[i].imag
sign = c_int(-1)
RealOutput = (c_float * buffer_size.value)()
ImagOutput = (c_float * buffer_size.value)()
cfft( real_array ,imag_array,RealOutput,ImagOutput,sign.value, buffer_size.value)
The Inputs passed were received by dll,in dll inputs are manipulated,real values,Imaginary values are stored in pointers RealOutput,ImagOutput respectively.
while trying to print the data at RealOutput,ImagOutput
Output:
pOpReal[1] is -1.#QNAN0
pOpImag[1] is -1.#QNAN0
pOpReal[2] is -1.#QNAN0
pOpImag[2] is -1.#QNAN0
pOpReal[3] is -1.#QNAN0
pOpImag[3] is -1.#QNAN0
pOpReal[4] is -1.#QNAN0
pOpImag[4] is -1.#QNAN0
pOpReal[5] is -1.#QNAN0
pOpImag[5] is -1.#QNAN0
In Ruby:
require 'ffi'
pointers = Array.new( 4 ) { FFI::MemoryPointer.new( :float, size ) }
* input is huge array of complex numbers
Copying Input :
real_input = input.map { |c| c.to_c.real }
imag_input = input.map { |c| c.to_c.imag }
pointers[RealInput].write_array_of_float real_input
pointers[ImagInput].write_array_of_float imag_input
Copying Output:
real_output = pointers[RealOutput].get_array_of_float( 0, buffer_size)
imag_output = pointers[ImagOutput].get_array_of_float( 0, buffer_size)
Output :
pOpReal[1] is -0.000063
pOpImag[1] is -0.005755
pOpReal[2] is -0.000076
pOpImag[2] is 0.015815
pOpReal[3] is 0.010016
pOpImag[3] is -0.011680
pOpReal[4] is -0.000109
pOpImag[4] is -0.006708
pOpReal[5] is -0.012282
Successfully got the output.
Finally
1)Is there anything wrong in my approach
2)Is there any way to create MemoryPointers in Python like ruby.
Thanks in advance.