C++矩阵转置。提升 uBLAS 和双*?
我需要对一个大矩阵进行就地转置(因此分配另一个矩阵并转置到它的最简单方法不起作用)。不幸的是,这个大矩阵不是正方形的。更糟糕的是,矩阵存储在双精度数组中,列数和行数分别存储。
我发现 boost 有 uBLAS 库,但我没有找到一种方法将我的双精度数组包装在 uBLAS 矩阵中。有办法做到这一点吗?
或者您推荐其他方法来完成这项工作?
I need to do a in-place transposition of a large matrix(so the simplest way to allocate another matrix and transpose to it won't work). Unfortunately, this large matrix isn't square. And worse, the matrix is stored in an array of doubles with number of columns and rows stored separately.
I found that boost has the uBLAS library, but I didn't find a way to wrap my array of doubles in uBLAS matrix. Is there a way to do this?
Or do you recommend another ways to do the job?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您有非常大的矩阵并且不想存储临时副本,一种解决方案是将矩阵数组包装到类中并提供不同的适配器,这些适配器将以正常或转置的方式迭代元素。这不是非常高效的缓存,但可以节省大型矩阵的内存。
If you have very big matrices and you dont want to store the temporary copies one solution would be to wrap your matrix array into the class and provide different adapters which will iterate through the elements in normal or transposed way. This is not very cache efficient but saves memory on large matrices.
随着矩阵运算的进行,矩阵转置相当容易得到正确的结果。我建议你自己做,而不用担心 uBLAS(至少对于这个问题)。虽然有一些微妙之处,但维基百科关于就地矩阵转置的文章非常全面。
如果您对数据表示有一点控制,您可以做得更好。如果您有一个带有转置 T 的矩阵 M,那么显然 M[x][y] == T[y][x],因此根据您需要的转置矩阵,您可能不需要执行任何数据转换全部。
As matrix operations go, matrix transposition is fairly easy to get right. I'd recommend just doing it yourself, and not worrying about uBLAS (at least for this problem). There are a few subtleties, but wikipedia's article on in-place matrix transposition is startlingly thorough.
If you have a little control over the data representation, you can do even better. If you have a matrix M with a transpose T, then clearly M[x][y] == T[y][x], so depending on what you need the transposed matrix for you may not need to perform any data transformations at all.
根据您的用例细节,您对大型非方形转置的看法是正确的。核心内与外-core 似乎是任何人关心的最大区别。
Depending on your use case particulars you're right about large, non-square transposition. In core versus out-of-core seems to be the biggest distinction anyone cares about.