Skip to content

Instantly share code, notes, and snippets.

@davidshepherd7
Created June 28, 2013 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidshepherd7/5883871 to your computer and use it in GitHub Desktop.
Save davidshepherd7/5883871 to your computer and use it in GitHub Desktop.
/// \short Indexed output function to print a matrix to the stream outfile
/// as i,j,a(i,j) for a(i,j)!=0 only with a specified precision.
void sparse_indexed_output(std::ostream &outfile,
const unsigned &precision,
const bool& output_bottom_right_entry_regardless=false) const
{
// Note: we might have to specify "output_bottom_right_entry_regardless"
// as well (can't be a default). C++ can silently convert between
// unsigned and bool, so having a default set for
// output_bottom_right_entry_regardless would give the same function
// signature as the normal sparse_indexed_output.
// Set precision and store the previous value
unsigned old_precision = outfile.precision();
outfile.precision(precision);
// Output as normal
sparse_indexed_output(outfile, output_bottom_right_entry_regardless);
// Restore the old value
outfile.precision(old_precision);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment