Skip to content

Commit aa2b3ef

Browse files
authored
Fix warnings from use of std::accumulate in xbuilder (#2926)
# Checklist - [ ] The title and commit message(s) are descriptive. - [ ] Small commits made to fix your PR have been squashed to avoid history pollution. - [ ] Tests have been added for new features or bug fixes. - [ ] API of new functions and classes are documented. # Description The internal type of std::accumulate is determined by the init parameter. Initializing with 0 (int) results in a "conversion from 'size_t' to 'type', possible loss of data" warning in MSVC. Related #2732 The second commit replacing size_t with std::size_t is just for consistency.
1 parent dd857e5 commit aa2b3ef

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

include/xtensor/generators/xbuilder.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ namespace xt
499499
{
500500
// trim off extra indices if provided to match behavior of containers
501501
auto dim_offset = std::distance(first, last) - std::get<0>(t).dimension();
502-
size_t axis_dim = *(first + axis + dim_offset);
502+
std::size_t axis_dim = *(first + axis + dim_offset);
503503
auto match = [&](auto& arr)
504504
{
505505
if (axis_dim >= arr.shape()[axis])
@@ -512,16 +512,16 @@ namespace xt
512512

513513
auto get = [&](auto& arr)
514514
{
515-
size_t offset = 0;
516-
const size_t end = arr.dimension();
517-
for (size_t i = 0; i < end; i++)
515+
std::size_t offset = 0;
516+
const std::size_t end = arr.dimension();
517+
for (std::size_t i = 0; i < end; i++)
518518
{
519519
const auto& shape = arr.shape();
520-
const size_t stride = std::accumulate(
520+
const std::size_t stride = std::accumulate(
521521
shape.begin() + i + 1,
522522
shape.end(),
523-
1,
524-
std::multiplies<size_t>()
523+
size_t(1),
524+
std::multiplies<std::size_t>()
525525
);
526526
if (i == axis)
527527
{
@@ -563,21 +563,21 @@ namespace xt
563563
{
564564
auto get_item = [&](auto& arr)
565565
{
566-
size_t offset = 0;
567-
const size_t end = arr.dimension();
568-
size_t after_axis = 0;
569-
for (size_t i = 0; i < end; i++)
566+
std::size_t offset = 0;
567+
const std::size_t end = arr.dimension();
568+
std::size_t after_axis = 0;
569+
for (std::size_t i = 0; i < end; i++)
570570
{
571571
if (i == axis)
572572
{
573573
after_axis = 1;
574574
}
575575
const auto& shape = arr.shape();
576-
const size_t stride = std::accumulate(
576+
const std::size_t stride = std::accumulate(
577577
shape.begin() + static_cast<std::ptrdiff_t>(i) + 1,
578578
shape.end(),
579-
size_t(1),
580-
std::multiplies<size_t>()
579+
std::size_t(1),
580+
std::multiplies<std::size_t>()
581581
);
582582
const auto len = (*(first + static_cast<std::ptrdiff_t>(i + after_axis)));
583583
offset += len * stride;

0 commit comments

Comments
 (0)