[Tensor] Fix invalid getIdx() method
Context
The Tensor getIdx() method for computing flat index from a coords list is wrong. There were two issues:
- when the coords is 0-rank (i.e. coords == {}) it created a segfault due to an access to an out-of-bound access
- when the coords rank differed from the tensor rank by more than 2 dimensions the computation was incorrect
This MR fixes getIdx() and add unit tests for get()/set()/getIdx() with index or coords.
After adding the first commit (unit tests) here is the output of the unit tests:
unit_testsbuild/unit_tests/tests_aidge_core --rng-seed 0 -c 'Tensor set/get'
/data/Test_Tensor.cpp:337: FAILED:
{Unknown expression after the reported line}
due to a fatal error condition:
SIGSEGV - Segmentation violation signal
===============================================================================
test cases: 5 | 4 passed | 1 failed
assertions: 232 | 231 passed | 1 failed
Segmentation fault
After applying the second patch which fixes the issue, here is the output:
unit_testsbuild/unit_tests/tests_aidge_core --rng-seed 0 -c 'Tensor set/get'
===============================================================================
All tests passed (8009 assertions in 77 test cases)
Modified files
First commit: add unit tests Tensor set/get
to Tensor unit tests (note that with this commit in isolation the unit tests fail.
Second Commit: fix implementation of getIdx()
Third commit: minor change to getStorageIdx()
which did not assert dimensions size before checking coords values.
Detailed major modifications
No major modification.
TODO
No forecasted todo.