TiledArray  0.7.0
tensor.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2015 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 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 General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Justus Calvin
19  * Department of Chemistry, Virginia Tech
20  *
21  * tensor.h
22  * Jun 16, 2015
23  *
24  */
25 
26 #ifndef TILEDARRAY_TENSOR_H__INCLUDED
27 #define TILEDARRAY_TENSOR_H__INCLUDED
28 
34 #include <TiledArray/block_range.h>
35 
36 namespace TiledArray {
37 
38  // Template aliases for TensorInterface objects
39 
40  template <typename T>
41  using TensorView =
43 
44  template <typename T>
45  using TensorConstView =
47 
48 
50 
56  template <typename T,
57  typename std::enable_if<
60  inline std::ostream& operator<<(std::ostream& os, const T& t) {
61  os << t.range() << " { ";
62  const auto n = t.range().volume();
63  for(auto i = 0ul; i < n; ++i)
64  os << t[i] << " ";
65 
66  os << "}";
67 
68  return os;
69  }
70 
72 
78  template <typename T,
79  typename std::enable_if<
81  ! detail::is_contiguous_tensor<T>::value>::type* = nullptr>
82  inline std::ostream& operator<<(std::ostream& os, const T& t) {
83 
84  const auto stride = inner_size(t);
85  const auto volume = t.range().volume();
86 
87  auto tensor_print_range =
88  [&os,stride] (typename T::const_pointer MADNESS_RESTRICT const t_data) {
89  for(decltype(t.range().volume()) i = 0ul; i < stride; ++i)
90  os << t_data[i] << " ";
91  };
92 
93  os << t.range() << " { ";
94 
95  for(decltype(t.range().volume()) i = 0ul; i < volume; i += stride)
96  tensor_print_range(t.data() + t.range().ordinal(i));
97 
98  os << "}";
99 
100  return os;
101  }
102 
103 } // namespace TiledArray
104 
105 #endif // TILEDARRAY_SRC_TILEDARRAY_TENSOR_H__INCLUDED
T1::size_type inner_size(const T1 &tensor1, const T2 &)
Get the inner size of two tensors.
Definition: utility.h:313
Tensor interface for external data.
std::ostream & operator<<(std::ostream &os, const DistArray< Tile, Policy > &a)
Add the tensor to an output stream.
Definition: dist_array.h:853
detail::TensorInterface< T, BlockRange > TensorView
Definition: tensor.h:42
Range that references a subblock of another range.
Definition: block_range.h:34
static constexpr bool value
Definition: type_traits.h:92