expand a dense matrix

亡梦爱人 提交于 2020-01-23 04:03:11

问题


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?


回答1:


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.




回答2:


If you have a Fortran 2003 Compiler you might make use of move_alloc: http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/lin/compiler_f/lref_for/source_files/rfmvallo.htm



来源:https://stackoverflow.com/questions/7468268/expand-a-dense-matrix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!