mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-11-13 18:33:53 +01:00
Bugfix: NDArary/NDView overflow in calculating number of elements (#322)
Fixed number of elements calculation that caused integer overflow. Now return size_t instead of int.
This commit is contained in:
1 parent
b78ea64ea7
commit
17d04083a7
3 files changed
+21
-2
No files matched your search
@@ -8,8 +8,27 @@
|
||||
#include <vector>
|
||||
|
||||
using aare::NDView;
|
||||
using aare::num_elements;
|
||||
using aare::Shape;
|
||||
|
||||
TEST_CASE("Calculate size from a shape") {
|
||||
Shape<3> shape{2, 3, 4};
|
||||
REQUIRE(num_elements(shape) == 24);
|
||||
|
||||
Shape<2> shape2{5, 5};
|
||||
REQUIRE(num_elements(shape2) == 25);
|
||||
|
||||
Shape<1> shape3{10};
|
||||
REQUIRE(num_elements(shape3) == 10);
|
||||
|
||||
Shape<3> shape4{1000, 512, 1024};
|
||||
REQUIRE(num_elements(shape4) == 524288000);
|
||||
|
||||
// 10GB which is more than INT_MAX bytes
|
||||
Shape<3> shape5{10000, 1024, 1024};
|
||||
REQUIRE(num_elements(shape5) == 10485760000);
|
||||
}
|
||||
|
||||
TEST_CASE("Element reference 1D") {
|
||||
std::vector<int> vec;
|
||||
for (int i = 0; i != 10; ++i) {
|
||||
|
||||
Reference in new issue
Block a user