v0.6.10
Tensor1_value.hpp
Go to the documentation of this file.
1 /* The general version, not for pointers. */
2 
3 template <class T, int Tensor_Dim>
4 class Tensor1
5 {
6  T data[Tensor_Dim];
7 public:
8  /* Initializations for varying numbers of elements, with each one
9  defined for a particular Tensor_Dim. To initialize a different
10  dimension, just add the appropriate constructor and call to
11  the Tensor1_constructor constructor. */
12  Tensor1(T d0, T d1)
13  {
15  }
16  Tensor1(T d0, T d1, T d2)
17  {
19  }
20  Tensor1(T d0, T d1, T d2, T d3)
21  {
23  }
24 
25  Tensor1() {}
26 
27  /* There are two operator(int)'s, one for non-consts that lets you
28  change the value, and one for consts that doesn't. */
29 
30  T & operator()(const int N)
31  {
32 #ifdef FTENSOR_DEBUG
33  if(N>=Tensor_Dim || N<0)
34  {
35  std::stringstream s;
36  s << "Bad index in Tensor1<T," << Tensor_Dim
37  << ">.operator(" << N << ")" << std::endl;
38  throw std::runtime_error(s.str());
39  }
40 #endif
41  return data[N];
42  }
43  T operator()(const int N) const
44  {
45 #ifdef FTENSOR_DEBUG
46  if(N>=Tensor_Dim || N<0)
47  {
48  std::stringstream s;
49  s << "Bad index in Tensor1<T," << Tensor_Dim
50  << ">.operator(" << N << ") const" << std::endl;
51  throw std::runtime_error(s.str());
52  }
53 #endif
54  return data[N];
55  }
56 
57  /* These operator()'s are the first part in constructing template
58  expressions. They can be used to slice off lower dimensional
59  parts. They are not entirely safe, since you can accidently use a
60  higher dimension than what is really allowed (like Dim=5). */
61 
62  template<char i, int Dim>
65  {
66  return Tensor1_Expr<Tensor1<T,Tensor_Dim>,T,Dim,i>(*this);
67  }
68 
69  template<char i, int Dim>
71  operator()(const Index<i,Dim> &) const
72  {
73  return Tensor1_Expr<const Tensor1<T,Tensor_Dim>,T,Dim,i>(*this);
74  }
75 };
Tensor1(T d0, T d1, T d2, T d3)
Tensor1_Expr< Tensor1< T, Tensor_Dim >, T, Dim, i > operator()(const Index< i, Dim > &)
Tensor1_Expr< const Tensor1< T, Tensor_Dim >, T, Dim, i > operator()(const Index< i, Dim > &) const
T data[Tensor_Dim]
T & operator()(const int N)
Tensor1(T d0, T d1)
Definition: Index.hpp:20
Tensor1(T d0, T d1, T d2)
const int N
Definition: speed_test.cpp:3
T operator()(const int N) const