Skip to content

Commit f858aef

Browse files
authored
Merge pull request #348 from jcarpent/devel
Add full support of Eigen::Tensor
2 parents a32e9de + aeb242d commit f858aef

20 files changed

+1371
-253
lines changed

.github/workflows/linux.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
- run: |
2121
sudo apt-get update
2222
sudo apt-get install cmake libboost-all-dev libeigen3-dev python*-numpy python*-dev
23+
echo $(sudo apt list --installed)
24+
echo $(g++ --version)
2325
- run: cmake -DPYTHON_EXECUTABLE=$(which python${{ matrix.python }}) .
2426
- run: make -j2
2527
- run: make test

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ repos:
55
rev: v15.0.7
66
hooks:
77
- id: clang-format
8-
args: ['--style={BasedOnStyle: Google, SortIncludes: false}']
8+
args: ['--style={BasedOnStyle: Google, SortIncludes: false, Standard: Cpp03}']
99
- repo: https://github.com/pre-commit/pre-commit-hooks
1010
rev: v4.4.0
1111
hooks:

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ string(REPLACE "-pedantic" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
6767

6868
# If needed, fix CMake policy for APPLE systems
6969
apply_default_apple_configuration()
70+
check_minimal_cxx_standard(11 ENFORCE)
7071

7172
if(WIN32)
7273
set(LINK copy_if_different)
@@ -164,6 +165,7 @@ set(${PROJECT_NAME}_HEADERS
164165
include/eigenpy/std-vector.hpp
165166
include/eigenpy/pickle-vector.hpp
166167
include/eigenpy/stride.hpp
168+
include/eigenpy/tensor/eigen-from-python.hpp
167169
include/eigenpy/swig.hpp
168170
include/eigenpy/version.hpp)
169171

include/eigenpy/alignment.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023, INRIA
2+
* Copyright 2023 INRIA
33
*/
44

55
#ifndef __eigenpy_alignment_hpp__
@@ -67,6 +67,23 @@ struct referent_storage<
6767
typename eigenpy::aligned_storage<referent_size<T &>::value>::type type;
6868
};
6969

70+
#ifdef EIGENPY_WITH_TENSOR_SUPPORT
71+
template <typename Scalar, int Rank, int Options, typename IndexType>
72+
struct referent_storage<Eigen::Tensor<Scalar, Rank, Options, IndexType> &> {
73+
typedef Eigen::Tensor<Scalar, Rank, Options, IndexType> T;
74+
typedef
75+
typename eigenpy::aligned_storage<referent_size<T &>::value>::type type;
76+
};
77+
78+
template <typename Scalar, int Rank, int Options, typename IndexType>
79+
struct referent_storage<
80+
const Eigen::Tensor<Scalar, Rank, Options, IndexType> &> {
81+
typedef Eigen::Tensor<Scalar, Rank, Options, IndexType> T;
82+
typedef
83+
typename eigenpy::aligned_storage<referent_size<T &>::value>::type type;
84+
};
85+
#endif
86+
7087
template <typename Scalar, int Options>
7188
struct referent_storage<Eigen::Quaternion<Scalar, Options> &> {
7289
typedef Eigen::Quaternion<Scalar, Options> T;

include/eigenpy/details.hpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,49 @@
1717
#include "eigenpy/scalar-conversion.hpp"
1818

1919
namespace eigenpy {
20-
template <typename MatType, typename EigenEquivalentType>
21-
EIGENPY_DEPRECATED void enableEigenPySpecific() {
22-
enableEigenPySpecific<MatType>();
23-
}
20+
21+
template <typename EigenType,
22+
typename BaseType = typename get_eigen_base_type<EigenType>::type>
23+
struct expose_eigen_type_impl;
2424

2525
template <typename MatType>
26-
void enableEigenPySpecific() {
27-
if (check_registration<MatType>()) return;
26+
struct expose_eigen_type_impl<MatType, Eigen::MatrixBase<MatType> > {
27+
static void run() {
28+
if (check_registration<MatType>()) return;
2829

29-
// to-python
30-
EigenToPyConverter<MatType>::registration();
30+
// to-python
31+
EigenToPyConverter<MatType>::registration();
3132
#if EIGEN_VERSION_AT_LEAST(3, 2, 0)
32-
EigenToPyConverter<Eigen::Ref<MatType> >::registration();
33-
EigenToPyConverter<const Eigen::Ref<const MatType> >::registration();
33+
EigenToPyConverter<Eigen::Ref<MatType> >::registration();
34+
EigenToPyConverter<const Eigen::Ref<const MatType> >::registration();
35+
#endif
36+
37+
// from-python
38+
EigenFromPyConverter<MatType>::registration();
39+
}
40+
};
41+
42+
#ifdef EIGENPY_WITH_TENSOR_SUPPORT
43+
template <typename TensorType>
44+
struct expose_eigen_type_impl<TensorType, Eigen::TensorBase<TensorType> > {
45+
static void run() {
46+
if (check_registration<TensorType>()) return;
47+
48+
// to-python
49+
EigenToPyConverter<TensorType>::registration();
50+
EigenToPyConverter<Eigen::TensorRef<TensorType> >::registration();
51+
EigenToPyConverter<
52+
const Eigen::TensorRef<const TensorType> >::registration();
53+
54+
// from-python
55+
EigenFromPyConverter<TensorType>::registration();
56+
}
57+
};
3458
#endif
3559

36-
// from-python
37-
EigenFromPyConverter<MatType>::registration();
60+
template <typename MatType>
61+
void enableEigenPySpecific() {
62+
expose_eigen_type_impl<MatType>::run();
3863
}
3964

4065
} // namespace eigenpy

0 commit comments

Comments
 (0)