Skip to content

Commit 68ecb55

Browse files
use effective inted in operator[] of NdOffsetMatrix<T, 1>
1 parent 0d94503 commit 68ecb55

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

libs/libvtrutil/src/vtr_ndoffsetmatrix.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define VTR_ND_OFFSET_MATRIX_H
33
#include <array>
44
#include <memory>
5+
#include <algorithm>
56

67
#include "vtr_assert.h"
78

@@ -309,9 +310,8 @@ class NdOffsetMatrixBase {
309310

310311
///@brief Swap two NdOffsetMatrixBase objects
311312
friend void swap(NdOffsetMatrixBase<T, N>& m1, NdOffsetMatrixBase<T, N>& m2) {
312-
using std::swap;
313-
swap(m1.dim_ranges_, m2.dim_ranges_);
314-
swap(m1.data_, m2.data_);
313+
std::swap(m1.dim_ranges_, m2.dim_ranges_);
314+
std::swap(m1.data_, m2.data_);
315315
}
316316

317317
private:
@@ -441,7 +441,9 @@ class NdOffsetMatrix<T, 1> : public NdOffsetMatrixBase<T, 1> {
441441
VTR_ASSERT_SAFE_MSG(index >= this->dim_ranges_[0].begin_index(), "Index out of range (below dimension minimum)");
442442
VTR_ASSERT_SAFE_MSG(index < this->dim_ranges_[0].end_index(), "Index out of range (above dimension maximum)");
443443

444-
return this->data_[index];
444+
int effective_index = index - this->dim_ranges_[0].begin_index();
445+
446+
return this->data_[effective_index];
445447
}
446448

447449
///@brief Access an element (mutable)

0 commit comments

Comments
 (0)