view release on metacpan or search on metacpan
break_value */
double break_value;
double obj_bound; /* ## Objective function bound for speedup of
B&B */
int iter; /* The number of iterations in the simplex
solver (LP) */
int total_iter; /* The total number of iterations (B&B)
(ILP) */
int max_level; /* The Deepest B&B level of the last solution */
int total_nodes; /* total number of nodes processed in b&b */
double *solution; /* sum_alloc+1 :The Solution of the last LP,
0 = The Optimal Value,
view all matches for this distribution
view release on metacpan or search on metacpan
C abs(H) = HMIN or 10 consecutive failures occurred.
C On a return with KFLAG negative, the values of TN and
C the YH array are as of the beginning of the last
C step, and H is the last step size attempted.
C MAXORD = the maximum order of integration method to be allowed.
C MAXCOR = the maximum number of corrector iterations allowed.
C MSBP = maximum number of steps between PJAC calls (MITER .gt. 0).
C MXNCF = maximum number of convergence failures allowed.
C METH/MITER = the method flags. See description in driver.
C N = the number of first-order differential equations.
C The values of CCMAX, H, HMIN, HMXI, TN, JSTART, KFLAG, MAXORD,
Cdir$ ivdep
DO 210 I = I1,NQNYH
210 YH1(I) = YH1(I) + YH1(I+NYH)
215 CONTINUE
C-----------------------------------------------------------------------
C Up to MAXCOR corrector iterations are taken. A convergence test is
C made on the R.M.S. norm of each correction, weighted by the error
C weight vector EWT. The sum of the corrections is accumulated in the
C vector ACOR(i). The YH array is not altered in the corrector loop.
C-----------------------------------------------------------------------
220 M = 0
C ABS(H) = HMIN or 10 consecutive failures occurred.
C On a return with KFLAG negative, the values of TN and
C the YH array are as of the beginning of the last
C step, and H is the last step size attempted.
C MAXORD = the maximum order of integration method to be allowed.
C MAXCOR = the maximum number of corrector iterations allowed.
C MSBP = maximum number of steps between PJAC calls (MITER .gt. 0).
C MXNCF = maximum number of convergence failures allowed.
C METH = current method.
C METH = 1 means Adams method (nonstiff)
C METH = 2 means BDF method (stiff)
DO 210 I = I1,NQNYH
210 YH1(I) = YH1(I) + YH1(I+NYH)
215 CONTINUE
PNORM = DMNORM (N, YH1, EWT)
C-----------------------------------------------------------------------
C Up to MAXCOR corrector iterations are taken. A convergence test is
C made on the RMS-norm of each correction, weighted by the error
C weight vector EWT. The sum of the corrections is accumulated in the
C vector ACOR(i). The YH array is not altered in the corrector loop.
C-----------------------------------------------------------------------
220 M = 0
C rate constant is stored in CRATE, and this is used in the test.
C
C We first check for a change of iterates that is the size of
C roundoff error. If this occurs, the iteration has converged, and a
C new rate estimate is not formed.
C In all other cases, force at least two iterations to estimate a
C local Lipschitz constant estimate for Adams methods.
C On convergence, form PDEST = local maximum Lipschitz constant
C estimate. PDLAST is the most recent nonzero estimate.
C-----------------------------------------------------------------------
400 CONTINUE
C ABS(H) = HMIN or 10 consecutive failures occurred.
C On a return with KFLAG negative, the values of TN and
C the YH array are as of the beginning of the last
C step, and H is the last step size attempted.
C MAXORD = the maximum order of integration method to be allowed.
C MAXCOR = the maximum number of corrector iterations allowed.
C MSBP = maximum number of steps between DPKSET calls (MITER .gt. 0).
C MXNCF = maximum number of convergence failures allowed.
C METH/MITER = the method flags. See description in driver.
C N = the number of first-order differential equations.
C-----------------------------------------------------------------------
CDIR$ IVDEP
DO 210 I = I1,NQNYH
210 YH1(I) = YH1(I) + YH1(I+NYH)
215 CONTINUE
C-----------------------------------------------------------------------
C Up to MAXCOR corrector iterations are taken. A convergence test is
C made on the RMS-norm of each correction, weighted by the error
C weight vector EWT. The sum of the corrections is accumulated in the
C vector ACOR(i). The YH array is not altered in the corrector loop.
C-----------------------------------------------------------------------
220 M = 0
C scaled inner products of A*V(*,k) and V(*,i).
C
C IPVT = an integer array containg pivoting information.
C It is loaded in DHEFA and used in DHESL.
C
C LIOM = the number of iterations performed, and current
C order of the upper Hessenberg matrix HES.
C
C NPSL = the number of calls to PSOL.
C
C IFLAG = integer error flag:
C 0 means convergence in LIOM iterations, LIOM.le.MAXL.
C 1 means the convergence test did not pass in MAXL
C iterations, but the residual norm is .lt. 1,
C or .lt. norm(b) if MNEWT = 0, and so X is computed.
C 2 means the convergence test did not pass in MAXL
C iterations, residual .gt. 1, and X is undefined.
C 3 means there was a recoverable error in PSOL
C caused by the preconditioner being out of date.
C -1 means there was a nonrecoverable error in PSOL.
C
C-----------------------------------------------------------------------
C On return
C
C X = the final computed approximation to the solution
C of the system A*x = b.
C
C LGMR = the number of iterations performed and
C the current order of the upper Hessenberg
C matrix HES.
C
C NPSL = the number of calls to PSOL.
C
C Q = real array of length 2*MAXL containing the components
C of the Givens rotations used in the QR decomposition
C of HES. It is loaded in DHEQR and used in DHELS.
C
C IFLAG = integer error flag:
C 0 means convergence in LGMR iterations, LGMR .le. MAXL.
C 1 means the convergence test did not pass in MAXL
C iterations, but the residual norm is .lt. 1,
C or .lt. norm(b) if MNEWT = 0, and so x is computed.
C 2 means the convergence test did not pass in MAXL
C iterations, residual .gt. 1, and X is undefined.
C 3 means there was a recoverable error in PSOL
C caused by the preconditioner being out of date.
C -1 means there was a nonrecoverable error in PSOL.
C
C-----------------------------------------------------------------------
C On return
C
C X = the final computed approximation to the solution
C of the system A*x = b.
C
C LPCG = the number of iterations performed, and current
C order of the upper Hessenberg matrix HES.
C
C NPSL = the number of calls to PSOL.
C
C IFLAG = integer error flag:
C 0 means convergence in LPCG iterations, LPCG .le. MAXL.
C 1 means the convergence test did not pass in MAXL
C iterations, but the residual norm is .lt. 1,
C or .lt. norm(b) if MNEWT = 0, and so X is computed.
C 2 means the convergence test did not pass in MAXL
C iterations, residual .gt. 1, and X is undefined.
C 3 means there was a recoverable error in PSOL
C caused by the preconditioner being out of date.
C 4 means there was a zero denominator in the algorithm.
C The system matrix or preconditioner matrix is not
C sufficiently close to being symmetric pos. definite.
IF (MNEWT .GT. 0) RETURN
CALL DCOPY (N, R, 1, X, 1)
RETURN
C
20 ZTR = 0.0D0
C Loop point for PCG iterations. ---------------------------------------
30 CONTINUE
LPCG = LPCG + 1
CALL DCOPY (N, R, 1, Z, 1)
IER = 0
IF (JPRE .EQ. 0) GO TO 40
C On return
C
C X = the final computed approximation to the solution
C of the system A*x = b.
C
C LPCG = the number of iterations performed, and current
C order of the upper Hessenberg matrix HES.
C
C NPSL = the number of calls to PSOL.
C
C IFLAG = integer error flag:
C 0 means convergence in LPCG iterations, LPCG .le. MAXL.
C 1 means the convergence test did not pass in MAXL
C iterations, but the residual norm is .lt. 1,
C or .lt. norm(b) if MNEWT = 0, and so X is computed.
C 2 means the convergence test did not pass in MAXL
C iterations, residual .gt. 1, and X is undefined.
C 3 means there was a recoverable error in PSOL
C caused by the preconditioner being out of date.
C 4 means there was a zero denominator in the algorithm.
C the scaled matrix or scaled preconditioner is not
C sufficiently close to being symmetric pos. definite.
IF (MNEWT .GT. 0) RETURN
CALL DCOPY (N, R, 1, X, 1)
RETURN
C
20 ZTR = 0.0D0
C Loop point for PCG iterations. ---------------------------------------
30 CONTINUE
LPCG = LPCG + 1
CALL DCOPY (N, R, 1, Z, 1)
IER = 0
IF (JPRE .EQ. 0) GO TO 40
C UROUND = machine unit roundoff
C EWT, ITOL, ATOL = error weights and tolerance parameters
C as described in the driver routine, input.
C Y, TEMP = work arrays of length N.
C H0 = step size to be attempted, output.
C NITER = number of iterations (and of f evaluations) to compute H0,
C output.
C IER = the error flag, returned with the value
C IER = 0 if no trouble occurred, or
C IER = -1 if TOUT and t0 are considered too close to proceed.
C-----------------------------------------------------------------------
ENDIF
ITER = ITER + 1
C-----------------------------------------------------------------------
C Test the stopping conditions.
C Stop if the new and previous H values differ by a factor of .lt. 2.
C Stop if four iterations have been done. Also, stop with previous H
C if hnew/hg .gt. 2 after first iteration, as this probably means that
C the second derivative value is bad because of cancellation error.
C-----------------------------------------------------------------------
IF (ITER .GE. 4) GO TO 80
HRAT = HNEW/HG
C ABS(H) = HMIN or 10 consecutive failures occurred.
C On a return with KFLAG negative, the values of TN and
C the YH array are as of the beginning of the last
C step, and H is the last step size attempted.
C MAXORD = the maximum order of integration method to be allowed.
C MAXCOR = the maximum number of corrector iterations allowed.
C MSBP = maximum number of steps between DSETPK calls (MITER .gt. 0).
C MXNCF = maximum number of convergence failures allowed.
C METH/MITER = the method flags. See description in driver.
C N = the number of first-order differential equations.
C-----------------------------------------------------------------------
CDIR$ IVDEP
DO 210 I = I1,NQNYH
210 YH1(I) = YH1(I) + YH1(I+NYH)
215 CONTINUE
C-----------------------------------------------------------------------
C Up to MAXCOR corrector iterations are taken. A convergence test is
C made on the RMS-norm of each correction, weighted by the error
C weight vector EWT. The sum of the corrections is accumulated in the
C vector ACOR(i). The YH array is not altered in the corrector loop.
C Within the corrector loop, an estimated rate of convergence (ROC)
C and a stiffness ratio estimate (STIFF) are kept. Corresponding
C ABS(H) = HMIN or 10 consecutive failures occurred.
C On a return with KFLAG negative, the values of TN and
C the YH array are as of the beginning of the last
C step, and H is the last step size attempted.
C MAXORD = the maximum order of integration method to be allowed.
C MAXCOR = the maximum number of corrector iterations allowed.
C MSBP = maximum number of steps between PJAC calls.
C MXNCF = maximum number of convergence failures allowed.
C METH/MITER = the method flags. See description in driver.
C N = the number of first-order differential equations.
C-----------------------------------------------------------------------
CDIR$ IVDEP
DO 210 I = I1,NQNYH
210 YH1(I) = YH1(I) + YH1(I+NYH)
215 CONTINUE
C-----------------------------------------------------------------------
C Up to MAXCOR corrector iterations are taken. A convergence test is
C made on the RMS-norm of each correction, weighted by H and the
C error weight vector EWT. The sum of the corrections is accumulated
C in ACOR(i). The YH array is not altered in the corrector loop.
C-----------------------------------------------------------------------
220 M = 0
view all matches for this distribution
view release on metacpan or search on metacpan
demos/euler.p view on Meta::CPAN
#################################################################################
# This script requires Math::GMPq, Math::GMPz, and Math::MPFR. #
# It calculates the euler number e (2.7182818...), correct to $ARGV[0] bits. #
# The calculated value is displayed unless $ARGV[1] is both provided and false. #
# With each iteration of the for{} loop (below) we get closer and closer to #
# the actual value of e. Furthermore, with successive iterations of the for{} #
# loop, the values alternate between "less than e" and "greater than e". #
# Hence the actual (irrational) value of e is always between the values #
# calculated by successive iterations of the for{} loop. #
# #
# Of course, the simplest and most efficient way to get the value of e, to #
# $ARGV[0] bits is simply to do: #
# Rmpfr_exp($rop, Math::MPFR->new(1), MPFR_RNDN) #
# where $rop is a $ARGV[0]-bit precision Math::MPFR object. #
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Matrix.pm view on Meta::CPAN
if ($abs_err_best <= $abs_tol || $rel_err_best <= $rel_tol) {
last;
} else {
# If we still haven't got the desired result, but have reached
# the maximum number of iterations, display a warning.
if ($iter == $max_iter) {
carp "mldiv() stopped because the maximum number of",
" iterations (max. iter = $max_iter) was reached without",
" converging to any of the desired tolerances (",
"rel_tol = ", $rel_tol, ", ",
"abs_tol = ", $abs_tol, ").",
" The best iterate (iter. = ", $iter_best, ") has",
" a relative residual of ", $rel_err_best, " and",
lib/Math/Matrix.pm view on Meta::CPAN
is satisfied, the algorithm terminates.
=head2 Stopping criteria
The algorithm stops when at least one of the errors are within the specified
tolerances or the maximum number of iterations is reached. If the maximum number
of iterations is reached, but noen of the errors are within the tolerances, a
warning is displayed and the best solution so far is returned.
=head2 Parameters
=over 4
=item MaxIter
The maximum number of iterations to perform. The value must be a positive
integer. The default is 20.
=item RelTol
The limit for the relative error. The value must be a non-negative. The default
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/MatrixReal.pm view on Meta::CPAN
my $dd = abs($d->[$m]) + abs($d->[$m+1]);
last if ((abs($e->[$m]) + $dd) == $dd);
}
if ($m != $l)
{
## why only allow 30 iterations?
croak("Too many iterations!") if ($iter++ >= 30);
my $g = ($d->[$l+1] - $d->[$l])
/ (2.0 * $e->[$l]);
my $r = _pythag($g, 1.0);
$g = $d->[$m] - $d->[$l]
+ $e->[$l] / ($g + (($g >= 0.0) ? abs($r) : -abs($r)));
lib/Math/MatrixReal.pm view on Meta::CPAN
my $dd = abs($d->[$m]) + abs($d->[$m+1]);
last if ((abs($e->[$m]) + $dd) == $dd);
}
if ($m != $l)
{
croak("Too many iterations!") if ($iter++ >= 30);
my $g = ($d->[$l+1] - $d->[$l])
/ (2.0 * $e->[$l]);
my $r = _pythag($g, 1.0);
$g = $d->[$m] - $d->[$l]
+ $e->[$l] / ($g + (($g >= 0.0) ? abs($r) : -abs($r)));
lib/Math/MatrixReal.pm view on Meta::CPAN
{'inverse' => sub { $matrix1->inverse(); },
'cofactor' => sub { (~$matrix1->cofactor)->each ( sub { (shift)/$det; } ) }
} );
Benchmark: timing 10 iterations of LR, cofactor, inverse...
inverse: 1 wallclock secs ( 0.56 usr + 0.00 sys = 0.56 CPU) @ 17.86/s (n=10)
cofactor: 36 wallclock secs (36.62 usr + 0.01 sys = 36.63 CPU) @ 0.27/s (n=10)
=item *
lib/Math/MatrixReal.pm view on Meta::CPAN
greater than by using an approximative (iterative) algorithm like one
of the three implemented here.
All three methods, GSM ("Global Step Method" or "Gesamtschrittverfahren"),
SSM ("Single Step Method" or "Einzelschrittverfahren") and RM ("Relaxation
Method" or "Relaxationsverfahren"), are fix-point iterations, that is, can
be described by an iteration function "C<x(t+1) = Phi( x(t) )>" which has
the property:
Phi(x) = x <==> A * x = b
view all matches for this distribution
view release on metacpan or search on metacpan
MatrixSparse.pm view on Meta::CPAN
C<< $matrix->jacobi($constant,$guess, $tol, $steps) >>
Uses Jacobi iteration to find and return the solution to the
system of equations $matrix * x = $constant, with initial guess
$constant, tolerance $tol, and maximum iterations $steps.
If $steps is undefined, the default value of 100 is used.
Care should be taken to ensure that $matrix is such that the
iteration actually converges.
MatrixSparse.pm view on Meta::CPAN
C<< $matrix->gaussseidel($constant,$guess, $tol, $steps) >>
Uses Gauss-Seidel iteration to find and return the solution to the
system of equations $matrix * x = $constant, with initial guess
$constant, tolerance $tol, and maximum
iterations $steps. This is equivalent to $matrix->SOR with
relaxation parameter 1.
Care should be taken to ensure that $matrix is such that the
iteration actually converges.
MatrixSparse.pm view on Meta::CPAN
C<< $matrix->SOR($constant,$guess, $relax, $tol, $steps) >>
Uses Successive Over-Relaxation to find and return the solution to the
system of equations $matrix * x = $constant, with initial guess
$constant, relaxation parameter $relax, tolerance $tol, and maximum
iterations $steps.
Care should be taken to ensure that $matrix is such that the
iteration actually converges.
=back
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/NLopt.pm view on Meta::CPAN
See L<Objective Functions>
=head2 set_maxeval
$opt->set_maxeval( $max_iterations );
=head2 set_maxtime
$opt->set_maxtime( $time );
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/NumSeq/AlphabeticalLengthSteps.pm view on Meta::CPAN
=for stopwords Ryde Math-NumSeq
=head1 NAME
Math::NumSeq::AlphabeticalLengthSteps -- iterations of length in characters
=head1 SYNOPSIS
use Math::NumSeq::AlphabeticalLengthSteps;
my $seq = Math::NumSeq::AlphabeticalLengthSteps->new;
view all matches for this distribution
view release on metacpan or search on metacpan
devel/haferman-carpet.pl view on Meta::CPAN
Array_1s_init1($n),
);
}
exit 0;
# num black cells after n iterations (9^(k+1) - (-5)^(k+1))/14 = 1,4,61,424
# Array1s(k+1) = 9^(k+1) - 5*Array1s(k)
# Array1s(0) = 1
# Array1s(1) = 9^1 - 5*1 = 4
# Array1s(2) = 9^2 - 5*(9^1 - 5*1)
# = 5^0*9^2 - 5^1*9^1 + 5^2*9^0
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Numerical.pm view on Meta::CPAN
The function supports the following parameters:
=over
=item C<max_iterations>
How many iterations of our algorithm will be applied at most while trying to
find a root for the given function. This gives an order of magnitude of the
number of times that C<$func> will be evaluated. Defaults to I<100>.
=item C<do_bracket>
lib/Math/Numerical.pm view on Meta::CPAN
return 0;
}
sub find_root ($func, $x1, $x2, %params) {
my $do_bracket = $params{do_bracket} // 1;
my $max_iter = $params{max_iterations} // $DEFAULT_MAX_ITERATIONS;
my $f = _wrap_func($func);
my ($xa, $xb, $fa, $fb);
if ($do_bracket) {
($xa, $xb, $fa, $fb) = bracket($func, $x1, $x2, %params);
croak 'Canât bracket a root of the function' unless defined $xa;
lib/Math/Numerical.pm view on Meta::CPAN
The function supports the following parameters:
=over
=item C<max_iterations>
How many iterations of our algorithm will be applied at most while trying to
bracket the given function. This gives an order of magnitude of the number of
times that C<$func> will be evaluated. Defaults to I<100>.
=item C<do_outward>
lib/Math/Numerical.pm view on Meta::CPAN
sub bracket ($func, $x1, $x2 = undef, %params) {
if (!defined $x2 || $x1 == $x2) {
Readonly my $LARGISH_FACTOR => 1000;
$x2 += $LARGISH_FACTOR * $EPS;
}
my $max_iter = $params{max_iterations} // $DEFAULT_MAX_ITERATIONS;
croak 'max_iterations must be positive' if $max_iter <= 0;
my $f = _wrap_func($func);
my $f1 = $f->($x1);
my $inward_state;
view all matches for this distribution
view release on metacpan or search on metacpan
t/MyTestHelpers.pm view on Meta::CPAN
#
# use Exporter;
# use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
# @ISA = ('Exporter');
# @EXPORT_OK = qw(findrefs
# main_iterations
# warn_suppress_gtk_icon
# glib_gtk_versions
# any_signal_connections
# nowarnings);
# %EXPORT_TAGS = (all => \@EXPORT_OK);
t/MyTestHelpers.pm view on Meta::CPAN
#-----------------------------------------------------------------------------
# Gtk/Glib helpers
# Gtk 2.16 can go into a hard loop on events_pending() / main_iteration_do()
# if dbus is not running, or something like that. In any case limiting the
# iterations is good for test safety.
#
sub main_iterations {
my $count = 0;
if (DEBUG) { MyTestHelpers::diag ("main_iterations() ..."); }
while (Gtk2->events_pending) {
$count++;
Gtk2->main_iteration_do (0);
if ($count >= 500) {
MyTestHelpers::diag ("main_iterations(): oops, bailed out after $count events/iterations");
return;
}
}
MyTestHelpers::diag ("main_iterations(): ran $count events/iterations");
}
# warn_suppress_gtk_icon() is a $SIG{__WARN__} handler which suppresses spam
# from Gtk trying to make you buy the hi-colour icon theme. Eg,
#
t/MyTestHelpers.pm view on Meta::CPAN
while (! $done) {
if (DEBUG >= 2) { MyTestHelpers::diag ("wait_for_event() iteration $count"); }
Gtk2->main_iteration;
$count++;
}
MyTestHelpers::diag ("wait_for_event(): '$signame' ran $count events/iterations\n");
$widget->signal_handler_disconnect ($sig_id);
Glib::Source->remove ($timer_id);
}
view all matches for this distribution
view release on metacpan or search on metacpan
Failed 16/82 test programs. 122/681 subtests failed.
XXX Our exception handler does not work as it should: the warning is already issued, so the error is empty.
Failed 16/82 test programs. 92/632 subtests failed. (without -O2 -s)
gclone() our tmp handlers ((x)->1), etc
Failed 16/82 test programs. 133/1249 subtests failed. (4 crashes; with -g)
We did not detach_stack() on restart. Now grows 6.7M on 1e5 iterations with 2.3.5 32bit windows (takes about 15min):
perl -Mblib -le "for (1..shift) {delete $INC{q(Math/Pari.pm)}; require Math::Pari; print sin Math::Pari::PARI(1)} END{warn 1; sleep 500}" 100000
XXX Probably worksv and workErrsv leaking???
XXX But this crashes with 100 (but not with 20):
perl -Mblib -wle "for (1..shift) {delete $INC{q(Math/Pari.pm)}; %Math::Pari::=(); require Math::Pari; $n=q(Math::Pari::PARI); *PARI = \&$n; print sin PARI(1)}" 100
To avoid warnings on redefinition, avoid function names in the script being resolved at compile time:
perl -Mblib -wle "for (1..shift) {delete $INC{q(Math/Pari.pm)}; %Math::Pari::=(); delete $::{PARI}; require Math::Pari; $n=q(Math::Pari::PARI); $N=q(PARI); *$N = \&$n; print sin &$N(1)}" 1000
but this cannot survive more than a few dozens of iterations... But this runs fine:
perl -wle "for (1..shift) {delete $INC{q(List/Util.pm)}; %List::Util:: = %Scalar::Util:: = %Sub::Util:: = (); $N=q(sum0); $n=qq(List::Util::$N); delete $::{$N}; require List::Util; *$N = \&$n; print 1 + &$N(1..10)}" 20000
The fix for -D_FORTIFY_SOURCE was not working. Redo.
2.030504
Patch for 2.5.0 was not updated. (Still not auto-applied.)
view all matches for this distribution
view release on metacpan or search on metacpan
t/MyTestHelpers.pm view on Meta::CPAN
# uncomment this to run the ### lines
#use Smart::Comments;
@ISA = ('Exporter');
@EXPORT_OK = qw(findrefs
main_iterations
warn_suppress_gtk_icon
glib_gtk_versions
any_signal_connections
nowarnings);
%EXPORT_TAGS = (all => \@EXPORT_OK);
t/MyTestHelpers.pm view on Meta::CPAN
#-----------------------------------------------------------------------------
# Gtk/Glib helpers
# Gtk 2.16 can go into a hard loop on events_pending() / main_iteration_do()
# if dbus is not running, or something like that. In any case limiting the
# iterations is good for test safety.
#
sub main_iterations {
my $count = 0;
if (DEBUG) { MyTestHelpers::diag ("main_iterations() ..."); }
while (Gtk2->events_pending) {
$count++;
Gtk2->main_iteration_do (0);
if ($count >= 500) {
MyTestHelpers::diag ("main_iterations(): oops, bailed out after $count events/iterations");
return;
}
}
MyTestHelpers::diag ("main_iterations(): ran $count events/iterations");
}
# warn_suppress_gtk_icon() is a $SIG{__WARN__} handler which suppresses spam
# from Gtk trying to make you buy the hi-colour icon theme. Eg,
#
t/MyTestHelpers.pm view on Meta::CPAN
while (! $done) {
if (DEBUG >= 2) { MyTestHelpers::diag ("wait_for_event() iteration $count"); }
Gtk2->main_iteration;
$count++;
}
MyTestHelpers::diag ("wait_for_event(): '$signame' ran $count events/iterations\n");
$widget->signal_handler_disconnect ($sig_id);
Glib::Source->remove ($timer_id);
}
view all matches for this distribution
view release on metacpan or search on metacpan
devel/dragon.pl view on Meta::CPAN
}
exit 0;
}
{
# convex hull iterations
#
require Math::Geometry::Planar;
my $points = [ [0,0], [1,0], [1,1] ];
my $nx = 1;
my $ny = 1;
view all matches for this distribution
view release on metacpan or search on metacpan
examples/newton_raphson.pl view on Meta::CPAN
die "division by zero: polynomial's derivate is 0 at $old_guess"
if ($dividend == 0);
$new_guess = $old_guess - $p->eval($old_guess)/$dividend;
$p->iterations($p->iterations + 1);
die "reached maximum number of iterations [$max_depth] without getting close enough to the root."
if ($p->iterations > $max_depth);
}
print "the root of:\n".$p->stringify."\nis: ".$new_guess."\n";
view all matches for this distribution
view release on metacpan or search on metacpan
t/MyTestHelpers.pm view on Meta::CPAN
#
# use Exporter;
# use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
# @ISA = ('Exporter');
# @EXPORT_OK = qw(findrefs
# main_iterations
# warn_suppress_gtk_icon
# glib_gtk_versions
# any_signal_connections
# nowarnings);
# %EXPORT_TAGS = (all => \@EXPORT_OK);
t/MyTestHelpers.pm view on Meta::CPAN
#-----------------------------------------------------------------------------
# Gtk/Glib helpers
# Gtk 2.16 can go into a hard loop on events_pending() / main_iteration_do()
# if dbus is not running, or something like that. In any case limiting the
# iterations is good for test safety.
#
sub main_iterations {
my $count = 0;
if (DEBUG) { MyTestHelpers::diag ("main_iterations() ..."); }
while (Gtk2->events_pending) {
$count++;
Gtk2->main_iteration_do (0);
if ($count >= 500) {
MyTestHelpers::diag ("main_iterations(): oops, bailed out after $count events/iterations");
return;
}
}
MyTestHelpers::diag ("main_iterations(): ran $count events/iterations");
}
# warn_suppress_gtk_icon() is a $SIG{__WARN__} handler which suppresses spam
# from Gtk trying to make you buy the hi-colour icon theme. Eg,
#
t/MyTestHelpers.pm view on Meta::CPAN
while (! $done) {
if (DEBUG >= 2) { MyTestHelpers::diag ("wait_for_event() iteration $count"); }
Gtk2->main_iteration;
$count++;
}
MyTestHelpers::diag ("wait_for_event(): '$signame' ran $count events/iterations\n");
$widget->signal_handler_disconnect ($sig_id);
Glib::Source->remove ($timer_id);
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Polynomial/Solve.pm view on Meta::CPAN
$ascending_flag = 1;
if ($option{hessenberg} or $#coefficients > 4)
{
#
# QR iterations from the matrix.
#
@x = hqr_eigen_hessenberg(
balance_matrix(build_companion(@coefficients))
);
}
lib/Math/Polynomial/Solve.pm view on Meta::CPAN
$n -= 2;
next ROOT;
}
croak "Too many iterations ($its) at n=$n\n" if ($its >= $iteration{hessenberg});
if ($its && $its % 10 == 0)
{
#
# Form exceptional shift.
lib/Math/Polynomial/Solve.pm view on Meta::CPAN
#
push @boundaries, sturm_bisection($chain_ref, $from, $mid);
push @boundaries, sturm_bisection($chain_ref, $mid, $to);
last ROOT;
}
croak "Too many iterations ($its) at mid=$mid\n" if ($its >= $iteration{sturm_bisection});
$its++;
}
return @boundaries;
}
lib/Math/Polynomial/Solve.pm view on Meta::CPAN
{
push @roots, $x;
last ROOT;
}
croak "Too many iterations ($its) at dx=$dx\n" if ($its >= $iteration{laguerre});
$its++;
}
### root found at iteration $its
#### $x
lib/Math/Polynomial/Solve.pm view on Meta::CPAN
#### At Iteration: $its
#### x: $x
#### f(x): $y
#### f'(x): $dy
#
croak "Too many iterations ($its) at dx=$dx\n" if ($its >= $iteration{newtonraphson});
$its++;
}
### root found at iteration $its
#### $x
lib/Math/Polynomial/Solve.pm view on Meta::CPAN
return @roots;
}
=head3 poly_iteration()
Sets the limit to the number of iterations that a solving method may go
through before giving up trying to find a root. Each method of root-finding
used by L</poly_roots()>, L</sturm_bisection_roots()>, and L</laguerre()>
has its own iteration limit, which may be found, like L</poly_option()>,
simply by looking at the return value of poly_iteration().
view all matches for this distribution
view release on metacpan or search on metacpan
spec/bpsw/trn.c view on Meta::CPAN
we also need to filter out all perfect square values of N, such as
1093^2 (a base-2 strong pseudoprime); this is because we will later
require an integer D for which Jacobi(D,N) = -1, and no such integer
exists if N is a perfect square. The algorithm as written would
still eventually return zero in this case, but would require
nearly sqrt(N)/2 iterations. */
iComp2=mpz_cmp_si(mpzN, 2);
if(iComp2 < 0)return(0);
if(iComp2==0)return(1);
if(mpz_even_p(mpzN))return(0);
spec/bpsw/trn.c view on Meta::CPAN
we also need to filter out all perfect square values of N, such as
1093^2 (a base-2 strong pseudoprime); this is because we will later
require an integer D for which Jacobi(D,N) = -1, and no such integer
exists if N is a perfect square. The algorithm as written would
still eventually return zero in this case, but would require
nearly sqrt(N)/2 iterations. */
iComp2=mpz_cmp_si(mpzN, 2);
if(iComp2 < 0)return(0);
if(iComp2==0)return(1);
if(mpz_even_p(mpzN))return(0);
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Prime/FastSieve.pm view on Meta::CPAN
deserve thanks and credit.
Dana Jacobsen provided several optimizations that improved even further on
the speed and memory performance of this module. Dana's contributions include
reducing the memory footprint of the bit sieve in half, and trimming cycles by
cutting in half the number of iterations of an inner loop in the sieve
generator. This module started fast and got even faster (and more memory
efficient) with Dana's contributions.
=head1 SEE ALSO
view all matches for this distribution
view release on metacpan or search on metacpan
k3 = log(k2);
w = k2-1-k3+(1+k3+(-1/2+(1/2)*k3*k3 +(-1/6+(-1+(-1/2+
(1/3) * k3) * k3) * k3) * k1) * k1) * k1;
}
/* Improve the FP estimate using two simple Halley iterations. */
if (x >= -0.36728) {
if (w != 0) w = (w/(1.0+w)) * (1.0+log(x/w));
if (w != 0) w = (w/(1.0+w)) * (1.0+log(x/w));
if (isnan(w)) w = DBL_EPSILON;
}
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Prime/Util.pm view on Meta::CPAN
on the approximate twin prime count.
=head2 nth_semiprime
Returns the Nth semiprime, similar to where a C<forsemiprimes> loop would
end after C<N> iterations, but much more efficiently.
=head2 nth_semiprime_approx
Returns an approximation to the Nth semiprime. The approximation is
orders of magnitude better than the simple C<n log n / log log n>
lib/Math/Prime/Util.pm view on Meta::CPAN
If no such pairs exist, an empty list is returned.
=head2 is_happy
Given a single non-negative integer C<n>, returns the number of iterations
required for the map of sum of squared base-10 digits to converge to C<1>,
or C<0> if it does not converge to the value C<1>.
This returns the height using the OEIS A090425 definition of height, which is
zero for non-happy numbers, 1 for C<n=1>, 2 for numbers that produce 1 after
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Prime/XS.pm view on Meta::CPAN
L<http://primes.utm.edu/glossary/page.php?sort=TrialDivision>
=head1 BENCHMARK
Following output resulted from a benchmark measuring the time to calculate
primes up to 1,000,000 with 100 iterations for each function. The tests
were conducted by the C<cmpthese> function of the Benchmark module.
Rate mod_primes trial_primes sum_primes sieve_primes
mod_primes 1.32/s -- -58% -79% -97%
trial_primes 3.13/s 137% -- -49% -93%
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Project3D.pm view on Meta::CPAN
} @ranges;
# Prepare counters for every range.
my @counters = (0) x scalar(@ranges);
# Calculate the number if iterations needed.
# It is $_+1 and not $_ because the lengths are the lengths we
# need for the comparisons inside the long for loop. We save one
# op in there that way.
my $iterations = 1;
$iterations *= ( $_ + 1 ) for @lengths;
# For all possible combinations of parameters...
for (my $i = 1; $i <= $iterations; $i++) {
# Get current function parameters
my @params;
# Get one parameter for every range
view all matches for this distribution
view release on metacpan or search on metacpan
xt/benchmark.pl view on Meta::CPAN
use Math::Random::MT::Perl;
use Math::Random::MT;
use Benchmark 'cmpthese';
my $count = $ARGV[0] || 10000;
print "Doing $count iterations\n";
my $p = Math::Random::MT::Perl->new(1);
my $c = Math::Random::MT->new(1);
cmpthese( $count, {
Perl => sub { $p->rand() },
C => sub { $c->rand() }, }
);
__DATA__
C:\Math-Random-MT-Perl-1.03\t>benchmark.pl 10000000
Doing 10000000 iterations
Rate Perl C
Perl 114654/s -- -63%
C 308880/s 169% --
view all matches for this distribution
view release on metacpan or search on metacpan
mtwist/randistrs.c view on Meta::CPAN
#endif /* MT_CACHING */
{
/*
* Range is different from last time, recalculate mask.
*
* A few iterations could be trimmed off of the loop if we
* started rangemask at the next power of 2 above
* RD_UNIFORM_THRESHOLD. However, I don't currently know
* a formula for generating that value (though there is
* probably one in HAKMEM).
*/
view all matches for this distribution
view release on metacpan or search on metacpan
lib/Math/Rational/Approx.pm view on Meta::CPAN
#
# find rational approximation to arbitrary precision using
# continued fractions
# one shot, 10 iterations
( $numerator, $denominator ) =
contfrac_nd( contfrac( 1.234871035, 10 ) );
# multiple calls on same number; useful for convergence tests
# keep array containing terms; get fraction and perhaps test it
view all matches for this distribution
view release on metacpan or search on metacpan
t/lib/Check_FairRound.pm view on Meta::CPAN
}
use Math::Round::Fair qw(round_adjacent);
sub run_case {
my ($in, $iterations, $how_unlikely) = @_;
die "Total loss of precision" if 1.0 - $how_unlikely/4.0 == 1.0;
my @in = @$in;
my $sum=0.0;
$sum += $_ for(@in);
my @accums = map { 0.0 } (@in, 'SUM');
for my $iteration (1..$iterations) {
eval {
my @out = round_adjacent(@in);
die "wrong number of results" unless @out==@in;
my $round_sum=0;
$round_sum += $_ for(@out);
t/lib/Check_FairRound.pm view on Meta::CPAN
chomp($@) and die "$@ on iteration number $iteration" if $@;
}
if($verify_stats) {
# Check that each average meets its expectation.
my @avgs = map { $_/$iterations } @accums;
for(
(map { [$in[$_], $avgs[$_]] } ($[..$#in)), [$sum, $avgs[-1]]
) {
my ($expect, $average) = @$_;
my $n = $iterations;
my $base = int($expect);
my $p = abs($expect - $base);
my $x = int($n * abs($average - $base) + 0.5);
my $prob = pbinom($x, $n, $p);
view all matches for this distribution
view release on metacpan or search on metacpan
Ryu_Library/ryu/benchmark/benchmark.cc view on Meta::CPAN
benchmark_options& operator=(const benchmark_options&) = delete;
bool run32() const { return m_run32; }
bool run64() const { return m_run64; }
int samples() const { return m_samples; }
int iterations() const { return m_iterations; }
bool verbose() const { return m_verbose; }
bool ryu_only() const { return m_ryu_only; }
bool classic() const { return m_classic; }
int small_digits() const { return m_small_digits; }
Ryu_Library/ryu/benchmark/benchmark.cc view on Meta::CPAN
m_classic = true;
} else if (strncmp(arg, "-samples=", 9) == 0) {
if (sscanf(arg, "-samples=%i", &m_samples) != 1 || m_samples < 1) {
fail(arg);
}
} else if (strncmp(arg, "-iterations=", 12) == 0) {
if (sscanf(arg, "-iterations=%i", &m_iterations) != 1 || m_iterations < 1) {
fail(arg);
}
} else if (strncmp(arg, "-small_digits=", 14) == 0) {
if (sscanf(arg, "-small_digits=%i", &m_small_digits) != 1 || m_small_digits < 1 || m_small_digits > 7) {
fail(arg);
Ryu_Library/ryu/benchmark/benchmark.cc view on Meta::CPAN
void fail(const char * const arg) {
printf("Unrecognized option '%s'.\n", arg);
exit(EXIT_FAILURE);
}
// By default, run both 32 and 64-bit benchmarks with 10000 samples and 1000 iterations each.
bool m_run32 = true;
bool m_run64 = true;
int m_samples = 10000;
int m_iterations = 1000;
bool m_verbose = false;
bool m_ryu_only = false;
bool m_classic = false;
int m_small_digits = 0;
};
Ryu_Library/ryu/benchmark/benchmark.cc view on Meta::CPAN
for (int i = 0; i < options.samples(); ++i) {
uint32_t r = 0;
const float f = generate_float(options, mt32, r);
auto t1 = steady_clock::now();
for (int j = 0; j < options.iterations(); ++j) {
f2s_buffered(f, bufferown);
throwaway += bufferown[2];
}
auto t2 = steady_clock::now();
double delta1 = duration_cast<nanoseconds>(t2 - t1).count() / static_cast<double>(options.iterations());
mv1.update(delta1);
double delta2 = 0.0;
if (!options.ryu_only()) {
t1 = steady_clock::now();
for (int j = 0; j < options.iterations(); ++j) {
fcv(f);
throwaway += buffer[2];
}
t2 = steady_clock::now();
delta2 = duration_cast<nanoseconds>(t2 - t1).count() / static_cast<double>(options.iterations());
mv2.update(delta2);
}
if (options.verbose()) {
if (options.ryu_only()) {
Ryu_Library/ryu/benchmark/benchmark.cc view on Meta::CPAN
for (int i = 0; i < options.samples(); ++i) {
uint32_t r = 0;
vec[i] = generate_float(options, mt32, r);
}
for (int j = 0; j < options.iterations(); ++j) {
auto t1 = steady_clock::now();
for (int i = 0; i < options.samples(); ++i) {
f2s_buffered(vec[i], bufferown);
throwaway += bufferown[2];
}
Ryu_Library/ryu/benchmark/benchmark.cc view on Meta::CPAN
for (int i = 0; i < options.samples(); ++i) {
uint64_t r = 0;
const double f = generate_double(options, mt32, r);
auto t1 = steady_clock::now();
for (int j = 0; j < options.iterations(); ++j) {
d2s_buffered(f, bufferown);
throwaway += bufferown[2];
}
auto t2 = steady_clock::now();
double delta1 = duration_cast<nanoseconds>(t2 - t1).count() / static_cast<double>(options.iterations());
mv1.update(delta1);
double delta2 = 0.0;
if (!options.ryu_only()) {
t1 = steady_clock::now();
for (int j = 0; j < options.iterations(); ++j) {
dcv(f);
throwaway += buffer[2];
}
t2 = steady_clock::now();
delta2 = duration_cast<nanoseconds>(t2 - t1).count() / static_cast<double>(options.iterations());
mv2.update(delta2);
}
if (options.verbose()) {
if (options.ryu_only()) {
Ryu_Library/ryu/benchmark/benchmark.cc view on Meta::CPAN
for (int i = 0; i < options.samples(); ++i) {
uint64_t r = 0;
vec[i] = generate_double(options, mt32, r);
}
for (int j = 0; j < options.iterations(); ++j) {
auto t1 = steady_clock::now();
for (int i = 0; i < options.samples(); ++i) {
d2s_buffered(vec[i], bufferown);
throwaway += bufferown[2];
}
view all matches for this distribution