[Tensor] Disambiguate undefined Tensor dimensions from Scalar Tensor
Context
Complete Aidge Core support for Scalar Tensors by disambiguating between undefined rank/dims and scalar.
The proposed change is to add a Tensor::undefined() method to disambiguate Tensors which have not been assigned dimensions yet from empty() Tensors which have empty dimensions.
The choice have been made to keep the previous implementation of Tensor::empty() as is for backward compatibility.
I.e.:
- if undefined() is true => the tensor has been constructed with the default ctor, and resize() was not yet called,
- if empty() is true => either the tensor is undefined(), or it is scalar (rank of 0, of nb dims == 0)
It implies that:
- forward dims related operations should now use undefined() instead of empty() to check whether an input has some undefined dimension,
- testing if a tensor is defined and scalar should be done with !undefined() and empty(). Or simply empty() if the tensor is known to be defined.
- more generally before using the rank of actual dimensions of a Tensor for any purpose, one should check whether the tensor is !undefined
Modified files
Changes have been done in the first commit to:
- add definition for undefined() (based on mSize == 0 predicate)
- update every places in aidge_core where empty() was used as a predicate for "undefined dimension"
- add Tensor::undefined() in the python binding
- unit_tests are passing with these changes
Changes have been done in the second commit to augment tests for scalar use cases:
- activate all previously present scalar tests for elementwise ops (Add|Mul|Pow|Sub|Div)
- add scalar tests for MatMul op
- add negative scalar tests for Concat and Transpose
Detailed major modifications
The change should be backward compatible.
Questions to reviewer
When running unit tests several times in aidge_core (before my changes), I never get the same number XXX in the test output "XXX assertions in 76 tests cases". For instance running it twice:
build/unit_tests/tests_aidge_core --rng-seed 1 --out all_tests.txt
build/unit_tests/tests_aidge_core --rng-seed 1 --out all_tests_2.txt
And comparing outputs:
diff all_tests.txt all_tests_2.txt
< All tests passed (47742 assertions in 76 test cases)
---
> All tests passed (43928 assertions in 76 test cases)
Is it known? Do you have a method to actually get the full count of tested assertions or use case?
TODO
-
aidge_core unit_tests ok