1 | /* |
---|
2 | * Copyright (C) 1997 Todd Veldhuizen <tveldhui@oonumerics.org> |
---|
3 | * All rights reserved. Please see <blitz/blitz.h> for terms and |
---|
4 | * conditions of use. |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #ifndef BZ_TINYMATIO_CC |
---|
9 | #define BZ_TINYMATIO_CC |
---|
10 | |
---|
11 | #ifndef BZ_TINYMAT_H |
---|
12 | #include <blitz/tinymat.h> |
---|
13 | #endif |
---|
14 | |
---|
15 | BZ_NAMESPACE(blitz) |
---|
16 | |
---|
17 | template <typename P_numtype, int N_rows, int N_columns> |
---|
18 | ostream& operator<<(ostream& os, |
---|
19 | const TinyMatrix<P_numtype, N_rows, N_columns>& x) |
---|
20 | { |
---|
21 | os << "(" << N_rows << "," << N_columns << "): " << endl; |
---|
22 | for (int i=0; i < N_rows; ++i) |
---|
23 | { |
---|
24 | os << " [ "; |
---|
25 | for (int j=0; j < N_columns; ++j) |
---|
26 | { |
---|
27 | os << setw(10) << x(i,j); |
---|
28 | if (!((j+1)%7)) |
---|
29 | os << endl << " "; |
---|
30 | } |
---|
31 | os << " ]" << endl; |
---|
32 | } |
---|
33 | return os; |
---|
34 | } |
---|
35 | |
---|
36 | template <typename P_numtype, int N_rows, int N_columns> |
---|
37 | istream& operator>>(istream& is, |
---|
38 | TinyMatrix<P_numtype, N_rows, N_columns>& x) |
---|
39 | { |
---|
40 | int rows, columns; |
---|
41 | char sep; |
---|
42 | |
---|
43 | is >> rows >> columns; |
---|
44 | |
---|
45 | BZPRECHECK(rows == N_rows, "Size mismatch in number of rows"); |
---|
46 | BZPRECHECK(columns == N_columns, "Size mismatch in number of columns"); |
---|
47 | |
---|
48 | for (int i=0; i < N_rows; ++i) |
---|
49 | { |
---|
50 | is >> sep; |
---|
51 | BZPRECHECK(sep == '[', "Format error while scanning input matrix" |
---|
52 | << endl << " (expected '[' before beginning of row data)"); |
---|
53 | for (int j = 0; j < N_columns; ++j) |
---|
54 | { |
---|
55 | BZPRECHECK(!is.bad(), "Premature end of input while scanning matrix"); |
---|
56 | is >> x(i,j); |
---|
57 | } |
---|
58 | is >> sep; |
---|
59 | BZPRECHECK(sep == ']', "Format error while scanning input matrix" |
---|
60 | << endl << " (expected ']' after end of row data)"); |
---|
61 | } |
---|
62 | |
---|
63 | return is; |
---|
64 | } |
---|
65 | |
---|
66 | BZ_NAMESPACE_END |
---|
67 | |
---|
68 | #endif // BZ_TINYMATIO_CC |
---|
69 | |
---|