Skip to content
Snippets Groups Projects
Commit b5723823 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

core: add allocator for Eigen::Tensor

parent c7445082
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2020-2022 INRIA
* Copyright 2020-2023 INRIA
*/
#ifndef __eigenpy_numpy_allocator_hpp__
#define __eigenpy_numpy_allocator_hpp__
#include "eigenpy/eigen-allocator.hpp"
#include "eigenpy/fwd.hpp"
#include "eigenpy/eigen-allocator.hpp"
#include "eigenpy/numpy-type.hpp"
#include "eigenpy/register.hpp"
......@@ -29,6 +29,23 @@ struct NumpyAllocator {
return pyArray;
}
#ifdef EIGENPY_WITH_TENSOR_SUPPORT
template <typename Scalar, int Rank, int Options, typename IndexType>
static PyArrayObject *allocate(
const Eigen::Tensor<Scalar, Rank, Options, IndexType> &tensor,
npy_intp nd, npy_intp *shape) {
typedef Eigen::Tensor<Scalar, Rank, Options, IndexType> Tensor;
const int code = Register::getTypeCode<Scalar>();
PyArrayObject *pyArray = (PyArrayObject *)call_PyArray_SimpleNew(
static_cast<int>(nd), shape, code);
// Copy data
EigenAllocator<Tensor>::copy(tensor, pyArray);
return pyArray;
}
#endif
};
template <typename MatType>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment