Skip to content

Commit 5d1662d

Browse files
authored
Merge pull request #374 from pariterre/python_wrapper
Added back compatibility with python 3.10 to 3.12
2 parents 958a633 + c85a75f commit 5d1662d

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

binding/python3/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ if(MSVC)
1414
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}")
1515
endif()
1616

17-
# We need to trick MSVC into keeping the rbdl-casadi as the first import. If we
17+
# We need to trick MSVC (and why not all of them) into keeping the rbdl-casadi as the first import. If we
1818
# just add it, it is pushed at the end because BIORBD will also includes it but
1919
# as an external:import. Added the /../ tricks the parser into not recognizing
2020
# that it is in fact the same directory
2121
set(FORCED_FIRST_INCLUDE_DIRS "")
22-
if(MSVC AND ${MATH_LIBRARY_BACKEND} STREQUAL "Casadi")
22+
if(${MATH_LIBRARY_BACKEND} STREQUAL "Casadi")
2323
set(FORCED_FIRST_INCLUDE_DIRS
2424
"${RBDLCasadi_INCLUDE_DIR}/../rbdl-casadi"
2525
)

binding/python3/wrapper/extended_kalman_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ def reconstruct_frame(self, markers: BiorbdArray):
5353

5454
def reconstruct_frames(
5555
self, all_markers: list[BiorbdArray]
56-
) -> Generator[tuple[BiorbdArray, BiorbdArray, BiorbdArray]]:
56+
) -> Generator[tuple[BiorbdArray, BiorbdArray, BiorbdArray], None, None]:
5757
for markers in all_markers:
5858
yield self.reconstruct_frame(markers)

binding/python3/wrapper/misc.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any
2+
import sys
23

34
import numpy as np
45

@@ -11,12 +12,22 @@
1112

1213
# If we are using the Eigen backend, returns are np.arrays, if we are using CasADi backend, returns are MX
1314
# So declare an "Array" typedef that will be np.array or MX depending on the backend
14-
if currentLinearAlgebraBackend() == BIORBD_CASADI:
15-
type BiorbdArray = MX
16-
type BiorbdScalar = MX
15+
if sys.version_info >= (3, 12):
16+
if currentLinearAlgebraBackend() == BIORBD_CASADI:
17+
type BiorbdArray = MX
18+
type BiorbdScalar = MX
19+
else:
20+
type BiorbdArray = np.ndarray
21+
type BiorbdScalar = float
1722
else:
18-
type BiorbdArray = np.ndarray
19-
type BiorbdScalar = float
23+
from typing import TypeAlias
24+
25+
if currentLinearAlgebraBackend() == BIORBD_CASADI:
26+
BiorbdArray: TypeAlias = MX
27+
BiorbdScalar: TypeAlias = MX
28+
else:
29+
BiorbdArray: TypeAlias = np.ndarray
30+
BiorbdScalar: TypeAlias = float
2031

2132

2233
# Declare a method that converts output to BiorbdArray

0 commit comments

Comments
 (0)