Reputation: 1490
In Matlab, I allocate space for sparse matrix like this:
%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. I looked at documentation of Armadillo; however, could not find something similar.
Some help would be appreciated.
Upvotes: 1
Views: 638
Reputation: 36433
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...
Upvotes: 2