提交 fe15239a 编写于 作者: M Megvii Engine Team

fix(imperative): fix error message for tensors with intbx data type

GitOrigin-RevId: cbb42f8127320c4d45ac6dcb8171515e53e69bcb
上级 10af44ab
......@@ -24,7 +24,7 @@ template <size_t N>
struct LowBitType {
static_assert(N < 8, "low bit only supports less than 8 bits");
static int npy_typenum;
//! numerical value (-3, -1, 1, 3)
//! allowed numerical value: odd numbers between (-max_value, max_value)
int8_t value;
struct PyObj;
......@@ -32,16 +32,17 @@ struct LowBitType {
const static int32_t max_value = (1 << N) - 1;
//! check whether val is (-3, -1, 1, 3) and set python error
//! check whether val is odd and between (-max_value, max_value) and set python error
static bool check_value_set_err(int val) {
int t = val + max_value;
if ((t & 1) || t < 0 || t > (max_value << 1)) {
PyErr_SetString(
PyExc_ValueError, mgb::ssprintf(
"low bit dtype number error: "
"value=%d; allowed {-3, -1, 1, 3}",
val)
.c_str());
PyExc_ValueError,
mgb::ssprintf(
"low bit dtype number error: "
"value=%d; allowed values are odd numbers between [%d,%d]",
val, -max_value, max_value)
.c_str());
return false;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册