mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 14:45:12 +00:00
Make the "Pointer types ... are not supported" message Eigen-specific, as suggested by @Lalaland. Move to new pybind11/eigen/common.h header.
This commit is contained in:
parent
ddb625e69d
commit
03dafde5cb
@ -126,6 +126,7 @@ set(PYBIND11_HEADERS
|
||||
include/pybind11/complex.h
|
||||
include/pybind11/options.h
|
||||
include/pybind11/eigen.h
|
||||
include/pybind11/eigen/common.h
|
||||
include/pybind11/eigen/matrix.h
|
||||
include/pybind11/eigen/tensor.h
|
||||
include/pybind11/embed.h
|
||||
|
@ -1034,11 +1034,6 @@ struct format_descriptor<
|
||||
static std::string format() { return std::string(1, c); }
|
||||
};
|
||||
|
||||
// Common message for `static_assert()`s, which are useful to easily preempt much less obvious
|
||||
// errors in code that does not support `format_descriptor<PyObject *>`.
|
||||
#define PYBIND11_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED \
|
||||
"Pointer types (in particular `PyObject *`) are not supported."
|
||||
|
||||
PYBIND11_NAMESPACE_BEGIN(detail)
|
||||
// Returns the index of the given type in the type char array below, and in the list in numpy.h
|
||||
// The order here is: bool; 8 ints ((signed,unsigned)x(8,16,32,64)bits); float,double,long double;
|
||||
|
9
include/pybind11/eigen/common.h
Normal file
9
include/pybind11/eigen/common.h
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright (c) 2023 The pybind Community.
|
||||
|
||||
#pragma once
|
||||
|
||||
// Common message for `static_assert()`s, which are useful to easily
|
||||
// preempt much less obvious errors.
|
||||
#define PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED \
|
||||
"Pointer types (in particular `PyObject *`) are not supported as scalar types for Eigen " \
|
||||
"types."
|
@ -10,6 +10,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../numpy.h"
|
||||
#include "common.h"
|
||||
|
||||
/* HINT: To suppress warnings originating from the Eigen headers, use -isystem.
|
||||
See also:
|
||||
@ -288,7 +289,7 @@ template <typename Type>
|
||||
struct type_caster<Type, enable_if_t<is_eigen_dense_plain<Type>::value>> {
|
||||
using Scalar = typename Type::Scalar;
|
||||
static_assert(!std::is_pointer<Scalar>::value,
|
||||
PYBIND11_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
using props = EigenProps<Type>;
|
||||
|
||||
bool load(handle src, bool convert) {
|
||||
@ -408,7 +409,7 @@ private:
|
||||
template <typename MapType>
|
||||
struct eigen_map_caster {
|
||||
static_assert(!std::is_pointer<typename MapType::Scalar>::value,
|
||||
PYBIND11_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
|
||||
private:
|
||||
using props = EigenProps<MapType>;
|
||||
@ -463,7 +464,7 @@ private:
|
||||
using props = EigenProps<Type>;
|
||||
using Scalar = typename props::Scalar;
|
||||
static_assert(!std::is_pointer<Scalar>::value,
|
||||
PYBIND11_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
using MapType = Eigen::Map<PlainObjectType, 0, StrideType>;
|
||||
using Array
|
||||
= array_t<Scalar,
|
||||
@ -612,7 +613,7 @@ private:
|
||||
template <typename Type>
|
||||
struct type_caster<Type, enable_if_t<is_eigen_other<Type>::value>> {
|
||||
static_assert(!std::is_pointer<typename Type::Scalar>::value,
|
||||
PYBIND11_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
|
||||
protected:
|
||||
using Matrix
|
||||
@ -643,7 +644,7 @@ template <typename Type>
|
||||
struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
|
||||
using Scalar = typename Type::Scalar;
|
||||
static_assert(!std::is_pointer<Scalar>::value,
|
||||
PYBIND11_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
using StorageIndex = remove_reference_t<decltype(*std::declval<Type>().outerIndexPtr())>;
|
||||
using Index = typename Type::Index;
|
||||
static constexpr bool rowMajor = Type::IsRowMajor;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../numpy.h"
|
||||
#include "common.h"
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
|
||||
static_assert(__GNUC__ > 5, "Eigen Tensor support in pybind11 requires GCC > 5.0");
|
||||
@ -165,7 +166,7 @@ PYBIND11_WARNING_POP
|
||||
template <typename Type>
|
||||
struct type_caster<Type, typename eigen_tensor_helper<Type>::ValidType> {
|
||||
static_assert(!std::is_pointer<typename Type::Scalar>::value,
|
||||
PYBIND11_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
using Helper = eigen_tensor_helper<Type>;
|
||||
static constexpr auto temp_name = get_tensor_descriptor<Type, false>::value;
|
||||
PYBIND11_TYPE_CASTER(Type, temp_name);
|
||||
@ -362,7 +363,7 @@ template <typename Type, int Options>
|
||||
struct type_caster<Eigen::TensorMap<Type, Options>,
|
||||
typename eigen_tensor_helper<remove_cv_t<Type>>::ValidType> {
|
||||
static_assert(!std::is_pointer<typename Type::Scalar>::value,
|
||||
PYBIND11_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
PYBIND11_EIGEN_MESSAGE_POINTER_TYPES_ARE_NOT_SUPPORTED);
|
||||
using MapType = Eigen::TensorMap<Type, Options>;
|
||||
using Helper = eigen_tensor_helper<remove_cv_t<Type>>;
|
||||
|
||||
|
@ -57,6 +57,7 @@ detail_headers = {
|
||||
}
|
||||
|
||||
eigen_headers = {
|
||||
"include/pybind11/eigen/common.h",
|
||||
"include/pybind11/eigen/matrix.h",
|
||||
"include/pybind11/eigen/tensor.h",
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user