From 9c2240d10d1ea1442580299945a2bcd98031b881 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 22 Nov 2008 18:50:28 -0800 Subject: [PATCH] Add support for creating VectorComplex objects with Math::Complex objects --- pod/VectorComplex.pod | 7 +++++++ t/VectorComplex.t | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/pod/VectorComplex.pod b/pod/VectorComplex.pod index 1426bb9..8ee77f3 100644 --- a/pod/VectorComplex.pod +++ b/pod/VectorComplex.pod @@ -4,6 +4,8 @@ use Data::Dumper; use Carp qw/croak/; use Math::GSL::Errno qw/:all/; use Math::GSL::BLAS qw/gsl_blas_ddot/; +use Math::GSL::Complex qw/:all/; +use Math::Complex; use overload '*' => \&_multiplication, '+' => \&_addition, @@ -64,11 +66,16 @@ You can also create and set directly the values of the vector like this : my $vector = Math::GSL::VectorComplex->new([2,4,1]); =cut + sub new { my ($class, $values) = @_; my $length = $#$values; my $this = {}; my $vector; + + # we expected $values to have Math::Complex objects + @$values = map { gsl_complex_rect(Re($_), Im($_)) } @$values; + if ( ref $values eq 'ARRAY' ){ die __PACKAGE__.'::new($x) - $x must be a nonempty array reference' if $length == -1; $vector = gsl_vector_complex_alloc($length+1); diff --git a/t/VectorComplex.t b/t/VectorComplex.t index 1be0bd7..cb9422c 100755 --- a/t/VectorComplex.t +++ b/t/VectorComplex.t @@ -24,5 +24,9 @@ sub GSL_VECTOR_COMPLEX_NEW : Tests { my $u = Math::GSL::VectorComplex->new(10); isa_ok($u, 'Math::GSL::VectorComplex'); ok( $u->length == 10, 'length'); + + my $z = Math::Complex->make(2,5); + my $v = Math::GSL::VectorComplex->new([ $z, $z ** 2 ] ); + isa_ok($v, 'Math::GSL::VectorComplex'); } Test::Class->runtests; -- 2.11.4.GIT