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) ...@@ -66,7 +66,9 @@ if(XDMF_WRAP_PYTHON)
# Target Name = the output target name will have ${python_name} as its name # Target Name = the output target name will have ${python_name} as its name
macro(XDMF_SWIG_PYTHON python_name) macro(XDMF_SWIG_PYTHON python_name)
set(CMAKE_SWIG_OUTDIR ${CMAKE_BINARY_DIR}) 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_source_files_properties(${python_name}.i PROPERTIES CPLUSPLUS ON)
set(swig_extra_generated_files "") set(swig_extra_generated_files "")
swig_add_module(${python_name} python ${python_name}.i) swig_add_module(${python_name} python ${python_name}.i)
......
...@@ -222,6 +222,42 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.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 */ #endif /* SWIGPYTHON */
// Shared Pointer Templates // Shared Pointer Templates
......
...@@ -109,29 +109,6 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i ...@@ -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=%{ %pragma(java) jniclasscode=%{
static { static {
try { try {
...@@ -205,97 +182,75 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i ...@@ -205,97 +182,75 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
return None return None
}; };
%pythoncode { void insertAsInt8(int startIndex, PyObject * list) {
def insertAsInt8(self, startIndex, values): Py_ssize_t size = PyList_Size(list);
for i in range(0, len(values)): for(Py_ssize_t i = 0; i < size; ++i) {
self.insertValueAsInt8(i+startIndex, values[i]) $self->insert(i+startIndex, (char)(PyLong_AsLong(PyList_GetItem(list, 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 insertValueAsInt32(int index, int value) { void insertAsInt16(int startIndex, PyObject * list) {
$self->insert(index, value); 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) { void insertAsInt32(int startIndex, PyObject * list) {
$self->insert(index, value); 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) { void insertAsInt64(int startIndex, PyObject * list) {
$self->insert(index, value); 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) { void insertAsFloat32(int startIndex, PyObject * list) {
$self->insert(index, value); 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) { void insertAsFloat64(int startIndex, PyObject * list) {
$self->insert(index, value); 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) { void insertAsUInt8(int startIndex, PyObject * list) {
$self->insert(index, value); 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) { void insertAsUInt16(int startIndex, PyObject * list) {
$self->insert(index, value); 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))));
}
} }
}; void insertAsUInt32(int startIndex, PyObject * list) {
Py_ssize_t size = PyList_Size(list);
// Define equality operators for(Py_ssize_t i = 0; i < size; ++i) {
%extend XdmfItem { $self->insert(i+startIndex, (unsigned int)(PyLong_AsUnsignedLong(PyList_GetItem(list, i))));
}
bool __eq__(boost::shared_ptr<XdmfItem> item) {
return self == item.get();
} }
}; };
%extend XdmfItemProperty { %extend XdmfArrayType {
bool __eq__(const XdmfArrayType * arrayType) {
bool __eq__(boost::shared_ptr<XdmfItemProperty> itemProperty) { return $self == arrayType;
return self == itemProperty.get();
} }
}; };
#endif /* SWIGPYTHON */ #endif /* SWIGPYTHON */
...@@ -338,7 +293,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i ...@@ -338,7 +293,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%shared_ptr(XdmfWriter) %shared_ptr(XdmfWriter)
// Abstract Base Classes // Abstract Base Classes
%template() Loki::BaseVisitable<void>; %template(BaseVisitable) Loki::BaseVisitable<void>;
%template() Loki::Visitor<XdmfArray>; %template() Loki::Visitor<XdmfArray>;
%template() Loki::Visitor<XdmfItem>; %template() Loki::Visitor<XdmfItem>;
...@@ -396,6 +351,16 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i ...@@ -396,6 +351,16 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%template(initializeAsUInt16) XdmfArray::initialize<unsigned short>; %template(initializeAsUInt16) XdmfArray::initialize<unsigned short>;
%template(initializeAsUInt32) XdmfArray::initialize<unsigned int>; %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(pushBackAsInt8) XdmfArray::pushBack<char>;
%template(pushBackAsInt16) XdmfArray::pushBack<short>; %template(pushBackAsInt16) XdmfArray::pushBack<short>;
%template(pushBackAsInt32) XdmfArray::pushBack<int>; %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