#!/usr/bin/perl # # Last saved: Sat 24 Apr 2010 10:40:53 AM use strict; use warnings; use PDL; use Test::More; # Here's the function that is being tested sub PDL::Core::new_pdl_from_string { my ($new, $value, $this, $type) = @_; # some basic checks that can/should be run on everything. # Make sure that each closing bracket followed by an opening bracket # has a comma in between them: $value =~ s/\]\s*\[/],[/g; # Semicolons require special handling: if ($value =~ /;/) { $value =~ s/(\[[^\]]+;[^\]]+\])/[$1]/g; $value =~ s/;/],[/g; } # Append zeroes after ending decimal points $value =~ s/(\d)\.\s+/$1.0 /g; # Insert zeroes in front of starting decimal points $value =~ s/([^\d])\./${1}0./g; # make unambiguous addition/subtraction (white-space on both sides # of operator) by removing white-space from both sides $value =~ s/(\d)\s+([+-])\s+(?=[\d])/$1$2/g; # Replace white-space separators with commas: $value =~ s/([.\d])\s+(?=[+\-\d])/$1,/g; # Let's see if the darn thing compiles as normal Perl code, in which # case we just assume the result is a stringified bunch of nested # arrays: my $val = eval $value; if (ref $val eq 'ARRAY') { return PDL::Core::pdl_avref($val,$this,$type); } else { barf "PDL::Core::new_pdl_from_string: error happened!\n"; } } my $compare = pdl([ [1, 0, 8], [6, 3, 5], [3, 0, 5], [2, 4, 2] ]); #print "Compare is $compare\n"; my $test_string = <