diff --git a/include/eigenpy/eigen-allocator.hpp b/include/eigenpy/eigen-allocator.hpp
index b4397d90f96fa30ea9d852f4daf543609110bb08..cdcec2c01248e48952f9d672572d12720a370dfb 100644
--- a/include/eigenpy/eigen-allocator.hpp
+++ b/include/eigenpy/eigen-allocator.hpp
@@ -342,11 +342,8 @@ struct eigen_allocator_impl_tensor {
       tensor)
 
   /// \brief Copy Python array into the input matrix mat.
-  template <typename TensorDerived, int AccessLevel>
-  static void copy(
-      const Eigen::TensorBase<TensorDerived, AccessLevel> &tensor_) {
-    TensorDerived &tensor = const_cast<TensorDerived &>(
-        static_cast<const TensorDerived &>(tensor_));
+  template <typename TensorDerived>
+  static void copy(PyArrayObject *pyArray, TensorDerived &tensor) {
     const int pyArray_type_code = EIGENPY_GET_PY_ARRAY_TYPE(pyArray);
     const int Scalar_type_code = Register::getTypeCode<Scalar>();
 
diff --git a/include/eigenpy/numpy-allocator.hpp b/include/eigenpy/numpy-allocator.hpp
index 026f65bc0f72f0bf5a15fab5759b5b467ca8b72b..61653940ac6104a02bda828eeaef530d32574c49 100644
--- a/include/eigenpy/numpy-allocator.hpp
+++ b/include/eigenpy/numpy-allocator.hpp
@@ -78,8 +78,8 @@ struct numpy_allocator_impl<const TensorType,
 template <typename TensorType>
 struct numpy_allocator_impl_tensor {
   template <typename TensorDerived>
-  static PyArrayObject *allocate(const Eigen::TensorBase<TensorDerived> &tensor,
-                                 npy_intp nd, npy_intp *shape) {
+  static PyArrayObject *allocate(const TensorDerived &tensor, npy_intp nd,
+                                 npy_intp *shape) {
     const int code = Register::getTypeCode<typename TensorDerived::Scalar>();
     PyArrayObject *pyArray = (PyArrayObject *)call_PyArray_SimpleNew(
         static_cast<int>(nd), shape, code);
@@ -250,10 +250,7 @@ struct numpy_allocator_impl_tensor<Eigen::TensorRef<TensorType> > {
 
       return pyArray;
     } else {
-      return NumpyAllocator<TensorType>::allocate(
-          static_cast<Eigen::TensorBase<Eigen::TensorRef<TensorType> > &>(
-              tensor),
-          nd, shape);
+      return NumpyAllocator<TensorType>::allocate(tensor, nd, shape);
     }
   }
 };
@@ -281,11 +278,7 @@ struct numpy_allocator_impl_tensor<const Eigen::TensorRef<const TensorType> > {
 
       return pyArray;
     } else {
-      return NumpyAllocator<TensorType>::allocate(
-          static_cast<
-              const Eigen::TensorBase<Eigen::TensorRef<const TensorType> > &>(
-              tensor),
-          nd, shape);
+      return NumpyAllocator<TensorType>::allocate(tensor, nd, shape);
     }
   }
 };