Commit 48c377c3 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Enable performance improving flags for SWIG wrapper generation in python.

parent fa50bf20
......@@ -66,7 +66,9 @@ if(XDMF_WRAP_PYTHON)
# Target Name = the output target name will have ${python_name} as its name
macro(XDMF_SWIG_PYTHON python_name)
set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR})
set(CMAKE_SWIG_FLAGS ${XDMF_SWIG_FLAGS})
# optimize swig generation --- these are all flags corresponding to -O
# except -fvirtual which breaks visitor operation
set(CMAKE_SWIG_FLAGS ${XDMF_SWIG_FLAGS} -builtin -modern -fastdispatch -nosafecstrings -noproxydel -fastproxy -fastinit -fastunpack -fastquery -modernargs -nobuildnone)
set_source_files_properties(${python_name}.i PROPERTIES CPLUSPLUS ON)
set(swig_extra_generated_files "")
swig_add_module(${python_name} python ${python_name}.i)
......
......@@ -222,6 +222,42 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
}
}
%extend XdmfAttributeCenter {
bool __eq__(const XdmfAttributeCenter * attributeCenter) {
return $self == attributeCenter;
}
}
%extend XdmfAttributeType {
bool __eq__(const XdmfAttributeType * attributeType) {
return $self == attributeType;
}
}
%extend XdmfGeometryType {
bool __eq__(const XdmfGeometryType * geometryType) {
return $self == geometryType;
}
}
%extend XdmfGridCollectionType {
bool __eq__(const XdmfGridCollectionType * gridCollectionType) {
return $self == gridCollectionType;
}
}
%extend XdmfSetType {
bool __eq__(const XdmfSetType * setType) {
return $self == setType;
}
}
%extend XdmfTopologyType {
bool __eq__(const XdmfTopologyType * topologyType) {
return $self == topologyType;
}
}
#endif /* SWIGPYTHON */
// Shared Pointer Templates
......
......@@ -109,29 +109,6 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
}
%}
%extend XdmfArray {
void insertValueAsInt8(int index, char value) {
$self->insert(index, value);
}
void insertValueAsInt16(int index, short value) {
$self->insert(index, value);
}
void insertValueAsInt32(int index, int value) {
$self->insert(index, value);
}
void insertValueAsFloat32(int index, float value) {
$self->insert(index, value);
}
void insertValueAsFloat64(int index, double value) {
$self->insert(index, value);
}
};
%pragma(java) jniclasscode=%{
static {
try {
......@@ -205,97 +182,75 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
return None
};
%pythoncode {
def insertAsInt8(self, startIndex, values):
for i in range(0, len(values)):
self.insertValueAsInt8(i+startIndex, values[i])
def insertAsInt16(self, startIndex, values):
for i in range(0, len(values)):
self.insertValueAsInt16(i+startIndex, values[i])
def insertAsInt32(self, startIndex, values):
for i in range(0, len(values)):
self.insertValueAsInt32(i+startIndex, values[i])
def insertAsInt64(self, startIndex, values):
for i in range(0, len(values)):
self.insertValueAsInt64(i+startIndex, values[i])
def insertAsFloat32(self, startIndex, values):
for i in range(0, len(values)):
self.insertValueAsFloat32(i+startIndex, values[i])
def insertAsFloat64(self, startIndex, values):
for i in range(0, len(values)):
self.insertValueAsFloat64(i+startIndex, values[i])
def insertAsUInt8(self, startIndex, values):
for i in range(0, len(values)):
self.insertValueAsUInt8(i+startIndex, values[i])
def insertAsUInt16(self, startIndex, values):
for i in range(0, len(values)):
self.insertValueAsUInt16(i+startIndex, values[i])
def insertAsUInt32(self, startIndex, values):
for i in range(0, len(values)):
self.insertValueAsUInt32(i+startIndex, values[i])
};
void insertValueAsInt8(int index, char value) {
$self->insert(index, value);
}
void insertValueAsInt16(int index, short value) {
$self->insert(index, value);
void insertAsInt8(int startIndex, PyObject * list) {
Py_ssize_t size = PyList_Size(list);
for(Py_ssize_t i = 0; i < size; ++i) {
$self->insert(i+startIndex, (char)(PyLong_AsLong(PyList_GetItem(list, i))));
}
}
void insertValueAsInt32(int index, int value) {
$self->insert(index, value);
void insertAsInt16(int startIndex, PyObject * list) {
Py_ssize_t size = PyList_Size(list);
for(Py_ssize_t i = 0; i < size; ++i) {
$self->insert(i+startIndex, (short)(PyLong_AsLong(PyList_GetItem(list, i))));
}
}
void insertValueAsInt64(int index, long value) {
$self->insert(index, value);
void insertAsInt32(int startIndex, PyObject * list) {
Py_ssize_t size = PyList_Size(list);
for(Py_ssize_t i = 0; i < size; ++i) {
$self->insert(i+startIndex, (int)(PyLong_AsLong(PyList_GetItem(list, i))));
}
}
void insertValueAsFloat32(int index, float value) {
$self->insert(index, value);
void insertAsInt64(int startIndex, PyObject * list) {
Py_ssize_t size = PyList_Size(list);
for(Py_ssize_t i = 0; i < size; ++i) {
$self->insert(i+startIndex, PyLong_AsLong(PyList_GetItem(list, i)));
}
}
void insertValueAsFloat64(int index, double value) {
$self->insert(index, value);
void insertAsFloat32(int startIndex, PyObject * list) {
Py_ssize_t size = PyList_Size(list);
for(Py_ssize_t i = 0; i < size; ++i) {
$self->insert(i+startIndex, (float)PyFloat_AsDouble(PyList_GetItem(list, i)));
}
}
void insertValueAsUInt8(int index, unsigned char value) {
$self->insert(index, value);
void insertAsFloat64(int startIndex, PyObject * list) {
Py_ssize_t size = PyList_Size(list);
for(Py_ssize_t i = 0; i < size; ++i) {
$self->insert(i+startIndex, PyFloat_AsDouble(PyList_GetItem(list, i)));
}
}
void insertValueAsUInt16(int index, unsigned short value) {
$self->insert(index, value);
void insertAsUInt8(int startIndex, PyObject * list) {
Py_ssize_t size = PyList_Size(list);
for(Py_ssize_t i = 0; i < size; ++i) {
$self->insert(i+startIndex, (unsigned char)(PyLong_AsUnsignedLong(PyList_GetItem(list, i))));
}
}
void insertValueAsUInt32(int index, unsigned int value) {
$self->insert(index, value);
void insertAsUInt16(int startIndex, PyObject * list) {
Py_ssize_t size = PyList_Size(list);
for(Py_ssize_t i = 0; i < size; ++i) {
$self->insert(i+startIndex, (unsigned short)(PyLong_AsUnsignedLong(PyList_GetItem(list, i))));
}
}
};
// Define equality operators
%extend XdmfItem {
bool __eq__(boost::shared_ptr<XdmfItem> item) {
return self == item.get();
void insertAsUInt32(int startIndex, PyObject * list) {
Py_ssize_t size = PyList_Size(list);
for(Py_ssize_t i = 0; i < size; ++i) {
$self->insert(i+startIndex, (unsigned int)(PyLong_AsUnsignedLong(PyList_GetItem(list, i))));
}
}
};
%extend XdmfItemProperty {
bool __eq__(boost::shared_ptr<XdmfItemProperty> itemProperty) {
return self == itemProperty.get();
%extend XdmfArrayType {
bool __eq__(const XdmfArrayType * arrayType) {
return $self == arrayType;
}
};
#endif /* SWIGPYTHON */
......@@ -338,7 +293,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%shared_ptr(XdmfWriter)
// Abstract Base Classes
%template() Loki::BaseVisitable<void>;
%template(BaseVisitable) Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>;
......@@ -396,6 +351,16 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%template(initializeAsUInt16) XdmfArray::initialize<unsigned short>;
%template(initializeAsUInt32) XdmfArray::initialize<unsigned int>;
%template(insertValueAsInt8) XdmfArray::insert<char>;
%template(insertValueAsInt16) XdmfArray::insert<short>;
%template(insertValueAsInt32) XdmfArray::insert<int>;
%template(insertValueAsInt64) XdmfArray::insert<long>;
%template(insertValueAsFloat32) XdmfArray::insert<float>;
%template(insertValueAsFloat64) XdmfArray::insert<double>;
%template(insertValueAsUInt8) XdmfArray::insert<unsigned char>;
%template(insertValueAsUInt16) XdmfArray::insert<unsigned short>;
%template(insertValueAsUInt32) XdmfArray::insert<unsigned int>;
%template(pushBackAsInt8) XdmfArray::pushBack<char>;
%template(pushBackAsInt16) XdmfArray::pushBack<short>;
%template(pushBackAsInt32) XdmfArray::pushBack<int>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment