Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
71af3b07
Commit
71af3b07
authored
Sep 24, 2016
by
Dean Moldovan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify base class detection for Eigen types
parent
88628878
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
39 deletions
+28
-39
include/pybind11/common.h
+15
-0
include/pybind11/eigen.h
+13
-39
No files found.
include/pybind11/common.h
View file @
71af3b07
...
@@ -390,6 +390,21 @@ template <template<class> class Predicate, class Default, class... T> using firs
...
@@ -390,6 +390,21 @@ template <template<class> class Predicate, class Default, class... T> using firs
template
<
typename
T
,
typename
...
/*Us*/
>
struct
deferred_type
{
using
type
=
T
;
};
template
<
typename
T
,
typename
...
/*Us*/
>
struct
deferred_type
{
using
type
=
T
;
};
template
<
typename
T
,
typename
...
Us
>
using
deferred_t
=
typename
deferred_type
<
T
,
Us
...
>::
type
;
template
<
typename
T
,
typename
...
Us
>
using
deferred_t
=
typename
deferred_type
<
T
,
Us
...
>::
type
;
template
<
template
<
typename
...
>
class
Base
>
struct
is_template_base_of_impl
{
template
<
typename
...
Us
>
static
std
::
true_type
check
(
Base
<
Us
...
>
*
);
static
std
::
false_type
check
(...);
};
/// Check if a template is the base of a type. For example:
/// `is_template_base_of<Base, T>` is true if `struct T : Base<U> {}` where U can be anything
template
<
template
<
typename
...
>
class
Base
,
typename
T
>
#if !defined(_MSC_VER)
using
is_template_base_of
=
decltype
(
is_template_base_of_impl
<
Base
>::
check
((
T
*
)
nullptr
));
#else // MSVC2015 has trouble with decltype in template aliases
struct
is_template_base_of
:
decltype
(
is_template_base_of_impl
<
Base
>::
check
((
T
*
)
nullptr
))
{
};
#endif
/// Ignore that a variable is unused in compiler warnings
/// Ignore that a variable is unused in compiler warnings
inline
void
ignore_unused
(
const
int
*
)
{
}
inline
void
ignore_unused
(
const
int
*
)
{
}
...
...
include/pybind11/eigen.h
View file @
71af3b07
...
@@ -34,47 +34,18 @@
...
@@ -34,47 +34,18 @@
NAMESPACE_BEGIN
(
pybind11
)
NAMESPACE_BEGIN
(
pybind11
)
NAMESPACE_BEGIN
(
detail
)
NAMESPACE_BEGIN
(
detail
)
template
<
typename
T
>
class
is_eigen_dense
{
template
<
typename
T
>
using
is_eigen_dense
=
is_template_base_of
<
Eigen
::
DenseBase
,
T
>
;
private
:
template
<
typename
T
>
using
is_eigen_sparse
=
is_template_base_of
<
Eigen
::
SparseMatrixBase
,
T
>
;
template
<
typename
Derived
>
static
std
::
true_type
test
(
const
Eigen
::
DenseBase
<
Derived
>
&
);
template
<
typename
T
>
using
is_eigen_ref
=
is_template_base_of
<
Eigen
::
RefBase
,
T
>
;
static
std
::
false_type
test
(...);
public
:
static
constexpr
bool
value
=
decltype
(
test
(
std
::
declval
<
T
>
()))
::
value
;
};
// Eigen::Ref<Derived> satisfies is_eigen_dense, but isn't constructible, so it needs a special
// type_caster to handle argument copying/forwarding.
template
<
typename
T
>
class
is_eigen_ref
{
private
:
template
<
typename
Derived
>
static
enable_if_t
<
std
::
is_same
<
typename
std
::
remove_const
<
T
>::
type
,
Eigen
::
Ref
<
Derived
>>::
value
,
Derived
>
test
(
const
Eigen
::
Ref
<
Derived
>
&
);
static
void
test
(...);
public
:
typedef
decltype
(
test
(
std
::
declval
<
T
>
()))
Derived
;
static
constexpr
bool
value
=
!
std
::
is_void
<
Derived
>::
value
;
};
template
<
typename
T
>
class
is_eigen_sparse
{
private
:
template
<
typename
Derived
>
static
std
::
true_type
test
(
const
Eigen
::
SparseMatrixBase
<
Derived
>
&
);
static
std
::
false_type
test
(...);
public
:
static
constexpr
bool
value
=
decltype
(
test
(
std
::
declval
<
T
>
()))
::
value
;
};
// Test for objects inheriting from EigenBase<Derived> that aren't captured by the above. This
// Test for objects inheriting from EigenBase<Derived> that aren't captured by the above. This
// basically covers anything that can be assigned to a dense matrix but that don't have a typical
// basically covers anything that can be assigned to a dense matrix but that don't have a typical
// matrix data layout that can be copied from their .data(). For example, DiagonalMatrix and
// matrix data layout that can be copied from their .data(). For example, DiagonalMatrix and
// SelfAdjointView fall into this category.
// SelfAdjointView fall into this category.
template
<
typename
T
>
class
is_eigen_base
{
template
<
typename
T
>
using
is_eigen_base
=
bool_constant
<
private
:
is_template_base_of
<
Eigen
::
EigenBase
,
T
>::
value
template
<
typename
Derived
>
static
std
::
true_type
test
(
const
Eigen
::
EigenBase
<
Derived
>
&
);
&&
!
is_eigen_dense
<
T
>::
value
&&
!
is_eigen_sparse
<
T
>::
value
static
std
::
false_type
test
(...);
>
;
public
:
static
constexpr
bool
value
=
!
is_eigen_dense
<
T
>::
value
&&
!
is_eigen_sparse
<
T
>::
value
&&
decltype
(
test
(
std
::
declval
<
T
>
()))
::
value
;
};
template
<
typename
Type
>
template
<
typename
Type
>
struct
type_caster
<
Type
,
enable_if_t
<
is_eigen_dense
<
Type
>::
value
&&
!
is_eigen_ref
<
Type
>::
value
>>
{
struct
type_caster
<
Type
,
enable_if_t
<
is_eigen_dense
<
Type
>::
value
&&
!
is_eigen_ref
<
Type
>::
value
>>
{
...
@@ -159,10 +130,13 @@ protected:
...
@@ -159,10 +130,13 @@ protected:
static
PYBIND11_DESCR
cols
()
{
return
_
<
T
::
ColsAtCompileTime
>
();
}
static
PYBIND11_DESCR
cols
()
{
return
_
<
T
::
ColsAtCompileTime
>
();
}
};
};
template
<
typename
Type
>
// Eigen::Ref<Derived> satisfies is_eigen_dense, but isn't constructable, so it needs a special
struct
type_caster
<
Type
,
enable_if_t
<
is_eigen_dense
<
Type
>::
value
&&
is_eigen_ref
<
Type
>::
value
>>
{
// type_caster to handle argument copying/forwarding.
template
<
typename
CVDerived
,
int
Options
,
typename
StrideType
>
struct
type_caster
<
Eigen
::
Ref
<
CVDerived
,
Options
,
StrideType
>>
{
protected
:
protected
:
using
Derived
=
typename
std
::
remove_const
<
typename
is_eigen_ref
<
Type
>::
Derived
>::
type
;
using
Type
=
Eigen
::
Ref
<
CVDerived
,
Options
,
StrideType
>
;
using
Derived
=
typename
std
::
remove_const
<
CVDerived
>::
type
;
using
DerivedCaster
=
type_caster
<
Derived
>
;
using
DerivedCaster
=
type_caster
<
Derived
>
;
DerivedCaster
derived_caster
;
DerivedCaster
derived_caster
;
std
::
unique_ptr
<
Type
>
value
;
std
::
unique_ptr
<
Type
>
value
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment