Unverified Commit d4c398a8 authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub
Browse files

Merge pull request #66 from jcarpent/devel

core: make np_type static thhrough a Singleton
parents aacf9982 070d223d
......@@ -89,18 +89,19 @@ namespace eigenpy
static void switchToNumpyArray()
{
getInstance().CurrentNumpyType = getInstance().NumpyArrayObject;
getInstance().np_type = ARRAY_TYPE;
getType() = ARRAY_TYPE;
}
static void switchToNumpyMatrix()
{
getInstance().CurrentNumpyType = getInstance().NumpyMatrixObject;
getInstance().np_type = MATRIX_TYPE;
getType() = MATRIX_TYPE;
}
static NP_TYPE getType()
static NP_TYPE & getType()
{
return getInstance().np_type;
static NP_TYPE np_type;
return np_type;
}
protected:
......@@ -121,6 +122,7 @@ namespace eigenpy
//NumpyAsMatrixType = reinterpret_cast<PyTypeObject*>(NumpyAsMatrixObject.ptr());
CurrentNumpyType = NumpyMatrixObject; // default conversion
getType() = MATRIX_TYPE;
}
bp::object CurrentNumpyType;
......@@ -131,11 +133,8 @@ namespace eigenpy
//bp::object NumpyAsMatrixObject; PyTypeObject * NumpyAsMatrixType;
bp::object NumpyArrayObject; PyTypeObject * NumpyArrayType;
static NP_TYPE np_type;
};
NP_TYPE NumpyType::np_type = MATRIX_TYPE;
template<typename MatType>
struct EigenObjectAllocator
{
......
......@@ -36,3 +36,4 @@ ENDIF()
ADD_PYTHON_UNIT_TEST("py-matrix" "unittest/python/test_matrix.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-geometry" "unittest/python/test_geometry.py" "unittest")
ADD_PYTHON_UNIT_TEST("py-switch" "unittest/python/test_switch.py" "python/eigenpy")
ADD_PYTHON_UNIT_TEST("py-dimensions" "unittest/python/test_dimensions.py" "python/eigenpy")
from __future__ import print_function
import eigenpy
import numpy as np
quat = eigenpy.Quaternion()
# By default, we convert as numpy.matrix
coeffs_vector = quat.coeffs()
assert len(coeffs_vector.shape) == 2
# Switch to numpy.array
eigenpy.switchToNumpyArray()
coeffs_vector = quat.coeffs()
assert len(coeffs_vector.shape) == 1
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment