Skip to content

Commit

Permalink
Fix ad(x) so it works when x is an int (with new Boost Python)
Browse files Browse the repository at this point in the history
doc.omh: new date on version of pycppad.
install.omh: improve requirements, fix spelling error, update version.
__init__.py: fix ad(x) here.
setup.template: imporve boost python user setting names and error messages.
  • Loading branch information
Brad Bell committed May 12, 2009
1 parent 0a5ee6a commit 50d62fe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion brad/doc.omh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $hiliteseq%
%.%reverse%(% reverse
%$$

$section pycppad-20090213: A Python Algorithm Derivative Package$$
$section pycppad-20090512: A Python Algorithm Derivative Package$$

$index AD, python$$
$index python, AD$$
Expand Down
28 changes: 17 additions & 11 deletions brad/omh/install.omh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$begin install$$
$dollar @$$
$spell
numpy
usr
inplace
undef
Expand All @@ -27,13 +28,18 @@ $section Installing pycppad$$
$index install, pycppad$$
$index pycppad, install$$

$head Requires$$
This package requires the following other packages to be installed:
Boost Python (development version),
numpy.

$head Downloading$$
$index download, pycppad$$
$index pycppad, download$$
Download the file
$href%
http://www.seanet.com/~bradbell/pycppad-20090213.tar.gz%
pycppad-20090213.tar.gz
http://www.seanet.com/~bradbell/pycppad-20090512.tar.gz%
pycppad-20090512.tar.gz
%$$
and store it on your machine.

Expand All @@ -44,14 +50,14 @@ $index extract, pycppad$$
$index pycppad, extract$$
On unix, you could use the command
$codep
tar -xvzf pycppad-20090213.tar.gz
tar -xvzf pycppad-20090512.tar.gz
$$
which would create the directory $code pycppad-20090213$$.
which would create the directory $code pycppad-20090512$$.

$head Required Setup Information$$
The value of the following setup variables, in the file
$codep
pycppad-20090213/setup.py
pycppad-20090512/setup.py
$$
must be set to agree with your system:
$code
Expand All @@ -64,7 +70,7 @@ properly set this information
$head Building$$
$index build, pycppad$$
$index pycppad, build$$
Change into the directory $code pycppad-20090213$$ and execute the command
Change into the directory $code pycppad-20090512$$ and execute the command
$codep
./setup.py build_ext --inplace --debug --undef NDEBUG
$$
Expand Down Expand Up @@ -98,7 +104,7 @@ $index test, pycppad$$
$index pycppad, test$$
You can test of all the
$cref/examples/example/$$ in the $code pycppad$$ documentation.
Change into the directory $code pycppad-20090213$$ and execute the command
Change into the directory $code pycppad-20090512$$ and execute the command
$codep
python test_example.py
$$
Expand All @@ -115,7 +121,7 @@ You may or may not preform this step:
$pre

$$
Change into the directory $code pycppad-20090213$$ and execute the command
Change into the directory $code pycppad-20090512$$ and execute the command
$codei%
python setup.py install --prefix=%prefix%
%$$
Expand All @@ -134,7 +140,7 @@ an uninstall command. You can uninstall the $code pycppad$$ package
by removing the entries
$codei%
%prefix%/lib/python%major%.%minor%/site-packages/pycppad
%prefix%/lib/python%major%.%minor%/site-packages/pycppad-20090213.egg-info
%prefix%/lib/python%major%.%minor%/site-packages/pycppad-20090512.egg-info
%prefix%/share/doc/pycppad
%$$
where $icode major$$ and $icode minor$$
Expand All @@ -152,7 +158,7 @@ $codei%
%$$
unless the distribution directory
$codep
pycppad-20090213
pycppad-20090512
$$
or (provided you installed $code pycppad$$) the installation directory
$codei%
Expand All @@ -174,7 +180,7 @@ $codei%
$head pycppad Documentation$$
The documentation for $code pycppad$$ starts out in the directory
$codep
pycppad-20090213/doc
pycppad-20090512/doc
$$
During the installation process, it is copied to the directory
$codei%
Expand Down
4 changes: 3 additions & 1 deletion brad/pycppad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ def ad(x) :
(AD level 1). If x is an a_float (AD level 1), ad(x) is an a2float
(AD level 2). Higher AD levels for the argument x are not yet supported.
"""
if isinstance(x, int) or isinstance(x, float) :
if isinstance(x, int) :
return a_float( float(x) )
elif isinstance(x, float) :
return a_float(x)
elif isinstance(x, a_float) :
return a2float(x)
Expand Down
25 changes: 16 additions & 9 deletions brad/setup.template
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env python
# ---------------------------------------------------------------------
# The code below is included verbatim in omh/install.omh
# BEGIN USER SETTINGS
boost_lib_dir = '/usr/lib' # Directory where boost::python library is located
boost_python_lib = 'boost_python' # name of the library in that directory
# Directory where Boost Python library is located
boost_python_lib_dir = '/usr/lib'
# The name of the Boost Python library in that directory which must
# begin with 'lib' and end with '.so'.
boost_python_lib_name = 'libboost_python-py26.so'
# END USER SETTINGS
# ---------------------------------------------------------------------
# See http://docs.python.org/distutils/setupscript.html
Expand All @@ -28,20 +32,23 @@ else :
exit(1)
cppad_include_dir = cppad_parent_dir + '/' + cppad_dir
# ---------------------------------------------------------------------

import re
import os
import sys
from distutils.core import setup, Extension
from numpy.distutils.misc_util import get_numpy_include_dirs
# ---------------------------------------------------------------------
boost_python_lib_path = boost_lib_dir + '/lib' + boost_python_lib + '.so'
m = re.search('lib([a-zA-Z0-9_-]+)[.]so', boost_python_lib_name)
if m == None :
print 'boost_python_lib_name must begin with \'lib\' and end with \'.so\''
boost_python_lib = m.group(1)
boost_python_lib_path = boost_python_lib_dir + boost_python_lib_name
if not os.access ( boost_python_lib_path , os.R_OK ) :
print 'Cannot find the boost::python library'
print boost_python_lib_path
print 'Cannot find the Boost Python library.'
print 'Use the following web page for information about boost::python'
print 'http://www.boost.org/doc/libs/1_37_0/libs/python/doc/index.html'
print 'Make sure that boost_lib_dir and boost_python_lib are set correctly'
print 'at the beginnin of the file setup.py'
print 'Make sure that boost_python_lib_dir and boost_python_lib_name'
print 'are set correctly at the beginnin of the file setup.py'
# ---------------------------------------------------------------------
# set cppad_include_dir
build_source_dist = False
Expand Down Expand Up @@ -81,7 +88,7 @@ package_license = 'BSD'
cppad_extension_name = 'pycppad' + '/cppad_'
cppad_extension_include_dirs = get_numpy_include_dirs()
cppad_extension_include_dirs.append( cppad_include_dir )
cppad_extension_library_dirs = [ boost_lib_dir ]
cppad_extension_library_dirs = [ boost_python_lib_dir ]
cppad_extension_libraries = [ boost_python_lib ]
cppad_extension_sources = [
'pycppad' + '/adfun.cpp' ,
Expand Down

0 comments on commit 50d62fe

Please sign in to comment.