Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • jcarpent/eigenpy
  • gsaurel/eigenpy
  • stack-of-tasks/eigenpy
3 results
Show changes
Showing
with 326 additions and 199 deletions
/*
* Copyright 2024 INRIA
*/
#include "eigenpy/eigenpy.hpp"
#include <cstdint>
namespace eigenpy {
void exposeMatrixInt16() {
exposeType<int16_t>();
exposeType<int16_t, Eigen::RowMajor>();
}
} // namespace eigenpy
/*
* Copyright 2020 INRIA
*/
#include "eigenpy/eigenpy.hpp"
#include <cstdint>
namespace eigenpy {
void exposeMatrixInt32() {
exposeType<int32_t>();
exposeType<int32_t, Eigen::RowMajor>();
}
} // namespace eigenpy
/*
* Copyright 2020 INRIA
*/
#include "eigenpy/eigenpy.hpp"
#include <cstdint>
namespace eigenpy {
void exposeMatrixInt64() {
exposeType<int64_t>();
exposeType<int64_t, Eigen::RowMajor>();
}
} // namespace eigenpy
/*
* Copyright 2020 INRIA
*/
#include "eigenpy/eigenpy.hpp"
#include <cstdint>
namespace eigenpy {
void exposeMatrixInt8() {
exposeType<int8_t>();
exposeType<int8_t, Eigen::RowMajor>();
}
} // namespace eigenpy
/*
* Copyright 2024 INRIA
*/
#include "eigenpy/eigenpy.hpp"
namespace eigenpy {
void exposeMatrixLinuxLongLong() {
// On Linux, long long is a 64 bytes type but it's a different type than int64_t
#ifdef __linux__
exposeType<long long>();
exposeType<long long, Eigen::RowMajor>();
#endif // linux
}
} // namespace eigenpy
/*
* Copyright 2024 INRIA
*/
#include "eigenpy/eigenpy.hpp"
namespace eigenpy {
void exposeMatrixLinuxULongLong() {
// On Linux, long long is a 64 bytes type but it's a different type than int64_t
#ifdef __linux__
exposeType<unsigned long long>();
exposeType<unsigned long long, Eigen::RowMajor>();
#endif // linux
}
} // namespace eigenpy
...@@ -4,11 +4,9 @@ ...@@ -4,11 +4,9 @@
#include "eigenpy/eigenpy.hpp" #include "eigenpy/eigenpy.hpp"
namespace eigenpy namespace eigenpy {
{ void exposeMatrixLongDouble() {
void exposeMatrixLongDouble() exposeType<long double>();
{ exposeType<long double, Eigen::RowMajor>();
exposeType<long double>();
exposeType<long double,Eigen::RowMajor>();
}
} }
} // namespace eigenpy
/*
* Copyright 2020 INRIA
*/
#include "eigenpy/eigenpy.hpp"
namespace eigenpy
{
void exposeMatrixLong()
{
exposeType<long>();
exposeType<long,Eigen::RowMajor>();
}
}
/*
* Copyright 2024 INRIA
*/
#include "eigenpy/eigenpy.hpp"
namespace eigenpy {
void exposeMatrixMacLong() {
// On Mac, long is a 64 bytes type but it's a different type than int64_t
#ifdef __APPLE__
exposeType<long>();
exposeType<long, Eigen::RowMajor>();
#endif // Mac
}
} // namespace eigenpy
/*
* Copyright 2024 INRIA
*/
#include "eigenpy/eigenpy.hpp"
namespace eigenpy {
void exposeMatrixMacULong() {
// On Mac, long is a 64 bytes type but it's a different type than int64_t
#ifdef __APPLE__
exposeType<unsigned long>();
exposeType<unsigned long, Eigen::RowMajor>();
#endif // Mac
}
} // namespace eigenpy
/*
* Copyright 2024 INRIA
*/
#include "eigenpy/eigenpy.hpp"
#include <cstdint>
namespace eigenpy {
void exposeMatrixUInt16() {
exposeType<uint16_t>();
exposeType<uint16_t, Eigen::RowMajor>();
}
} // namespace eigenpy
/*
* Copyright 2024 INRIA
*/
#include "eigenpy/eigenpy.hpp"
#include <cstdint>
namespace eigenpy {
void exposeMatrixUInt32() {
exposeType<uint32_t>();
exposeType<uint32_t, Eigen::RowMajor>();
}
} // namespace eigenpy
/*
* Copyright 2020 INRIA
*/
#include "eigenpy/eigenpy.hpp"
#include <cstdint>
namespace eigenpy {
void exposeMatrixUInt64() {
exposeType<uint64_t>();
exposeType<uint64_t, Eigen::RowMajor>();
}
} // namespace eigenpy
/*
* Copyright 2020 INRIA
*/
#include "eigenpy/eigenpy.hpp"
#include <cstdint>
namespace eigenpy {
void exposeMatrixUInt8() {
exposeType<std::uint8_t>();
exposeType<std::uint8_t, Eigen::RowMajor>();
}
} // namespace eigenpy
/*
* Copyright 2024 INRIA
*/
#include "eigenpy/eigenpy.hpp"
namespace eigenpy {
void exposeMatrixWindowsLong() {
// On Windows, long is a 32 bytes type but it's a different type than int
#ifdef WIN32
exposeType<long>();
exposeType<long, Eigen::RowMajor>();
#endif // WIN32
}
} // namespace eigenpy
/*
* Copyright 2024 INRIA
*/
#include "eigenpy/eigenpy.hpp"
namespace eigenpy {
void exposeMatrixWindowsULong() {
// On Windows, long is a 32 bytes type but it's a different type than int
#ifdef WIN32
exposeType<unsigned long>();
exposeType<unsigned long, Eigen::RowMajor>();
#endif // WIN32
}
} // namespace eigenpy
/* /*
* Copyright 2018-2020 INRIA * Copyright 2018-2023 INRIA
*/ */
#include "eigenpy/numpy-type.hpp" #include "eigenpy/numpy-type.hpp"
#include <patchlevel.h> // For PY_MAJOR_VERSION #include <patchlevel.h> // For PY_MAJOR_VERSION
namespace eigenpy namespace eigenpy {
{
namespace bp = boost::python;
NumpyType & NumpyType::getInstance()
{
static NumpyType instance;
return instance;
}
bp::object NumpyType::make(PyArrayObject* pyArray, bool copy) NumpyType& NumpyType::getInstance() {
{ return make((PyObject*)pyArray,copy); } static NumpyType instance;
return instance;
bp::object NumpyType::make(PyObject* pyObj, bool copy) }
{
bp::object m; bp::object NumpyType::make(PyArrayObject* pyArray, bool copy) {
if(isMatrix()) return make((PyObject*)pyArray, copy);
m = getInstance().NumpyMatrixObject(bp::object(bp::handle<>(pyObj)), bp::object(), copy); }
// m = NumpyAsMatrixObject(bp::object(bp::handle<>(pyObj)));
else if(isArray()) bp::object NumpyType::make(PyObject* pyObj, bool /*copy*/) {
m = bp::object(bp::handle<>(pyObj)); // nothing to do here bp::object m;
m = bp::object(bp::handle<>(pyObj)); // nothing to do here
Py_INCREF(m.ptr());
return m; Py_INCREF(m.ptr());
} return m;
}
void NumpyType::setNumpyType(bp::object & obj)
{ void NumpyType::sharedMemory(const bool value) {
PyTypeObject * obj_type = PyType_Check(obj.ptr()) ? reinterpret_cast<PyTypeObject*>(obj.ptr()) : obj.ptr()->ob_type; getInstance().shared_memory = value;
if(PyType_IsSubtype(obj_type,getInstance().NumpyMatrixType)) }
switchToNumpyMatrix();
else if(PyType_IsSubtype(obj_type,getInstance().NumpyArrayType)) bool NumpyType::sharedMemory() { return getInstance().shared_memory; }
switchToNumpyArray();
} const PyTypeObject* NumpyType::getNumpyArrayType() {
return getInstance().NumpyArrayType;
void NumpyType::sharedMemory(const bool value) }
{
getInstance().shared_memory = value; NumpyType::NumpyType() {
} pyModule = bp::import("numpy");
bool NumpyType::sharedMemory()
{
return getInstance().shared_memory;
}
void NumpyType::switchToNumpyArray()
{
getInstance().CurrentNumpyType = getInstance().NumpyArrayObject;
getInstance().getType() = ARRAY_TYPE;
}
void NumpyType::switchToNumpyMatrix()
{
getInstance().CurrentNumpyType = getInstance().NumpyMatrixObject;
getInstance().getType() = MATRIX_TYPE;
}
NP_TYPE & NumpyType::getType()
{
return getInstance().np_type;
}
bp::object NumpyType::getNumpyType()
{
return getInstance().CurrentNumpyType;
}
const PyTypeObject * NumpyType::getNumpyMatrixType()
{
return getInstance().NumpyMatrixType;
}
const PyTypeObject * NumpyType::getNumpyArrayType()
{
return getInstance().NumpyArrayType;
}
bool NumpyType::isMatrix()
{
return PyType_IsSubtype(reinterpret_cast<PyTypeObject*>(getInstance().CurrentNumpyType.ptr()),
getInstance().NumpyMatrixType);
}
bool NumpyType::isArray()
{
if(getInstance().isMatrix()) return false;
return PyType_IsSubtype(reinterpret_cast<PyTypeObject*>(getInstance().CurrentNumpyType.ptr()),
getInstance().NumpyArrayType);
}
NumpyType::NumpyType()
{
pyModule = bp::import("numpy");
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
// TODO I don't know why this Py_INCREF is necessary. // TODO I don't know why this Py_INCREF is necessary.
// Without it, the destructor of NumpyType SEGV sometimes. // Without it, the destructor of NumpyType SEGV sometimes.
Py_INCREF(pyModule.ptr()); Py_INCREF(pyModule.ptr());
#endif #endif
NumpyMatrixObject = pyModule.attr("matrix"); NumpyArrayObject = pyModule.attr("ndarray");
NumpyMatrixType = reinterpret_cast<PyTypeObject*>(NumpyMatrixObject.ptr()); NumpyArrayType = reinterpret_cast<PyTypeObject*>(NumpyArrayObject.ptr());
NumpyArrayObject = pyModule.attr("ndarray");
NumpyArrayType = reinterpret_cast<PyTypeObject*>(NumpyArrayObject.ptr()); shared_memory = true;
//NumpyAsMatrixObject = pyModule.attr("asmatrix");
//NumpyAsMatrixType = reinterpret_cast<PyTypeObject*>(NumpyAsMatrixObject.ptr());
CurrentNumpyType = NumpyArrayObject; // default conversion
np_type = ARRAY_TYPE;
shared_memory = true;
}
} }
} // namespace eigenpy
/* /*
* Copyright 2020-2021 INRIA * Copyright 2020-2024 INRIA
*/ */
#include "eigenpy/numpy.hpp" #include "eigenpy/numpy.hpp"
namespace eigenpy namespace eigenpy {
{ void import_numpy() {
void import_numpy() if (_import_array() < 0) {
{ PyErr_Print();
if(_import_array() < 0) PyErr_SetString(PyExc_ImportError,
{ "numpy.core.multiarray failed to import");
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
}
} }
}
int PyArray_TypeNum(PyTypeObject * type) int PyArray_TypeNum(PyTypeObject* type) {
{ PyArray_Descr* descr =
return PyArray_TypeNumFromName(const_cast<char*>(type->tp_name)); PyArray_DescrFromTypeObject(reinterpret_cast<PyObject*>(type));
if (descr == NULL) {
return NPY_NOTYPE;
} }
return descr->type_num;
}
#if defined _WIN32 || defined __CYGWIN__ #if defined _WIN32 || defined __CYGWIN__
bool call_PyArray_Check(PyObject * py_obj) bool call_PyArray_Check(PyObject* py_obj) { return PyArray_Check(py_obj); }
{
return PyArray_Check(py_obj);
}
PyObject* call_PyArray_SimpleNew(int nd, npy_intp * shape, int np_type) PyObject* call_PyArray_SimpleNew(int nd, npy_intp* shape, int np_type) {
{ return PyArray_SimpleNew(nd, shape, np_type);
return PyArray_SimpleNew(nd,shape,np_type); }
}
PyObject* call_PyArray_New(PyTypeObject * py_type_ptr, int nd, npy_intp * shape, int np_type, void * data_ptr, int options) PyObject* call_PyArray_New(PyTypeObject* py_type_ptr, int nd, npy_intp* shape,
{ int np_type, void* data_ptr, int options) {
return PyArray_New(py_type_ptr,nd,shape,np_type,NULL,data_ptr,0,options,NULL); return PyArray_New(py_type_ptr, nd, shape, np_type, NULL, data_ptr, 0,
} options, NULL);
}
int call_PyArray_ObjectType(PyObject * obj, int val)
{
return PyArray_ObjectType(obj,val);
}
PyTypeObject * getPyArrayType() { return &PyArray_Type; } PyObject* call_PyArray_New(PyTypeObject* py_type_ptr, int nd, npy_intp* shape,
int np_type, npy_intp* strides, void* data_ptr,
int options) {
return PyArray_New(py_type_ptr, nd, shape, np_type, strides, data_ptr, 0,
options, NULL);
}
PyArray_Descr * call_PyArray_DescrFromType(int typenum) int call_PyArray_ObjectType(PyObject* obj, int val) {
{ return PyArray_ObjectType(obj, val);
return PyArray_DescrFromType(typenum); }
}
void call_PyArray_InitArrFuncs(PyArray_ArrFuncs * funcs) PyTypeObject* getPyArrayType() { return &PyArray_Type; }
{
PyArray_InitArrFuncs(funcs);
}
int call_PyArray_RegisterDataType(PyArray_Descr * dtype) PyArray_Descr* call_PyArray_DescrFromType(int typenum) {
{ return PyArray_DescrFromType(typenum);
return PyArray_RegisterDataType(dtype); }
}
PyArray_Descr * call_PyArray_MinScalarType(PyArrayObject * arr) void call_PyArray_InitArrFuncs(PyArray_ArrFuncs* funcs) {
{ PyArray_InitArrFuncs(funcs);
return PyArray_MinScalarType(arr); }
}
int call_PyArray_RegisterCanCast(PyArray_Descr *descr, int totype, NPY_SCALARKIND scalar) int call_PyArray_RegisterDataType(PyArray_DescrProto* dtype) {
{ return PyArray_RegisterDataType(dtype);
return PyArray_RegisterCanCast(descr,totype,scalar); }
}
int call_PyArray_RegisterCastFunc(PyArray_Descr* descr, int totype, PyArray_VectorUnaryFunc* castfunc) PyArray_Descr* call_PyArray_MinScalarType(PyArrayObject* arr) {
{ return PyArray_MinScalarType(arr);
return PyArray_RegisterCastFunc(descr,totype,castfunc); }
}
#endif int call_PyArray_RegisterCanCast(PyArray_Descr* descr, int totype,
NPY_SCALARKIND scalar) {
return PyArray_RegisterCanCast(descr, totype, scalar);
}
int call_PyArray_RegisterCastFunc(PyArray_Descr* descr, int totype,
PyArray_VectorUnaryFunc* castfunc) {
return PyArray_RegisterCastFunc(descr, totype, castfunc);
} }
#endif
} // namespace eigenpy
///
/// Copyright 2023 CNRS, INRIA
///
#include "eigenpy/optional.hpp"
namespace eigenpy {
void exposeNoneType() {
detail::NoneToPython<boost::none_t>::registration();
#ifdef EIGENPY_WITH_CXX17_SUPPORT
detail::NoneToPython<std::nullopt_t>::registration();
#endif
}
} // namespace eigenpy
/* /*
* Copyright 2014-2019, CNRS * Copyright 2014-2019, CNRS
* Copyright 2018-2019, INRIA * Copyright 2018-2023, INRIA
*/ */
#include "eigenpy/memory.hpp" #include <Eigen/Geometry>
#include "eigenpy/geometry.hpp" #include "eigenpy/geometry.hpp"
#include "eigenpy/quaternion.hpp" #include "eigenpy/quaternion.hpp"
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(Eigen::Quaterniond) namespace eigenpy {
void exposeQuaternion() { expose<Eigen::Quaterniond>(); }
namespace eigenpy } // namespace eigenpy
{
void exposeQuaternion()
{
expose<Eigen::Quaterniond>();
}
} // namespace eigenpy