source: trunk/ADOL-C/swig/adolc-python.i @ 764

Last change on this file since 764 was 764, checked in by mbanovic, 4 months ago

Merge branch swig into svn.

The following commits have been merged:

commit 15c64c07d051ef872afd8bc04f772624ac3c0580
Merge: a22cb31 617f278
Author: Mladen Banovic <mladenbanovic2705@…>
Date: Wed Jan 30 14:53:13 2019 +0100

Merge branch 'swig'

commit 617f2781bde18dd7c58f3a2554dec70d94cedd92
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Dec 21 16:23:11 2018 +0100

remove unnecessary %include

commit b7718a5407516afea3b1dabafeb3fa084a9b1ab3
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Dec 21 16:12:06 2018 +0100

fix destructors for EDF classes

commit 79ae7862f370fbbc04033d42cfd796b429c19e5f
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Dec 21 15:52:29 2018 +0100

improve test.py example

commit 0dbe7842bde1f9f92909fed8459e8298183c7890
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Dec 21 15:47:43 2018 +0100

add python examples

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 08ae3d98cadfb86016a48322319548d549ae3418
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Dec 21 15:47:14 2018 +0100

Make external functions work

EDFobject_v2 is not implemented yet

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit acfd9c5e41c2c2e99d7e530f0837dd6a5b0dac96
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Dec 11 12:07:01 2018 +0100

regenerate doc

commit c673f73ee35f8b8ce74258add01e085e68c0c13a
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Dec 11 12:06:21 2018 +0100

add python and R installation to doc

commit 317c3c5a6744d38091e809d804c23d637d900fe9
Author: kulshres <kulshres@94ac48a7-3327-4b6a-8511-9a4036a20e83>
Date: Wed Jun 13 15:21:36 2018 +0000

make init_lib() static to avoid name clashes in other units

git-svn-id: https://projects.coin-or.org/svn/ADOL-C/trunk@758 94ac48a7-3327-4b6a-8511-9a4036a20e83

commit 9a291b9b5646ae665382efafc3e9993c51aa4bc0
Author: kulshres <kulshres@94ac48a7-3327-4b6a-8511-9a4036a20e83>
Date: Wed Jun 13 15:02:22 2018 +0000

rename void init() to void init_lib()

this function is totally internal to tape_handling.cpp and called
from the constructor of Keeper class. However the name init() seems to refer
to something else in the scope of the class and correct initialization
isn't done, causing errors later.

git-svn-id: https://projects.coin-or.org/svn/ADOL-C/trunk@757 94ac48a7-3327-4b6a-8511-9a4036a20e83

commit f84f47f5f12c9a69ef44ccefe1b654fa3524cda3
Merge: 5021e4a 6c0d2d5
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Oct 11 21:53:14 2017 +0200

Merge branch 'swig' of gitlab.com:adol-c/adol-c into swig

commit 5021e4ab8cab3fd0760635e13c1a59e25f3c7eb6
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Oct 11 21:44:36 2017 +0200

add abs and rename asin/acos/atan to arcsin/arccos/arctan etc

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 6c0d2d5c9c90350b384b360dfb9659c9f2ca4bd6
Merge: cba0df1 2444ff3
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Oct 5 19:39:47 2017 +0000

Merge branch 'swig' into 'swig'

Python setup.py and R interface

See merge request adol-c/adol-c!11

commit 2444ff3a28e4a33a4670c8ebf6956f7c85a2274e
Merge: 068b059 946c873
Author: Sri Hari Krishna Narayanan <snarayan@…>
Date: Thu Oct 5 12:26:38 2017 -0500

Merge branch 'swig' of gitlab.com:sriharikrishna/adol-c into swig

commit 068b0592f59cbd11a434dca90be74ffbb767bde3
Author: Sri Hari Krishna Narayanan <snarayan@…>
Date: Thu Oct 5 12:19:52 2017 -0500

Change all use of clib to lib

commit ac987aca06b5c932adbd31bcf08811008b325257
Author: Sri Hari Krishna Narayanan <snarayan@…>
Date: Thu Oct 5 12:10:27 2017 -0500

Add python linking libraries

commit cba0df178387670ec3a1b94c237e13542090e78d
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Sep 5 13:37:03 2017 +0200

make psdrivers numpy conformant and remove one warning

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit e450b62a4b3e501e9940400137fc89351dbdb8ba
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Sep 5 13:35:07 2017 +0200

Make interface of psdrivers conformant and remove redundant parameter

Letters are as represented in the 2017 OMS paper.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 83c5f035130849b98a299857c7c5524a6ffb29a2
Merge: a50a2e1 363e176
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Aug 3 14:05:37 2017 +0200

Merge branch 'master' into swig

commit a50a2e19f79d3178592948c400d6eb89ed828b06
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Jun 22 13:52:26 2017 +0200

make setup.py install do everything

Of course this assumes you have autotools, libtool, and C++ compiler
previously installed as well as boost library and colpack.

