15.12.2012 Views

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

scipy tutorial - Baustatik-Info-Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

SciPy Reference Guide, Release 0.8.dev<br />

needs some work). So, this section covers items 1 and 4 from the list. Item 2 is covered later in the chapter covering<br />

the ext_tools module, and distutils is covered by a completely separate document xxx.<br />

Passing Variables in/out of the C/C++ code<br />

Note: Passing variables into the C code is pretty straight forward, but there are subtlties to how variable modifications<br />

in C are returned to Python. see Returning Values for a more thorough discussion of this issue.<br />

Type Conversions<br />

Note: Maybe xxx_converter instead of xxx_specification is a more descriptive name. Might change in<br />

future version?<br />

By default, inline() makes the following type conversions between Python and C++ types.<br />

Table 1.3: Default Data Type Conversions<br />

Python C++<br />

int int<br />

float double<br />

complex std::complex<br />

string py::string<br />

list py::list<br />

dict py::dict<br />

tuple py::tuple<br />

file FILE*<br />

callable py::object<br />

instance py::object<br />

numpy.ndarray PyArrayObject*<br />

wxXXX wxXXX*<br />

The Py:: namespace is defined by the SCXX library which has C++ class equivalents for many Python types. std::<br />

is the namespace of the standard library in C++.<br />

Note:<br />

• I haven’t figured out how to handle long int yet (I think they are currenlty converted to int - - check this).<br />

• Hopefully VTK will be added to the list soon<br />

Python to C++ conversions fill in code in several locations in the generated inline extension function. Below is the<br />

basic template for the function. This is actually the exact code that is generated by calling weave.inline("").<br />

The /* inline code */ section is filled with the code passed to the inline() function call. The<br />

/*argument convserion code*/ and /* cleanup code */ sections are filled with code that handles<br />

conversion from Python to C++ types and code that deallocates memory or manipulates reference counts before the<br />

function returns. The following sections demostrate how these two areas are filled in by the default conversion methods.<br />

* Note: I’m not sure I have reference counting correct on a few of these. The only thing I increase/decrease the<br />

ref count on is NumPy arrays. If you see an issue, please let me know.<br />

NumPy Argument Conversion<br />

Integer, floating point, and complex arguments are handled in a very similar fashion. Consider the following inline<br />

function that has a single integer variable passed in:<br />

1.12. Weave 105

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!