"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "GENERATED/PDL/MatrixOps.pm" between
PDL-2.081.tar.gz and PDL-2.082.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.pm  (PDL-2.081):MatrixOps.pm  (PDL-2.082)
skipping to change at line 326 skipping to change at line 326
provide the key but leave the value undefined, then the LU decomposition provide the key but leave the value undefined, then the LU decomposition
goes in here; if you put an LU decomposition here, it will be used and goes in here; if you put an LU decomposition here, it will be used and
the matrix will not be decomposed again. the matrix will not be decomposed again.
=back =back
=cut =cut
*PDL::det = \&det; *PDL::det = \&det;
sub det { sub det {
my($x) = shift; my ($x, $opt) = @_;
my($opt) = shift;
$opt = {} unless defined($opt); $opt = {} unless defined($opt);
my($lu,$perm,$par); my($lu,$perm,$par);
if(exists ($opt->{lu}) and (ref $opt->{lu} eq 'ARRAY')) { if(exists ($opt->{lu}) and (ref $opt->{lu} eq 'ARRAY')) {
($lu,$perm,$par) = @{$opt->{lu}}; ($lu,$perm,$par) = @{$opt->{lu}};
} else { } else {
($lu,$perm,$par) = lu_decomp($x); ($lu,$perm,$par) = lu_decomp($x);
$opt->{lu} = [$lu,$perm,$par] $opt->{lu} = [$lu,$perm,$par]
if(exists($opt->{lu})); if(exists($opt->{lu}));
} }
defined $lu ? $lu->diagonal(0,1)->prodover * $par : PDL->zeroes(sbyte,1);
( (defined $lu) ? $lu->diagonal(0,1)->prodover * $par : 0 );
} }
#line 368 "MatrixOps.pm" #line 365 "MatrixOps.pm"
#line 349 "matrixops.pd" #line 346 "matrixops.pd"
=head2 determinant =head2 determinant
=for sig =for sig
Signature: (a(m,m)) Signature: (a(m,m))
=for usage =for usage
$det = determinant($x); $det = determinant($x);
skipping to change at line 425 skipping to change at line 422
determinant($x->slice("0:".($i-1).",1:-1")-> determinant($x->slice("0:".($i-1).",1:-1")->
append($x->slice(($i+1).":-1,1:-1"))); append($x->slice(($i+1).":-1,1:-1")));
} }
# Do beginning and end submatrices # Do beginning and end submatrices
$sum += $x->slice("(0),(0)") * determinant($x->slice('1:-1,1:-1')); $sum += $x->slice("(0),(0)") * determinant($x->slice('1:-1,1:-1'));
$sum -= $x->slice("(-1),(0)") * determinant($x->slice('0:-2,1:-1')) * (1 - 2*( $n % 2)); $sum -= $x->slice("(-1),(0)") * determinant($x->slice('0:-2,1:-1')) * (1 - 2*( $n % 2));
return $sum; return $sum;
} }
#line 455 "MatrixOps.pm" #line 452 "MatrixOps.pm"
#line 949 "../../blib/lib/PDL/PP.pm" #line 958 "../../blib/lib/PDL/PP.pm"
=head2 eigens_sym =head2 eigens_sym
=for sig =for sig
Signature: ([phys]a(m); [o,phys]ev(n,n); [o,phys]e(n)) Signature: ([phys]a(m); [o,phys]ev(n,n); [o,phys]e(n))
=for ref =for ref
Eigenvalues and -vectors of a symmetric square matrix. If passed Eigenvalues and -vectors of a symmetric square matrix. If passed
skipping to change at line 471 skipping to change at line 468
($ev, $e) = eigens_sym($x); # e-vects & e-values ($ev, $e) = eigens_sym($x); # e-vects & e-values
$e = eigens_sym($x); # just eigenvalues $e = eigens_sym($x); # just eigenvalues
=for bad =for bad
eigens_sym ignores the bad-value flag of the input ndarrays. eigens_sym ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 509 "MatrixOps.pm" #line 506 "MatrixOps.pm"
#line 950 "../../blib/lib/PDL/PP.pm" #line 959 "../../blib/lib/PDL/PP.pm"
sub PDL::eigens_sym { sub PDL::eigens_sym {
my ($x) = @_; my ($x) = @_;
my (@d) = $x->dims; my (@d) = $x->dims;
barf "Need real square matrix for eigens_sym" barf "Need real square matrix for eigens_sym"
if $#d < 1 or $d[0] != $d[1]; if $#d < 1 or $d[0] != $d[1];
my ($n) = $d[0]; my ($n) = $d[0];
my ($sym) = 0.5*($x + $x->transpose); my ($sym) = 0.5*($x + $x->transpose);
my ($err) = PDL::max(abs($sym)); my ($err) = PDL::max(abs($sym));
barf "Need symmetric component non-zero for eigens_sym" barf "Need symmetric component non-zero for eigens_sym"
skipping to change at line 507 skipping to change at line 504
)->copy; )->copy;
my $ev = PDL->zeroes($sym->dims); my $ev = PDL->zeroes($sym->dims);
my $e = PDL->zeroes($sym->index(0)->dims); my $e = PDL->zeroes($sym->index(0)->dims);
&PDL::_eigens_sym_int($lt, $ev, $e); &PDL::_eigens_sym_int($lt, $ev, $e);
return $ev->transpose, $e return $ev->transpose, $e
if(wantarray); if(wantarray);
$e; #just eigenvalues $e; #just eigenvalues
} }
#line 548 "MatrixOps.pm" #line 545 "MatrixOps.pm"
#line 951 "../../blib/lib/PDL/PP.pm" #line 960 "../../blib/lib/PDL/PP.pm"
*eigens_sym = \&PDL::eigens_sym; *eigens_sym = \&PDL::eigens_sym;
#line 555 "MatrixOps.pm" #line 552 "MatrixOps.pm"
#line 949 "../../blib/lib/PDL/PP.pm" #line 958 "../../blib/lib/PDL/PP.pm"
=head2 eigens =head2 eigens
=for sig =for sig
Signature: ([phys]a(m); [o,phys]ev(l,n,n); [o,phys]e(l,n)) Signature: ([phys]a(m); [o,phys]ev(l,n,n); [o,phys]e(l,n))
=for ref =for ref
Real eigenvalues and -vectors of a real square matrix. Real eigenvalues and -vectors of a real square matrix.
skipping to change at line 584 skipping to change at line 581
($ev, $e) = eigens($x); # e'vects & e'vals ($ev, $e) = eigens($x); # e'vects & e'vals
$e = eigens($x); # just eigenvalues $e = eigens($x); # just eigenvalues
=for bad =for bad
eigens ignores the bad-value flag of the input ndarrays. eigens ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 635 "MatrixOps.pm" #line 631 "MatrixOps.pm"
#line 950 "../../blib/lib/PDL/PP.pm" #line 959 "../../blib/lib/PDL/PP.pm"
sub PDL::eigens { sub PDL::eigens {
my ($x) = @_; my ($x) = @_;
my (@d) = $x->dims; my (@d) = $x->dims;
my $n = $d[0]; my $n = $d[0];
barf "Need real square matrix for eigens" barf "Need real square matrix for eigens"
if $#d < 1 or $d[0] != $d[1]; if $#d < 1 or $d[0] != $d[1];
my $deviation = PDL::max(abs($x - $x->transpose))/PDL::max(abs($x)); my $deviation = PDL::max(abs($x - $x->transpose))/PDL::max(abs($x));
if ( $deviation <= 1e-5 ) { if ( $deviation <= 1e-5 ) {
#taken from eigens_sym code #taken from eigens_sym code
skipping to change at line 633 skipping to change at line 630
my $ev = PDL->zeroes(2, $x->dims); my $ev = PDL->zeroes(2, $x->dims);
my $e = PDL->zeroes(2, $x->index(0)->dims); my $e = PDL->zeroes(2, $x->index(0)->dims);
&PDL::_eigens_int($x->clump(0,1), $ev, $e); &PDL::_eigens_int($x->clump(0,1), $ev, $e);
return $ev->index(0)->transpose->sever, $e->index(0)->sever return $ev->index(0)->transpose->sever, $e->index(0)->sever
if(wantarray); if(wantarray);
return $e->index(0)->sever; #just eigenvalues return $e->index(0)->sever; #just eigenvalues
} }
} }
#line 687 "MatrixOps.pm" #line 683 "MatrixOps.pm"
#line 951 "../../blib/lib/PDL/PP.pm" #line 960 "../../blib/lib/PDL/PP.pm"
*eigens = \&PDL::eigens; *eigens = \&PDL::eigens;
#line 694 "MatrixOps.pm" #line 690 "MatrixOps.pm"
#line 949 "../../blib/lib/PDL/PP.pm" #line 958 "../../blib/lib/PDL/PP.pm"
=head2 svd =head2 svd
=for sig =for sig
Signature: (a(n,m); [o]u(n,m); [o,phys]z(n); [o]v(n,n)) Signature: (a(n,m); [t]w(wsize); [o]u(n,m); [o,phys]z(n); [o]v(n,n))
=for usage =for usage
($u, $s, $v) = svd($x); ($u, $s, $v) = svd($x);
=for ref =for ref
Singular value decomposition of a matrix. Singular value decomposition of a matrix.
C<svd> is broadcastable. C<svd> is broadcastable.
skipping to change at line 702 skipping to change at line 699
$r2 *= $s; # implicit broadcasting for cheap mult. $r2 *= $s; # implicit broadcasting for cheap mult.
$x .= $r2 x $r1; # a gets r2 x ess x r1 $x .= $r2 x $r1; # a gets r2 x ess x r1
} }
=for bad =for bad
svd ignores the bad-value flag of the input ndarrays. svd ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 766 "MatrixOps.pm" #line 761 "MatrixOps.pm"
#line 951 "../../blib/lib/PDL/PP.pm" #line 960 "../../blib/lib/PDL/PP.pm"
*svd = \&PDL::svd; *svd = \&PDL::svd;
#line 773 "MatrixOps.pm" #line 768 "MatrixOps.pm"
#line 814 "matrixops.pd" #line 800 "matrixops.pd"
=head2 lu_decomp =head2 lu_decomp
=for sig =for sig
Signature: (a(m,m); [o]lu(m,m); [o]perm(m); [o]parity) Signature: (a(m,m); [o]lu(m,m); [o]perm(m); [o]parity)
=for ref =for ref
LU decompose a matrix, with row permutation LU decompose a matrix, with row permutation
skipping to change at line 883 skipping to change at line 880
return if !$notbig->isempty; return if !$notbig->isempty;
# Divide by the diagonal element (which is now the largest element) # Divide by the diagonal element (which is now the largest element)
my $tout; my $tout;
($tout = $out->slice("($col),".($col+1).":$n1")) /= $big->slice('*1'); ($tout = $out->slice("($col),".($col+1).":$n1")) /= $big->slice('*1');
} # end of pivoting part } # end of pivoting part
} # end of column loop } # end of column loop
wantarray ? ($out,$permute,$parity) : $out; wantarray ? ($out,$permute,$parity) : $out;
} }
#line 952 "MatrixOps.pm" #line 947 "MatrixOps.pm"
#line 993 "matrixops.pd" #line 979 "matrixops.pd"
=head2 lu_decomp2 =head2 lu_decomp2
=for sig =for sig
Signature: (a(m,m); [o]lu(m,m)) Signature: (a(m,m); [o]lu(m,m))
=for ref =for ref
LU decompose a matrix, with no row permutation LU decompose a matrix, with no row permutation
skipping to change at line 1001 skipping to change at line 998
if($col < $n1) { if($col < $n1) {
# Divide the rest of the column by the diagonal element # Divide the rest of the column by the diagonal element
my $tmp; # work around for perl -d "feature" my $tmp; # work around for perl -d "feature"
($tmp = $out->slice("($col),".($col+1).":$n1")) /= $diagonal->index($col)- >dummy(0,$n1-$col); ($tmp = $out->slice("($col),".($col+1).":$n1")) /= $diagonal->index($col)- >dummy(0,$n1-$col);
} }
} # end of column loop } # end of column loop
wantarray ? ($out,$perm,$par) : $out; wantarray ? ($out,$perm,$par) : $out;
} }
#line 1074 "MatrixOps.pm" #line 1069 "MatrixOps.pm"
#line 1115 "matrixops.pd" #line 1101 "matrixops.pd"
=head2 lu_backsub =head2 lu_backsub
=for sig =for sig
Signature: (lu(m,m); perm(m); b(m)) Signature: (lu(m,m); perm(m); b(m))
=for ref =for ref
Solve A x = B for matrix A, by back substitution into A's LU decomposition. Solve A x = B for matrix A, by back substitution into A's LU decomposition.
skipping to change at line 1216 skipping to change at line 1213
)->sumover; )->sumover;
($tmp = $out->index($r1)) /= $ludiag->index($r1)->dummy(0); # TODO: check broadcast dims ($tmp = $out->index($r1)) /= $ludiag->index($r1)->dummy(0); # TODO: check broadcast dims
} }
if ($y->is_inplace) { if ($y->is_inplace) {
$y->setdims([$out->dims]) if !PDL::all($y->shape == $out->shape); # assgn n eeds same shape $y->setdims([$out->dims]) if !PDL::all($y->shape == $out->shape); # assgn n eeds same shape
$y .= $out; $y .= $out;
} }
$out; $out;
} }
#line 1292 "MatrixOps.pm" #line 1287 "MatrixOps.pm"
#line 949 "../../blib/lib/PDL/PP.pm" #line 958 "../../blib/lib/PDL/PP.pm"
=head2 simq =head2 simq
=for sig =for sig
Signature: ([phys]a(n,n); [phys]b(n); [o,phys]x(n); int [o,phys]ips(n); int fl ag) Signature: ([phys]a(n,n); [phys]b(n); [o,phys]x(n); int [o,phys]ips(n); int fl ag)
=for ref =for ref
Solution of simultaneous linear equations, C<a x = b>. Solution of simultaneous linear equations, C<a x = b>.
skipping to change at line 1254 skipping to change at line 1251
See also L</lu_backsub>, which does the same thing with a slightly See also L</lu_backsub>, which does the same thing with a slightly
less opaque interface. less opaque interface.
=for bad =for bad
simq ignores the bad-value flag of the input ndarrays. simq ignores the bad-value flag of the input ndarrays.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1338 "MatrixOps.pm" #line 1333 "MatrixOps.pm"
#line 951 "../../blib/lib/PDL/PP.pm" #line 960 "../../blib/lib/PDL/PP.pm"
*simq = \&PDL::simq; *simq = \&PDL::simq;
#line 1345 "MatrixOps.pm" #line 1340 "MatrixOps.pm"
#line 949 "../../blib/lib/PDL/PP.pm" #line 958 "../../blib/lib/PDL/PP.pm"
=head2 squaretotri =head2 squaretotri
=for sig =for sig
Signature: (a(n,n); b(m)) Signature: (a(n,n); b(m))
=for ref =for ref
Convert a symmetric square matrix to triangular vector storage. Convert a symmetric square matrix to triangular vector storage.
=for bad =for bad
squaretotri does not process bad values. squaretotri does not process bad values.
It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays. It will set the bad-value flag of all output ndarrays if the flag is set for any of the input ndarrays.
=cut =cut
#line 1373 "MatrixOps.pm" #line 1368 "MatrixOps.pm"
#line 951 "../../blib/lib/PDL/PP.pm" #line 960 "../../blib/lib/PDL/PP.pm"
*squaretotri = \&PDL::squaretotri; *squaretotri = \&PDL::squaretotri;
#line 1380 "MatrixOps.pm" #line 1375 "MatrixOps.pm"
#line 1410 "matrixops.pd" #line 1396 "matrixops.pd"
=head1 AUTHOR =head1 AUTHOR
Copyright (C) 2002 Craig DeForest (deforest@boulder.swri.edu), Copyright (C) 2002 Craig DeForest (deforest@boulder.swri.edu),
R.J.R. Williams (rjrw@ast.leeds.ac.uk), Karl Glazebrook R.J.R. Williams (rjrw@ast.leeds.ac.uk), Karl Glazebrook
(kgb@aaoepp.aao.gov.au). There is no warranty. You are allowed to (kgb@aaoepp.aao.gov.au). There is no warranty. You are allowed to
redistribute and/or modify this work under the same conditions as PDL redistribute and/or modify this work under the same conditions as PDL
itself. If this file is separated from the PDL distribution, then the itself. If this file is separated from the PDL distribution, then the
PDL copyright notice should be included in this file. PDL copyright notice should be included in this file.
=cut =cut
#line 1399 "MatrixOps.pm" #line 1394 "MatrixOps.pm"
# Exit with OK status # Exit with OK status
1; 1;
 End of changes. 40 change blocks. 
42 lines changed or deleted 39 lines changed or added

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