Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make GenMatrix's PrintDebug work with templates #40

Closed
rcurtin opened this issue Dec 29, 2014 · 6 comments
Closed

Make GenMatrix's PrintDebug work with templates #40

rcurtin opened this issue Dec 29, 2014 · 6 comments
Assignees
Milestone

Comments

@rcurtin
Copy link
Member

rcurtin commented Dec 29, 2014

Reported by march on 10 Oct 40155575 11:33 UTC
PrintDebug() for a GenMatrix only prints floating points correctly. It would be nice if it could handle other basic types (e.g. ints and bools).

@rcurtin
Copy link
Member Author

rcurtin commented Dec 29, 2014

Commented by rcurtin on 19 Feb 40156236 14:40 UTC
metadata fill-in-the-blank (mostly from boredom)

@rcurtin
Copy link
Member Author

rcurtin commented Dec 29, 2014

Commented by jcline3 on 1 Sep 40305653 20:53 UTC
We could do it like so:

  void PrintDebug( const char *name = "", std::ostream& os ) const {
     os <<  "----- MATRIX" << name << " ------" << std::endl;
     for( index_t i = 0; i < length(); i++ ) {
        os << std::fixed << std::setprecision(3) << std::setw(3) << get(i) << " "; 
     }    
     os << std::endl;
  }

(This maintains the previous formatting of "%3.3f ", but should work with other types).

To call it:

obj.PrintDebug( "name", std::cout );

or

obj.PrintDebug( "name", std::cerr );

To actually write to a file, though, you'd have to do:

std::ofstream file("filename");
obj.PrintDebug( "name", file );
file.close();

This means we'd have to go through and change all the things that call it, which isn't a huge deal I guess. We'd just be including ofstream/ostream, and changing the calls like I demonstrated.

@rcurtin
Copy link
Member Author

rcurtin commented Dec 29, 2014

Commented by jcline3 on 19 Feb 40305658 19:33 UTC

void PrintDebug( const char *name = "", std::ostream& os = std::cerr ) const {
...

D'oh.

@rcurtin
Copy link
Member Author

rcurtin commented Dec 29, 2014

Commented by jcline3 on 4 Jul 40305849 15:33 UTC
D'oh part 2.

This one was for !GenVertex.

  void PrintDebug( const char *name = "", std::ostream& os = std::cerr ) const {
     os <<  "----- VERTEX" << name << " ------" << std::endl;
     for( index_t i = 0; i < length(); i++ ) {
        os << std::fixed << std::setprecision(3) << std::setw(3) << std::showpos << get(i) << " "; 
     }    
     os << std::endl;
  }

And for !GenMatrix:

  void PrintDebug( const char *name = "", std::ostream& os = std::cerr ) const {
     os <<  "----- MATRIX" << name << " ------" << std::endl;
     for( index_t r = 0; r < n_rows(); r++ ) {
        for( index_t c = 0; c < n_cols(); c++ ) {
          os << std::fixed << std::setprecision(3) << std::setw(3) << std::showpos << get(r, c) << " ";
        }
     }    
     os << std::endl;
  }

I realized I was stupid after I left today. Anyway, theoretically these are correct.

@rcurtin
Copy link
Member Author

rcurtin commented Dec 29, 2014

Commented by jcline3 on 2 Feb 40363014 20:00 UTC
Whatever we do for the new output system(?) should probably be how we handle this, as well, assuming the class isn't entirely replaced by armadillo.

@rcurtin
Copy link
Member Author

rcurtin commented Dec 29, 2014

Commented by jcline3 on 1 Dec 41152116 20:13 UTC
This class is just getting replaced with arma::mat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants