C++ boost ublas + units 维数约束

标签 c++ boost ublas units-of-measurement

我正在寻求有关如何在可能使用 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/

相关文章:

c++ - 将 cpp_int 类型导出到位时,boost::multiprecision::export_bits 丢失符号

c++ - 更改 boost vector 的构造函数

c++ - 如何将 boost::numeric::ublas::vector 复制到矩阵?

稀疏矩阵实现的 C++11 兼容性

c++ - 将 printf 更改为 cout

c++ - shared_ptr 如何存储删除器?

c++ - 如何在 C++ 中记录函数的堆栈返回地址

c++ - 大写 Visual Studio itemTemplate 参数

c++ - 使用 boost::spirit::qi 解析类型化的 csv 文件

elasticsearch - 基于整数值的 boost 分数 - Elasticsearch