Skip to content

Commit

Permalink
explicitly set the precision when saving complex matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
conrad committed Mar 15, 2017
1 parent 14fa924 commit 86b29aa
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions include/armadillo_bits/diskio_meat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,29 +797,33 @@ diskio::save_raw_ascii(const Mat<eT>& x, std::ostream& f)

uword cell_width;

// TODO: need sane values for complex numbers

if( (is_float<eT>::value) || (is_double<eT>::value) )
if(is_real<eT>::value)
{
f.setf(ios::scientific);
f.precision(14);
cell_width = 22;
}

if(is_cx<eT>::value)
{
f.setf(ios::scientific);
f.precision(14);
}

for(uword row=0; row < x.n_rows; ++row)
{
for(uword col=0; col < x.n_cols; ++col)
{
f.put(' ');

if( (is_float<eT>::value) || (is_double<eT>::value) )
if(is_real<eT>::value)
{
f.width(std::streamsize(cell_width));
}

arma_ostream::print_elem(f, x.at(row,col), false);
}

f.put('\n');
}

Expand Down Expand Up @@ -923,22 +927,26 @@ diskio::save_arma_ascii(const Mat<eT>& x, std::ostream& f)

uword cell_width;

// TODO: need sane values for complex numbers

if( (is_float<eT>::value) || (is_double<eT>::value) )
if(is_real<eT>::value)
{
f.setf(ios::scientific);
f.precision(14);
cell_width = 22;
}


if(is_cx<eT>::value)
{
f.setf(ios::scientific);
f.precision(14);
}

for(uword row=0; row < x.n_rows; ++row)
{
for(uword col=0; col < x.n_cols; ++col)
{
f.put(' ');

if( (is_float<eT>::value) || (is_double<eT>::value) )
if(is_real<eT>::value)
{
f.width(std::streamsize(cell_width));
}
Expand Down Expand Up @@ -1000,7 +1008,7 @@ diskio::save_csv_ascii(const Mat<eT>& x, std::ostream& f)

const ios::fmtflags orig_flags = f.flags();

// TODO: need sane values for complex numbers
// TODO: need to write each complex elements as "a+ib" instead of the default "(a,b)"

if( (is_float<eT>::value) || (is_double<eT>::value) )
{
Expand Down Expand Up @@ -3138,15 +3146,19 @@ diskio::save_raw_ascii(const Cube<eT>& x, std::ostream& f)

uword cell_width;

// TODO: need sane values for complex numbers

if( (is_float<eT>::value) || (is_double<eT>::value) )
if(is_real<eT>::value)
{
f.setf(ios::scientific);
f.precision(14);
cell_width = 22;
}

if(is_cx<eT>::value)
{
f.setf(ios::scientific);
f.precision(14);
}

for(uword slice=0; slice < x.n_slices; ++slice)
{
for(uword row=0; row < x.n_rows; ++row)
Expand All @@ -3155,7 +3167,7 @@ diskio::save_raw_ascii(const Cube<eT>& x, std::ostream& f)
{
f.put(' ');

if( (is_float<eT>::value) || (is_double<eT>::value) )
if(is_real<eT>::value)
{
f.width(std::streamsize(cell_width));
}
Expand Down Expand Up @@ -3267,15 +3279,19 @@ diskio::save_arma_ascii(const Cube<eT>& x, std::ostream& f)

uword cell_width;

// TODO: need sane values for complex numbers

if( (is_float<eT>::value) || (is_double<eT>::value) )
if(is_real<eT>::value)
{
f.setf(ios::scientific);
f.precision(14);
cell_width = 22;
}


if(is_cx<eT>::value)
{
f.setf(ios::scientific);
f.precision(14);
}

for(uword slice=0; slice < x.n_slices; ++slice)
{
for(uword row=0; row < x.n_rows; ++row)
Expand All @@ -3284,7 +3300,7 @@ diskio::save_arma_ascii(const Cube<eT>& x, std::ostream& f)
{
f.put(' ');

if( (is_float<eT>::value) || (is_double<eT>::value) )
if(is_real<eT>::value)
{
f.width(std::streamsize(cell_width));
}
Expand Down

0 comments on commit 86b29aa

Please sign in to comment.