commit 1a5f22002c83b99e8d69c297ae89cb03cc304e50
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Jun 22 13:51:41 2017 +0200

add missing support for numpy.sqrt

this was seemingly just oversight

commit f06f5011e183a203eca79444d6b175556f242f6a
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Jun 16 12:43:46 2017 +0200

add a setup.py for compatibilty with python installers

like pip or anaconda. In this case the setup.py will compile the C/C++
original library as well as the swig wrapper.
arguments to build are:
--lib-prefix=<DIR>

will install the C/C++ library andn headers in <DIR>/include <DIR>/lib64

--colpack-dir=<DIR>

will assume that ColPack? is installed in <DIR>/include and <DIR>/lib64

--boost-dir=<DIR>

will assume that boost is installed in <DIR>/include and <DIR>/lib64

I haven't tested on anything except 64-bit linux until now.

for install I've only tested installing with --user option

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit cd793f6a8503a1e3751cfaeb843af249c522ce46
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri May 5 10:16:23 2017 +0200

a slightly more meaningful naming

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 4c2a248fe5937daf292948e8ace9af0e4ccdffc1
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri May 5 10:08:24 2017 +0200

Fix Python Exception properly

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit f272c673fcb0941f3f054462eb9843be4e8b829a
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Apr 26 17:29:37 2017 +0200

export the cleanUp() function for wrappers

commit 0ed3a9394d3ed0e2804a3cef8b39dba105817e84
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Apr 19 18:09:39 2017 +0200

python3 compatibility and slight change in swigprocess.py

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit c085c16e96c2f5bce7f4a50a77d4164bcaa47cf6
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Feb 16 15:58:46 2017 +0100

add headers for implicit inclusions in edfclasses.h

commit 239078661e4d41e6ecdb131311f2fafe560874f3
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Feb 16 09:24:17 2017 +0100

add support for vectors and matrices in octave drivers

forward and reverse drivers to come. sparse drivers to come

commit 19e89992da84bdf392233c8add69d02bed714e60
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Dec 22 10:24:44 2016 +0100

Add swig interface for octave

commit 76a264d5412c5599102a4c9a182d3163a6ab6851
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Nov 18 15:49:36 2016 +0100

rename persistent local header to .hpp

since it is a c++ header. And some temporary .h files are created that
will require cleaning in 'make clean'

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit b59d463221a708e98af350decd97bdd26feb27d7
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Nov 18 14:01:19 2016 +0100

reorder some lines to fix compilation and %ignore issues

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 26535bfc6d9db954c246d991b5ef09d8cd8d66d1
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Nov 17 10:43:14 2016 +0100

Add directors for python extension of edfclasses.h

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit c522a5f6400e819eb393cfe44a68cae06fbb9ffe
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Nov 2 14:26:11 2016 -0500

call() must not be overloaded by child classes either

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 98fc1f127e71c3ffef73ed43525cd21ec45942b1
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Nov 2 14:19:59 2016 -0500

init_edf() must not be overloaded by child classes

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 1e5e0c68a7a0ff3369e9a3991edaa7d04164a3e5
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Nov 2 14:05:40 2016 -0500

design a C++ object oriented wrapper for external functions

it is easier to work with classes, inheritence and overloaded member
functions in scripting languages like python and R instead of raw
pointers to functions in order to call arbitrary code.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 782465d4175a2453934cd1ffe9649e3f78a42c75
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Sep 14 09:49:12 2016 +0200

add support for calling numpy.cos and friends on adouble arrays

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit b0ed723914bdc46ce9128727972dc287288b0a71
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Aug 10 18:28:43 2016 +0200

helper for printing exception

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 6f263543749e7fcb688e8af5cde68da3745886b5
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Aug 10 18:06:59 2016 +0200

expose FatalError? to swig python interface

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 7f579bb5629eb5f5c5a49ce4d0484a306640748d
Merge: d2f49d3 3bbd2a2
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Aug 10 17:54:41 2016 +0200

Merge branch 'master' into swig

commit d2f49d373e00f583e9b7c0ee69c160fbae1322c7
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Aug 10 13:37:10 2016 +0200

improve logic in fmin and fmax

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit e138ca65b6361b23a4000c77128d0ed684662e1c
Merge: cafefb7 3c5e311
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Aug 10 13:31:06 2016 +0200

Merge remote-tracking branch 'origin/swig' into swig

commit cafefb7081ff8d5ba7c772b5b022404101b813e0
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Aug 10 13:30:32 2016 +0200

wrap newly added functions in master branch

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit ff975ebd035995f0e9dc01578ac3e84b91b1604f
Merge: 02e32a7 4c79b27
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Aug 10 13:11:42 2016 +0200

Merge remote-tracking branch 'origin/master' into swig

commit 02e32a7aa72d4310238f7ae9b85a52e29b46cf4a
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Aug 10 13:09:31 2016 +0200

add fmin, fmax, fabs, and printTapeStats for swig-python

