summaryrefslogtreecommitdiff
path: root/debian
diff options
context:
space:
mode:
authorGard Spreemann <gspreemann@gmail.com>2018-06-12 18:44:43 +0200
committerGard Spreemann <gspreemann@gmail.com>2018-06-13 10:04:12 +0200
commit87e19e911150252505b9dc2348cea196d3be612f (patch)
tree2530e07e785d5d9fdeddccedc1d5f7dd2473c315 /debian
parent40f8a399c94a026992e309ef0060513f076c53f6 (diff)
Add tests.
Diffstat (limited to 'debian')
-rw-r--r--debian/control2
-rw-r--r--debian/copyright4
-rw-r--r--debian/tests/control2
-rw-r--r--debian/tests/test1.f90106
-rw-r--r--debian/tests/test2.f90139
-rwxr-xr-xdebian/tests/tests.sh32
6 files changed, 284 insertions, 1 deletions
diff --git a/debian/control b/debian/control
index 4b107c0..4074fab 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: lbfgsb
Maintainer: Gard Spreemann <gspreemann@gmail.com>
Section: math
Priority: optional
-Standards-Version: 4.1.3
+Standards-Version: 4.1.4
Build-Depends: debhelper (>= 11), gfortran, libblas-dev, liblapack-dev, dh-exec
Homepage: http://users.iems.northwestern.edu/~nocedal/lbfgsb.html
Vcs-Browser: https://git.nonempty.org/debian-lbfgsb
diff --git a/debian/copyright b/debian/copyright
index eae63cf..f97164f 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -13,6 +13,10 @@ Files: debian/*
Copyright: 2013-2016 Gard Spreemann <gspreemann@gmail.com>
License: BSD-3-clause
+Files: debian/tests/*.f90
+Copyright: Ciyou Zhu, Richard Byrd, Jorge Nocedal, Jose Luis Morales
+License: BSD-3-clause
+
License: BSD-3-clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..d681ba0
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,2 @@
+Tests: tests.sh
+Depends: gfortran, shunit2, liblbfgsb-dev \ No newline at end of file
diff --git a/debian/tests/test1.f90 b/debian/tests/test1.f90
new file mode 100644
index 0000000..a70f9ef
--- /dev/null
+++ b/debian/tests/test1.f90
@@ -0,0 +1,106 @@
+! Simple self-test based on the driver*.f90 examples. Returns 1 in
+! the incorrect value is reached. Only other change is the removal of
+! long headers and comments.
+!
+! Copyright Ciyou Zhu, Richard Byrd, Jorge Nocedal, Jose Luis
+! Morales. 3-clause BSD license.
+
+ program driver
+
+ implicit none
+!
+ integer, parameter :: n = 25, m = 5, iprint = 1
+ integer, parameter :: dp = kind(1.0d0)
+ real(dp), parameter :: factr = 1.0d+7, pgtol = 1.0d-5
+!
+ character(len=60) :: task, csave
+ logical :: lsave(4)
+ integer :: isave(44)
+ real(dp) :: f
+ real(dp) :: dsave(29)
+ integer, allocatable :: nbd(:), iwa(:)
+ real(dp), allocatable :: x(:), l(:), u(:), g(:), wa(:)
+
+! Declare a few additional variables for this sample problem
+
+ real(dp) :: t1, t2
+ integer :: i
+
+! Allocate dynamic arrays
+
+ allocate ( nbd(n), x(n), l(n), u(n), g(n) )
+ allocate ( iwa(3*n) )
+ allocate ( wa(2*m*n + 5*n + 11*m*m + 8*m) )
+!
+ do 10 i=1, n, 2
+ nbd(i) = 2
+ l(i) = 1.0d0
+ u(i) = 1.0d2
+ 10 continue
+
+! Next set bounds on the even-numbered variables.
+
+ do 12 i=2, n, 2
+ nbd(i) = 2
+ l(i) = -1.0d2
+ u(i) = 1.0d2
+ 12 continue
+
+! We now define the starting point.
+
+ do 14 i=1, n
+ x(i) = 3.0d0
+ 14 continue
+
+ write (6,16)
+ 16 format(/,5x, 'Solving sample problem.', &
+ /,5x, ' (f = 0.0 at the optimal solution.)',/)
+
+! We start the iteration by initializing task.
+
+ task = 'START'
+
+! The beginning of the loop
+
+ do while(task(1:2).eq.'FG'.or.task.eq.'NEW_X'.or. &
+ task.eq.'START')
+
+! This is the call to the L-BFGS-B code.
+
+ call setulb ( n, m, x, l, u, nbd, f, g, factr, pgtol, &
+ wa, iwa, task, iprint,&
+ csave, lsave, isave, dsave )
+
+ if (task(1:2) .eq. 'FG') then
+
+ f=.25d0*( x(1)-1.d0 )**2
+ do 20 i=2, n
+ f = f + ( x(i)-x(i-1 )**2 )**2
+ 20 continue
+ f = 4.d0*f
+
+! Compute gradient g for the sample problem.
+
+ t1 = x(2) - x(1)**2
+ g(1) = 2.d0*(x(1) - 1.d0) - 1.6d1*x(1)*t1
+ do 22 i=2, n-1
+ t2 = t1
+ t1 = x(i+1) - x(i)**2
+ g(i) = 8.d0*t2 - 1.6d1*x(i)*t1
+ 22 continue
+ g(n) = 8.d0*t1
+
+ end if
+ end do
+ if (abs(f) < 1e-6) then
+ stop 0
+ else
+ stop 1
+ end if
+
+
+! end of loop do while
+
+
+ end program driver
+
diff --git a/debian/tests/test2.f90 b/debian/tests/test2.f90
new file mode 100644
index 0000000..23c80ba
--- /dev/null
+++ b/debian/tests/test2.f90
@@ -0,0 +1,139 @@
+! Simple self-test based on the driver*.f90 examples. Returns 1 in
+! the incorrect value is reached. Only other change is the removal of
+! long headers and comments.
+!
+! Copyright Ciyou Zhu, Richard Byrd, Jorge Nocedal, Jose Luis
+! Morales. 3-clause BSD license.
+
+ program driver
+
+
+ implicit none
+
+
+ integer, parameter :: n = 25, m = 5, iprint = -1
+ integer, parameter :: dp = kind(1.0d0)
+ real(dp), parameter :: factr = 0.0d0, pgtol = 0.0d0
+
+ character(len=60) :: task, csave
+ logical :: lsave(4)
+ integer :: isave(44)
+ real(dp) :: f
+ real(dp) :: dsave(29)
+ integer, allocatable :: nbd(:), iwa(:)
+ real(dp), allocatable :: x(:), l(:), u(:), g(:), wa(:)
+!
+ real(dp) :: t1, t2
+ integer :: i
+
+ allocate ( nbd(n), x(n), l(n), u(n), g(n) )
+ allocate ( iwa(3*n) )
+ allocate ( wa(2*m*n + 5*n + 11*m*m + 8*m) )
+
+ do 10 i=1, n,2
+ nbd(i)=2
+ l(i)=1.0d0
+ u(i)=1.0d2
+ 10 continue
+
+! Next set bounds on the even numbered variables.
+
+ do 12 i=2, n,2
+ nbd(i)=2
+ l(i)=-1.0d2
+ u(i)=1.0d2
+ 12 continue
+
+! We now define the starting point.
+
+ do 14 i=1, n
+ x(i)=3.0d0
+ 14 continue
+
+! We now write the heading of the output.
+
+ write (6,16)
+ 16 format(/,5x, 'Solving sample problem.', &
+ /,5x, ' (f = 0.0 at the optimal solution.)',/)
+
+
+! We start the iteration by initializing task.
+!
+ task = 'START'
+
+! ------- the beginning of the loop ----------
+
+ do while( task(1:2).eq.'FG'.or.task.eq.'NEW_X'.or. &
+ task.eq.'START')
+
+! This is the call to the L-BFGS-B code.
+
+ call setulb(n,m,x,l,u,nbd,f,g,factr,pgtol,wa,iwa,task,iprint, &
+ csave,lsave,isave,dsave)
+
+ if (task(1:2) .eq. 'FG') then
+
+! the minimization routine has returned to request the
+! function f and gradient g values at the current x.
+
+! Compute function value f for the sample problem.
+
+ f =.25d0*(x(1) - 1.d0)**2
+ do 20 i=2,n
+ f = f + (x(i) - x(i-1)**2)**2
+ 20 continue
+ f = 4.d0*f
+
+! Compute gradient g for the sample problem.
+
+ t1 = x(2) - x(1)**2
+ g(1) = 2.d0*(x(1) - 1.d0) - 1.6d1*x(1)*t1
+ do 22 i= 2,n-1
+ t2 = t1
+ t1 = x(i+1) - x(i)**2
+ g(i) = 8.d0*t2 - 1.6d1*x(i)*t1
+ 22 continue
+ g(n)=8.d0*t1
+!
+ else
+!
+ if (task(1:5) .eq. 'NEW_X') then
+!
+
+ if (isave(34) .ge. 99) &
+ task='STOP: TOTAL NO. of f AND g EVALUATIONS EXCEEDS LIMIT'
+
+ if (dsave(13) .le. 1.d-10*(1.0d0 + abs(f))) &
+ task='STOP: THE PROJECTED GRADIENT IS SUFFICIENTLY SMALL'
+
+
+ write (6,'(2(a,i5,4x),a,1p,d12.5,4x,a,1p,d12.5)') 'Iterate' &
+ , isave(30),'nfg =',isave(34),'f =',f,'|proj g| =',dsave(13)
+
+! If the run is to be terminated, we print also the information
+! contained in task as well as the final value of x.
+
+ if (task(1:4) .eq. 'STOP') then
+ write (6,*) task
+ write (6,*) 'Final X='
+ write (6,'((1x,1p, 6(1x,d11.4)))') (x(i),i = 1,n)
+ end if
+
+ end if
+ end if
+
+ end do
+
+ if (abs(f) < 1e-6) then
+ stop 0
+ else
+ stop 1
+ end if
+! ---------- the end of the loop -------------
+
+! If task is neither FG nor NEW_X we terminate execution.
+
+ end program driver
+
+!======================= The end of driver2 ============================
+
diff --git a/debian/tests/tests.sh b/debian/tests/tests.sh
new file mode 100755
index 0000000..135564c
--- /dev/null
+++ b/debian/tests/tests.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+oneTimeSetUp() {
+ set -u
+ cp debian/tests/test*.f90 $AUTOPKGTEST_TMP
+}
+
+test() {
+ cwd=$(pwd)
+ cd $AUTOPKGTEST_TMP
+
+ names="test1 test2"
+ for name in $names
+ do
+ echo "Building."
+ set -x
+ gfortran -O3 -march=native -llbfgsb -o $name $name.f90
+ ret=$?
+ set +x
+ assertEquals 0 $ret
+
+ echo "Running."
+ set -x
+ ./$name
+ ret=$?
+ set +x
+ assertEquals 0 $ret
+ done
+ cd $cwd
+}
+
+. shunit2