From a7614c1d0db3127d21604ac5c5cf05929ff36991 Mon Sep 17 00:00:00 2001 From: Jonathan Leto Date: Wed, 3 Sep 2008 00:47:11 -0700 Subject: [PATCH] FFT typemap and test --- FFT.i | 22 +++++++++++++--------- gsl_typemaps.i | 2 +- t/FFT.t | 42 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/FFT.i b/FFT.i index 5bc5552..5ffbc0c 100644 --- a/FFT.i +++ b/FFT.i @@ -2,8 +2,19 @@ %include "typemaps.i" %include "gsl_typemaps.i" -%typemap(argout) double [] %{ -%} + +%typemap(argout) (double data[], const size_t stride, const size_t n) { + int i=0; + AV* tempav = newAV(); + + while( i < $3 ) { + av_push(tempav, newSVnv((double) $1[i])); + i++; + } + + $result = sv_2mortal( newRV_noinc( (SV*) tempav) ); + argvi++; +} %{ @@ -19,13 +30,6 @@ %include "gsl/gsl_fft_complex.h" %include "gsl/gsl_fft_halfcomplex.h" %include "gsl/gsl_fft_real.h" -/* -int gsl_fft_real_radix2_transform (double *INOUT, size_t - STRIDE, size_t N); -%apply double *INOUT { double DATA[] }; -*/ - - %perlcode %{ @EXPORT_complex = qw/ diff --git a/gsl_typemaps.i b/gsl_typemaps.i index 45cb5e7..e2fb576 100644 --- a/gsl_typemaps.i +++ b/gsl_typemaps.i @@ -64,7 +64,7 @@ double x; if (!SvROK($input)) { - croak("Math::GSL : not a reference value!"); + croak("Math::GSL : %s is not a reference value!", $1_name); } if (Callbacks == (HV*)NULL) Callbacks = newHV(); diff --git a/t/FFT.t b/t/FFT.t index 78d397a..4e46898 100644 --- a/t/FFT.t +++ b/t/FFT.t @@ -8,7 +8,8 @@ use Data::Dumper; use Math::GSL::Errno qw/:all/; use strict; -BEGIN { gsl_set_error_handler_off(); } +BEGIN { gsl_set_error_handler_off() } + sub make_fixture : Test(setup) { } @@ -18,8 +19,42 @@ sub teardown : Test(teardown) { sub FFT_REAL_RADIX2_TRANSFORM : Tests { my $data = [ (0) x 5, (1) x 22, (0) x 5 ]; - ok_status( gsl_fft_real_radix2_transform ($data, 1, 32)); - print Dumper [ $data ]; + my ($status1, $pass1 ) = gsl_fft_real_radix2_transform ($data, 1, 32); + ok_status($status1); + ok_similar( $pass1, [ + 22, + -8.44205264582682, + -4.64465605976076, + -0.643126602526688, + 1.70710678118655, + 1.8349201998544, + 0.572726230154202, + -0.676964287646119, + -1, + -0.455944707054924, + 0.255700894591988, + 0.524240654352147, + 0.292893218813453, + -0.059180002187481, + -0.183771064985432, + -0.0818926089645147, + 0, + -0.831469612302545, + -0.923879532511287, + -0.195090322016128, + 0.707106781186547, + 0.98078528040323, + 0.38268343236509, + -0.555570233019602, + -1, + -0.555570233019602, + 0.38268343236509, + 0.980785280403231, + 0.707106781186547, + -0.195090322016128, + -0.923879532511287, + -0.831469612302545 + ]); } sub FFT_COMPLEX_RADIX2_FORWARD : Tests @@ -31,6 +66,7 @@ sub FFT_VARS : Tests { cmp_ok( $gsl_fft_forward, '==', -1, 'gsl_fft_forward' ); cmp_ok( $gsl_fft_backward, '==', +1, 'gsl_fft_backward' ); } + sub WAVETABLE_ALLOC_FREE: Tests { my $wavetable = gsl_fft_complex_wavetable_alloc(42); isa_ok($wavetable, 'Math::GSL::FFT' ); -- 2.11.4.GIT