Skip to content

Commit c6afe2c

Browse files
committed
pprint: fixed python notation where small start offset was ignored
1 parent 32de06c commit c6afe2c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: core/bh_array.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,25 @@ vector<tuple<int64_t, int64_t, int64_t> > bh_view::python_notation() const
146146
int64_t offset = this->start;
147147
for(size_t i=0; i<sns.size(); ++i)
148148
{
149-
int64_t stride = std::get<0>(sns[i]);
150-
int64_t shape = std::get<1>(sns[i]);
151-
int64_t index = std::get<2>(sns[i]);
149+
const int64_t stride = std::get<0>(sns[i]);
150+
const int64_t shape = std::get<1>(sns[i]);
151+
const int64_t index = std::get<2>(sns[i]);
152152

153153
int64_t start = 0;
154154
if (stride > 0)//avoid division by zero
155155
start = offset / stride;
156156
int64_t end = start + shape;
157157
offset -= start * stride;
158+
assert(offset >= 0);
158159
sne[index] = make_tuple(start, end, stride);
159160
}
160161

162+
// If 'offset' wasn't reduced to zero, we have to append a singleton dimension
163+
// with the stride of 'offset'
164+
if (offset > 0) {
165+
sne.push_back(make_tuple(1, 2, offset));
166+
}
167+
161168
/*
162169
//Find the contiguous strides, that is the stride of each dimension
163170
//assuming the view is contiguous.

Diff for: filter/pprint/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Impl : public ComponentImplWithChild {
4343
f << "Trace " << count << ":" << endl;
4444
for(const bh_instruction &instr: bhir->instr_list) {
4545
f << instr << endl;
46+
// f << instr.pprint(false) << endl;
4647
}
4748
f << endl;
4849
f.close();

0 commit comments

Comments
 (0)