tensor-0.1.0
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
io.h
1 // -*- mode: c++; fill-column: 80; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  Copyright (c) 2010 Juan Jose Garcia Ripoll
4 
5  Tensor is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published
7  by the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Library General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef TENSOR_IO_H
21 #define TENSOR_IO_H
22 
23 #include <iostream>
24 #include <tensor/tensor.h>
25 #include <tensor/sparse.h>
26 
27 namespace tensor {
28 
30 template<typename elt_t>
31 std::ostream &operator<<(std::ostream &s, const Vector<elt_t> &t);
32 
34 template<typename elt_t>
35 std::ostream &operator<<(std::ostream &s, const Tensor<elt_t> &t);
36 
38 template<typename elt_t>
39 std::ostream &operator<<(std::ostream &s, const Tensor<elt_t> &t);
40 
41 template<typename t, size_t n>
42 inline std::ostream &operator<<(std::ostream &s, const StaticVector<t,n> &v)
43 {
44  return s << Vector<t>(v);
45 }
46 
48 template<typename elt_t>
49 inline std::ostream &operator<<(std::ostream &s, const Sparse<elt_t> &t)
50 {
51  return s << full(t);
52 }
53 
54 /* The following is a template used for creating an object that displays
55  * a tensor with a slightly more attractive representation. We need to
56  * create a template and then specializations because templates do not do
57  * implicit type coercion. */
58 template<typename elt_t>
59 class MatrixForm {
60  const Tensor<elt_t> data;
61  MatrixForm();
62 public:
64  MatrixForm(const Tensor<elt_t> &t) : data(t) {}
65  std::ostream &display(std::ostream &s) const;
66 };
67 
68 template<typename elt_t>
69 inline std::ostream &operator<<(std::ostream &s, const MatrixForm<elt_t> &m) {
70  return m.display(s);
71 }
72 
74 const MatrixForm<double> matrix_form(const Tensor<double> &t);
75 
77 const MatrixForm<cdouble> matrix_form(const Tensor<cdouble> &t);
78 
80 const MatrixForm<double> matrix_form(const Sparse<double> &t);
81 
83 const MatrixForm<cdouble> matrix_form(const Sparse<cdouble> &t);
84 
85 } // namespace tensor
86 
87 #include <tensor/detail/io.hpp>
88 
89 #endif // !TENSOR_IO_H