fmin, fmax and fabs should work on scalars as well as badoubles

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 3c5e3112cdb978f0274f4d6cacd128abc034ff9b
Merge: dd06803 7aa4b9a
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Aug 8 13:37:12 2016 +0200

Merge branch 'master' into swig

commit dd06803b3f40b3057976c315241f583bc0007397
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Aug 4 15:08:45 2016 +0200

raise exceptions for retracing in python

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit d253dfaa74f38b5b545f4f88ba08d86a65aa960a
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Jul 21 13:49:16 2016 +0200

fix typo in variable name

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit ade470ecf44fad03025ef9fcfadc5cac5d3e9f80
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Jul 21 11:36:06 2016 +0200

handle locint as an unsigned long

for some reason swig doesn't do this on it's own.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit e60c95d9dd70d962aed3caed4e05d0ef48ffcab2
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Jul 21 11:04:44 2016 +0200

use the compiler set up in ${CXX}

if ${CXX} is not set it defaults to 'c++'

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 42b439a47e2601325cb4d02aa27ac4b9c0535eea
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Jul 21 03:12:12 2016 +0200

add numpy compatible set_param_vec()

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 774a2204590aeb57cbc18e654bc6fe21763142c2
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Jul 21 02:41:22 2016 +0200

add function to convert numpy arrays directly to adouble arrays

works for any contiguous iterable type like list, tuple etc.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit c3e04155d83b3ee76df294c2adea78ca1df865f0
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Jul 14 10:57:43 2016 +0200

refresh swig patches for current swig master branch

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 48e0ef1cf7650d5b2e232d0d5450a158080d7849
Merge: 52445e4 06427e9
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Jul 14 10:36:59 2016 +0200

Merge branch 'master' into swig

commit 52445e41a8b768299084702418973ec79bd972c2
Merge: 666ba79 7507929
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Mar 23 14:59:05 2016 +0100

Merge branch 'master' into swig

commit 666ba7931e001bfd78171c7347b400b359dbd2d2
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Wed Mar 23 14:58:59 2016 +0100

add reverse drivers and use kwargs for overloaded forward/reverse call

also add tapestats.
more reverse drivers coming.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit c16bf7ff198728740896a804d85684c0575c1e47
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Mar 21 16:08:10 2016 +0100

add conversion for contiguous matrices and tensors

this time in the swig interface only, because they aren't
needed anywhere else.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit f3895ffd1dbb07b8a04e867982683ae8de7a5052
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Mar 21 15:45:22 2016 +0100

Revert "add conversion for contiguous matrices and tensors"

This reverts commit 7ad2746027b650147ec1d2da6567a3e5a7ecb876.

commit 76eb5d0899280cb9e3b4f4c1902823a45e884774
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Mar 21 13:46:12 2016 +0100

change forward drivers to return numpy arrays

instead of expecting inplace arguments

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 73bde825b256809ae07d124c1c6c66e9ae50eb82
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Mar 21 12:57:20 2016 +0100

change drivers to return numpy arrays

instead of expecting inplace arguments for output

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 946c87335675e68b7ea826eadd801d8d6fca4f54
Author: Sri Hari Krishna Narayanan <sriharikrishna@…>
Date: Thu Mar 17 07:55:25 2016 -0500

R: Added special handling for sparse_jac

commit 74d1c42cf5704c5ed7ae193cab6b2344334219c5
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Mar 15 14:32:47 2016 +0100

fix inclusion of sparse drivers for swig (and other users)

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit e97a73cc2a33645c517a83367d3e709ff3f4a244
Merge: de9eef7 dbc9f38
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 10 22:52:57 2016 +0000

Merge branch 'swig' into 'swig'

Swig/R

Cleanup

See merge request !4

commit dbc9f3847b58781367d8bcfd0545f3283d3ce350
Merge: b2dd718 de9eef7
Author: Sri Hari Krishna Narayanan <sriharikrishna@…>
Date: Thu Mar 10 16:45:26 2016 -0600

Merge remote-tracking branch 'origin/swig' into swig

commit b2dd71855ce277d4f956c99f04e03f954b0ff344
Author: Sri Hari Krishna Narayanan <sriharikrishna@…>
Date: Thu Mar 10 16:45:01 2016 -0600

R: removed extraneous pragmas

commit de9eef7ce7ba0d5a4256018f4d0bbf79bba25f7f
Merge: 0096858 fdaa52b
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 10 22:37:21 2016 +0000

Merge branch 'swig' into 'swig'

Swig/R

Bugfixes for SWIG/R interface

See merge request !3

commit fdaa52bf6654fa2558c2982738f4de1f49c2c960
Merge: 2fa790a 0096858
Author: Sri Hari Krishna Narayanan <sriharikrishna@…>
Date: Thu Mar 10 16:20:57 2016 -0600

Merge remote-tracking branch 'origin/swig' into swig

commit 2fa790a85c04b41755e5587baa21e59fe7416ab9
Author: Sri Hari Krishna Narayanan <sriharikrishna@…>
Date: Thu Mar 10 16:13:41 2016 -0600

