Wrappers for ADOL-C in scripting languages using SWIG
نویسندگان
چکیده
R is a language and environment for statistical computing and graphics [1]. It currently is widely used in statistics and data mining. To obtain derivatives in R, one can use several non-native approaches, including the TMB system [2] and Ryacas [3]. However, none of these options support the di↵erentiation of functions expressed as R programs, as would an algorithmic di↵erentiation (AD) tool for R. Attempts to develop such a tool include radx [4]. This tool is capable of computing firstand second-order forward-mode derivatives of univariate functions. But it is no longer actively developed. Natively, inside R, the numderiv package provides methods for calculating (usually) accurate numerical first and second order derivatives [5]. Accurate calculations are done by using Richardson’s extrapolation, or, when applicable, a complex step derivative is available. A simple di↵erence method is also provided. The deriv function from the stats package computes derivatives of simple expressions, symbolically [6]. Because numerical di↵erences cannot be reliably accurate and cannot compute adjoints, there is a need to provide derivatives within R using AD tools. One method to obtaining derivatives is ADOL-C [7]. It is a mature and widely applied tool for algorithmic di↵erentiation using operator overloading in the C++ language. Because of the language dependency it can natively be used only with applications that were originally written in C or C++. Previously, a Python-wrapper [8, 9] was written for the most widely used functionality in ADOL-C. It can be used to compute first and higher order derivatives in both forward and reverse mode for applications written in Python. This wrapper was written manually, however, and must be maintained and updated manually to keep in sync with the changes and new features of the C++ library. Also only the most commonly used ADOL-C API calls were available. Given the success of manually interfacing Python with ADOL-C we have investigated an automated interfacing mechanism for ADOL-C with R and Python. We used the SWIG interface generator for this purpose. Using the interfaces that were generated, we are able to use ADOL-C from within R and Python to obtain derivatives. The rest of the document shows how SWIG was used and provides examples of ADOL-C usage.
منابع مشابه
An Extensible Compiler for Creating Scriptable Scientific Software
Scripting languages such as Python and Tcl have become a powerful tool for the construction of exible scienti c software because they provide scientists with an interpreted problem solving environment and they form a modular framework for controlling software components written in C,C++, and Fortran. However, a common problem faced by the developers of a scripted scienti c application is that o...
متن کاملBuilding Flexible Large-Scale Scientific Computing Applications with Scripting Languages
We describe our use of scripting languages with a large-scale molecular dynamics code. We will show how one can build an interactive, highly modular, and easily extensible system without sacrificing performance, building a huge monolithic package, or complicating code development. We will also describe our use of the Python language and the SWIG automated interface generation tool that we have ...
متن کاملA Foreign-Function Interface Generator for occam-pi
occam-pi is a programming language based on the CSP process algebra and the pi-calculus, and has a powerful syntax for expressing concurrency. occam-pi does not however, come with interfaces to a broad range of standard libraries (such as those used for graphics or mathematics). Programmers wishing to use these must write their own wrappers using occam-pi’s foreign function interface, which can...
متن کاملEmbed Scripting inside SystemC
Embedded system designs and simulations become tedious and time consuming due to the complexity of modern applications. Thus, languages allowing high level description, such as SystemC, are more and more used. We present in this paper a new methodology allowing scripting inside SystemC. We integrate both SystemC and Python within a single framework for system designs and simulations called Syst...
متن کاملMeta-level Language Bridging
Scripting and composition languages offer high-level mechanisms to combine and compose services provided by a lower-level host programming language. Inter-language bridging mechanisms are therefore needed to map host language entities and services to abstractions of the scripting language, and vice versa. Many popular languages such as Python, Perl, and Ruby use a bridging approach based on wra...
متن کامل