Skip to content

Commit 9a0970d

Browse files
authored
Merge pull request #455 from jorisv/topic/fix_int_conversion
Fix int conversion
2 parents f1613f1 + 670a147 commit 9a0970d

37 files changed

+849
-237
lines changed

.github/workflows/windows-conda.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
if errorlevel 1 exit 1
5959
6060
:: Build and Install
61-
cmake --build . --config Release --target install
61+
cmake --build . -j3 --config Release --target install
6262
if errorlevel 1 exit 1
6363
6464
:: Testing

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99
### Added
1010
- Allow use of installed JRL-cmakemodule ([#446](https://github.com/stack-of-tasks/eigenpy/pull/446)
1111
- Support of Numpy 2.0.0b1 ([#448](https://github.com/stack-of-tasks/eigenpy/pull/448))
12+
- Support new primitive type (char, int8_t, uint8_t, int16_t, uint16_t, uint32_t, uint64_t) ([#455]()https://github.com/stack-of-tasks/eigenpy/pull/455)
13+
- Support conversion between signed <-> unsigned integers ([#455](https://github.com/stack-of-tasks/eigenpy/pull/455))
14+
- Support conversion between complex numbers ([#455](https://github.com/stack-of-tasks/eigenpy/pull/455))
1215

1316
### Fixed
1417
- Fix unit test build in C++11 ([#442](https://github.com/stack-of-tasks/eigenpy/pull/442))
1518
- Fix unit test function signature [#443](https://github.com/stack-of-tasks/eigenpy/pull/443))
1619
- Fix CMake export ([#446](https://github.com/stack-of-tasks/eigenpy/pull/446)
20+
- Fix `int` management on Windows ([#455](https://github.com/stack-of-tasks/eigenpy/pull/455))
21+
- Fix `long long` management on Mac ([#455](https://github.com/stack-of-tasks/eigenpy/pull/455))
22+
23+
### Removed
24+
- Remove casting when converting from Eigen scalar to Numpy scalar.
25+
This should not remove any functionality since Numpy array are created from the Eigen scalar type
26+
([#455](https://github.com/stack-of-tasks/eigenpy/pull/455))
1727

1828
## [3.4.0] - 2024-02-26
1929

CMakeLists.txt

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ set(CMAKE_VERBOSE_MAKEFILE True)
5454
option(INSTALL_DOCUMENTATION "Generate and install the documentation" OFF)
5555
option(SUFFIX_SO_VERSION "Suffix library name with its version" OFF)
5656
option(BUILD_TESTING_SCIPY
57-
"Build the SciPy tests (scipy should be installed on the machine)" OFF)
57+
"Build the SciPy tests (scipy should be installed on the machine)" ON)
5858

5959
include("${JRL_CMAKE_MODULES}/base.cmake")
6060
compute_project_args(PROJECT_ARGS LANGUAGES CXX)
@@ -267,7 +267,16 @@ set(${PROJECT_NAME}_SOLVERS_SOURCES src/solvers/preconditioners.cpp
267267
src/solvers/solvers.cpp)
268268

269269
set(${PROJECT_NAME}_DECOMPOSITIONS_SOURCES
270-
src/decompositions/decompositions.cpp)
270+
src/decompositions/decompositions.cpp
271+
src/decompositions/eigen-solver.cpp
272+
src/decompositions/llt-solver.cpp
273+
src/decompositions/ldlt-solver.cpp
274+
src/decompositions/minres-solver.cpp
275+
src/decompositions/eigen-solver.cpp
276+
src/decompositions/self-adjoint-eigen-solver.cpp
277+
src/decompositions/permutation-matrix.cpp
278+
src/decompositions/simplicial-llt-solver.cpp
279+
src/decompositions/simplicial-ldlt-solver.cpp)
271280

272281
if(BUILD_WITH_CHOLMOD_SUPPORT)
273282
list(APPEND ${PROJECT_NAME}_DECOMPOSITIONS_SOURCES
@@ -294,8 +303,21 @@ set(${PROJECT_NAME}_SOURCES
294303
src/matrix-long-double.cpp
295304
src/matrix-complex-long-double.cpp
296305
src/matrix-bool.cpp
297-
src/matrix-int.cpp
298-
src/matrix-long.cpp
306+
src/matrix-char.cpp
307+
src/matrix-int8.cpp
308+
src/matrix-uint8.cpp
309+
src/matrix-int16.cpp
310+
src/matrix-uint16.cpp
311+
src/matrix-int32.cpp
312+
src/matrix-uint32.cpp
313+
src/matrix-windows-long.cpp
314+
src/matrix-windows-ulong.cpp
315+
src/matrix-mac-long.cpp
316+
src/matrix-mac-ulong.cpp
317+
src/matrix-int64.cpp
318+
src/matrix-uint64.cpp
319+
src/matrix-linux-long-long.cpp
320+
src/matrix-linux-ulong-long.cpp
299321
src/angle-axis.cpp
300322
src/quaternion.cpp
301323
src/geometry-conversion.cpp

include/eigenpy/eigen-allocator.hpp

Lines changed: 95 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,91 @@ struct cast<Scalar, NewScalar, EigenBase, false> {
198198
mat, NumpyMap<MatType, NewScalar>::map( \
199199
pyArray, details::check_swap(pyArray, mat)))
200200

201+
// Define specific cast for Windows and Mac
202+
#if defined _WIN32 || defined __CYGWIN__
203+
// Manage NPY_INT on Windows (NPY_INT32 is NPY_LONG).
204+
// See https://github.com/stack-of-tasks/eigenpy/pull/455
205+
#define EIGENPY_CAST_FROM_NUMPY_TO_EIGEN_SWITCH_OS_SPECIFIC( \
206+
MatType, Scalar, pyArray, mat, CAST_MACRO) \
207+
case NPY_INT: \
208+
CAST_MACRO(MatType, int32_t, Scalar, pyArray, mat); \
209+
break; \
210+
case NPY_UINT: \
211+
CAST_MACRO(MatType, uint32_t, Scalar, pyArray, mat); \
212+
break;
213+
#elif defined __APPLE__
214+
// Manage NPY_LONGLONG on Mac (NPY_INT64 is NPY_LONG).
215+
// long long and long are both the same type
216+
// but NPY_LONGLONG and NPY_LONG are different dtype.
217+
// See https://github.com/stack-of-tasks/eigenpy/pull/455
218+
#define EIGENPY_CAST_FROM_NUMPY_TO_EIGEN_SWITCH_OS_SPECIFIC( \
219+
MatType, Scalar, pyArray, mat, CAST_MACRO) \
220+
case NPY_LONGLONG: \
221+
CAST_MACRO(MatType, int64_t, Scalar, pyArray, mat); \
222+
break; \
223+
case NPY_ULONGLONG: \
224+
CAST_MACRO(MatType, uint64_t, Scalar, pyArray, mat); \
225+
break;
226+
#else
227+
#define EIGENPY_CAST_FROM_NUMPY_TO_EIGEN_SWITCH_OS_SPECIFIC( \
228+
MatType, Scalar, pyArray, mat, CAST_MACRO)
229+
#endif
230+
231+
/// Define casting between Numpy matrix type to Eigen type.
232+
#define EIGENPY_CAST_FROM_NUMPY_TO_EIGEN_SWITCH( \
233+
pyArray_type_code, MatType, Scalar, pyArray, mat, CAST_MACRO) \
234+
switch (pyArray_type_code) { \
235+
case NPY_BOOL: \
236+
CAST_MACRO(MatType, bool, Scalar, pyArray, mat); \
237+
break; \
238+
case NPY_INT8: \
239+
CAST_MACRO(MatType, int8_t, Scalar, pyArray, mat); \
240+
break; \
241+
case NPY_INT16: \
242+
CAST_MACRO(MatType, int16_t, Scalar, pyArray, mat); \
243+
break; \
244+
case NPY_INT32: \
245+
CAST_MACRO(MatType, int32_t, Scalar, pyArray, mat); \
246+
break; \
247+
case NPY_INT64: \
248+
CAST_MACRO(MatType, int64_t, Scalar, pyArray, mat); \
249+
break; \
250+
case NPY_UINT8: \
251+
CAST_MACRO(MatType, uint8_t, Scalar, pyArray, mat); \
252+
break; \
253+
case NPY_UINT16: \
254+
CAST_MACRO(MatType, uint16_t, Scalar, pyArray, mat); \
255+
break; \
256+
case NPY_UINT32: \
257+
CAST_MACRO(MatType, uint32_t, Scalar, pyArray, mat); \
258+
break; \
259+
case NPY_UINT64: \
260+
CAST_MACRO(MatType, uint64_t, Scalar, pyArray, mat); \
261+
break; \
262+
case NPY_FLOAT: \
263+
CAST_MACRO(MatType, float, Scalar, pyArray, mat); \
264+
break; \
265+
case NPY_CFLOAT: \
266+
CAST_MACRO(MatType, std::complex<float>, Scalar, pyArray, mat); \
267+
break; \
268+
case NPY_DOUBLE: \
269+
CAST_MACRO(MatType, double, Scalar, pyArray, mat); \
270+
break; \
271+
case NPY_CDOUBLE: \
272+
CAST_MACRO(MatType, std::complex<double>, Scalar, pyArray, mat); \
273+
break; \
274+
case NPY_LONGDOUBLE: \
275+
CAST_MACRO(MatType, long double, Scalar, pyArray, mat); \
276+
break; \
277+
case NPY_CLONGDOUBLE: \
278+
CAST_MACRO(MatType, std::complex<long double>, Scalar, pyArray, mat); \
279+
break; \
280+
EIGENPY_CAST_FROM_NUMPY_TO_EIGEN_SWITCH_OS_SPECIFIC( \
281+
MatType, Scalar, pyArray, mat, CAST_MACRO) \
282+
default: \
283+
throw Exception("You asked for a conversion which is not implemented."); \
284+
}
285+
201286
template <typename EigenType>
202287
struct EigenAllocator;
203288

@@ -247,43 +332,9 @@ struct eigen_allocator_impl_matrix {
247332
pyArray, details::check_swap(pyArray, mat)); // avoid useless cast
248333
return;
249334
}
250-
251-
switch (pyArray_type_code) {
252-
case NPY_INT:
253-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX(MatType, int, Scalar, pyArray,
254-
mat);
255-
break;
256-
case NPY_LONG:
257-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX(MatType, long, Scalar,
258-
pyArray, mat);
259-
break;
260-
case NPY_FLOAT:
261-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX(MatType, float, Scalar,
262-
pyArray, mat);
263-
break;
264-
case NPY_CFLOAT:
265-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX(MatType, std::complex<float>,
266-
Scalar, pyArray, mat);
267-
break;
268-
case NPY_DOUBLE:
269-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX(MatType, double, Scalar,
270-
pyArray, mat);
271-
break;
272-
case NPY_CDOUBLE:
273-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX(MatType, std::complex<double>,
274-
Scalar, pyArray, mat);
275-
break;
276-
case NPY_LONGDOUBLE:
277-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX(MatType, long double, Scalar,
278-
pyArray, mat);
279-
break;
280-
case NPY_CLONGDOUBLE:
281-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX(
282-
MatType, std::complex<long double>, Scalar, pyArray, mat);
283-
break;
284-
default:
285-
throw Exception("You asked for a conversion which is not implemented.");
286-
}
335+
EIGENPY_CAST_FROM_NUMPY_TO_EIGEN_SWITCH(
336+
pyArray_type_code, MatType, Scalar, pyArray, mat,
337+
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX);
287338
}
288339

289340
/// \brief Copy mat into the Python array using Eigen::Map
@@ -301,43 +352,8 @@ struct eigen_allocator_impl_matrix {
301352
details::check_swap(pyArray, mat)) = mat;
302353
return;
303354
}
304-
305-
switch (pyArray_type_code) {
306-
case NPY_INT:
307-
EIGENPY_CAST_FROM_EIGEN_MATRIX_TO_PYARRAY(MatType, Scalar, int, mat,
308-
pyArray);
309-
break;
310-
case NPY_LONG:
311-
EIGENPY_CAST_FROM_EIGEN_MATRIX_TO_PYARRAY(MatType, Scalar, long, mat,
312-
pyArray);
313-
break;
314-
case NPY_FLOAT:
315-
EIGENPY_CAST_FROM_EIGEN_MATRIX_TO_PYARRAY(MatType, Scalar, float, mat,
316-
pyArray);
317-
break;
318-
case NPY_CFLOAT:
319-
EIGENPY_CAST_FROM_EIGEN_MATRIX_TO_PYARRAY(
320-
MatType, Scalar, std::complex<float>, mat, pyArray);
321-
break;
322-
case NPY_DOUBLE:
323-
EIGENPY_CAST_FROM_EIGEN_MATRIX_TO_PYARRAY(MatType, Scalar, double, mat,
324-
pyArray);
325-
break;
326-
case NPY_CDOUBLE:
327-
EIGENPY_CAST_FROM_EIGEN_MATRIX_TO_PYARRAY(
328-
MatType, Scalar, std::complex<double>, mat, pyArray);
329-
break;
330-
case NPY_LONGDOUBLE:
331-
EIGENPY_CAST_FROM_EIGEN_MATRIX_TO_PYARRAY(MatType, Scalar, long double,
332-
mat, pyArray);
333-
break;
334-
case NPY_CLONGDOUBLE:
335-
EIGENPY_CAST_FROM_EIGEN_MATRIX_TO_PYARRAY(
336-
MatType, Scalar, std::complex<long double>, mat, pyArray);
337-
break;
338-
default:
339-
throw Exception("You asked for a conversion which is not implemented.");
340-
}
355+
throw Exception(
356+
"Scalar conversion from Eigen to Numpy is not implemented.");
341357
}
342358
};
343359

@@ -394,42 +410,9 @@ struct eigen_allocator_impl_tensor {
394410
return;
395411
}
396412

397-
switch (pyArray_type_code) {
398-
case NPY_INT:
399-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_TENSOR(TensorType, int, Scalar,
400-
pyArray, tensor);
401-
break;
402-
case NPY_LONG:
403-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_TENSOR(TensorType, long, Scalar,
404-
pyArray, tensor);
405-
break;
406-
case NPY_FLOAT:
407-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_TENSOR(TensorType, float, Scalar,
408-
pyArray, tensor);
409-
break;
410-
case NPY_CFLOAT:
411-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_TENSOR(
412-
TensorType, std::complex<float>, Scalar, pyArray, tensor);
413-
break;
414-
case NPY_DOUBLE:
415-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_TENSOR(TensorType, double, Scalar,
416-
pyArray, tensor);
417-
break;
418-
case NPY_CDOUBLE:
419-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_TENSOR(
420-
TensorType, std::complex<double>, Scalar, pyArray, tensor);
421-
break;
422-
case NPY_LONGDOUBLE:
423-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_TENSOR(TensorType, long double,
424-
Scalar, pyArray, tensor);
425-
break;
426-
case NPY_CLONGDOUBLE:
427-
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_TENSOR(
428-
TensorType, std::complex<long double>, Scalar, pyArray, tensor);
429-
break;
430-
default:
431-
throw Exception("You asked for a conversion which is not implemented.");
432-
}
413+
EIGENPY_CAST_FROM_NUMPY_TO_EIGEN_SWITCH(
414+
pyArray_type_code, TensorType, Scalar, pyArray, tensor,
415+
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_TENSOR);
433416
}
434417

435418
#define EIGENPY_CAST_FROM_EIGEN_TENSOR_TO_PYARRAY(TensorType, Scalar, \
@@ -454,42 +437,8 @@ struct eigen_allocator_impl_tensor {
454437
return;
455438
}
456439

457-
switch (pyArray_type_code) {
458-
case NPY_INT:
459-
EIGENPY_CAST_FROM_EIGEN_TENSOR_TO_PYARRAY(TensorType, Scalar, int,
460-
tensor, pyArray);
461-
break;
462-
case NPY_LONG:
463-
EIGENPY_CAST_FROM_EIGEN_TENSOR_TO_PYARRAY(TensorType, Scalar, long,
464-
tensor, pyArray);
465-
break;
466-
case NPY_FLOAT:
467-
EIGENPY_CAST_FROM_EIGEN_TENSOR_TO_PYARRAY(TensorType, Scalar, float,
468-
tensor, pyArray);
469-
break;
470-
case NPY_CFLOAT:
471-
EIGENPY_CAST_FROM_EIGEN_TENSOR_TO_PYARRAY(
472-
TensorType, Scalar, std::complex<float>, tensor, pyArray);
473-
break;
474-
case NPY_DOUBLE:
475-
EIGENPY_CAST_FROM_EIGEN_TENSOR_TO_PYARRAY(TensorType, Scalar, double,
476-
tensor, pyArray);
477-
break;
478-
case NPY_CDOUBLE:
479-
EIGENPY_CAST_FROM_EIGEN_TENSOR_TO_PYARRAY(
480-
TensorType, Scalar, std::complex<double>, tensor, pyArray);
481-
break;
482-
case NPY_LONGDOUBLE:
483-
EIGENPY_CAST_FROM_EIGEN_TENSOR_TO_PYARRAY(TensorType, Scalar,
484-
long double, tensor, pyArray);
485-
break;
486-
case NPY_CLONGDOUBLE:
487-
EIGENPY_CAST_FROM_EIGEN_TENSOR_TO_PYARRAY(
488-
TensorType, Scalar, std::complex<long double>, tensor, pyArray);
489-
break;
490-
default:
491-
throw Exception("You asked for a conversion which is not implemented.");
492-
}
440+
throw Exception(
441+
"Scalar conversion from Eigen to Numpy is not implemented.");
493442
}
494443
};
495444
#endif

0 commit comments

Comments
 (0)