Indeed you are correct: different subtypes of sparse matrices have their specific storement engines.
Firstly, all subtypes must to store some auxiliar information as the total number of rows, columns and non zero cells (NNZ: Number of Non Zeroes), not only cell contens. This space is very small and independent of matrix size, but, when you have just one cell it can be larger than data.
In your example A is a Cholmod.R.Triplet virtual matrix that stores just non null cells as triplets with this information
. row: integer of 4 bytes
. col: integer of 4 bytes
. value: real of 8 bytes
So the total number of bytes of data contens is 16*NNZ
However B is a Cholmod.R.Sparse that store a vector of pointers to column data where cells can be packed in a compact and fast to access way. Most operations returns matrices in packed mode but some times it is not possible. You can force packed mode by means of TOL function VMatrix Pack(VMatrix data)
. You can see more about this theme here
In your example NNZ=1 and Cholmod.R.Sparse lost efficience in global.
You can try this code for different values of n
to view how efficience of Cholmod.R.Sparse growns with n
Real n = 10;
Set triplets =
For(1,n, Set(Real k) { SetOfReal(Max(1,k-1),k,Rand(-1,1)) }) <<
For(1,n, Set(Real k) { SetOfReal(n-k+1,Min(n,k+1),Rand(-1,1)) });
VMatrix A = Triplet(triplets, n, n) ;
VMatrix B = Mat2VMat(VMat2Mat(A));
If you are agree with this explanation you can answer OK or resolve it as fixed yourself.
Thanks for reporting.