R: debug all SWIG and R related bugs.

SWIG 3.0.8 needs the two patches and the generated adolc.R needs
the diff. Then ADOL-C can be imported into the R runtime by
source ("init_adolc.R")

commit 009685847f9d81b97d7efcc85d02aa7325bb6b6a
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 10 22:05:52 2016 +0100

reflect file rename in Makefile.am for packaging

commit 9c10d2065974fe1afba0284f5970e55f2e7f28b7
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 10 22:05:04 2016 +0100

add numpy implementation for common drivers

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 08b723756aa4e6ab2e6ff3f6c3d532691c831019
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 10 22:04:26 2016 +0100

change header extension to .hpp to suppress clang warning

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 109cb5ca0ae4c07592854af2a48cb6935e2e629b
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 10 20:51:16 2016 +0100

numpy: Be more verbose in error message for mismatch of dimension

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit d76918c8e2306ca2e13665fae7feb183b45652aa
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 10 19:58:08 2016 +0100

more licensing info

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 075bda30cf9d1a6432a9db4e587d6f3897ec8f1d
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 10 18:47:47 2016 +0100

compile interface based on choice

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit c368a02f8d44ad772da5659234a8bdeed254ab7c
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 10 18:21:54 2016 +0100

add numpy support to python swig interface for forward mode

also in swigprocess compatibility with macosx and general bugfixing

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 7ad2746027b650147ec1d2da6567a3e5a7ecb876
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 10 18:13:35 2016 +0100

add conversion for contiguous matrices and tensors

Just a contiguous row major chunk for matrices ins't
good for indexing using 2 indices, we need to convert
it to double and add pointers. Similarly for tensors.

These will do just that, required for supporting numpy
arrays in the python swig interface

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 41cb636430fa636b4e25ab81da73d2e6fd741dec
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 3 17:08:03 2016 +0100

more verbosity for invoking shell commands

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 82ee8be28c090f84da7eb8a1254440d301fc5675
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 3 17:07:43 2016 +0100

add copyright and licensing everywhere

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit e5ec0154c1743d68b28e3fba1864742b23e3715b
Merge: 6ac52a6 a539d68
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 3 16:28:40 2016 +0100

Merge branch 'master' into swig

commit 6ac52a6a45d8fc9c11c9b0c3b1d0399f6537eadc
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Mar 3 16:28:33 2016 +0100

make script more verbose

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit a6ef9a80ea9593ea5f1861d3ff19315b92a75130
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Feb 2 08:09:26 2016 +0100

correction in documentation of sparse functions

commit dbd7a07a1f5bcd6871d9a728f34a3d0679e01e4f
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Dec 17 22:50:11 2015 +0100

add error handling and make script python3 compatible

the swig generated interface may still not be python3 compatible

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 35ee8b63bea8bf7a0dea7af0e85f69336c6702e5
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Dec 17 18:14:12 2015 +0100

define better python operators

just renaming doesn't work. Maybe we'll need something similar in R too
but since I don't know R, I can't say.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 9654fa7e3b2a83187ee828f2ec9b39e6300ecaa7
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Thu Dec 17 14:34:58 2015 +0100

Add a swig based python and R interface to ADOL-C

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

