-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatrixIO.h
79 lines (53 loc) · 1.57 KB
/
MatrixIO.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include "Matrix.h"
namespace Numeric_lib {
//-----------------------------------------------------------------------------
template<class T> std::ostream& operator<<(std::ostream& os, const Matrix<T>& v)
{
os << '{';
for (Index i = 0; i<v.dim1(); ++i) {
os << " ";
os << v(i);
}
os << '}';
return os;
}
//-----------------------------------------------------------------------------
template<class T> std::ostream& operator<<(std::ostream& os, const Matrix<T,2>& m)
{
os << "{\n";
for (Index i = 0; i<m.dim1(); ++i)
os << m[i] << '\n';
os << '}';
return os;
}
//-----------------------------------------------------------------------------
template<class T> std::istream& operator>>(std::istream& is, Matrix<T>& v)
{
char ch;
is >> ch;
if (ch!='{') error("'{' missing in Matrix<T,1> input");
for (Index i = 0; i<v.dim1(); ++i)
is >> v(i);
is >> ch;
if (ch!='}') error("'}' missing in Matrix<T,1> input");
return is;
}
//-----------------------------------------------------------------------------
template<class T> std::istream& operator>>(std::istream& is, Matrix<T,2>& m)
{
char ch;
is >> ch;
if (ch!='{') error("'{' missing in Matrix<T,2> input");
for (Index i = 0; i<m.dim1(); ++i)
{
Matrix<T,1> tmp(m.dim2());
is >> tmp;
m[i] = tmp;
}
is >> ch;
if (ch!='}') error("'}' missing in Matrix<T,2> input");
return is;
}
//-----------------------------------------------------------------------------
}