Skip to content

Commit

Permalink
Fix ArrayIndex test
Browse files Browse the repository at this point in the history
  • Loading branch information
dayo09 committed Jan 20, 2025
1 parent 5e7e09c commit bfc562d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 8 additions & 2 deletions compiler/luci/pass/src/helpers/ArrayIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
#include "ArrayIndex.h"

#include <cassert>
#include <stdexcept>

namespace luci
{
#define UNLESS_INVALID_ARGUMENT(COND) \
if (not(COND)) \
throw std::invalid_argument("");

Array4DIndex::Array4DIndex(uint32_t D0, uint32_t D1, uint32_t D2, uint32_t D3)
: _dim{D0, D1, D2, D3}
{
assert(D0 > 0 && D1 > 0 && D2 > 0 && D3 > 0);

_strides[3] = 1;
_strides[2] = D3;
_strides[1] = D3 * D2;
Expand All @@ -39,7 +43,9 @@ Array4DIndex::Array4DIndex(uint32_t D0, uint32_t D1, uint32_t D2, uint32_t D3)

uint32_t Array4DIndex::operator()(uint32_t i0, uint32_t i1, uint32_t i2, uint32_t i3) const
{
assert(i0 < _dim[0] && i1 < _dim[1] && i2 < _dim[2] && i3 < _dim[3]);
UNLESS_INVALID_ARGUMENT(i0 < _dim[0] && i1 < _dim[1] && i2 < _dim[2] && i3 < _dim[3]);
UNLESS_INVALID_ARGUMENT(0 <= i0 && 0 <= i1 && 0 <= i2 && 0 <= i3);

return i0 * _strides[0] + i1 * _strides[1] + i2 * _strides[2] + i3 * _strides[3];
}

Expand Down
4 changes: 1 addition & 3 deletions compiler/luci/pass/src/helpers/ArrayIndex.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ TEST(LuciPassHelpersArrayIndex, array_index_4d)
{
luci::Array4DIndex idx(5, 4, 3, 2);

EXPECT_EQ(idx.rank(), 4);

EXPECT_EQ(idx(0, 0, 0, 0), 0);

EXPECT_EQ(idx(1, 0, 0, 0), idx.stride(0));
Expand All @@ -36,5 +34,5 @@ TEST(LuciPassHelpersArrayIndex, array_index_4d)

TEST(LuciPassHelpersArrayIndex, array_index_4d_NEG)
{
ASSERT_THROW(luci::Array4DIndex idx(5, 4, 3, -1));
EXPECT_ANY_THROW(luci::Array4DIndex idx(-1000, 4, 3, -1));
}

0 comments on commit bfc562d

Please sign in to comment.