arXiv.itsnick.co

an independent field guide to 23 million papers from arXiv & OpenAlex — not affiliated with arXiv.org

Author

Adam Gladstone

8 papers · 2022–2022

2022: 8
2022peak 8 in 20222022

Papers

showing 1–8 of 8 RSS

Building a Python Extension Module

Adam Gladstone

Artificial Intelligence · Apress eBooks · · cited 1× · DOI ↗ · more like this ·

In this chapter and the next, we look at building Python extension modules. These are components that connect C/C++ to Python. Python has been around for quite some time, and over the years, a number of different approaches to accomplishing this have been developed. Table 7-1 lists some of the approaches.

Building a C++/CLI Wrapper

Adam Gladstone

Information Systems · Apress eBooks · · cited 0× · DOI ↗ · more like this ·

In this chapter, we build our first wrapper component. We use C++/CLI which allows .NET clients to call C++ code. We take StatsLib, our small library of statistical functions that we built in Chapter 2 , and expose the functionality via C++/CLI.

Module Development with Boost.Python and PyBind

Adam Gladstone

Artificial Intelligence · Apress eBooks · · cited 0× · DOI ↗ · more like this ·

In the previous chapter, we saw how to create a basic Python extension module. We added code to expose functionality from the underlying C++ library of statistical functions. We saw how to perform the conversion between PyObject pointers and native C++ types. While not especially difficult, we saw that it is potentially error prone. In this chapter, we consider two frameworks – Boost.Python and PyBind – that overcome these difficulties, making the development of Python extension modules easier. We build two quite similar wrapper components, the first based on Boost.Python and the second on PyBind. The intention here is to compare the two frameworks. Following this, we look at a typical Python client and develop a script to measure the relative performance of the extension modules. We end the chapter with a simple Flask app that demonstrates using our PyBind module as part of a (limited)…

Exposing Functions Using Rcpp

Adam Gladstone

Artificial Intelligence · Apress eBooks · · cited 0× · DOI ↗ · more like this ·

In the previous chapter, we built an R package using Rcpp. Moreover, using CodeBlocks, we established the infrastructure for developing and building our ABI-compliant library of statistical functions (libStatsLib.a), which we linked into our R package (StatsR.dll). For the moment, we have only used a single function, library_version (defined in StatsR.cpp). We used this to illustrate the build process and to test the communication between R and C++.

C# Clients: Consuming the Managed Wrapper

Adam Gladstone

Computer Networks and Communications · Apress eBooks · · cited 0× · DOI ↗ · more like this ·

In this chapter, we look at consuming StatsCLR, the C++/CLI component we have built in the previous chapter. To some extent, we have done this already with the StatsCLR.UnitTests testing module. However, in this chapter, we take a broader look at using the component in a variety of different contexts.

Building an R Package

Adam Gladstone

Artificial Intelligence · Apress eBooks · · cited 0× · DOI ↗ · more like this ·

In this chapter and the next, we connect our simple C++ library of statistical functions to R. We do this by creating an R package using Rcpp. We then use this wrapper component to expose the functionality we want. This chapter focuses on both the project setup and the mechanics of building packages with RStudio. The following chapter focuses on the details of using Rcpp as a framework for connecting C++ and R.

Conclusion

Adam Gladstone

Artificial Intelligence · Apress eBooks · · cited 0× · DOI ↗ · more like this ·

Our goal in this book has been to develop components that connect a C++ codebase (albeit a simple, slightly artificial one) to client software written in other languages, specifically C#, R, and Python. The intention has been to make the functionality in a C++ library available and to allow access to this functionality from other client languages. This is what we have accomplished. In doing so, we have covered quite a lot of ground.

C++ Components and C++ Clients

Adam Gladstone

Artificial Intelligence · Apress eBooks · · cited 0× · DOI ↗ · more like this ·

In this chapter, we introduce the C++ codebase. This consists of a small set of statistical functions and classes. The intention is not to provide a fully fledged statistical library, but rather to provide some limited but useful functionality that we want to expose to clients. The functionality is only of interest insofar as it illustrates how we might expose it later to clients.