# use pp_addbegin() to force =head1 NAME to appear before =head1 FUNCTIONS
pp_addbegin( <<'EOD' );

# ABSTRACT: XS utils for PDL::NDBin

=head1 NAME

PDL::NDBin::Utils_PP - XS utils for PDL::NDBin

=head1 DESCRIPTION

This module contains internal utilities for PDL::NDBin. The
subroutines are not intended to be called by the user.

=cut

# silence Test::Pod::Coverage warning
=for Pod::Coverage set_boundscheck set_debugging

=cut

EOD

# note that version numbers with trailing zeroes (e.g, 0.010) created problems
# in some of the tests
our $VERSION = '0.020';
pp_setversion( $VERSION );

# ensure that a grid is monotonically increasing or decreasing

pp_def( '_validate_grid',
	Pars => "grid(n)",
	Doc => 'Validate a grid.

This function throws an exception if a grid is not monotonically increasing or decreasing.',
	Code => '
	        if ( $grid(n => 0) < $grid(n => $SIZE(n)-1) ) {
		  loop (n=:-1) %{
		      if ( $grid() >= $grid( n => n+1 ) )
		        $CROAK( "grid is not monotonically increasing\n" );
		  %}
		}
	        else if ( $grid(n => 0) > $grid(n => $SIZE(n)-1) ) {
		  loop (n=:-1) %{
		      if ( $grid() <= $grid( n => n+1 ) )
		        $CROAK( "grid is not monotonically decreasing\n" );
		  %}
		}
		else {
	          $CROAK( "grid is not monotonically increasing or decreasing\n" );
		}
	',
);

pp_done();

# vim:set filetype=perl: