MyraMath
print.h
Go to the documentation of this file.
1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
6 #ifndef MYRAMATH_EXPRESSION_PRINT_H
7 #define MYRAMATH_EXPRESSION_PRINT_H
8 
16 
17 #include <iostream>
18 
19 namespace myra {
20 
22 template<class Number> std::ostream& operator << (std::ostream& out, const Expression<1,Number>& e)
23  {
24  Index<1> index = e.size();
25  int N = index[0];
26  out << "size " << N << " arity-1 Expression of " << typestring<Number>() << ": " << std::endl;
27  out << "[ ";
28  for (int n = 0; n < N; ++n)
29  out << e.evaluate(make_Index(n)) << " ";
30  out << "]" << std::endl;
31  return out;
32  }
33 
35 template<class Number> std::ostream& operator << (std::ostream& out, const Expression<2,Number>& e)
36  {
37  Index<2> index = e.size();
38  int I = index[0];
39  int J = index[1];
40  out << "size " << I << " by " << J << " arity-2 Expression of " << typestring<Number>() << ": " << std::endl;
41  for (int i = 0; i < I; ++i)
42  {
43  out << "[ ";
44  for (int j = 0; j < J; ++j)
45  out << e.evaluate(make_Index(i,j)) << " ";
46  out << "]" << std::endl;
47  }
48  return out;
49  }
50 
52 template<int Arity> std::ostream& operator << (std::ostream& out, const Index<Arity>& index)
53  {
54  out << "[ ";
55  int N = Arity;
56  for (int n = 0; n < N; ++n)
57  out << index[n] << " ";
58  out << "]";
59  return out;
60  }
61 
62 } // namespace myra
63 
64 #endif
Implementation detail of Expression templates.
An interface used to fill containers from Expression&#39;s (see Matrix::evaluate(), for example)...
Definition: syntax.dox:1
Essentially a std::array<int,N>, provided for backwards compatibility.
Definition: Index.h:23