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 MatrixToNDArray { //clang-format off
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 } // namespace Converters
38}; // namespace PythonInterface
39//clang-format on
40} // namespace Converters
41} // namespace PythonInterface
42} // namespace Mantid
Numerical Matrix class.
Definition Matrix.h:41
std::pair< size_t, size_t > size() const
Access matrix sizes.
Definition Matrix.h:140
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.