11//
2- // Copyright (c) 2020-2021 INRIA
2+ // Copyright (c) 2020-2022 INRIA
33//
44
55#ifndef __eigenpy_user_type_hpp__
@@ -19,14 +19,14 @@ namespace eigenpy
1919 {
2020 static To run (const From & from)
2121 {
22- return (To) from;
22+ return static_cast <To>( from) ;
2323 }
24-
24+
2525 };
2626
2727 namespace internal
2828 {
29-
29+
3030 template <typename From, typename To>
3131 static void cast (void * from_, void * to_, npy_intp n, void * /* fromarr*/ , void * /* toarr*/ )
3232 {
@@ -38,7 +38,7 @@ namespace eigenpy
3838 to[i] = eigenpy::cast<From,To>::run (from[i]);
3939 }
4040 }
41-
41+
4242 template <typename T, int type_code = NumpyEquivalentType<T>::type_code>
4343 struct SpecialMethods
4444 {
@@ -54,7 +54,7 @@ namespace eigenpy
5454 inline static int fillwithscalar (void * buffer_, npy_intp length,
5555 void * value, void * arr);
5656 };
57-
57+
5858 template <typename T>
5959 struct OffsetOf
6060 {
@@ -63,10 +63,10 @@ namespace eigenpy
6363 char c;
6464 T v;
6565 };
66-
66+
6767 enum { value = offsetof (Data, v) };
6868 };
69-
69+
7070 template <typename T>
7171 struct SpecialMethods <T,NPY_USERDEF>
7272 {
@@ -79,7 +79,7 @@ namespace eigenpy
7979 T & t2 = *static_cast <T*>(src);
8080 t1 = t2;
8181 }
82-
82+
8383 if (swap)
8484 {
8585 T & t1 = *static_cast <T*>(dst);
@@ -112,14 +112,14 @@ namespace eigenpy
112112 // / pointed to by data. This function deals with “misbehaved” arrays.
113113 // / If successful, a zero is returned, otherwise, a negative one is returned
114114 // / (and a Python error set).
115-
115+
116116 // / \param[in] src_obj Pointer to the location of the python object
117117 // / \param[in] dest_ptr Pointer to the location in the array where the source object should be saved.
118118 // / \param[in] array Pointer to the location of the array
119119 // /
120120 // / \returns int Success(0) or Failure(-1)
121121 // /
122-
122+
123123 inline static int setitem (PyObject * src_obj, void * dest_ptr, void * array)
124124 {
125125// std::cout << "setitem" << std::endl;
@@ -132,7 +132,7 @@ namespace eigenpy
132132 PyArray_Descr * descr = PyArray_DTYPE (py_array);
133133 PyTypeObject * array_scalar_type = descr->typeobj ;
134134 PyTypeObject * src_obj_type = Py_TYPE (src_obj);
135-
135+
136136 if (array_scalar_type != src_obj_type)
137137 {
138138 std::stringstream ss;
@@ -141,7 +141,7 @@ namespace eigenpy
141141 eigenpy::Exception (ss.str ());
142142 return -1 ;
143143 }
144-
144+
145145 bp::extract<T&> extract_src_obj (src_obj);
146146 if (!extract_src_obj.check ())
147147 {
@@ -151,33 +151,33 @@ namespace eigenpy
151151 eigenpy::Exception (ss.str ());
152152 return -1 ;
153153 }
154-
154+
155155 const T & src = extract_src_obj ();
156156 T & dest = *static_cast <T*>(dest_ptr);
157157 dest = src;
158158
159159 return 0 ;
160160 }
161-
161+
162162 inline static void copyswapn (void * dst, long dstride, void * src, long sstride,
163163 long n, int swap, void * array)
164164 {
165165// std::cout << "copyswapn" << std::endl;
166-
166+
167167 char *dstptr = static_cast <char *>(dst);
168168 char *srcptr = static_cast <char *>(src);
169-
169+
170170 PyArrayObject * py_array = static_cast <PyArrayObject *>(array);
171171 PyArray_CopySwapFunc * copyswap = PyArray_DESCR (py_array)->f ->copyswap ;
172-
172+
173173 for (npy_intp i = 0 ; i < n; i++)
174174 {
175175 copyswap (dstptr, srcptr, swap, array);
176176 dstptr += dstride;
177177 srcptr += sstride;
178178 }
179179 }
180-
180+
181181 inline static npy_bool nonzero (void * ip, void * array)
182182 {
183183// std::cout << "nonzero" << std::endl;
@@ -196,7 +196,7 @@ namespace eigenpy
196196 return (npy_bool)(tmp_value != ZeroValue);
197197 }
198198 }
199-
199+
200200 inline static void dotfunc (void * ip0_, npy_intp is0, void * ip1_, npy_intp is1,
201201 void * op, npy_intp n, void * /* arr*/ )
202202 {
@@ -208,11 +208,11 @@ namespace eigenpy
208208 ConstMapType
209209 v0 (static_cast <T*>(ip0_),n,InputStride (is0/sizeof (T))),
210210 v1 (static_cast <T*>(ip1_),n,InputStride (is1/sizeof (T)));
211-
211+
212212 *static_cast <T*>(op) = v0.dot (v1);
213213 }
214-
215-
214+
215+
216216 inline static int fillwithscalar (void * buffer_, npy_intp length,
217217 void * value, void * /* arr*/ )
218218 {
@@ -225,8 +225,8 @@ namespace eigenpy
225225 }
226226 return 0 ;
227227 }
228-
229-
228+
229+
230230 static int fill (void * data_, npy_intp length, void * /* arr*/ )
231231 {
232232// std::cout << "fillwithscalar" << std::endl;
@@ -240,10 +240,10 @@ namespace eigenpy
240240 }
241241 return 0 ;
242242 }
243-
243+
244244
245245 }; // struct SpecialMethods<T,NPY_USERDEF>
246-
246+
247247 } // namespace internal
248248
249249
@@ -252,17 +252,17 @@ namespace eigenpy
252252 {
253253 PyArray_Descr* from_array_descr = Register::getPyArrayDescr<From>();
254254// int from_typenum = Register::getTypeCode<From>();
255-
255+
256256// PyTypeObject * to_py_type = Register::getPyType<To>();
257257 int to_typenum = Register::getTypeCode<To>();
258258 assert (to_typenum >= 0 && " to_typenum is not valid" );
259259 assert (from_array_descr != NULL && " from_array_descr is not valid" );
260-
260+
261261 std::cout << " From: " << bp::type_info (typeid (From)).name () << " " << Register::getTypeCode<From>()
262262 << " to: " << bp::type_info (typeid (To)).name () << " " << Register::getTypeCode<To>()
263263 << " \n to_typenum: " << to_typenum
264264 << std::endl;
265-
265+
266266 if (call_PyArray_RegisterCastFunc (from_array_descr,
267267 to_typenum,
268268 static_cast <PyArray_VectorUnaryFunc *>(&eigenpy::internal::cast<From,To>)) < 0 )
@@ -277,7 +277,7 @@ namespace eigenpy
277277 eigenpy::Exception (ss.str ());
278278 return false ;
279279 }
280-
280+
281281 if (safe && call_PyArray_RegisterCanCast (from_array_descr,
282282 to_typenum,
283283 NPY_NOSCALAR) < 0 )
@@ -292,7 +292,7 @@ namespace eigenpy
292292 eigenpy::Exception (ss.str ());
293293 return false ;
294294 }
295-
295+
296296 return true ;
297297 }
298298
@@ -307,34 +307,34 @@ namespace eigenpy
307307 bp::type_info type = bp::type_id<T>();
308308 const bp::converter::registration* registration =
309309 bp::converter::registry::query (type);
310-
310+
311311 // If the class is not registered, return None.
312312 if (!registration) {
313313 // std::cerr<<"Class Not Registered. Returning Empty."<<std::endl;
314314 return bp::object ();
315315 }
316-
316+
317317 bp::handle<PyTypeObject> handle (bp::borrowed (registration->get_class_object ()));
318318 return bp::object (handle);
319319 }
320-
320+
321321 template <typename Scalar>
322322 int registerNewType (PyTypeObject * py_type_ptr = NULL )
323323 {
324324 // Check whether the type is a Numpy native type.
325325 // In this case, the registration is not required.
326326 if (isNumpyNativeType<Scalar>())
327327 return NumpyEquivalentType<Scalar>::type_code;
328-
328+
329329 // Retrieve the registered type for the current Scalar
330330 if (py_type_ptr == NULL )
331331 { // retrive the type from Boost.Python
332332 py_type_ptr = Register::getPyType<Scalar>();
333333 }
334-
334+
335335 if (Register::isRegistered (py_type_ptr))
336336 return Register::getTypeCode (py_type_ptr); // the type is already registered
337-
337+
338338 PyArray_GetItemFunc * getitem = &internal::SpecialMethods<Scalar>::getitem;
339339 PyArray_SetItemFunc * setitem = &internal::SpecialMethods<Scalar>::setitem;
340340 PyArray_NonzeroFunc * nonzero = &internal::SpecialMethods<Scalar>::nonzero;
@@ -343,7 +343,7 @@ namespace eigenpy
343343 PyArray_DotFunc * dotfunc = &internal::SpecialMethods<Scalar>::dotfunc;
344344 PyArray_FillFunc * fill = &internal::SpecialMethods<Scalar>::fill;
345345 PyArray_FillWithScalarFunc * fillwithscalar = &internal::SpecialMethods<Scalar>::fillwithscalar;
346-
346+
347347 int code = Register::registerNewType (py_type_ptr,
348348 &typeid (Scalar),
349349 sizeof (Scalar),
@@ -353,13 +353,13 @@ namespace eigenpy
353353 dotfunc,
354354 fill,
355355 fillwithscalar);
356-
356+
357357 call_PyArray_RegisterCanCast (call_PyArray_DescrFromType (NPY_OBJECT),
358358 code, NPY_NOSCALAR);
359-
359+
360360 return code;
361361 }
362-
362+
363363} // namespace eigenpy
364364
365365#endif // __eigenpy_user_type_hpp__
0 commit comments