处理 boost ublas 稀疏或稠密矩阵的 API
我对 Boost ublas 文档有点困惑。我似乎不清楚稀疏矩阵类和稠密矩阵类共享一个共同的父类——我相信这是设计使然。但是,假设只需要使用 operator() 访问器对矩阵的条目进行操作,那么我如何设计一个可以接受稀疏矩阵或密集矩阵的 API。例如,这样的事情:
float doMatrixMath(matrix_base<float> m)
{
return m(1,1)+m(2,2);
}
也许我的想法是错误的。任何关于如何考虑 ublas 类的对象建模的指导将不胜感激!
I am a bit perplexed by the Boost ublas documentation. It does not seem clear to me that the sparse and dense matrix classes share a common parent class---which I believe is by design. But then how can I design an API that can accept either sparse or dense matrix, assuming that it need only operate on entries of the matrix using the operator() accessor, say. For example, something like this:
float doMatrixMath(matrix_base<float> m)
{
return m(1,1)+m(2,2);
}
Perhaps my thinking about this is wrong-headed. Any guidance regarding how to think about the object modeling of ublas classes would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是模板。您可以使用非常通用的类型,或者深入研究并找到更具体的东西,但总体思路是:
当然可以通过更具体的类型和返回值检测来增强......
Templates unfortunately. You can use a very generic type, or dig in and find something more concrete, but the general idea is:
Of course this can be enhanced with a more concrete type and return value detection...