Two elements disappear when I print the vector out


(Alec) #1

I generated a random integer array and put 628 number into a DenseVector like this:

Vector Data = new DenseVector(new double[] {
19,15,99,14,76,47,65,68,60,2,75,34,43,39,71,11,54,34,78,66,48,32,80,22,55,53,62,76,38,57,57,49,4,51,96,88,55,94,92,42,57,53,97,28,96,45,4,64,28,1,59,55,56,56,23,4,31,1,39,86,88,76,73,37,100,81,11,42,82,64,93,7,50,90,47,24,79,81,77,14,27,28,34,25,89,63,61,58,51,32,69,21,72,76,7,6,86,7,84,85,84,38,96,10,56,39,56,35,54,96,22,55,11,19,55,78,32,16,92,82,82,57,7,8,96,17,43,49,58,83,37,24,48,8,99,11,12,93,62,6,51,11,80,91,37,17,68,47,96,16,47,50,89,59,14,97,64,24,72,60,34,60,19,49,30,87,74,37,18,54,51,7,90,28,74,39,78,49,95,69,49,91,3,2,39,64,48,80,52,62,7,69,92,78,98,11,63,5,73,18,88,98,92,20,36,92,39,93,87,4,2,85,99,36,31,44,56,79,87,75,81,44,96,4,84,18,96,78,73,11,9,93,2,13,96,91,38,25,66,82,29,61,14,26,24,56,89,6,98,48,58,61,82,19,66,39,11,96,37,100,96,75,81,65,66,9,26,87,95,53,47,22,69,26,46,31,79,66,6,56,34,92,68,78,31,50,30,73,86,60,86,74,23,97,84,74,1,40,21,28,12,61,91,80,49,64,9,31,15,78,89,51,81,57,53,56,17,87,14,3,8,84,64,12,22,67,39,82,3,22,56,89,81,68,11,44,4,3,21,19,97,49,26,44,78,56,71,97,51,93,32,3,33,72,82,19,48,74,55,65,7,34,37,97,24,11,9,36,90,95,59,54,2,69,88,33,40,15,96,30,30,52,72,61,89,95,98,90,32,70,90,6,38,2,72,25,73,58,98,2,58,78,3,27,51,53,12,67,8,2,90,81,74,3,63,28,26,24,51,93,96,12,1,86,82,67,54,18,93,53,44,29,43,78,79,52,56,15,83,50,8,10,90,60,68,76,38,1,66,40,38,60,80,34,33,99,31,98,22,33,5,39,34,97,71,50,5,68,19,97,3,49,28,22,71,59,56,83,82,1,9,64,39,84,39,59,23,100,31,38,33,33,88,10,86,65,27,56,55,24,6,2,28,74,29,92,3,5,50,93,67,13,53,34,83,24,83,47,91,47,22,72,90,64,3,28,70,71,41,22,3,22,25,61,89,20,45,65,22,28,48,63,79,33,24,93,38,35,49,41,9,36,38,7,45,87,86,27,95,72,11,74,3,87,31,14,87,70,22,8,98,69,71,86,27,12,23,93,52,94,29,73,70,25,22,55,68,88,19,54,31,83,52,29,73,6,18,22,42,38,85,74,29,5,90,59,11,18,94,8,10,42,84,38,88,22,22,52,55,61,41,76,52,34,57,41,69,60
} );

When I print it out by:
Console.WriteLine(Data.ToString());

It will always show two “…” instead of showing right number at last four elements.

Can anyone help to solve this problem?

Thanks.


(Christoph Rüegg) #2

It prints dots as ellipsis to indicate that it did not print the whole vector. Note that the dots stand for more than two numbers, as only 226 numbers have been actually printed. This is optimized for typical console usage where you would usually not want to fully print e.g. a sparse vector with millions of zeros.

You can customize this by using one of the overloads or alternatives. For example, Data.ToString(64,120) will print up to 64 numbers per column, and only as many columns such that no resulting row has more than 120 characters (otherwise it will introduce ellipsis again).


(Alec) #3

Thanks!
So is this a constraint by ToString() ?


(Christoph Rüegg) #4

Yes, by design. The reasoning is that ToString is mostly used for testing, prototyping, debugging and interactive use, where such a safeguard is useful. How exactly a vector or matrix should be formatted to a string is very application specific and thus a concern of the application, not the toolkit.

However, I do agree that we should provide at least one way to format the whole vector or matrix to a string. Could you open an issue for that? Thanks!