展开一个密集的矩阵 [英] expand a dense matrix

查看:152
本文介绍了展开一个密集的矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在FORTRAN中用新列扩展密集矩阵的最有效方法是什么?

说T是一个密集的矩阵m乘n

,我想用n + 1。
我能想到的一个策略:在每一步重新分配并分配最后一列,或者是否会有一些更好的方法,比如先分配一些空间并检查是否足够,如果不是这样的重新分配类型的东西?任何想法?

解决方案

假设 m 在某些意义上,n 不会太大,这样你的矩阵就可以适应内存,而你所追求的是时间表现,我会做什么我会分配一个大的矩阵并存储实际的大小分开。例如,这就是BLAS库用作主要维度的原因。然后,当您需要添加列时,请检查您的实际大小是否仍小于最大大小,并在必要时重新分配内存。

What would be the most efficient way to expand a dense matrix with new columns in FORTRAN?

Say T is a dense matrix m by n

and I would like to make it m by n+1. One strategy I could think of : Reallocate at each step and assign the last column or would there be some better ways, such as allocating some space before and checking if that is sufficient and if not do the reallocation kind of stuff? Any ideas?

解决方案

Assuming m and n are in some sense not exceedingly large, so that your matrices fit into memory and what you're after is performance in time, what I'd do I'd allocate a large matrix and store the actual size separately. This is what, for example, BLAS libraries use as a 'leading dimension'. Then, when you need to add a column, you check if your actual size is still smaller than the maximum size, and reallocate memory if necessary.

这篇关于展开一个密集的矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