gpt4 book ai didi

C++ boost ublas + units 维数约束

转载 作者:太空狗 更新时间:2023-10-29 23:09:57 24 4
gpt4 key购买 nike

我正在寻求有关如何在可能使用 boost 单元的 ublas 矩阵/vector 上强制矩阵维度约束的设计/一般想法的建议。

例如,设矩阵 A 的维度为时间 x 力(例如)

// does not have dimensions, time x force and force x time are not distinguished.
matrix<double> A;

//something like?
dimension<time, force, matrix<double> > A;
dimension<force, time, matrix<double> > B = trans(A);

// or maybe custom layouts, although ensuring dimension becomes harder between matrixes?
matrix<double, dimension<time, force> > A;

你有没有做过这样的事情,或者你对如何组织这些约束有什么好主意?我正在寻找更多的语法/语义建议而不是实现。

我浏览了 ublas 文件,有一些讨论,但没有具体内容。

谢谢

最佳答案

看看这个不错的 Boost 教程,它介绍了使用模板元编程的维度分析功能:

http://www.boost.org/doc/libs/1_35_0/libs/mpl/doc/tutorial/representing-dimensions.html

这将要求您为要在应用中使用的每个维度创建一整套模板特化,但结果是值得的——它不会让您犯错或在维度中增加歧义。

关于C++ boost ublas + units 维数约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3033716/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com