-
Notifications
You must be signed in to change notification settings - Fork 547
Assert macros: minimize spacings between values in context window #2263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
349156a
to
35c36c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. This might not be the most efficient way to do this but it works. It would be nice if the values were right-aligned instead of left.
test/testHelpers.hpp
Outdated
// as numbers | ||
|
||
template<typename T> | ||
std::string operator+(const T& val) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary. You can remove this function. You only need to overload for the af::cfloat and af::cdouble.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 That makes sense. The whole point is just to avoid the + being interpreted as an addition for af complex types, and the stream << operator is already overloaded for those types, so simply returning the same value is enough.
test/testHelpers.hpp
Outdated
} | ||
|
||
template<> | ||
std::string operator+(const af::cfloat& val) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should just return the same value. It shouldn't convert to a string. That is done by the operator<<
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
test/testHelpers.hpp
Outdated
|
||
template<> | ||
std::string operator+(const af::cdouble& val) { | ||
std::ostringstream os; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
test/testHelpers.hpp
Outdated
std::ostringstream tmpOs; | ||
|
||
uint dim0 = dim0Start + i; | ||
if (dim0 == coords[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use braces even if there is only one statement in the body of the if condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
test/testHelpers.hpp
Outdated
std::vector<int> valsWidths; | ||
std::vector<std::string> ctxDim0; | ||
std::vector<std::string> ctxOutVals; | ||
std::vector<std::string> ctxGoldVals; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reserve these vectors if you know the size ahead of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Yeah that's faster than having vectors resize from time to time as it grows
test/testHelpers.hpp
Outdated
|
||
int maxWidth = std::max<int>(dim0Len, outLen); | ||
maxWidth = std::max<int>(maxWidth, goldLen); | ||
valsWidths.push_back(maxWidth); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to store the lengths of each of the values? I would have thought max would be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the max of all the string lengths would be enough, but I thought if there's one value that's abnormally long (compared to the rest of the values), or if the indices are long compared to the values, then there would be a lot of unnecessary spaces as well. Thus I decided to just use the maximum per element between the index, the out value, and the reference value. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a big deal. This code shouldn't be running all the time anyway.
test/testHelpers.hpp
Outdated
|
||
// Display dim0 positions | ||
// Display dim0 positions, output values, and reference values | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
test/testHelpers.hpp
Outdated
} else | ||
os << std::setw(valsWidth) << std::left << i << " "; | ||
for (uint i = 0; i < (dim0End - dim0Start); ++i) { | ||
os << std::setw(valsWidths[i]) << std::left << ctxDim0[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you need the extra space at the end if you added one to the setw value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Turns out that I don't!
test/testHelpers.hpp
Outdated
|
||
// Get dim0 positions and out/reference values for the context window | ||
// Also get the max string length between the position and out/ref values | ||
// per item so that it can be used later as the field width for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space at the beginning of the comment line.
35c36c2
to
97a9ee2
Compare
Here are the sample error messages after the changes:
|
97a9ee2
to
088a83f
Compare
I had to fix the uneven border spaces near the braces haha |
Maybe the indices should be right/center aligned as well. the complex example looks weird. |
088a83f
to
df774f3
Compare
Haha true. Here's the outputs now:
|
Following up on #2257, the spacing between consecutive values in the context window (when values differ at some point) has been reduced in this change. It was previously hardcoded as 10 space chars - now, the output field width is the maximum between the string lengths of the dim0 position, the output value, and the reference value, so any unnecessary spaces are removed.
This also fixes a bug when u8 (unsigned char) is used. Previously, the context displays the character representation of the value. It's fixed now so it displays the number representation instead.
In addtion, this also changes the implementation of
ravelIdx()
from an explicit multiply-and-accumulate to usingstd::inner_product()
Here's a sample error message:
Using "normal" equality for u8 (unsigned char) type:
And using c32 (complex float):