Mantid
Loading...
Searching...
No Matches
MatrixToNDArray.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2012 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
11#include <boost/python/detail/prefix.hpp>
12
13namespace Mantid {
14namespace PythonInterface {
15namespace Converters {
16//-----------------------------------------------------------------------
17// Converter implementation
18//-----------------------------------------------------------------------
26template <typename ElementType, typename ConversionPolicy> struct DLLExport MatrixToNDArray {
32 inline PyObject *operator()(const Kernel::Matrix<ElementType> &cmatrix) const {
33 const std::pair<size_t, size_t> matrixDims = cmatrix.size();
34 Py_intptr_t dims[2] = {static_cast<Py_intptr_t>(matrixDims.first), static_cast<Py_intptr_t>(matrixDims.second)};
35 using policy = typename ConversionPolicy::template apply<ElementType>;
36 return policy::createFromArray(&(cmatrix[0][0]), 2, dims);
37 }
38};
39} // namespace Converters
40} // namespace PythonInterface
41} // namespace Mantid
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
Numerical Matrix class.
Definition: Matrix.h:42
std::pair< size_t, size_t > size() const
Access matrix sizes.
Definition: Matrix.h:141
Helper class which provides the Collimation Length for SANS instruments.
Converter that takes a Mantid Matrix and converts it into a numpy array.
PyObject * operator()(const Kernel::Matrix< ElementType > &cmatrix) const
Operator to convert a matrix to a numpy array.