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 259 additions and 160 deletions
...@@ -4,11 +4,9 @@ ...@@ -4,11 +4,9 @@
#include "eigenpy/eigenpy.hpp" #include "eigenpy/eigenpy.hpp"
namespace eigenpy namespace eigenpy {
{ void exposeMatrixDouble() {
void exposeMatrixDouble() exposeType<double>();
{ exposeType<double, Eigen::RowMajor>();
exposeType<double>();
exposeType<double,Eigen::RowMajor>();
}
} }
} // namespace eigenpy
...@@ -4,11 +4,9 @@ ...@@ -4,11 +4,9 @@
#include "eigenpy/eigenpy.hpp" #include "eigenpy/eigenpy.hpp"
namespace eigenpy namespace eigenpy {
{ void exposeMatrixFloat() {
void exposeMatrixFloat() exposeType<float>();
{ exposeType<float, Eigen::RowMajor>();
exposeType<float>();
exposeType<float,Eigen::RowMajor>();
}
} }
} // namespace eigenpy
/*
* Copyright 2020 INRIA
*/
#include "eigenpy/eigenpy.hpp"
namespace eigenpy
{
void exposeMatrixInt()
{
exposeType<int>();
exposeType<int,Eigen::RowMajor>();
}
}
/*
* 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