boost::uBLAS 如何处理矩阵的嵌套乘积?
我读了一篇关于使用动态规划优化矩阵嵌套积的文章,我想看看它是如何在 boost::uBLAS 中实现的。
如何才能实现呢?图书馆如何“移动括号”?当编写这样的代码行时,我认为将评估 prod
的参数,然后运行该函数。
常见问题解答提到了表达式的概念模板。是相连的吗?
I read an article about the optimisation of nested product of matrices, using dynamic programming, and I wanted to see how it is implemented in boost::uBLAS.
I'm not sure I understood the documentation (they talk about it at the very end of the page), but it seems they handle this problem. When you write R = prod(A, prod(B,C));
, the library computes A x (B x C)
or (A x B) x C
depending on the sizes of A
, B
and C
.
How can it be achieved ? How can the library "move the brackets" ? When writing such a code line, I thought the arguments of prod
would be evaluated, and then the function would be run.
The FAQ mentions the notion of expression templates. Is it linked ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,涉及表达式模板(您可以在“表达式树”名称下找到)。
基本上,prod 不返回结果,而是保存操作(矩阵乘法)和指向两个输入的指针的包装对象。如果使用这样的包装器作为输入来调用 prod,它可以应用重新排序优化。
然而,从我对该页面的阅读来看,没有应用这样的优化(它说它尊重括号结构)。
Yes, expression templates (which you may find under the name "expression trees") are involved.
Basically,
prod
doesn't return the result, but a wrapper object holding the operation (matrix multiply) and pointers to the two inputs. Ifprod
is called with such a wrapper as input, it can apply reordering optimizations.However, from my reading of that page, no such optimization is applied (it says it honors bracketing structure).