Skip to content

Commit

Permalink
QOL
Browse files Browse the repository at this point in the history
  • Loading branch information
Atanas Dimitrov committed Sep 10, 2024
1 parent f8f4be1 commit 192cf23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions onnxruntime/core/providers/cpu/math/cumsum.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#include <functional>

#include "cumsum.h"
#include "core/providers/common.h"
#include "core/providers/cpu/tensor/utils.h"
Expand Down Expand Up @@ -162,9 +164,10 @@ Status CumSum<T>::Compute(OpKernelContext* ctx) const {

// we solve the problem by using the identity that(in the case of exclusive)
// 1) out[upper_dims...][0][lower_dims...] = 0
// 2) out[upper_dims...][i][lower_dims...] = in[upper_dims...][i-1][lower_dims...] + out[upper_dims...][i-1][lower_dims...]
// 2) out[upper_dims...][i][lower_dims...] =
// in[upper_dims...][i-1][lower_dims...] + out[upper_dims...][i-1][lower_dims...]
// we loop through the [upper_dims...] and start applying the identity in each slice
// in each slice since again the [lower_dims...] are adjecent in memory, we can add them like vectors
// since the [lower_dims...] are adjecent in memory, so we can add them like vectors

const auto dim = input->Shape()[axis]; // dimension size for the axis
const auto input_shape = input->Shape().GetDims();
Expand Down
6 changes: 3 additions & 3 deletions onnxruntime/test/providers/cpu/math/cumsum_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ TEST(CumSumTest, _1DTestdouble_WithInt64Axis) {
}
TEST(CumSumTest, _1DTestLong) {
OpTester test("CumSum", 11, onnxruntime::kOnnxDomain);
const int N = 1000000;
test.AddInput<int32_t>("x", {N}, std::vector<int32_t>(N, 1));
test.AddInput<int32_t>("axis", {}, {0});
const int N = 10000000;

Check warning

Code scanning / PREfast

The const variable 'N' can be computed at compile-time. Consider using constexpr (con.5). Warning test

The const variable 'N' can be computed at compile-time. Consider using constexpr (con.5).
std::vector<int32_t> output_value(N);
std::iota(output_value.begin(), output_value.end(), 1);
test.AddInput<int32_t>("x", {N}, std::vector<int32_t>(N, 1));
test.AddInput<int32_t>("axis", {}, {0});
test.AddOutput<int32_t>("y", {N}, output_value);
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider});
}
Expand Down

0 comments on commit 192cf23

Please sign in to comment.