Skip to content

Commit

Permalink
Fix issue with V3D in tables from Python on intel
Browse files Browse the repository at this point in the history
Refs #8760
  • Loading branch information
martyngigg committed Jun 14, 2014
1 parent 0ca6b59 commit cf741c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Expand Up @@ -13,6 +13,7 @@
#include <boost/python/converter/builtin_converters.hpp>
#include <boost/preprocessor/list/for_each.hpp>
#include <boost/preprocessor/tuple/to_list.hpp>
#include <cstring>
#include <vector>

// See http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PY_ARRAY_UNIQUE_SYMBOL
Expand Down Expand Up @@ -64,7 +65,7 @@ namespace
result = to_python_value<const T&>()(column->cell<T>(row));\
}
#define GET_USER(R, _, T) \
else if(typeID == typeid(T))\
else if(strcmp(typeID.name(), typeid(T).name()) == 0) \
{\
const converter::registration *entry = converter::registry::query(typeid(T));\
if(!entry) throw std::invalid_argument("Cannot find converter from C++ type.");\
Expand Down Expand Up @@ -98,19 +99,20 @@ namespace
*/
void setValue(const Column_sptr column, const int row, const bpl::object & value)
{
if(column->get_type_info() == typeid(Mantid::API::Boolean))
const auto & typeID = column->get_type_info();
if(typeID == typeid(Mantid::API::Boolean))
{
column->cell<Mantid::API::Boolean>(row) = bpl::extract<bool>(value)();
return;
}

#define SET_CELL(R, _, T) \
else if(typeID == typeid(T)) \
else if(strcmp(typeID.name(), typeid(T).name()) == 0)\
{\
column->cell<T>(row) = bpl::extract<T>(value)();\
}
#define SET_VECTOR_CELL(R, _, T) \
else if(typeID == typeid(T)) \
else if(typeID == typeid(T)) \
{\
if( ! PyArray_Check( value.ptr() ) ) \
{ \
Expand All @@ -122,16 +124,12 @@ namespace
} \
}


// -- Use the boost preprocessor to generate a list of else if clause to cut out copy
// and pasted code.
// I think cppcheck is getting confused by the define
// cppcheck-suppress unreadVariable
const std::type_info & typeID = column->get_type_info();
if(false){} // So that it always falls through to the list checking
BOOST_PP_LIST_FOR_EACH(SET_CELL, _ , BUILTIN_TYPES)
BOOST_PP_LIST_FOR_EACH(SET_VECTOR_CELL, _ , ARRAY_TYPES)
BOOST_PP_LIST_FOR_EACH(SET_CELL, _ , USER_TYPES)
BOOST_PP_LIST_FOR_EACH(SET_VECTOR_CELL, _ , ARRAY_TYPES)
else
{
throw std::invalid_argument("Cannot convert Python type to C++: " + column->type());
Expand Down
Expand Up @@ -110,6 +110,15 @@ def test_set_and_extract_boolean_columns(self):
self.assertTrue(table.cell(0, 0))
self.assertFalse(table.cell(1, 0))

def test_set_and_extract_v3d_columns(self):
from mantid.kernel import V3D

table = WorkspaceFactory.createTable()
table.addColumn(type='V3D', name='pos')
table.addRow([V3D(1,1,1)])

self.assertEquals(V3D(1,1,1), table.cell(0, 0))

def test_set_and_extract_vector_columns(self):
table = WorkspaceFactory.createTable()
table.addColumn(type='vector_int', name='values')
Expand Down

0 comments on commit cf741c3

Please sign in to comment.