-
Notifications
You must be signed in to change notification settings - Fork 56
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
householder函数向量模为0情况下计算错误以及是否需要添加0 == _x->data[0]的情况 #11
Comments
作者你好,这部分修改代码有一个BUG需要修正一下。 |
这里不会提前释放的,w在w = M_numul(w, 1 / M_norm(w, 2));这一行就指向了一个新生成的matrix,反而是修改后的版本Matrix_copy生成的matrix没有释放,会导致内存泄漏 |
好吧,我发现是我本地修改了M_numul的实现,返回值是新申请了一个矩阵=_= |
不好意思,因为我本地修改了M_numul的实现,返回值是新申请了一个矩阵,所以上面的改动有错误。 if (_x->data[0] > 1e-5f)
{
w = M_add_sub(1, _x, -1, y);
Matrix *temp_w = w;
w = M_numul(w, 1 / M_norm(w, 2));
M_free(temp_w);
}
else if (fabs(_x->data[0]) <= 1e-5f)
{
w = _x;
w = M_numul(w, 1 / M_norm(w, 2));
}
else
{
w = M_add_sub(1, _x, 1, y);
Matrix *temp_w = w;
w = M_numul(w, 1 / M_norm(w, 2));
M_free(temp_w);
} 应该为 if (_x->data[0] > 1e-5f)
{
w = M_add_sub(1,_x,-1,y);
M_numul(w,1/M_norm(w, 2));
}
else if (fabs(_x->data[0]) <= 1e-5f)
{
w = Matrix_copy(_x);
w = M_numul(w, 1 / M_norm(w, 2));
}
else
{
w = M_add_sub(1, _x, 1, y);
M_numul(w, 1 / M_norm(w, 2));
} |
作者你好,感谢开源
householder函数使用过程中遇到一些问题,当待变换的向量为0向量时,会计算错误,我将householder函数前4行修改为:
当向量为0向量时,将H阵设为单位阵,计算就不会出现错误了,
此外我看参考文档https://max.book118.com/html/2017/0527/109650252.shtm 中提到sgn(a)在a=0的时候为0,所以将if分支修改为:
从而和文档上对应。
The text was updated successfully, but these errors were encountered: