Skip to content

Commit

Permalink
Refs #4399 Avoid symbol clash.
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Feb 16, 2012
1 parent 54ecb7a commit b762c20
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
#include "MantidKernel/System.h"
#include <boost/python/detail/prefix.hpp> // Safe include of Python.h

#ifndef _WIN32
#define PY_ARRAY_UNIQUE_SYMBOL KERNEL_ARRAY_API
#endif
#define NO_ARRAY_IMPORT
#include <numpy/ndarrayobject.h>
//#define PY_ARRAY_UNIQUE_SYMBOL KERNEL_ARRAY_API
//#define NO_ARRAY_IMPORT
//#include <numpy/ndarrayobject.h>

namespace Mantid
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,56 @@
// Includes
//-----------------------------------------------------------------------------
#include "MantidPythonInterface/kernel/Converters/NDArrayToVectorConverter.h"
#include "MantidPythonInterface/kernel/Converters/NDArrayTypeIndex.h"
//#include "MantidPythonInterface/kernel/Converters/NDArrayTypeIndex.h"
#include <boost/python/extract.hpp>

// See http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PY_ARRAY_UNIQUE_SYMBOL
#define PY_ARRAY_UNIQUE_SYMBOL KERNEL_ARRAY_API
#define NO_IMPORT_ARRAY
#include <numpy/ndarrayobject.h>

namespace Mantid
{
namespace PythonInterface
{
namespace Numpy
{
/**
* Defines a mapping between C++ type given by
* the template parameter and numpy type enum
* NPY_TYPES.
*
* There is no general definition, only specialized
* versions are defined. Each specialization should
* contain a static const NPY_TYPES definition giving
* the result of the mapping
*/
template<typename T>
struct NDArrayTypeIndex
{};

/// Macro to define mappings between the CType and Numpy enum
#define DEFINE_TYPE_MAPPING(CType, NDTypeNum) \
template<>\
struct NDArrayTypeIndex<CType>\
{\
static int typenum() { return NDTypeNum; }\
};

DEFINE_TYPE_MAPPING(int16_t, NPY_INT16);
DEFINE_TYPE_MAPPING(uint16_t, NPY_UINT16);
DEFINE_TYPE_MAPPING(int32_t, NPY_INT32);
DEFINE_TYPE_MAPPING(uint32_t, NPY_UINT32);
DEFINE_TYPE_MAPPING(int64_t, NPY_INT64);
#ifdef __APPLE__
DEFINE_TYPE_MAPPING(unsigned long, NPY_ULONG);
#endif
DEFINE_TYPE_MAPPING(uint64_t, NPY_UINT64);
DEFINE_TYPE_MAPPING(double, NPY_DOUBLE);
// Not needed outside here
#undef DEFINE_TYPE_MAPPING

}
namespace
{
//-------------------------------------------------------------------------
Expand Down

0 comments on commit b762c20

Please sign in to comment.