Michele De Stefano's C++ Utilities
ublas_pkg_usage.i
1 // ublas_pkg_usage.i
2 //
3 // This SWIG interface shows how to reuse classes wrapped by the
4 // mds_utils.ublas.ublas.py module.
5 //
6 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
7 //
8 // Distributed under the MIT License (See accompanying file LICENSE)
9 
10 /*
11  * Usage example for the mds_utils.ublas Python module.
12  *
13  * Instructions for generating and building the extension:
14  *
15  * 1. swig -c++ -Wall -python -I../../../../include -I../../../../python -o ublas_pkg_usage_wrap.cpp ublas_pkg_usage.i
16  *
17  * 2. python setup.py build
18  *
19  * Instructions for using the generated example:
20  *
21  * Before using the generated python module, ensure that your
22  * PYTHONPATH environment variable contains the path to reach the
23  * mds_utils Python package. For example, if the mds_utils package has
24  * been built but not installed yet, it is typically found into the
25  * mds-utils/python/build/lib.linux-<arch>-<Python version> directory
26  * (for a Linux build) and you have to add this path to your PYTHONPATH
27  * variable. After that, you can import the ublas_pkg_usage module and
28  * try it. The use from the command line is shown into the
29  * ublas_pkg_usage.pycmd file.
30  */
31 
32 
33 %module ublas_pkg_usage
34 
35 // Make all necessary inclusions before importing the ublas module
36 %include <mds_utils/python/common.i>
37 
38 // Import the ublas module: this will share the wrapped objects in ublas
39 %import "mds_utils/ublas/ublas.i"
40 
41 // Start wrapping code for the ublas_pkg_usage module
42 
43 %header %{
44 #include <boost/numeric/ublas/vector.hpp>
45 #include <boost/numeric/ublas/matrix_sparse.hpp>
46 %}
47 
48 %inline %{
49 
50 boost::numeric::ublas::vector<double> create_vector() {
51 
52  using namespace boost::numeric::ublas;
53 
54  vector<double> v(3);
55 
56  v[0] = 1.1; v[1] = 2.2; v[2] = 3.3;
57 
58  return v;
59 }
60 
61 boost::numeric::ublas::compressed_matrix<double>
62  create_compressed_matrix() {
63 
64  using namespace boost::numeric::ublas;
65 
66  compressed_matrix<double>
67  m(4,3);
68 
69  m(1,0) = 1.1; m(0,2) = 2.2; m(3,1) = 3.3;
70 
71  return m;
72 }
73 
74 // Tests inheritance
75 class my_vec : public boost::numeric::ublas::vector<double> {
76 };
77 
78 
79 %}