简体   繁体   English

犰狳稀疏分配矩阵

[英]Armadillo sparse allocation of a matrix

In Matlab, I allocate space for sparse matrix like this: 在Matlab中,我为稀疏矩阵分配空间,如下所示:

%Notice "Const_Block_Upper" is a dense matrix
%Number of nonzero element
nz = size(Const_Block_Upper,1)*size(Const_Block_Upper,2)*No_of_Voxels;
SizeR = No_of_Voxels*size(Const_Block_Upper,1)
SizeC = No_of_Voxels*size(Const_Block_Upper,2);

%Allocates space for sparse matrix of size (SizeR, SizeC) with atmost nz non-zeros
A = spalloc(SizeR, SizeC, nz);

I am wondering if I can do something similar in C++ lib Armadillo. 我想知道我是否可以在C ++ lib Armadillo中做类似的事情。 I looked at documentation of Armadillo; 我看了犰狳的文件; however, could not find something similar. 但是,找不到类似的东西。

Some help would be appreciated. 一些帮助,将不胜感激。

I wonder at which part of the documentation you looked, because the official documentation contains a lot about the sparse matrix types. 我想知道您看了文档的哪一部分,因为官方文档包含了很多有关稀疏矩阵类型的信息。 For example about batch insertion: 例如关于批量插入:

Batch insertion constructors: 批处理插入构造函数:

 form 1: sp_mat(locations, values, sort_locations = true) form 2: sp_mat(locations, values, n_rows, n_cols, sort_locations = true, check_for_zeros = true) form 3: sp_mat(add_values, locations, values, n_rows, n_cols, sort_locations = true, check_for_zeros = true) form 4: sp_mat(rowind, colptr, values, n_rows, n_cols) 

EDIT: Ah, I understand your question now; 编辑:啊,我现在明白你的问题了; you want to preallocate the space necessary for element storage; 您想预分配元素存储所需的空间; I'm afraid there's no possibility to do so with the underlying sparse matrix storage format... 恐怕无法使用底层稀疏矩阵存储格式来执行此操作...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM