/
matrix-io.h
55 lines (40 loc) · 1.08 KB
/
matrix-io.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// matrix-io.h -- Debugging output for Matrix type
//
// Copyright (C) 2010, 2011 Miles Bader <miles@gnu.org>
//
// This source code is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 3, or (at
// your option) any later version. See the file COPYING for more details.
//
// Written by Miles Bader <miles@gnu.org>
//
#ifndef SNOGRAY_MATRIX_IO_H
#define SNOGRAY_MATRIX_IO_H
#include <iosfwd>
#include "nice-io.h"
#include "matrix.h"
namespace snogray {
template<typename T>
std::ostream&
operator<< (std::ostream &os, const Matrix<T> &matrix)
{
// this syntax isn't the prettiest, but is kind of compatible with
// emacs calc, Lua, and C
os << "matrix{{";
for (unsigned row = 0; row < matrix.rows(); row++)
{
if (row > 0)
os << "}, {";
for (unsigned col = 0; col < matrix.columns(); col++)
{
if (col > 0)
os << ", ";
output_nicely (os, matrix (col, row));
}
}
os << "}}";
return os;
}
}
#endif // SNOGRAY_MATRIX_IO_H