Skip to content

Commit

Permalink
Fix missing resize in initial values
Browse files Browse the repository at this point in the history
  • Loading branch information
azucca committed Sep 20, 2024
1 parent 857f4c1 commit da57e28
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dwave/optimization/src/nodes/mathematical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,10 @@ void PartialReduceNode<BinaryOp>::initialize_state(State& state) const {
assert(static_cast<int>(state.size()) > index && "unexpected state length");
assert(state[index] == nullptr && "already initialized state");

std::vector<double> values;
values.reserve(size(state));
std::vector<double> values(size(state));

for (ssize_t i = 0; i < size(state); ++i) {
assert(i < static_cast<ssize_t>(values.size()));
values[i] = reduce(state, i);
}

Expand Down Expand Up @@ -733,6 +733,7 @@ double PartialReduceNode<std::plus<double>>::reduce(const State& state, ssize_t
for (ssize_t i = begin; i < array_ptr_->shape()[this->axis_]; ++i) {
ssize_t p_index =
start_idx + i * this->parent_strides_c_[this->axis_] / array_ptr_->itemsize();
assert(p_index < static_cast<ssize_t>(array_ptr_->size(state)));
double other = array_ptr_->view(state)[p_index];
val = func(val, other);
}
Expand Down

0 comments on commit da57e28

Please sign in to comment.