update swig on windows
This commit is contained in:
24
winx64/bin/swigwin-4.0.0/Examples/python/std_vector/Makefile
Normal file
24
winx64/bin/swigwin-4.0.0/Examples/python/std_vector/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
TOP = ../..
|
||||
SWIGEXE = $(TOP)/../swig
|
||||
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||
CXXSRCS =
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
||||
|
||||
static:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
||||
@@ -0,0 +1,25 @@
|
||||
/* File : example.h */
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
|
||||
double average(std::vector<int> v) {
|
||||
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
||||
}
|
||||
|
||||
std::vector<double> half(const std::vector<double>& v) {
|
||||
std::vector<double> w(v);
|
||||
for (unsigned int i=0; i<w.size(); i++)
|
||||
w[i] /= 2.0;
|
||||
return w;
|
||||
}
|
||||
|
||||
void halve_in_place(std::vector<double>& v) {
|
||||
// would you believe this is the same as the above?
|
||||
std::transform(v.begin(),v.end(),v.begin(),
|
||||
std::bind2nd(std::divides<double>(),2.0));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include stl.i
|
||||
/* instantiate the required template specializations */
|
||||
namespace std {
|
||||
%template(IntVector) vector<int>;
|
||||
%template(DoubleVector) vector<double>;
|
||||
}
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
35
winx64/bin/swigwin-4.0.0/Examples/python/std_vector/runme.py
Normal file
35
winx64/bin/swigwin-4.0.0/Examples/python/std_vector/runme.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# file: runme.py
|
||||
|
||||
import example
|
||||
|
||||
# Call average with a Python list...
|
||||
|
||||
print example.average([1, 2, 3, 4])
|
||||
|
||||
# ... or a wrapped std::vector<int>
|
||||
|
||||
v = example.IntVector(4)
|
||||
for i in range(len(v)):
|
||||
v[i] = i + 1
|
||||
print example.average(v)
|
||||
|
||||
|
||||
# half will return a Python list.
|
||||
# Call it with a Python tuple...
|
||||
|
||||
print example.half((1.0, 1.5, 2.0, 2.5, 3.0))
|
||||
|
||||
# ... or a wrapped std::vector<double>
|
||||
|
||||
v = example.DoubleVector()
|
||||
for i in [1, 2, 3, 4]:
|
||||
v.append(i)
|
||||
print example.half(v)
|
||||
|
||||
|
||||
# now halve a wrapped std::vector<double> in place
|
||||
|
||||
example.halve_in_place(v)
|
||||
for i in range(len(v)):
|
||||
print v[i], "; ",
|
||||
print
|
||||
Reference in New Issue
Block a user