"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "t/matrixops.t" between
PDL-2.074.tar.gz and PDL-2.075.tar.gz

About: PDL (Perl Data Language) aims to turn perl into an efficient numerical language for scientific computing (similar to IDL and MatLab).

matrixops.t  (PDL-2.074):matrixops.t  (PDL-2.075)
skipping to change at line 80 skipping to change at line 80
[ -2.1111111 1.1111111 -0.33333333] [ -2.1111111 1.1111111 -0.33333333]
[ 1.7222222 -0.72222222 0.16666667] [ 1.7222222 -0.72222222 0.16666667]
] ]
EOF EOF
check_inplace($pa, sub { inv($_[0], $opt) }, $inv_expected, "inv 3x3"); check_inplace($pa, sub { inv($_[0], $opt) }, $inv_expected, "inv 3x3");
ok(ref ($opt->{lu}->[0]) eq 'PDL',"inverse: lu_decomp first entry is an ndarray" ); ok(ref ($opt->{lu}->[0]) eq 'PDL',"inverse: lu_decomp first entry is an ndarray" );
ok(tapprox(matmult($inv_expected,$pa),identity(3),$tol),"matrix mult by its inve rse gives identity matrix"); ok(tapprox(matmult($inv_expected,$pa),identity(3),$tol),"matrix mult by its inve rse gives identity matrix");
} }
{ {
### Check inv() with added thread dims (simple check) ### Check inv() with added broadcast dims (simple check)
my $C22 = pdl([5,5],[5,7.5]); my $C22 = pdl([5,5],[5,7.5]);
my $inv_expected = pdl([0.6, -0.4], [-0.4, 0.4]); my $inv_expected = pdl([0.6, -0.4], [-0.4, 0.4]);
check_inplace($C22, sub { $_[0]->inv }, $inv_expected, "inv 2x2"); check_inplace($C22, sub { $_[0]->inv }, $inv_expected, "inv 2x2");
check_inplace($C22->dummy(2,2), sub { $_[0]->inv }, $inv_expected->dummy(2,2), " inv 2x2 extra dim"); check_inplace($C22->dummy(2,2), sub { $_[0]->inv }, $inv_expected->dummy(2,2), " inv 2x2 extra dim");
} }
{ {
### Check inv() for matrices with added thread dims (bug #3172882 on sf.net) ### Check inv() for matrices with added broadcast dims (bug #3172882 on sf.net)
my $a334 = pdl <<'EOF'; my $a334 = pdl <<'EOF';
[ [
[ [
[ 1 0 4] [ 1 0 4]
[-1 -1 -3] [-1 -1 -3]
[ 0 1 0] [ 0 1 0]
] ]
[ [
[ 4 -4 -5] [ 4 -4 -5]
[ 1 -5 -3] [ 1 -5 -3]
skipping to change at line 157 skipping to change at line 157
my $m1 = pdl [[1,2],[3,4]]; # det -2 my $m1 = pdl [[1,2],[3,4]]; # det -2
my $opt1 = {lu=>undef}; my $opt1 = {lu=>undef};
ok($m1->det($opt1) == -2, "det([[1,2],[3,4]]"); ok($m1->det($opt1) == -2, "det([[1,2],[3,4]]");
ok($opt1->{lu}[0]->index2d(0,0) == 3, "set lu"); ok($opt1->{lu}[0]->index2d(0,0) == 3, "set lu");
my $m2 = pdl [[2,1],[4,3]]; # det 2 my $m2 = pdl [[2,1],[4,3]]; # det 2
ok($m2->det == 2, "det([[2,1],[3,4]]"); ok($m2->det == 2, "det([[2,1],[3,4]]");
ok($m2->det($opt1) == -2, "correctly used wrong lu"); ok($m2->det($opt1) == -2, "correctly used wrong lu");
} }
{ {
### Check threaded determinant -- simultaneous recursive det of four 4x4's ### Check broadcasted determinant -- simultaneous recursive det of four 4x4's
my $pa = pdl([3,4,5,6],[6,7,8,9],[9,0,7,6],[4,3,2,0]); # det=48 my $pa = pdl([3,4,5,6],[6,7,8,9],[9,0,7,6],[4,3,2,0]); # det=48
my $pb = pdl([1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]); # det=1 my $pb = pdl([1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]); # det=1
my $c = pdl([0,1,0,0],[1,0,0,0],[0,0,1,0],[0,0,0,1]); # det=-1 my $c = pdl([0,1,0,0],[1,0,0,0],[0,0,1,0],[0,0,0,1]); # det=-1
my $d = pdl([1,2,3,4],[5,4,3,2],[0,0,3,0],[3,0,1,6]); # det=-216 my $d = pdl([1,2,3,4],[5,4,3,2],[0,0,3,0],[3,0,1,6]); # det=-216
my $e = ($pa->cat($pb)) -> cat( $c->cat($d) ); my $e = ($pa->cat($pb)) -> cat( $c->cat($d) );
my $det = $e->determinant; my $det = $e->determinant;
ok(all($det == pdl([48,1],[-1,-216])), "threaded determinant"); ok(all($det == pdl([48,1],[-1,-216])), "broadcasted determinant");
} }
{ {
### Check identity and stretcher matrices... ### Check identity and stretcher matrices...
ok((identity(2)->flat == pdl(1,0,0,1))->all, "identity matrix"); ok((identity(2)->flat == pdl(1,0,0,1))->all, "identity matrix");
ok((identity(pdl 2)->flat == pdl(1,0,0,1))->all, "identity matrix with scalar nd array"); ok((identity(pdl 2)->flat == pdl(1,0,0,1))->all, "identity matrix with scalar nd array");
ok((identity(zeroes 2, 3)->flat == pdl(1,0,0,1))->all, "identity matrix with dim ensioned ndarray"); ok((identity(zeroes 2, 3)->flat == pdl(1,0,0,1))->all, "identity matrix with dim ensioned ndarray");
my @deep_identity_dims = identity(zeroes 2, 3, 4)->dims; my @deep_identity_dims = identity(zeroes 2, 3, 4)->dims;
is_deeply \@deep_identity_dims, [2, 2, 4], "identity matrix with multi-dimension ed ndarray" or diag 'got: ', explain \@deep_identity_dims; is_deeply \@deep_identity_dims, [2, 2, 4], "identity matrix with multi-dimension ed ndarray" or diag 'got: ', explain \@deep_identity_dims;
ok((stretcher(pdl(2,3))->flat == pdl(2,0,0,3))->all, "stretcher 2x2"); ok((stretcher(pdl(2,3))->flat == pdl(2,0,0,3))->all, "stretcher 2x2");
 End of changes. 4 change blocks. 
4 lines changed or deleted 4 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)