~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

Viewing changes to scipy/weave/examples/increment_example.py

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# examples/increment_example.py
 
2
 
 
3
#from weave import ext_tools
 
4
 
 
5
# use the following so that development version is used.
 
6
import sys
 
7
sys.path.insert(0,'..')
 
8
import ext_tools
 
9
 
 
10
def build_increment_ext():
 
11
    """ Build a simple extension with functions that increment numbers.
 
12
        The extension will be built in the local directory.
 
13
    """
 
14
    mod = ext_tools.ext_module('increment_ext')
 
15
 
 
16
    a = 1 # effectively a type declaration for 'a' in the
 
17
          # following functions.
 
18
 
 
19
    ext_code = "return_val = PyInt_FromLong(a+1);"
 
20
    func = ext_tools.ext_function('increment',ext_code,['a'])
 
21
    mod.add_function(func)
 
22
 
 
23
    ext_code = "return_val = PyInt_FromLong(a+2);"
 
24
    func = ext_tools.ext_function('increment_by_2',ext_code,['a'])
 
25
    mod.add_function(func)
 
26
 
 
27
    mod.compile()
 
28
 
 
29
if __name__ == "__main__":
 
30
    try:
 
31
        import increment_ext
 
32
    except ImportError:
 
33
        build_increment_ext()
 
34
        import increment_ext
 
35
    a = 1
 
36
    print 'a, a+1:', a, increment_ext.increment(a)
 
37
    print 'a, a+2:', a, increment_ext.increment_by_2(a)