Requirements helper was introduced to replace plain checks for making them output informative messages (Debug and Verbose mode) and also replace macros REQUIRE_TRUE.
it will lazily evaluate values and messages if the type wrapped and hasgetValue and getMsg methods
it is implicit bool. this makes it usable with logical operators and also inside if conditions. Besides it will benefit from shortcircuit nature of those operators.
there is generic template InfoVariable wrapper for types to make it informative. you can use lambda operators with them as well to make it lazily evaluated
we added custom ShapeInfoVariable wrapper for the NDArray and vector<> shapes to make them informative
one can use expect to add its own proper comparision. simple lambda for that will be like this:
[](constdecltype(expType)& l,constdecltype(reqType)& r){ //compare and returnreturn ....; }
Requirement Helper Example#5: twenty {20} expected to be equal to twenty one 21
6. use bool nature and also log the success case
```cpp
Requirements req6("Requirement Helper Example#6");
NDArray * arr= nullptr;
arr !=nullptr && req6.expectEq(arr->rankOf(), 3) ;
req6.logTheSuccess();
Output:
Requirement Helper Example#6: meets the requirements
custom comparision lambda and also another usage of the custom wrapper written by us ShapeInfoVariable. Note: we will use std::vector<int>. this wrapper can be used with NDArray as well.
terminate called after throwing an instance of 'std::invalid_argument'
what(): Op validation failed
...
Requirement Helper Example#8: {6} expected to be one of these {[1, 2, 3, 7, 8, 9, ]}
Here is live example:
Note: some classes were mocked there and do not represent the exact implementations in libnd4j. https://godbolt.org/z/sq98vchs5