@@ -132,34 +132,46 @@ struct SpecialMethods<T, NPY_USERDEF> {
132
132
eigenpy::Exception (" Cannot retrieve the type stored in the array." );
133
133
return -1 ;
134
134
}
135
+
135
136
PyArrayObject* py_array = static_cast <PyArrayObject*>(array);
136
137
PyArray_Descr* descr = PyArray_DTYPE (py_array);
137
138
PyTypeObject* array_scalar_type = descr->typeobj ;
138
139
PyTypeObject* src_obj_type = Py_TYPE (src_obj);
139
140
141
+ T& dest = *static_cast <T*>(dest_ptr);
140
142
if (array_scalar_type != src_obj_type) {
141
- std::stringstream ss;
142
- ss << " The input type is of wrong type. " ;
143
- ss << " The expected type is " << bp::type_info (typeid (T)).name ()
144
- << std::endl;
145
- eigenpy::Exception (ss.str ());
146
- return -1 ;
147
- }
143
+ long long src_value = PyLong_AsLongLong (src_obj);
144
+ if (src_value == -1 && PyErr_Occurred ()) {
145
+ std::stringstream ss;
146
+ ss << " The input type is of wrong type. " ;
147
+ ss << " The expected type is " << bp::type_info (typeid (T)).name ()
148
+ << std::endl;
149
+ eigenpy::Exception (ss.str ());
150
+ return -1 ;
151
+ }
152
+
153
+ dest = T (src_value);
148
154
149
- bp::extract<T&> extract_src_obj (src_obj);
150
- if (!extract_src_obj.check ()) {
151
- std::stringstream ss;
152
- ss << " The input type is of wrong type. " ;
153
- ss << " The expected type is " << bp::type_info (typeid (T)).name ()
154
- << std::endl;
155
- eigenpy::Exception (ss.str ());
156
- return -1 ;
155
+ } else {
156
+ bp::extract<T&> extract_src_obj (src_obj);
157
+ if (!extract_src_obj.check ()) {
158
+ std::cout << " if (!extract_src_obj.check())" << std::endl;
159
+ std::stringstream ss;
160
+ ss << " The input type is of wrong type. " ;
161
+ ss << " The expected type is " << bp::type_info (typeid (T)).name ()
162
+ << std::endl;
163
+ eigenpy::Exception (ss.str ());
164
+ return -1 ;
165
+ }
166
+
167
+ const T& src = extract_src_obj ();
168
+ const T& src = extract_src_obj ();
169
+ T& dest = *static_cast <T*>(dest_ptr);
170
+ const T& src = extract_src_obj ();
171
+ T& dest = *static_cast <T*>(dest_ptr);
172
+ dest = src;
157
173
}
158
174
159
- const T& src = extract_src_obj ();
160
- T& dest = *static_cast <T*>(dest_ptr);
161
- dest = src;
162
-
163
175
return 0 ;
164
176
}
165
177
0 commit comments