1

Is it possible to show more float precision in armadillo matrix?

For example, 1.51421993970923477456e-001 instead of 1.514219939709e-001.

KTBFFH
  • 65
  • 1
  • 8
  • 1
    That is an elementary C (for `printf()`) or C++ (for `iostream`) formatting question and will hopefully be 'dupe closed' in short time (and I don't think I have the dupe hammer for C++ myself). – Dirk Eddelbuettel Mar 21 '16 at 01:12
  • Turns out I do after all... – Dirk Eddelbuettel Mar 21 '16 at 01:13
  • This is not the end of the story in armadillo though! If you manually set the precision for cout and then output a matrix to stdout, it will ALWAYS use a standard (armadillo constant) precision of 4 digits. – Darkdragon84 Mar 21 '16 at 01:20
  • This is because armadillo defines its own ostream object ``arma_ostream`` (in arma_ostream_bones.hpp and arma_ostream_meat.hpp) and uses that for pretty much all outputs. You can circumvent the (annoying) fixed width of 4 digits by using the ``.raw_print()`` method of arma objects, but the ouput then looks quite messy. – Darkdragon84 Mar 21 '16 at 01:28
  • I would be interested in a solution myself, so please, Odin, unhammer this... – Darkdragon84 Mar 21 '16 at 01:29
  • @DirkEddelbuettel: I dont want to print it out (I can use armadillo-function .raw_print() in this case). I want to store the values with the higher precision for the furher computation. – KTBFFH Mar 21 '16 at 01:33
  • @KTBFFH You may be confusing _formatting precision_ with internal precision. A double is always a double. – Dirk Eddelbuettel Mar 21 '16 at 01:35
  • 2
    the armadillo ``save`` and ``load`` methods store the values in binary format (by default, you can also specify different formats), so with the same precision as the data type, as Dirk pointed out. So even though armadillo might only show you 4 digits, it does store the values with their full precision. – Darkdragon84 Mar 21 '16 at 01:41
  • Well, all your output examples here have different precision. Are you generating the vector in python and then load it in C++? Or are you transferring everything, i.e. you create, store and load the vector entirely in C++ with armadillo? If you create the data outside and then load it with armadillo you might have to pay attention, if you do everything within C++ and armadillo you need not worry about precision. – Darkdragon84 Mar 21 '16 at 02:52
  • @Darkdragon84 sorry.. it was only the first part of my comment. I had no more characters to post the output of the dot-product I got with armadillo. But you are right, the output examples have different precision. And it has a huge difference if I operate with high-dimensional matrices. In my final result (comparing with python-results) only 4 decimal digits of precision of every value matched. To your question: I load the data from txt-file: vector.load("vector.txt", raw_ascii), where vector is fvec (for float). And I want exactly the same output as in python. – KTBFFH Mar 21 '16 at 03:13
  • but the result of the dot product is correct? – Darkdragon84 Mar 21 '16 at 03:53
  • @Darkdragon84: that's a really good question. in python I calculate the dot product with mu.dot(mu), where mu ist the vector with a 1x200 dimension. in armadillo I calculate dot(mu, mu) (also accu(mu%mu) ) giving me the other result. I mean, that only 6 decimal digits of the result matches. Trying to figure out where I made a mistake, I reduced the vector to 10 values -> same result of the dot product for python and armadillo (the same essentially noise for 17+ digits). Then with 20 values -> same result with high precision. – KTBFFH Mar 21 '16 at 12:45
  • @Darkdragon84 But when I tryied with 25 values, I suddenly got the huge difference! python: 1.2013219594955 armadillo: 1.2013220787048. Only 5 decimal digits matched! Why?. Thanks in advance – KTBFFH Mar 21 '16 at 12:46

0 Answers0