File size: 17.8 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     adolc-python.i
4 Revision: $Id$
5 Contents: Provides all C/C++ interfaces of ADOL-C.
6 
7 Copyright (c) Kshitij Kulshreshtha
8
9 This file is part of ADOL-C. This software is provided as open source.
10 Any use, reproduction, or distribution of the software constitutes
11 recipient's acceptance of the terms of the accompanying license file. 
12 
13----------------------------------------------------------------------------*/
14
15%module(directors="1") adolc
16%{
17#define SWIG_FILE_WITH_INIT
18#include <adolc/adolc.h>
19#include "matrixmemory.hpp"
20#include <adolc/adolc_fatalerror.h>
21
22static PyObject *PyExc_AdolcException, *PyExc_AdolcFatalError;
23%}
24
25%pythonbegin %{
26from __future__ import print_function
27%}
28
29%{
30#if !defined(ATRIG_ERF)
31    adub asinh(const badouble&) {
32        throw FatalError(-1,"Not compiled in, reconfigure ADOL-C with --enable-atrig-erf",__func__,__FILE__,__LINE__);
33    }
34    adub acosh(const badouble&) {
35        throw FatalError(-1,"Not compiled in, reconfigure ADOL-C with --enable-atrig-erf",__func__,__FILE__,__LINE__);
36    }
37    adub atanh(const badouble&) {
38        throw FatalError(-1,"Not compiled in, reconfigure ADOL-C with --enable-atrig-erf",__func__,__FILE__,__LINE__);
39    }
40    adub erf(const badouble&) {
41        throw FatalError(-1,"Not compiled in, reconfigure ADOL-C with --enable-atrig-erf",__func__,__FILE__,__LINE__);
42    }
43    adub asinh(const pdouble&) {
44        throw FatalError(-1,"Not compiled in, reconfigure ADOL-C with --enable-atrig-erf",__func__,__FILE__,__LINE__);
45    }
46    adub acosh(const pdouble&) {
47        throw FatalError(-1,"Not compiled in, reconfigure ADOL-C with --enable-atrig-erf",__func__,__FILE__,__LINE__);
48    }
49    adub atanh(const pdouble&) {
50        throw FatalError(-1,"Not compiled in, reconfigure ADOL-C with --enable-atrig-erf",__func__,__FILE__,__LINE__);
51    }
52    adub erf(const pdouble&) {
53        throw FatalError(-1,"Not compiled in, reconfigure ADOL-C with --enable-atrig-erf",__func__,__FILE__,__LINE__);
54    }
55#endif
56%}
57
58%include "numpy.i"
59
60%init %{
61import_array();
62PyExc_AdolcException = PyErr_NewExceptionWithDoc("adolc.BranchException",
63"This exception is thrown if an error condition happens during the call"
64" to an ADOL-C library function, which in a pure C/C++ environment would be"
65" detected by the return value of that library function. This is generally"
66" a warning to retrace the original function at the current point",
67                                PyExc_RuntimeError, NULL);
68PyModule_AddObject(m,"BranchException",PyExc_AdolcException);
69PyExc_AdolcFatalError = PyErr_NewExceptionWithDoc("adolc.FatalError",
70"This exception is thrown if an error condition happens during the call"
71" to an ADOL-C library function, which in a pure C/C++ environment would be"
72" flagged as a fatal error and stop execution.", PyExc_RuntimeError, NULL);
73PyModule_AddObject(m,"FatalError",PyExc_AdolcFatalError);
74%}
75
76%feature("novaluewrapper") badouble;
77%feature("novaluewrapper") adub;
78%feature("novaluewrapper") pdouble;
79%feature("novaluewrapper") adubref;
80%feature("novaluewrapper") adouble;
81%feature("novaluewrapper") advector;
82
83%rename (AdolcFatalError) FatalError;
84%include "../include/adolc/adolc_fatalerror.h"
85
86%extend FatalError {
87    virtual const char* __repr__() const throw() {
88        return (*($self)).what();
89    }
90}
91
92%ignore operator<<;
93%ignore operator>>;
94%ignore operator<=;
95%ignore operator<;
96%ignore operator>=;
97%ignore operator>;
98%ignore operator==;
99%ignore operator!=;
100%ignore pow;
101%ignore *::operator++;
102%ignore *::operator--;
103%ignore *::operator=;
104%ignore zos_forward_nk;
105%ignore zos_forward_partx;
106%ignore fos_forward_nk;
107%ignore fos_forward_partx;
108%ignore hos_forward_nk;
109%ignore hos_forward_partx;
110%ignore fov_forward_partx;
111%ignore fov_offset_forward;
112%ignore hov_forward_partx;
113%ignore function_;
114%ignore gradient_;
115%ignore jacobian_;
116%ignore large_jacobian_;
117%ignore vec_jac_;
118%ignore jac_vec_;
119%ignore hessian_;
120%ignore hess_vec_;
121%ignore hessian2_;
122%ignore hess_mat_;
123%ignore lagra_hess_vec_;
124%ignore forodec_;
125%ignore accodec_;
126%ignore hos_forward_;
127%ignore fov_forward_;
128%ignore hov_forward_;
129%ignore hov_wk_forward_;
130%ignore fos_reverse_;
131%ignore hos_reverse_;
132%ignore hos_ti_reverse_;
133%ignore hos_ov_reverse_;
134%ignore fov_reverse_;
135%ignore hov_reverse_;
136%ignore hov_ti_reverse_;
137%ignore directional_active_gradient_;
138%ignore abs_normal_;
139%ignore spread1;
140%ignore pack1;
141%ignore spread2;
142%ignore pack2;
143%ignore spread3;
144%ignore pack3;
145%ignore *::operator[](const badouble&);
146%ignore *::operator[](size_t);
147%ignore *::operator[](const badouble&) const;
148%ignore *::operator[](size_t) const;
149%ignore *::operator double;
150%ignore *::operator double const&;
151%ignore *::operator double&&;
152%ignore *::operator adub;
153%ignore *::operator const std::vector<adouble>&;
154%ignore *::operator std::vector<adouble>&;
155%ignore *::operator adouble*;
156%ignore advector::advector(const std::vector<adouble>&);
157%ignore ext_diff_fct;
158%ignore ext_diff_fct_v2;
159%ignore reg_ext_fct;
160%ignore call_ext_fct;
161%ignore get_ext_diff_fct;
162%ignore get_ext_diff_fct_v2;
163%ignore EDFobject;
164%ignore EDFobject_iArr;
165%ignore EDFobject_v2;
166
167%feature("director") PyEDF;
168%feature("director") PyEDF_iArr;
169%feature("director") PyEDF_v2;
170
171%rename (EDFobject) PyEDF;
172%rename (EDFobject_iArr) PyEDF_iArr;
173%rename (EDFobject_v2) PyEDF_v2;
174
175%typemap(in) locint {
176    $1 = PyLong_AsUnsignedLong($input);
177 }
178
179%typemap(out) locint {
180    $result = PyLong_FromUnsignedLong($1);
181 }
182
183%pythoncode %{
184BranchException = _adolc.BranchException
185FatalError = _adolc.FatalError
186%}
187
188
189%inline %{
190#define CHECKEXCEPT(rc, func) \
191    if ((rc) < 0) {                                                     \
192        PyErr_Format(PyExc_AdolcException,                              \
193                     "An error has been detected in an ADOL-C library"  \
194                     "function (%s). It returned the code %d."          \
195                     " Look at previous messages"                       \
196                     " printed.",                                       \
197                     func, (rc));                                       \
198    }
199%}
200
201%exception {
202    try {
203        $action
204        if (PyErr_Occurred()) SWIG_fail;
205    } catch (FatalError &_e) {
206        PyErr_SetObject(PyExc_AdolcFatalError,SWIG_NewPointerObj(
207            (new FatalError(static_cast<const FatalError& >(_e))), 
208            SWIGTYPE_p_FatalError,SWIG_POINTER_OWN));
209    SWIG_fail;
210    }
211}
212
213%include "pydirectors.hpp"
214%include "adolc-numpy-for.i"
215%include "adolc-numpy-rev.i"
216%include "adolc-numpy-drv.i"
217%inline %{
218#include "pyedfclasses.hpp"
219%}
220%rename (arctan2) atan2;
221%include "adolc_all.hpp"
222
223%extend advector {
224    adub* __getitem__(const badouble& index) const {
225        if (index.value() >= (*($self)).size()) {
226            SWIG_exception_fail(SWIG_IndexError,"Index out of bounds");
227        }
228        return (adub*) (*($self))[index];
229    fail:
230        return NULL;
231    }
232    adubref* __getitem__(const badouble& index) {
233        if (index.value() >= (*($self)).size()) {
234            SWIG_exception_fail(SWIG_IndexError,"Index out of bounds");
235        }
236        return (adubref*) (*($self))[index];
237    fail:
238        return NULL;
239    }
240    adouble* __getitem__(size_t index) {
241        if (index >= (*($self)).size()) {
242            SWIG_exception_fail(SWIG_IndexError,"Index out of bounds");
243        }
244        return &((*($self))[index]);
245    fail:
246        return NULL;
247    }
248    const adouble* __getitem__(size_t index) const {
249        if (index >= (*($self)).size()) {
250            SWIG_exception_fail(SWIG_IndexError,"Index out of bounds");
251        }
252        return &((*($self))[index]);
253    fail:
254        return NULL;
255    }
256    size_t __len__() const {
257        return (*($self)).size();
258    }
259    // ADD __setitem__ and __iter__
260    void __setitem__(size_t index,double val) {
261        if (index >= (*($self)).size()) {
262            SWIG_exception_fail(SWIG_IndexError,"Index out of bounds");
263        }
264        (*($self))[index] = val;
265    fail:
266        return;
267    }
268    void __setitem__(size_t index,const badouble& val) {
269        if (index >= (*($self)).size()) {
270            SWIG_exception_fail(SWIG_IndexError,"Index out of bounds");
271        }
272        (*($self))[index] = val;
273    fail:
274        return;
275    }
276    void __setitem__(const badouble& index,double val) {
277        if (index.value() >= (*($self)).size()) {
278            SWIG_exception_fail(SWIG_IndexError,"Index out of bounds");
279        }
280        (*($self))[index] = val;
281    fail:
282        return;
283    }
284    void __setitem__(const badouble& index,const badouble& val) {
285        if (index.value() >= (*($self)).size()) {
286            SWIG_exception_fail(SWIG_IndexError,"Index out of bounds");
287        }
288        (*($self))[index] = val;
289    fail:
290        return;
291    }
292    advector(PyObject* obj0) {
293        PyArrayObject *array0 = NULL;
294        int is_new_object0 = 0;
295        int dim_temp0;
296        advector * $self;
297        npy_intp size[1] = {
298            -1
299        };
300        array0 = obj_to_array_allow_conversion(obj0,
301                                               NPY_OBJECT,
302                                               &is_new_object0);
303        if (!array0 || !require_dimensions(array0, 1) ||
304            !require_size(array0, size, 1)) SWIG_fail;
305        dim_temp0 = (int) array_size(array0,0);
306        $self = new advector(dim_temp0);
307        for (size_t i = 0; i < dim_temp0; i++) {
308            PyObject* elem = PyArray_GETITEM(array0, (const char*)PyArray_GetPtr(array0, (npy_intp*)&i));
309            void * argp1 = 0;
310            badouble* arg1 =  NULL;
311            double val1;
312            int res1 = SWIG_ConvertPtr(elem, &argp1,SWIGTYPE_p_badouble, 0 | 0);
313            int _v = SWIG_CheckState(res1);
314            if (_v) {
315                arg1 = reinterpret_cast<badouble*>(argp1);
316                (*($self))[i] = *arg1;
317            } else {
318                res1 = SWIG_AsVal_double(elem, &val1);
319                _v = SWIG_CheckState(res1);
320                if (_v) {
321                    (*($self))[i] = val1;
322                }
323                else {
324                    SWIG_exception_fail(SWIG_ArgError(res1), "in method '""new_advector""' ""input sequence must contain objects of type adouble or numbers");
325                }
326            }
327        }
328        if (is_new_object0 && array0) {
329            Py_DECREF(array0);
330        }
331        return ($self);
332    fail:
333        if (is_new_object0 && array0) {
334            Py_DECREF(array0);
335        }
336        return NULL;
337    }
338 }
339
340%ignore frexp;
341%ignore operator+;
342%ignore operator-;
343%ignore operator*;
344%ignore operator/;
345
346%include "adubswigfuncs.hpp"
347
348%extend badouble {
349    int __ne__ (const badouble& a) const {
350        return (*($self)) != a;
351    }
352    int __eq__ (const badouble& a) const {
353        return (*($self)) == a;
354    }
355    int __le__ (const badouble& a) const {
356        return (*($self)) <= a;
357    }
358    int __ge__ (const badouble& a) const {
359        return (*($self)) >= a;
360    }
361    int __lt__ (const badouble& a) const {
362        return (*($self)) < a;
363    }
364    int __gt__ (const badouble& a) const {
365        return (*($self)) > a;
366    }
367    int __ne__ (double a) const {
368        return (*($self)) != a;
369    }
370    int __eq__ (double a) const {
371        return (*($self)) == a;
372    }
373    int __le__ (double a) const {
374        return (*($self)) <= a;
375    }
376    int __ge__ (double a) const {
377        return (*($self)) >= a;
378    }
379    int __lt__ (double a) const {
380        return (*($self)) < a;
381    }
382    int __gt__ (double a) const {
383        return (*($self)) > a;
384    }
385    adouble __pow__ (const badouble& a) {
386        return pow((*($self)),a);
387    }
388    adub* __pow__(double c) {
389        return (adub*) pow((*($self)),c);
390    }
391    adouble __rpow__(double c) {
392        return pow(c,(*($self)));
393    }
394    adub* __pow__ (const pdouble& a) {
395        return (adub*) pow((*($self)),a);
396    }
397    adub* __neg__() {
398        return (adub*)( - (*($self)));
399    }
400    adub* __add__ (const badouble& a) {
401        return (adub*) ((*($self)) + a);
402    }
403    adub* __add__ (double a) {
404        return (adub*) ((*($self)) + a);
405    }
406    adub* __radd__ (double a) {
407        return (adub*) (a + (*($self)));
408    }
409    adub* __add__ (const pdouble& a) {
410        return (adub*) ((*($self)) + a);
411    }
412    adub* __sub__ (const badouble& a) {
413        return (adub*) ((*($self)) - a);
414    }
415    adub* __sub__ (double a) {
416        return (adub*) ((*($self)) - a);
417    }
418    adub* __rsub__ (double a) {
419        return (adub*) (a - (*($self)));
420    }
421    adub* __sub__ (const pdouble& a) {
422        return (adub*) ((*($self)) - a);
423    }
424    adub* __mul__ (const badouble& a) {
425        return (adub*) ((*($self)) * a);
426    }
427    adub* __mul__ (double a) {
428        return (adub*) ((*($self)) * a);
429    }
430    adub* __rmul__ (double a) {
431        return (adub*) (a * (*($self)));
432    }
433    adub* __mul__ (const pdouble& a) {
434        return (adub*) ((*($self)) * a);
435    }
436    adub* __div__ (const badouble& a) {
437        return (adub*) ((*($self)) / a);
438    }
439    adub* __div__ (double a) {
440        return (adub*) ((*($self)) / a);
441    }
442    adub* __rdiv__ (double a) {
443        return (adub*) (a / (*($self)));
444    }
445    adub* __div__ (const pdouble& a) {
446        return (adub*) ((*($self)) / a);
447    }   
448    adub* sin() {
449        return (adub*) sin(*($self));
450    }
451    adub* cos() {
452        return (adub*) cos(*($self));
453    }
454    adub* tan() {
455        return (adub*) tan(*($self));
456    }
457    adub* exp() {
458        return (adub*) exp(*($self));
459    }
460    adub* log() {
461        return (adub*) log(*($self));
462    }
463    adub* sqrt() {
464        return (adub*) sqrt(*($self));
465    }
466    adub* arcsin() {
467        return (adub*) asin(*($self));
468    }
469    adub* arccos() {
470        return (adub*) acos(*($self));
471    }
472    adub* arctan() {
473        return (adub*) atan(*($self));
474    }
475    adub* log10() {
476        return (adub*) log10(*($self));
477    }
478    adub* sinh() {
479        return (adub*) sinh(*($self));
480    }
481    adub* cosh() {
482        return (adub*) cosh(*($self));
483    }
484    adub* tanh() {
485        return (adub*) tanh(*($self));
486    }
487    adub* arcsinh() {
488        return (adub*) asinh(*($self));
489    }
490    adub* arccosh() {
491        return (adub*) acosh(*($self));
492    }
493    adub* arctanh() {
494        return (adub*) atanh(*($self));
495    }
496    adub* erf() {
497        return (adub*) erf(*($self));
498    }
499    adub* fabs() {
500        return (adub*) fabs(*($self));
501    }
502    adub* abs() {
503        return (adub*) fabs(*($self));
504    }
505    adub* __abs__() {
506        return (adub*) fabs(*($self));
507    }
508    adub* ceil() {
509        return (adub*) ceil(*($self));
510    }
511    adub* floor() {
512        return (adub*) floor(*($self));
513    }
514}
515
516%extend pdouble {
517    adub* __neg__() {
518        return (adub*)( - (*($self)));
519    }
520    adub* __add__ (const badouble& a) {
521        return (adub*) ((*($self)) + a);
522    }
523    adub* __add__ (double a) {
524        return (adub*) ((*($self)) + a);
525    }
526    adub* __radd__ (double a) {
527        return (adub*) (a + (*($self)));
528    }
529    adub* __sub__ (const badouble& a) {
530        return (adub*) ((*($self)) - a);
531    }
532    adub* __sub__ (double a) {
533        return (adub*) ((*($self)) - a);
534    }
535    adub* __rsub__ (double a) {
536        return (adub*) (a - (*($self)));
537    }
538    adub* __mul__ (const badouble& a) {
539        return (adub*) ((*($self)) * a);
540    }
541    adub* __mul__ (double a) {
542        return (adub*) ((*($self)) * a);
543    }
544    adub* __rmul__ (double a) {
545        return (adub*) (a * (*($self)));
546    }
547    adub* __div__ (const badouble& a) {
548        return (adub*) ((*($self)) / a);
549    }
550    adub* __div__ (double a) {
551        return (adub*) ((*($self)) / a);
552    }
553    adub* __rdiv__ (double a) {
554        return (adub*) (a / (*($self)));
555    }
556    adub* sin() {
557        return (adub*) sin(*($self));
558    }
559    adub* cos() {
560        return (adub*) cos(*($self));
561    }
562    adub* tan() {
563        return (adub*) tan(*($self));
564    }
565    adub* exp() {
566        return (adub*) exp(*($self));
567    }
568    adub* log() {
569        return (adub*) log(*($self));
570    }
571    adub* sqrt() {
572        return (adub*) sqrt(*($self));
573    }
574    adub* asin() {
575        return (adub*) asin(*($self));
576    }
577    adub* acos() {
578        return (adub*) acos(*($self));
579    }
580    adub* atan() {
581        return (adub*) atan(*($self));
582    }
583    adub* log10() {
584        return (adub*) log10(*($self));
585    }
586    adub* sinh() {
587        return (adub*) sinh(*($self));
588    }
589    adub* cosh() {
590        return (adub*) cosh(*($self));
591    }
592    adub* tanh() {
593        return (adub*) tanh(*($self));
594    }
595    adub* asinh() {
596        return (adub*) asinh(*($self));
597    }
598    adub* acosh() {
599        return (adub*) acosh(*($self));
600    }
601    adub* atanh() {
602        return (adub*) atanh(*($self));
603    }
604    adub* erf() {
605        return (adub*) erf(*($self));
606    }
607    adub* fabs() {
608        return (adub*) fabs(*($self));
609    }
610    adub* abs() {
611        return (adub*) fabs(*($self));
612    }
613    adub* ceil() {
614        return (adub*) ceil(*($self));
615    }
616    adub* floor() {
617        return (adub*) floor(*($self));
618    }
619}
620
621%pythoncode %{
622def fmin(a,b):
623    import numpy as np
624    if np.isscalar(a) and np.isscalar(b):
625        if a > b:
626            return b
627        else:
628            return a
629    elif isinstance(a,badouble) or isinstance(b,badouble):
630        return _adolc.fmin(a,b)
631    else:
632        raise(NotImplementedError('Arguments must be scalars or ADOL-C types'))
633
634def fmax(a,b):
635    import numpy as np
636    if np.isscalar(a) and np.isscalar(b):
637        if a < b:
638            return b
639        else:
640            return a
641    elif isinstance(a,badouble) or isinstance(b,badouble):
642        return _adolc.fmax(a,b)
643    else:
644        raise(NotImplementedError('Arguments must be scalars or ADOL-C types'))
645
646def fabs(a):
647    import numpy as np
648    import math as m
649    if np.isscalar(a):
650        return m.fabs(a)
651    elif isinstance(a,badouble):
652        return _adolc.fabs(a)
653    else:
654        raise(NotImplementedError('Arguments must be scalars or ADOL-C types'))
655%}
656
657%exception;
Note: See TracBrowser for help on using the repository browser.