primitive.pd (PDL-2.080) | : | primitive.pd (PDL-2.081) | ||
---|---|---|---|---|

use strict; | use strict; | |||

use warnings; | use warnings; | |||

use PDL::Types qw(ppdefs_all types); | use PDL::Types qw(ppdefs_all types); | |||

my $F = [map $_->ppsym, grep $_->real && !$_->integer, types()]; | my $F = [map $_->ppsym, grep $_->real && !$_->integer, types()]; | |||

my $AF = [map $_->ppsym, grep !$_->integer, types]; | ||||

pp_addpm({At=>'Top'},<<'EOD'); | pp_addpm({At=>'Top'},<<'EOD'); | |||

use strict; | use strict; | |||

use warnings; | use warnings; | |||

use PDL::Slices; | use PDL::Slices; | |||

use Carp; | use Carp; | |||

{ package PDL; | { package PDL; | |||

use overload ( | use overload ( | |||

'x' => sub { | 'x' => sub { | |||

skipping to change at line 1703 | skipping to change at line 1704 | |||

%} | %} | |||

} | } | |||

} | } | |||

EOC | EOC | |||

Doc =><<'EOD', | Doc =><<'EOD', | |||

=for ref | =for ref | |||

Enumerate a list of vectors with locally unique keys. | Enumerate a list of vectors with locally unique keys. | |||

Given a sorted list of vectors $v, generate a vector $k containing locally uniqu e keys for the elements of $v | Given a sorted list of vectors $v, generate a vector $k containing locally uniqu e keys for the elements of $v | |||

(where an "element" is a vector of length $M ocurring in $v). | (where an "element" is a vector of length $M occurring in $v). | |||

Note that the keys returned in $k are only unique over a run of a single vector in $v, | Note that the keys returned in $k are only unique over a run of a single vector in $v, | |||

so that each unique vector in $v has at least one 0 (zero) index in $k associate d with it. | so that each unique vector in $v has at least one 0 (zero) index in $k associate d with it. | |||

If you need global keys, see enumvecg(). | If you need global keys, see enumvecg(). | |||

Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||

EOD | EOD | |||

); | ); | |||

skipping to change at line 1739 | skipping to change at line 1740 | |||

$k(N=>vn) = ki; | $k(N=>vn) = ki; | |||

} | } | |||

} | } | |||

EOC | EOC | |||

Doc =><<'EOD', | Doc =><<'EOD', | |||

=for ref | =for ref | |||

Enumerate a list of vectors with globally unique keys. | Enumerate a list of vectors with globally unique keys. | |||

Given a sorted list of vectors $v, generate a vector $k containing globally uniq ue keys for the elements of $v | Given a sorted list of vectors $v, generate a vector $k containing globally uniq ue keys for the elements of $v | |||

(where an "element" is a vector of length $M ocurring in $v). | (where an "element" is a vector of length $M occurring in $v). | |||

Basically does the same thing as: | Basically does the same thing as: | |||

$k = $v->vsearchvec($v->uniqvec); | $k = $v->vsearchvec($v->uniqvec); | |||

... but somewhat more efficiently. | ... but somewhat more efficiently. | |||

Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | Contributed by Bryan Jurish E<lt>moocow@cpan.orgE<gt>. | |||

EOD | EOD | |||

); | ); | |||

skipping to change at line 2955 | skipping to change at line 2956 | |||

); | ); | |||

} | } | |||

############################################################### | ############################################################### | |||

# routines somehow related to interpolation | # routines somehow related to interpolation | |||

############################################################### | ############################################################### | |||

pp_def('interpolate', | pp_def('interpolate', | |||

HandleBad => 0, | HandleBad => 0, | |||

BadDoc => 'needs major (?) work to handles bad values', | BadDoc => 'needs major (?) work to handles bad values', | |||

Pars => 'xi(); x(n); y(n); [o] yi(); int [o] err()', | Pars => 'real xi(); real x(n); y(n); [o] yi(); int [o] err()', | |||

GenericTypes => $F, # too restrictive ? | GenericTypes => $AF, | |||

PMCode => 'sub PDL::interpolate { | ||||

my ($xi, $x, $y, $yi, $err) = @_; | ||||

croak "x must be real" if (ref($x) && ! $x->type->real); | ||||

croak "xi must be real" if (ref($xi) && ! $xi->type->real | ||||

); | ||||

$yi //= PDL->null; | ||||

$err //= PDL->null; | ||||

PDL::_interpolate_int($xi, $x, $y, $yi, $err); | ||||

($yi, $err); | ||||

}', | ||||

Code => ' | Code => ' | |||

$GENERIC() d; | $GENERIC() d; | |||

PDL_Indx n = $SIZE(n); | PDL_Indx n = $SIZE(n); | |||

PDL_Indx n1 = n-1; | PDL_Indx n1 = n-1; | |||

int up = ($x(n => n1) > $x(n => 0)); | int up = ($x(n => n1) > $x(n => 0)); | |||

PDL_Indx jl, jh, m; | PDL_Indx jl, jh, m; | |||

int carp; | int carp; | |||

broadcastloop %{ | broadcastloop %{ | |||

jl = -1; | jl = -1; | |||

skipping to change at line 3019 | skipping to change at line 3029 | |||

a start for the next search can be faster (compare Numerical Recipes | a start for the next search can be faster (compare Numerical Recipes | |||

C<hunt> routine). Feel free to implement that on top of the binary | C<hunt> routine). Feel free to implement that on top of the binary | |||

search if you like. For out of bounds values it just does a linear | search if you like. For out of bounds values it just does a linear | |||

extrapolation and sets the corresponding element of C<$err> to 1, | extrapolation and sets the corresponding element of C<$err> to 1, | |||

which is otherwise 0. | which is otherwise 0. | |||

See also L</interpol>, which uses the same routine, | See also L</interpol>, which uses the same routine, | |||

differing only in the handling of extrapolation - an error message | differing only in the handling of extrapolation - an error message | |||

is printed rather than returning an error ndarray. | is printed rather than returning an error ndarray. | |||

Note that C<interpolate> can use complex values for C<$y> and C<$yi> but | ||||

C<$x> and C<$xi> must be real. | ||||

=cut | =cut | |||

EOD | EOD | |||

pp_add_exported('', 'interpol'); | pp_add_exported('', 'interpol'); | |||

pp_addpm(<<'EOD'); | pp_addpm(<<'EOD'); | |||

=head2 interpol | =head2 interpol | |||

=for sig | =for sig | |||

End of changes. 5 change blocks. | ||||

4 lines changed or deleted | | 18 lines changed or added |