"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Libtmp/Transform/transform.pd" between
PDL-2.079.tar.gz and PDL-2.080.tar.gz

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

transform.pd  (PDL-2.079):transform.pd  (PDL-2.080)
skipping to change at line 2372 skipping to change at line 2372
if(!defined($o) && ((ref $source) eq 'HASH')) { if(!defined($o) && ((ref $source) eq 'HASH')) {
Carp::cluck("lookup transform called as sub not method; using 'PDL::Transfor m' as class...\n"); Carp::cluck("lookup transform called as sub not method; using 'PDL::Transfor m' as class...\n");
$o = $source; $o = $source;
$source = $class; $source = $class;
$class = "PDL::Transform"; $class = "PDL::Transform";
} }
$o = {} unless(ref $o eq 'HASH'); $o = {} unless(ref $o eq 'HASH');
my($me) = PDL::Transform::new($class); my($me) = $class->new;
my($bound) = _opt($o,['b','bound','boundary','Boundary']); my($bound) = _opt($o,['b','bound','boundary','Boundary']);
my($method)= _opt($o,['m','meth','method','Method']); my($method)= _opt($o,['m','meth','method','Method']);
$me->{idim} = $source->ndims - 1; $me->{idim} = $source->ndims - 1;
$me->{odim} = $source->dim($source->ndims-1); $me->{odim} = $source->dim($source->ndims-1);
$me->{params} = { $me->{params} = {
table => $source, table => $source,
scale => _opt($o,['s','scale','Scale'],1.0), scale => _opt($o,['s','scale','Scale'],1.0),
skipping to change at line 2611 skipping to change at line 2611
you are on your way. you are on your way.
=back =back
NOTES NOTES
the type/unit fields are currently ignored by t_linear. the type/unit fields are currently ignored by t_linear.
=cut =cut
@PDL::Transform::Linear::ISA = ('PDL::Transform'); { package PDL::Transform::Linear;
our @ISA = ('PDL::Transform');
*_opt = \&PDL::Transform::_opt;
sub t_linear { new PDL::Transform::Linear(@_); } sub PDL::Transform::t_linear { PDL::Transform::Linear->new(@_); }
sub PDL::Transform::Linear::new { sub new {
my($class) = shift; my($class) = shift;
my($o) = $_[0]; my($o) = $_[0];
pop @_ if (($#_ % 2 ==0) && !defined($_[-1])); pop @_ if (($#_ % 2 ==0) && !defined($_[-1]));
#suppresses a warning if @_ has an odd number of elements and the #suppresses a warning if @_ has an odd number of elements and the
#last is undef #last is undef
if(!(ref $o)) { if(!(ref $o)) {
$o = {@_}; $o = {@_};
} }
my($me) = PDL::Transform::new($class); my($me) = __PACKAGE__->SUPER::new;
$me->{name} = "linear"; $me->{name} = "linear";
$me->{params}{pre} = _opt($o,['pre','Pre','preoffset','offset', $me->{params}{pre} = _opt($o,['pre','Pre','preoffset','offset',
'Offset','PreOffset','Preoffset'],0); 'Offset','PreOffset','Preoffset'],0);
$me->{params}{pre} = pdl($me->{params}{pre}) $me->{params}{pre} = PDL->pdl($me->{params}{pre})
if(defined $me->{params}{pre}); if(defined $me->{params}{pre});
$me->{params}{post} = _opt($o,['post','Post','postoffset','PostOffset', $me->{params}{post} = _opt($o,['post','Post','postoffset','PostOffset',
'shift','Shift'],0); 'shift','Shift'],0);
$me->{params}{post} = pdl($me->{params}{post}) $me->{params}{post} = PDL->pdl($me->{params}{post})
if(defined $me->{params}{post}); if(defined $me->{params}{post});
$me->{params}{matrix} = _opt($o,['m','matrix','Matrix','mat','Mat']); $me->{params}{matrix} = _opt($o,['m','matrix','Matrix','mat','Mat']);
$me->{params}{matrix} = pdl($me->{params}{matrix}) $me->{params}{matrix} = PDL->pdl($me->{params}{matrix})
if(defined $me->{params}{matrix}); if(defined $me->{params}{matrix});
$me->{params}{rot} = _opt($o,['r','rot','rota','rotation','Rotation'], 0); $me->{params}{rot} = _opt($o,['r','rot','rota','rotation','Rotation'], 0);
$me->{params}{rot} = pdl($me->{params}{rot}); $me->{params}{rot} = PDL->pdl($me->{params}{rot});
my $o_dims = _opt($o,['d','dim','dims','Dims']); my $o_dims = _opt($o,['d','dim','dims','Dims']);
$o_dims = pdl($o_dims) if defined($o_dims); $o_dims = PDL->pdl($o_dims) if defined($o_dims);
my $scale = _opt($o,['s','scale','Scale']); my $scale = _opt($o,['s','scale','Scale']);
$scale = pdl($scale) if defined($scale); $scale = PDL->pdl($scale) if defined($scale);
# Figure out the number of dimensions to transform, and, # Figure out the number of dimensions to transform, and,
# if necessary, generate a new matrix. # if necessary, generate a new matrix.
if(defined($me->{params}{matrix})) { if(defined($me->{params}{matrix})) {
my $mat = $me->{params}{matrix} = $me->{params}{matrix}->slice(":,:"); my $mat = $me->{params}{matrix} = $me->{params}{matrix}->slice(":,:");
$me->{idim} = $mat->dim(0); $me->{idim} = $mat->dim(0);
$me->{odim} = $mat->dim(1); $me->{odim} = $mat->dim(1);
} else { } else {
skipping to change at line 2708 skipping to change at line 2710
# Subrotation closure -- rotates from axis $d->(0) --> $d->(1). # Subrotation closure -- rotates from axis $d->(0) --> $d->(1).
my $subrot = sub { my $subrot = sub {
my($d,$angle,$m)=@_; my($d,$angle,$m)=@_;
my($i) = identity($m->dim(0)); my($i) = identity($m->dim(0));
my($subm) = $i->dice($d,$d); my($subm) = $i->dice($d,$d);
$angle = $angle->at(0) $angle = $angle->at(0)
if(UNIVERSAL::isa($angle,'PDL')); if(UNIVERSAL::isa($angle,'PDL'));
my($x) = $angle * $PDL::Transform::DEG2RAD; my($x) = $angle * $PDL::Transform::DEG2RAD;
$subm .= $subm x pdl([cos($x),-sin($x)],[sin($x),cos($x)] ); $subm .= $subm x PDL->pdl([cos($x),-sin($x)],[sin($x),cos ($x)]);
$m .= $m x $i; $m .= $m x $i;
}; };
if(UNIVERSAL::isa($rot,'PDL') && $rot->nelem > 1) { if(UNIVERSAL::isa($rot,'PDL') && $rot->nelem > 1) {
if($rot->ndims == 2) { if($rot->ndims == 2) {
$me->{params}{matrix} x= $rot; $me->{params}{matrix} x= $rot;
} elsif($rot->nelem == 3) { } elsif($rot->nelem == 3) {
my $rm = identity(3); my $rm = identity(3);
# Do these in reverse order to make it more like # Do these in reverse order to make it more like
# function composition! # function composition!
&$subrot(pdl(0,1),$rot->at(2),$rm); &$subrot(PDL->pdl(0,1),$rot->at(2),$rm);
&$subrot(pdl(2,0),$rot->at(1),$rm); &$subrot(PDL->pdl(2,0),$rot->at(1),$rm);
&$subrot(pdl(1,2),$rot->at(0),$rm); &$subrot(PDL->pdl(1,2),$rot->at(0),$rm);
$me->{params}{matrix} .= $me->{params}{matrix} x $rm; $me->{params}{matrix} .= $me->{params}{matrix} x $rm;
} else { } else {
barf("PDL::Transform::Linear: Got a strange rot option -- giving up.\n") ; barf("PDL::Transform::Linear: Got a strange rot option -- giving up.\n") ;
} }
} else { } else {
if($rot != 0 and $me->{params}{matrix}->dim(0)>1) { if($rot != 0 and $me->{params}{matrix}->dim(0)>1) {
&$subrot(pdl(0,1),$rot,$me->{params}{matrix}); &$subrot(PDL->pdl(0,1),$rot,$me->{params}{matrix});
} }
} }
} }
# Apply scaling # Apply scaling
$me->{params}{matrix} = $me->{params}{matrix}->slice(":,:"); $me->{params}{matrix} = $me->{params}{matrix}->slice(":,:");
my $tmp; # work around perl -d "feature" my $tmp; # work around perl -d "feature"
($tmp = $me->{params}{matrix}->diagonal(0,1)) *= $scale ($tmp = $me->{params}{matrix}->diagonal(0,1)) *= $scale
if defined($scale); if defined($scale);
skipping to change at line 2780 skipping to change at line 2782
my($x) = $in->slice("0:$d")->copy - $opt->{post}; my($x) = $in->slice("0:$d")->copy - $opt->{post};
my($out) = $in->is_inplace ? $in : $in->copy; my($out) = $in->is_inplace ? $in : $in->copy;
my $tmp; # work around perl -d "feature" my $tmp; # work around perl -d "feature"
($tmp = $out->slice("0:$d")) .= $x x $opt->{inverse} - $opt->{pre}; ($tmp = $out->slice("0:$d")) .= $x x $opt->{inverse} - $opt->{pre};
$out; $out;
} : undef; } : undef;
return $me; return $me;
} }
sub PDL::Transform::Linear::stringify { sub stringify {
package PDL::Transform::Linear;
my($me) = shift; my($out) = SUPER::stringify $me; my($me) = shift; my($out) = SUPER::stringify $me;
my $mp = $me->{params}; my $mp = $me->{params};
if(!($me->{is_inverse})){ if(!($me->{is_inverse})){
$out .= "Pre-add: ".($mp->{pre})."\n" $out .= "Pre-add: ".($mp->{pre})."\n"
if(defined $mp->{pre}); if(defined $mp->{pre});
$out .= "Post-add: ".($mp->{post})."\n" $out .= "Post-add: ".($mp->{post})."\n"
if(defined $mp->{post}); if(defined $mp->{post});
skipping to change at line 2814 skipping to change at line 2815
$out .= "Forward matrix:".($mp->{inverse}) $out .= "Forward matrix:".($mp->{inverse})
if(defined $mp->{inverse}); if(defined $mp->{inverse});
$out .= "Inverse matrix:".($mp->{matrix}) $out .= "Inverse matrix:".($mp->{matrix})
if(defined $mp->{matrix}); if(defined $mp->{matrix});
} }
$out =~ s/\n/\n /go; $out =~ s/\n/\n /go;
$out; $out;
} }
}
+======EOD_t_linear====== +======EOD_t_linear======
pp_add_exported('t_scale'); pp_add_exported('t_scale');
pp_addpm(<<'+======EOD_t_scale======'); pp_addpm(<<'+======EOD_t_scale======');
=head2 t_scale =head2 t_scale
=for usage =for usage
skipping to change at line 3150 skipping to change at line 3152
=cut =cut
sub t_code { sub t_code {
my($class) = 'PDL::Transform'; my($class) = 'PDL::Transform';
my($func, $inv, $o) = @_; my($func, $inv, $o) = @_;
if(ref $inv eq 'HASH') { if(ref $inv eq 'HASH') {
$o = $inv; $o = $inv;
$inv = undef; $inv = undef;
} }
my($me) = PDL::Transform::new($class); my($me) = $class->new;
$me->{name} = _opt($o,['n','name','Name']) || "code"; $me->{name} = _opt($o,['n','name','Name']) || "code";
$me->{func} = $func; $me->{func} = $func;
$me->{inv} = $inv; $me->{inv} = $inv;
$me->{params} = _opt($o,['p','params','Params']) || {}; $me->{params} = _opt($o,['p','params','Params']) || {};
$me->{idim} = _opt($o,['i','idim']) || 2; $me->{idim} = _opt($o,['i','idim']) || 2;
$me->{odim} = _opt($o,['o','odim']) || 2; $me->{odim} = _opt($o,['o','odim']) || 2;
$me->{itype} = _opt($o,['itype']) || []; $me->{itype} = _opt($o,['itype']) || [];
$me->{otype} = _opt($o,['otype']) || []; $me->{otype} = _opt($o,['otype']) || [];
$me->{iunit} = _opt($o,['iunit']) || []; $me->{iunit} = _opt($o,['iunit']) || [];
$me->{ounit} = _opt($o,['ounit']) || []; $me->{ounit} = _opt($o,['ounit']) || [];
skipping to change at line 3268 skipping to change at line 3270
=cut =cut
*t_cylindrical = \&t_radial; *t_cylindrical = \&t_radial;
sub t_radial { sub t_radial {
my($class) = 'PDL::Transform'; my($class) = 'PDL::Transform';
my($o) = $_[0]; my($o) = $_[0];
if(ref $o ne 'HASH') { if(ref $o ne 'HASH') {
$o = { @_ }; $o = { @_ };
} }
my($me) = PDL::Transform::new($class); my($me) = $class->new;
$me->{params}{origin} = _opt($o,['o','origin','Origin']); $me->{params}{origin} = _opt($o,['o','origin','Origin']);
$me->{params}{origin} = pdl(0,0) $me->{params}{origin} = pdl(0,0)
unless defined($me->{params}{origin}); unless defined($me->{params}{origin});
$me->{params}{origin} = PDL->pdl($me->{params}{origin}); $me->{params}{origin} = PDL->pdl($me->{params}{origin});
$me->{params}{r0} = _opt($o,['r0','R0','c','conformal','Conformal']); $me->{params}{r0} = _opt($o,['r0','R0','c','conformal','Conformal']);
$me->{params}{origin} = PDL->pdl($me->{params}{origin}); $me->{params}{origin} = PDL->pdl($me->{params}{origin});
$me->{params}{u} = _opt($o,['u','unit','Unit'],'radians'); $me->{params}{u} = _opt($o,['u','unit','Unit'],'radians');
skipping to change at line 3417 skipping to change at line 3419
=back =back
=cut =cut
sub t_quadratic { sub t_quadratic {
my($class) = 'PDL::Transform'; my($class) = 'PDL::Transform';
my($o) = $_[0]; my($o) = $_[0];
if(ref $o ne 'HASH') { if(ref $o ne 'HASH') {
$o = {@_}; $o = {@_};
} }
my($me) = PDL::Transform::new($class); my($me) = $class->new;
$me->{params}->{origin} = _opt($o,['o','origin','Origin'],pdl(0)); $me->{params}->{origin} = _opt($o,['o','origin','Origin'],pdl(0));
$me->{params}->{l0} = _opt($o,['r0','l','l0','length','Length'],pdl(1)); $me->{params}->{l0} = _opt($o,['r0','l','l0','length','Length'],pdl(1));
$me->{params}->{str} = _opt($o,['s','str','strength','Strength'],pdl(0.1)); $me->{params}->{str} = _opt($o,['s','str','strength','Strength'],pdl(0.1));
$me->{params}->{dim} = _opt($o,['d','dim','dims','Dims']); $me->{params}->{dim} = _opt($o,['d','dim','dims','Dims']);
$me->{name} = "quadratic"; $me->{name} = "quadratic";
$me->{func} = sub { $me->{func} = sub {
my($data,$o) = @_; my($data,$o) = @_;
my($dd) = $data->copy - $o->{origin}; my($dd) = $data->copy - $o->{origin};
skipping to change at line 3517 skipping to change at line 3519
=back =back
=cut =cut
sub t_cubic { sub t_cubic {
my ($class) = 'PDL::Transform'; my ($class) = 'PDL::Transform';
my($o) = $_[0]; my($o) = $_[0];
if(ref $o ne 'HASH') { if(ref $o ne 'HASH') {
$o = {@_}; $o = {@_};
} }
my($me) = PDL::Transform::new($class); my($me) = $class->new;
$me->{params}->{dim} = _opt($o,['d','dim','dims','Dims'],undef); $me->{params}->{dim} = _opt($o,['d','dim','dims','Dims'],undef);
$me->{params}->{origin} = _opt($o,['o','origin','Origin'],pdl(0)); $me->{params}->{origin} = _opt($o,['o','origin','Origin'],pdl(0));
$me->{params}->{l0} = _opt($o,['r0','l','l0','length','Length'],pdl(1)); $me->{params}->{l0} = _opt($o,['r0','l','l0','length','Length'],pdl(1));
$me->{params}->{st} = _opt($o,['s','st','str'],pdl(0)); $me->{params}->{st} = _opt($o,['s','st','str'],pdl(0));
$me->{name} = "cubic"; $me->{name} = "cubic";
$me->{params}->{cuberoot} = sub { $me->{params}->{cuberoot} = sub {
my $x = shift; my $x = shift;
my $as = 1 - 2*($x<0); my $as = 1 - 2*($x<0);
skipping to change at line 3682 skipping to change at line 3684
=back =back
=cut =cut
sub t_quartic { sub t_quartic {
my($class) = 'PDL::Transform'; my($class) = 'PDL::Transform';
my($o) = $_[0]; my($o) = $_[0];
if(ref $o ne 'HASH') { if(ref $o ne 'HASH') {
$o = {@_}; $o = {@_};
} }
my($me) = PDL::Transform::new($class); my($me) = $class->new;
$me->{params}->{origin} = _opt($o,['o','origin','Origin'],pdl(0)); $me->{params}->{origin} = _opt($o,['o','origin','Origin'],pdl(0));
$me->{params}->{l0} = _opt($o,['r0','l','l0','length','Length'],pdl(1)); $me->{params}->{l0} = _opt($o,['r0','l','l0','length','Length'],pdl(1));
$me->{params}->{str} = _opt($o,['s','str','strength','Strength'],pdl(0.1)); $me->{params}->{str} = _opt($o,['s','str','strength','Strength'],pdl(0.1));
$me->{params}->{dim} = _opt($o,['d','dim','dims','Dims']); $me->{params}->{dim} = _opt($o,['d','dim','dims','Dims']);
$me->{name} = "quadratic"; $me->{name} = "quadratic";
$me->{func} = sub { $me->{func} = sub {
my($data,$o) = @_; my($data,$o) = @_;
my($dd) = $data->copy - $o->{origin}; my($dd) = $data->copy - $o->{origin};
skipping to change at line 3792 skipping to change at line 3794
=cut =cut
sub t_spherical { sub t_spherical {
my($class) = 'PDL::Transform'; my($class) = 'PDL::Transform';
my($o) = $_[0]; my($o) = $_[0];
if(ref $o ne 'HASH') { if(ref $o ne 'HASH') {
$o = { @_ } ; $o = { @_ } ;
} }
my($me) = PDL::Transform::new($class); my($me) = $class->new;
$me->{idim}=3; $me->{idim}=3;
$me->{odim}=3; $me->{odim}=3;
$me->{params}->{origin} = _opt($o,['o','origin','Origin']); $me->{params}->{origin} = _opt($o,['o','origin','Origin']);
$me->{params}->{origin} = PDL->zeroes(3) $me->{params}->{origin} = PDL->zeroes(3)
unless defined($me->{params}->{origin}); unless defined($me->{params}->{origin});
$me->{params}->{origin} = PDL->pdl($me->{params}->{origin}); $me->{params}->{origin} = PDL->pdl($me->{params}->{origin});
$me->{params}->{deg} = _opt($o,['d','degrees','Degrees']); $me->{params}->{deg} = _opt($o,['d','degrees','Degrees']);
skipping to change at line 3936 skipping to change at line 3938
=cut =cut
sub t_projective { sub t_projective {
my($class) = 'PDL::Transform'; my($class) = 'PDL::Transform';
my($o) = $_[0]; my($o) = $_[0];
if(ref $o ne 'HASH') { if(ref $o ne 'HASH') {
$o = { @_ }; $o = { @_ };
} }
my($me) = PDL::Transform::new($class); my($me) = $class->new;
$me->{name} = "projective"; $me->{name} = "projective";
### Set options... ### Set options...
$me->{params}->{idim} = $me->{idim} = _opt($o,['d','dim','Dim']); $me->{params}->{idim} = $me->{idim} = _opt($o,['d','dim','Dim']);
my $matrix; my $matrix;
if(defined ($matrix=_opt($o,['m','matrix','Matrix']))) { if(defined ($matrix=_opt($o,['m','matrix','Matrix']))) {
$matrix = pdl($matrix); $matrix = pdl($matrix);
 End of changes. 23 change blocks. 
25 lines changed or deleted 27 lines changed or added

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