Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/objutils@1.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ repos:
args: ["--line-length=132"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.1
rev: v0.16.2
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix"]
Expand Down
8 changes: 2 additions & 6 deletions objutils/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,8 +1326,7 @@ def write_asam_ndarray(
# axis breakpoint. This is identical to C-order (ROW_DIR) for a 2-D array.
if typed_array.ndim != 2:
raise ValueError(
"ALTERNATE_CURVES requires a 2-D array with shape "
"(num_axis_points, num_curves) in numpy convention"
"ALTERNATE_CURVES requires a 2-D array with shape " "(num_axis_points, num_curves) in numpy convention"
)
raw_data = typed_array.tobytes() # C-order = AoS
permuted = self._permute_asam_buffer(raw_data, internal_dtype, asam_byte_order)
Expand Down Expand Up @@ -1422,10 +1421,7 @@ def read_asam_ndarray(
# --- ALTERNATE_CURVES --------------------------------------------------
if index_mode == "ALTERNATE_CURVES":
if numpy_shape is None or len(numpy_shape) != 2:
raise ValueError(
"ALTERNATE_CURVES requires a 2-D shape (num_curves, num_axis_points) "
"in ASAM convention"
)
raise ValueError("ALTERNATE_CURVES requires a 2-D shape (num_curves, num_axis_points) " "in ASAM convention")
type_name = internal_dtype.split("_")[0]
type_size = TYPE_SIZES[type_name]
byte_count = length * type_size
Expand Down
125 changes: 107 additions & 18 deletions objutils/tests/test_asam_alternate_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,21 +731,96 @@ def test_column_dir_still_works():
# Das Beispiel-Array aus der Spezifikation: 5 Achsbreakpoints × 4 Kurven
VXP_TYPE_DATA = np.array(
[
[10, 3, 4, 8], # Breakpoint 0
[12, 2, 4, 6], # Breakpoint 1
[17, 9, 5, 8], # Breakpoint 2
[10, 1, 4, 8], # Breakpoint 3
[18, 3, 8, 8], # Breakpoint 4
[10, 3, 4, 8], # Breakpoint 0
[12, 2, 4, 6], # Breakpoint 1
[17, 9, 5, 8], # Breakpoint 2
[10, 1, 4, 8], # Breakpoint 3
[18, 3, 8, 8], # Breakpoint 4
],
dtype=np.int32,
)

VXP_FLAT_LE = [
10, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 0,
12, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0,
17, 0, 0, 0, 9, 0, 0, 0, 5, 0, 0, 0, 8, 0, 0, 0,
10, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 0,
18, 0, 0, 0, 3, 0, 0, 0, 8, 0, 0, 0, 8, 0, 0, 0,
10,
0,
0,
0,
3,
0,
0,
0,
4,
0,
0,
0,
8,
0,
0,
0,
12,
0,
0,
0,
2,
0,
0,
0,
4,
0,
0,
0,
6,
0,
0,
0,
17,
0,
0,
0,
9,
0,
0,
0,
5,
0,
0,
0,
8,
0,
0,
0,
10,
0,
0,
0,
1,
0,
0,
0,
4,
0,
0,
0,
8,
0,
0,
0,
18,
0,
0,
0,
3,
0,
0,
0,
8,
0,
0,
0,
8,
0,
0,
0,
] # 5 * 4 * 4 = 80 Bytes (SLONG, LE)


Expand All @@ -758,11 +833,26 @@ def test_alternate_curves_memory_layout_ubyte():
"""
arr = VXP_TYPE_DATA.astype(np.uint8)
expected = [
10, 3, 4, 8,
12, 2, 4, 6,
17, 9, 5, 8,
10, 1, 4, 8,
18, 3, 8, 8,
10,
3,
4,
8,
12,
2,
4,
6,
17,
9,
5,
8,
10,
1,
4,
8,
18,
3,
8,
8,
]
total_bytes = 5 * 4 # num_axis_points * num_curves
sec = Section(start_address=0x1000, data=bytearray(total_bytes + 8))
Expand Down Expand Up @@ -860,8 +950,7 @@ def test_alternate_curves_layout_equals_row_dir():
"""ALTERNATE_CURVES und ROW_DIR erzeugen identisches Speicher-Layout."""
arr = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint8)
sec_curves = Section(start_address=0, data=bytearray(16))
sec_row = Section(start_address=0, data=bytearray(16))
sec_row = Section(start_address=0, data=bytearray(16))
sec_curves.write_asam_ndarray(0, arr, "UBYTE", byte_order="MSB_LAST", index_mode="ALTERNATE_CURVES")
sec_row.write_asam_ndarray( 0, arr, "UBYTE", byte_order="MSB_LAST", index_mode="ROW_DIR")
sec_row.write_asam_ndarray(0, arr, "UBYTE", byte_order="MSB_LAST", index_mode="ROW_DIR")
assert sec_curves.read(0, 6) == sec_row.read(0, 6)

Loading