diff --git a/Basic/Slices/slices.pd b/Basic/Slices/slices.pd index 6077cdc41..45caab946 100644 --- a/Basic/Slices/slices.pd +++ b/Basic/Slices/slices.pd @@ -1042,20 +1042,12 @@ pp_def( 'rld', GenericTypes => [ppdefs_all], Pars=>'indx a(n); b(n); [o]c(m);', + OtherPars=>'IV sumover_max => m', PMCode =>pp_line_numbers(__LINE__, <<'EOD'), sub PDL::rld { my ($x,$y) = @_; - my ($c); - if ($#_ == 2) { - $c = $_[2]; - } else { -# XXX Need to improve emulation of broadcasting in auto-generating c - my ($size) = $x->sumover->max->sclr; - my (@dims) = $x->dims; - shift @dims; - $c = $y->zeroes($size,@dims); - } - &PDL::_rld_int($x,$y,$c); + my ($c,$sm) = @_ == 3 ? ($_[2], $_[2]->dim(0)) : (PDL->null, $x->sumover->max->sclr); + PDL::_rld_int($x,$y,$c,$sm); $c; } EOD @@ -1217,37 +1209,32 @@ EOD ); pp_def('rldvec', - Pars => 'indx a(N); b(M,N); [o]c(M,N)', - PMCode =>pp_line_numbers(__LINE__, <<'EOC'), + Pars => 'indx a(uniqvals); b(M,uniqvals); [o]c(M,decodedvals)', + OtherPars=>'IV sumover_max => decodedvals', + PMCode =>pp_line_numbers(__LINE__, <<'EOC'), sub PDL::rldvec { my ($a,$b,$c) = @_; - if (!defined($c)) { -# XXX Need to improve emulation of threading in auto-generating c - my ($rowlen) = $b->dim(0); - my ($size) = $a->sumover->max; - my (undef, @dims) = $a->dims; - $c = $b->zeroes($b->type,$rowlen,$size,@dims); - } - &PDL::_rldvec_int($a,$b,$c); + ($c,my $sm) = defined($c) ? ($c,$c->dim(1)) : (PDL->null,$a->sumover->max->sclr); + PDL::_rldvec_int($a,$b,$c,$sm); return $c; } EOC Code =>pp_line_numbers(__LINE__, <<'EOC'), PDL_Indx cn=0; - loop (N) %{ + loop (uniqvals) %{ PDL_Indx i, nrows = $a(); for (i=0; icn) = $b(); %} + loop (M) %{ $c(decodedvals=>cn) = $b(); %} cn++; } %} EOC - Doc =><<'EOD' + Doc =><<'EOD' =for ref Run-length decode a set of vectors, akin to a higher-order rld(). -Given a vector $a() of the number of occurrences of each row, and a set $c() +Given a vector $a() of the number of occurrences of each row, and a set $b() of row-vectors each of length $M, run-length decode to $c(). Can be used together with clump() to run-length decode "values" of arbitrary dimensions. @@ -1295,29 +1282,26 @@ EOD ); pp_def('rldseq', - Pars => 'indx a(N); b(N); [o]c(M)', - PMCode =>pp_line_numbers(__LINE__, <<'EOC'), + Pars => 'indx a(N); b(N); [o]c(M)', + OtherPars=>'IV sumover_max => M', + PMCode =>pp_line_numbers(__LINE__, <<'EOC'), sub PDL::rldseq { my ($a,$b,$c) = @_; - if (!defined($c)) { - my $size = $a->sumover->max; - my (undef, @dims) = $a->dims; - $c = $b->zeroes($b->type,$size,@dims); - } - &PDL::_rldseq_int($a,$b,$c); + ($c,my $sm) = defined($c) ? ($c,$c->dim(1)) : (PDL->null,$a->sumover->max->sclr); + PDL::_rldseq_int($a,$b,$c,$sm); return $c; } EOC Code =>pp_line_numbers(__LINE__, <<'EOC'), - size_t mi=0; + PDL_Indx mi=0; loop (N) %{ - size_t len = $a(), li; + PDL_Indx len = $a(), li; for (li=0; li < len; ++li, ++mi) { $c(M=>mi) = $b() + li; } %} EOC - Doc =><<'EOD' + Doc =><<'EOD' =for ref Run-length decode a subsequence vector. @@ -1364,7 +1348,7 @@ sub rleND { my @vdimsN = $data->dims; ##-- construct output pdls - my $counts = $#_ >= 0 ? $_[0] : zeroes(long, $vdimsN[$#vdimsN]); + my $counts = $#_ >= 0 ? $_[0] : PDL->null; my $elts = $#_ >= 1 ? $_[1] : zeroes($data->type, @vdimsN); ##-- guts: call rlevec() diff --git a/Libtmp/Compression/compression.pd b/Libtmp/Compression/compression.pd index 32d1a09cf..65a1885b6 100644 --- a/Libtmp/Compression/compression.pd +++ b/Libtmp/Compression/compression.pd @@ -145,16 +145,13 @@ sub PDL::rice_compress { ) { die("rice_compress: input needs to have type byte, short, ushort, or long, not ".($in->type)."\n"); } - # output buffer starts the same size; truncate at the end. - my ($out) = zeroes($in); - # lengths go here - my ($len) = zeroes(long, $in->slice("(0)")->dims); - PDL::_rice_compress_int( $in, $out, $len, $blocksize ); - my $l = $len->max; + PDL::_rice_compress_int( $in, my $out=PDL->null, my $len=PDL->null, $blocksize ); + my $l = $len->max->sclr; $out = $out->slice("0:".($l-1))->sever; return wantarray ? ($out, $in->dim(0), $blocksize, $len) : $out; } EOD + RedoDimsCode => '$SIZE(m) = $SIZE(n);', # output same size; truncate after Code => <<'EOD', int len; char *err = rcomp( $P(in), @@ -174,7 +171,8 @@ pp_def( "rice_expand", HandleBad=>0, Pars=>'in(n); [o]out(m);', - OtherPars=>'int blocksize', + OtherPars=>'IV dim0 => m; int blocksize', + OtherParsDefaults=>{ blocksize=>32 }, GenericTypes=>['B','S','US','L'], Doc=><<'EOD', =for ref @@ -185,17 +183,6 @@ Unsquishes a PDL that has been squished by rice_compress. ($out, $len, $blocksize, $dim0) = $pdl->rice_compress; $copy = $out->rice_expand($dim0, $blocksize); -EOD - PMCode => <<'EOD', -sub PDL::rice_expand { - my $squished = shift; - my $dim0 =shift; - my $blocksize = shift || 32; - # Allocate output array - my $out = zeroes( $squished->slice("(0),*$dim0") ); - PDL::_rice_expand_int( $squished, $out, $blocksize ); - return $out; -} EOD Code=><<'EOD', char *err = rdecomp( (unsigned char *)($P(in)), diff --git a/Libtmp/Filter/Linear.pm b/Libtmp/Filter/Linear.pm index 3f96dc766..8efccce3e 100644 --- a/Libtmp/Filter/Linear.pm +++ b/Libtmp/Filter/Linear.pm @@ -58,7 +58,7 @@ use strict; sub new($$) { my($type,$npoints,$sigma) = @_; my $cent = int($npoints/2); - my $x = ((PDL->zeroes($npoints )->xvals) - $cent)->float; + my $x = PDL->zeroes(float, $npoints )->xvals - $cent; my $y = exp(-($x**2)/(2*$sigma**2)); # Normalize to unit total $y /= sum($y); @@ -77,8 +77,8 @@ use strict; sub new($$) { my($type,$deg,$nleft,$nright) = @_; my $npoints = $nright + $nleft + 1; - my $x = ((PDL->zeroes($npoints )->xvals) - $nleft)->float; - my $mat1 = ((PDL->zeroes($npoints,$deg+1)->xvals))->float; + my $x = PDL->zeroes(float, $npoints )->xvals - $nleft; + my $mat1 = PDL->zeroes(float, $npoints,$deg+1)->xvals; for(0..$deg-1) { (my $tmp = $mat1->slice(":,($_)")) .= ($x ** $_); } @@ -88,4 +88,4 @@ sub new($$) { Point => $nleft}); } - +1; diff --git a/Libtmp/Slatec/Gaussian.pm b/Libtmp/Slatec/Gaussian.pm index 3616f6b55..606727362 100644 --- a/Libtmp/Slatec/Gaussian.pm +++ b/Libtmp/Slatec/Gaussian.pm @@ -130,12 +130,12 @@ sub new { } my $ndims1 = ($#{$ndims==0} ? $ndims : [1]); bless { - Mu => (PDL->zeroes (@$ndims1,@$nfuncs)->double), - ICV => (PDL->zeroes (@$ndims1,@$ndims1,@$nfuncs)->double), - CV => (PDL->zeroes (@$ndims1,@$ndims1,@$nfuncs)->double), - lnPrefactor=> (PDL->zeroes(@$nfuncs)->double), - EigVec => (PDL->zeroes (@$ndims1,@$ndims1,@$nfuncs)->double), - EigVal => (PDL->zeroes (@$ndims1,@$nfuncs)->double), + Mu => PDL->zeroes(PDL::double, @$ndims1,@$nfuncs), + ICV => PDL->zeroes(PDL::double, @$ndims1,@$ndims1,@$nfuncs), + CV => PDL->zeroes(PDL::double, @$ndims1,@$ndims1,@$nfuncs), + lnPrefactor=> PDL->zeroes(PDL::double, @$nfuncs), + EigVec => PDL->zeroes(PDL::double, @$ndims1,@$ndims1,@$nfuncs), + EigVal => PDL->zeroes(PDL::double, @$ndims1,@$nfuncs), NDims => $ndims, NFuncs => $nfuncs, },$type; @@ -193,9 +193,9 @@ sub upd_icovariance { sub _eigs { my($this,$mat) = @_; my $tmpvec = $this->{EigVec}->float; - my $fvone = (PDL->zeroes(@{$this->{NDims}}))->float; - my $fvtwo = (PDL->zeroes(@{$this->{NDims}}))->float; - my $ierr = (PDL->zeroes(@{$this->{NFuncs}}))->long; + my $fvone = PDL->zeroes(PDL::float, @{$this->{NDims}}); + my $fvtwo = PDL->zeroes(PDL::float, @{$this->{NDims}}); + my $ierr = PDL->zeroes(PDL::long, @{$this->{NFuncs}}); my $tmp = $mat->float; # Copy, since is destroyed. my $tmpval = $this->{EigVal}->float; @@ -242,7 +242,7 @@ sub calc_value ($$$) { sub calc_lnvalue ($$$) { my($this,$xorig,$p) = @_; my $x = $xorig; - my $muxed = (PDL->zeroes(@{$this->{NDims}},@{$p->{Dims}}))->double; + my $muxed = PDL->zeroes(PDL::double, @{$this->{NDims}},@{$p->{Dims}}); # print "MUXED1: $muxed\n"; diff --git a/Libtmp/Slatec/LinPred.pm b/Libtmp/Slatec/LinPred.pm index 385852534..2f58fe998 100644 --- a/Libtmp/Slatec/LinPred.pm +++ b/Libtmp/Slatec/LinPred.pm @@ -106,7 +106,7 @@ sub _mk_mat { my $auc = $this->{AutoCor}; - my $autocov = PDL::float PDL->zeroes($nl*2,$nl*2); + my $autocov = PDL->zeroes(PDL::float, $nl*2,$nl*2); $this->{AutoCov} = $autocov; my $sal = $this->{SymAutoCor}->px->lags(0,1,$this->{NLags})->px; @@ -130,7 +130,7 @@ sub _mk_mat { my $autocinv = inv($autocov); # print "$autocinv,$auc,$n\n"; $auc->slice("$n:-1"); - $this->{AutoSliceUsed} = PDL->zeroes(2*$nl)->float; + $this->{AutoSliceUsed} = PDL->zeroes(PDL::float, 2*$nl); ($tmp = $this->{AutoSliceUsed}->slice("0:$nl1")) .= $auc->slice(($n+$nl-1).":$n"); @@ -264,7 +264,7 @@ sub new ($$) { $this->{AutoCor} = $auc; my $n = $this->{NTotLags}; $this->{SymAutoCor} = - (PDL->zeroes($n * 2 - 1)->float); + PDL->zeroes(PDL::float, $n * 2 - 1); my $tmp; ($tmp = $this->{SymAutoCor}->slice("0:".($n-2))) .= $auc->slice("-1:1"); diff --git a/Libtmp/Slatec/slatec.pd b/Libtmp/Slatec/slatec.pd index 50803fb5f..343e31388 100644 --- a/Libtmp/Slatec/slatec.pd +++ b/Libtmp/Slatec/slatec.pd @@ -208,7 +208,7 @@ compute the determinant of an invertible matrix =for example - $mat = zeroes(5,5); $mat->diagonal(0,1) .= 1; # unity matrix + $mat = identity(5); # unity matrix $det = detslatec $mat; Usage: diff --git a/Libtmp/Transform/Cartography/Cartography.pm b/Libtmp/Transform/Cartography/Cartography.pm index 3135a6208..3bd33aedc 100644 --- a/Libtmp/Transform/Cartography/Cartography.pm +++ b/Libtmp/Transform/Cartography/Cartography.pm @@ -362,8 +362,8 @@ sub graticule { $yp->flat->append($ym->flat) )->mv(1,0); } else { - our $pp = (zeroes($xp)-1); $pp->slice("(-1)") .= 0; - our $pm = (zeroes($xm)-1); $pm->slice("(-1)") .= 0; + our $pp = zeroes($xp)-1; $pp->slice("(-1)") .= 0; + our $pm = zeroes($xm)-1; $pm->slice("(-1)") .= 0; if(wantarray) { return ( pdl( $xp->flat->append($xm->flat), diff --git a/Libtmp/Transform/transform.pd b/Libtmp/Transform/transform.pd index 150091fac..925aade1d 100644 --- a/Libtmp/Transform/transform.pd +++ b/Libtmp/Transform/transform.pd @@ -1826,8 +1826,7 @@ sub map { croak("Whups -- got a nonlinear t_fits transformation. Can't deal with it."); } - my $inv_sc_mat = zeroes($nd,$nd); - $inv_sc_mat->diagonal(0,1) .= $scale; + my $inv_sc_mat = PDL::MatrixOps::stretcher($scale); my $mat = $f_in->{params}->{matrix} x $inv_sc_mat; print "scale is $scale; mat is $mat\n" if($PDL::Transform::debug); @@ -2456,7 +2455,7 @@ sub t_lookup { my $maxvals = $p->{table}->clump($me->{idim})->maximum; # Scale so that the range runs from 0 through the top pixel in the table - my $scale = ( pdl( $itable->dims )->slice("0:-2")-1 ) / + my $scale = ( $itable->shape->slice("0:-2")-1 ) / (($maxvals - $minvals)+ (($maxvals-$minvals) == 0)); my $offset = - ($minvals * $scale); @@ -3843,8 +3842,7 @@ sub t_spherical { $me->{odim}=3; $me->{params}->{origin} = _opt($o,['o','origin','Origin']); - $me->{params}->{origin} = PDL->zeroes(3) - unless defined($me->{params}->{origin}); + $me->{params}->{origin} //= PDL->zeroes(3); $me->{params}->{origin} = PDL->pdl($me->{params}->{origin}); $me->{params}->{deg} = _opt($o,['d','degrees','Degrees']);