Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Leto committed Oct 3, 2008
1 parent 950f328 commit dc25479
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Vector.i
Expand Up @@ -213,7 +213,10 @@ You can also enter an array of indices to receive their corresponding values:

sub get {
my ($self, $indices) = @_;
return map { gsl_vector_get($self->{_vector}, $_ ) } @$indices ;
use Data::Dumper;
print "getting @$indices\n";
print Dumper [ $self->raw ];
return map { print "get idx $_\n"; gsl_vector_get($self->raw, $_ ) } @$indices ;
}

=head2 set()
Expand Down
24 changes: 24 additions & 0 deletions examples/vector/serialize
@@ -0,0 +1,24 @@
#!/usr/bin/perl -w

use strict;
use warnings;
use Data::Dumper;
use Math::GSL::Vector qw/:all/;
use Math::GSL::RNG qw/:all/;
use Storable;

if ( -e 'data' ) {
my $thawed = retrieve('data');
my $v = $thawed->{vector};
print "Thawed vector of length " . $v->length() . "\n";
print Dumper [ $v->as_list() ];
print join (" ", $v->as_list() ) . "\n";
} else {
my %data;
my $rng = Math::GSL::RNG->new;
my @stuff = map { $rng->get } (1..10) ;
my $vector = Math::GSL::Vector->new( \@stuff );
print "Serialized vector of length " . $vector->length() . "\n";
$data{vector} = $vector;
store \%data, 'data';
}
26 changes: 26 additions & 0 deletions examples/vector/speed
@@ -0,0 +1,26 @@
#!/usr/bin/perl -w

use strict;
use warnings;
use Math::GSL::Vector qw/:all/;
use Benchmark;
use Math::GSL::RNG qw/:all/;

my $min;
my $rng = Math::GSL::RNG->new;
my $num = 1000000;
my @stuff = map { $rng->get() } (1..$num);
my $vector = Math::GSL::Vector->new([@stuff]);


timethese(5000, {
'perl array ' => sub { $min = min(@stuff) },
'Math::GSL vector ' => sub { $min = $vector->min() },
});

sub min
{
$min = $_[0] < $min ? $_[0] : $min;
}


0 comments on commit dc25479

Please sign in to comment.