dense_shape.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2013 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  * dense_shape.h
22  * Jul 9, 2013
23  *
24  */
25 
26 #ifndef TILEDARRAY_DENSE_SHAPE_H__INCLUDED
27 #define TILEDARRAY_DENSE_SHAPE_H__INCLUDED
28 
29 #include <TiledArray/config.h>
30 #include <TiledArray/type_traits.h>
31 #include <cstdint>
32 
33 namespace madness {
34 class World;
35 } // namespace madness
36 
37 namespace TiledArray {
38 
39 // Forward declarations
40 namespace math {
41 class GemmHelper;
42 } // namespace math
43 class Range;
44 class Permutation;
45 class TiledRange;
46 using madness::World;
47 
49 
53 class DenseShape {
54  public:
55  using index1_type = TA_1INDEX_TYPE;
56  using value_type = float;
57 
58  // There is no data in DenseShape so the compiler generated constructors,
59  // assignment operator, and destructor are OK.
60 
61  DenseShape() = default;
62  DenseShape(const DenseShape&) = default;
63  DenseShape(DenseShape&&) = default;
64  DenseShape& operator=(const DenseShape&) = default;
66  ~DenseShape() = default;
67 
68  // Several no-op constructors are needed to make it interoperable with
69  // SparseShape
70  template <typename Real>
71  DenseShape(Real&&, const TiledRange&) {}
72 
74 
76  static void collective_init(World&) {}
77 
79 
81  static constexpr bool validate(const Range&) { return true; }
82 
84 
87  template <typename Index>
88  static constexpr bool is_zero(const Index&) {
89  return false;
90  }
91 
93 
95  static constexpr bool is_dense() { return true; }
96 
98 
100  static constexpr float sparsity() { return 0.0f; }
101 
103 
105  static value_type threshold() { return threshold_; }
106 
108 
110  static void threshold(const value_type thresh) { threshold_ = thresh; }
111 
113 
115  static constexpr bool empty() { return false; }
116 
117  DenseShape mask(const DenseShape&) const { return DenseShape{}; };
118 
119  template <typename Index1, typename Index2,
120  typename = std::enable_if_t<detail::is_integral_range_v<Index1> &&
121  detail::is_integral_range_v<Index2>>>
122  static DenseShape update_block(const Index1&, const Index2&,
123  const DenseShape&) {
124  return DenseShape();
125  }
126 
127  template <typename Index1, typename Index2,
128  typename = std::enable_if_t<std::is_integral_v<Index1> &&
129  std::is_integral_v<Index2>>>
130  static DenseShape update_block(const std::initializer_list<Index1>&,
131  const std::initializer_list<Index2>&,
132  const DenseShape&) {
133  return DenseShape();
134  }
135 
136  template <typename PairRange,
137  typename = std::enable_if_t<detail::is_gpair_range_v<PairRange>>>
138  DenseShape update_block(const PairRange& bounds,
139  const DenseShape& other) const {
140  return DenseShape();
141  }
142 
143  template <typename Index,
144  typename = std::enable_if_t<std::is_integral_v<Index>>>
146  const std::initializer_list<std::initializer_list<Index>>&,
147  const DenseShape&) {
148  return DenseShape();
149  }
150 
151  template <typename Index1, typename Index2,
152  typename = std::enable_if_t<detail::is_integral_range_v<Index1> &&
153  detail::is_integral_range_v<Index2>>>
154  static DenseShape block(const Index1&, const Index2&) {
155  return DenseShape();
156  }
157 
158  template <typename Index1, typename Index2,
159  typename = std::enable_if_t<std::is_integral_v<Index1> &&
160  std::is_integral_v<Index2>>>
161  static DenseShape block(const std::initializer_list<Index1>&,
162  const std::initializer_list<Index2>&) {
163  return DenseShape();
164  }
165 
166  template <typename PairRange,
167  typename = std::enable_if_t<detail::is_gpair_range_v<PairRange>>>
168  DenseShape block(const PairRange& bounds) const {
169  return DenseShape();
170  }
171 
172  template <typename Index,
173  typename = std::enable_if_t<std::is_integral_v<Index>>>
175  const std::initializer_list<std::initializer_list<Index>>&) {
176  return DenseShape();
177  }
178 
179  template <typename Index1, typename Index2, typename Scalar,
180  typename = std::enable_if_t<detail::is_integral_range_v<Index1> &&
181  detail::is_integral_range_v<Index2> &&
182  detail::is_numeric_v<Scalar>>>
183  static DenseShape block(const Index1&, const Index2&, const Scalar) {
184  return DenseShape();
185  }
186 
187  template <typename Index1, typename Index2, typename Scalar,
188  typename = std::enable_if_t<std::is_integral_v<Index1> &&
189  std::is_integral_v<Index2> &&
190  detail::is_numeric_v<Scalar>>>
191  static DenseShape block(const std::initializer_list<Index1>&,
192  const std::initializer_list<Index2>&, const Scalar) {
193  return DenseShape();
194  }
195 
196  template <typename PairRange, typename Scalar,
197  typename = std::enable_if_t<detail::is_gpair_range_v<PairRange> &&
198  detail::is_numeric_v<Scalar>>>
199  DenseShape block(const PairRange& bounds, const Scalar) const {
200  return DenseShape();
201  }
202 
203  template <typename Index, typename Scalar,
204  typename = std::enable_if_t<std::is_integral_v<Index> &&
205  detail::is_numeric_v<Scalar>>>
207  const std::initializer_list<std::initializer_list<Index>>&,
208  const Scalar) {
209  return DenseShape();
210  }
211 
212  template <typename Index1, typename Index2,
213  typename = std::enable_if_t<detail::is_integral_range_v<Index1> &&
214  detail::is_integral_range_v<Index2>>>
215  static DenseShape block(const Index1&, const Index2&, const Permutation&) {
216  return DenseShape();
217  }
218 
219  template <typename Index1, typename Index2,
220  typename = std::enable_if_t<std::is_integral_v<Index1> &&
221  std::is_integral_v<Index2>>>
222  static DenseShape block(const std::initializer_list<Index1>&,
223  const std::initializer_list<Index2>&,
224  const Permutation&) {
225  return DenseShape();
226  }
227 
228  template <typename PairRange,
229  typename = std::enable_if_t<detail::is_gpair_range_v<PairRange>>>
230  DenseShape block(const PairRange& bounds, const Permutation&) const {
231  return DenseShape();
232  }
233 
234  template <typename Index,
235  typename = std::enable_if_t<std::is_integral_v<Index>>>
237  const std::initializer_list<std::initializer_list<Index>>&,
238  const Permutation&) {
239  return DenseShape();
240  }
241 
242  template <typename Index1, typename Index2, typename Scalar,
243  typename = std::enable_if_t<detail::is_integral_range_v<Index1> &&
244  detail::is_integral_range_v<Index2> &&
245  detail::is_numeric_v<Scalar>>>
246  static DenseShape block(const Index1&, const Index2&, const Scalar,
247  const Permutation&) {
248  return DenseShape();
249  }
250 
251  template <typename Index1, typename Index2, typename Scalar,
252  typename = std::enable_if_t<std::is_integral_v<Index1> &&
253  std::is_integral_v<Index2> &&
254  detail::is_numeric_v<Scalar>>>
255  static DenseShape block(const std::initializer_list<Index1>&,
256  const std::initializer_list<Index2>&, const Scalar,
257  const Permutation&) {
258  return DenseShape();
259  }
260 
261  template <typename PairRange, typename Scalar,
262  typename = std::enable_if_t<detail::is_gpair_range_v<PairRange> &&
263  detail::is_numeric_v<Scalar>>>
264  DenseShape block(const PairRange& bounds, const Scalar,
265  const Permutation&) const {
266  return DenseShape();
267  }
268 
269  template <typename Index, typename Scalar,
270  typename = std::enable_if_t<std::is_integral_v<Index> &&
271  detail::is_numeric_v<Scalar>>>
273  const std::initializer_list<std::initializer_list<Index>>&, const Scalar,
274  const Permutation&) {
275  return DenseShape();
276  }
277 
278  static DenseShape perm(const Permutation&) { return DenseShape(); }
279 
280  template <typename Scalar>
281  static DenseShape scale(const Scalar) {
282  return DenseShape();
283  }
284 
285  template <typename Scalar>
286  static DenseShape scale(const Scalar, const Permutation&) {
287  return DenseShape();
288  }
289 
290  static DenseShape add(const DenseShape&) { return DenseShape(); }
291 
292  static DenseShape add(const DenseShape&, const Permutation&) {
293  return DenseShape();
294  }
295 
296  template <typename Scalar>
297  static DenseShape add(const DenseShape&, const Scalar) {
298  return DenseShape();
299  }
300 
301  template <typename Scalar>
302  static DenseShape add(const DenseShape&, const Scalar, const Permutation&) {
303  return DenseShape();
304  }
305 
306  template <typename Scalar>
307  static DenseShape add(const Scalar) {
308  return DenseShape();
309  }
310 
311  template <typename Scalar>
312  static DenseShape add(const Scalar, const Permutation&) {
313  return DenseShape();
314  }
315 
316  static DenseShape subt(const DenseShape&) { return DenseShape(); }
317 
318  static DenseShape subt(const DenseShape&, const Permutation&) {
319  return DenseShape();
320  }
321 
322  template <typename Scalar>
323  static DenseShape subt(const DenseShape&, const Scalar) {
324  return DenseShape();
325  }
326 
327  template <typename Scalar>
328  static DenseShape subt(const DenseShape&, const Scalar, const Permutation&) {
329  return DenseShape();
330  }
331 
332  template <typename Scalar>
333  static DenseShape subt(const Scalar) {
334  return DenseShape();
335  }
336 
337  template <typename Scalar>
338  static DenseShape subt(const Scalar, const Permutation&) {
339  return DenseShape();
340  }
341 
342  static DenseShape mult(const DenseShape&) { return DenseShape(); }
343 
344  static DenseShape mult(const DenseShape&, const Permutation&) {
345  return DenseShape();
346  }
347 
348  template <typename Scalar>
349  static DenseShape mult(const DenseShape&, const Scalar) {
350  return DenseShape();
351  }
352 
353  template <typename Scalar>
354  static DenseShape mult(const DenseShape&, const Scalar, const Permutation&) {
355  return DenseShape();
356  }
357 
358  template <typename Scalar>
359  static DenseShape gemm(const DenseShape&, const Scalar,
360  const math::GemmHelper&) {
361  return DenseShape();
362  }
363 
364  template <typename Scalar>
365  static DenseShape gemm(const DenseShape&, const Scalar,
366  const math::GemmHelper&, const Permutation&) {
367  return DenseShape();
368  }
369 
370  template <typename Archive>
371  void serialize(const Archive& ar) const {}
372 
373  private:
374  inline static value_type threshold_ =
375  std::numeric_limits<value_type>::epsilon();
376 }; // class DenseShape
377 
378 constexpr inline bool operator==(const DenseShape& a, const DenseShape& b) {
379  return true;
380 }
381 
382 constexpr inline bool operator!=(const DenseShape& a, const DenseShape& b) {
383  return !(a == b);
384 }
385 
386 constexpr inline bool is_replicated(World& world, const DenseShape& t) {
387  return true;
388 }
389 
390 } // namespace TiledArray
391 
392 #endif // TILEDARRAY_DENSE_SHAPE_H__INCLUDED
static constexpr bool is_dense()
Check density.
Definition: dense_shape.h:95
static DenseShape perm(const Permutation &)
Definition: dense_shape.h:278
static DenseShape update_block(const std::initializer_list< std::initializer_list< Index >> &, const DenseShape &)
Definition: dense_shape.h:145
Contraction to *GEMM helper.
Definition: gemm_helper.h:40
DenseShape block(const PairRange &bounds, const Permutation &) const
Definition: dense_shape.h:230
static DenseShape mult(const DenseShape &, const Scalar)
Definition: dense_shape.h:349
DenseShape block(const PairRange &bounds) const
Definition: dense_shape.h:168
static DenseShape block(const std::initializer_list< Index1 > &, const std::initializer_list< Index2 > &, const Permutation &)
Definition: dense_shape.h:222
DenseShape & operator=(const DenseShape &)=default
void serialize(const Archive &ar) const
Definition: dense_shape.h:371
static DenseShape block(const Index1 &, const Index2 &, const Permutation &)
Definition: dense_shape.h:215
static DenseShape block(const std::initializer_list< std::initializer_list< Index >> &, const Scalar)
Definition: dense_shape.h:206
static DenseShape block(const std::initializer_list< std::initializer_list< Index >> &)
Definition: dense_shape.h:174
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:130
bool operator==(const BlockRange &r1, const BlockRange &r2)
BlockRange equality comparison.
Definition: block_range.h:433
static DenseShape add(const Scalar, const Permutation &)
Definition: dense_shape.h:312
static DenseShape block(const std::initializer_list< Index1 > &, const std::initializer_list< Index2 > &, const Scalar)
Definition: dense_shape.h:191
DenseShape block(const PairRange &bounds, const Scalar, const Permutation &) const
Definition: dense_shape.h:264
static DenseShape subt(const DenseShape &, const Permutation &)
Definition: dense_shape.h:318
constexpr bool operator!=(const DenseShape &a, const DenseShape &b)
Definition: dense_shape.h:382
static DenseShape block(const std::initializer_list< Index1 > &, const std::initializer_list< Index2 > &)
Definition: dense_shape.h:161
static DenseShape gemm(const DenseShape &, const Scalar, const math::GemmHelper &, const Permutation &)
Definition: dense_shape.h:365
DenseShape(const DenseShape &)=default
static DenseShape update_block(const Index1 &, const Index2 &, const DenseShape &)
Definition: dense_shape.h:122
static DenseShape block(const Index1 &, const Index2 &)
Definition: dense_shape.h:154
static constexpr bool validate(const Range &)
Validate shape range.
Definition: dense_shape.h:81
static void collective_init(World &)
Collective initialization of a shape.
Definition: dense_shape.h:76
DenseShape update_block(const PairRange &bounds, const DenseShape &other) const
Definition: dense_shape.h:138
DenseShape block(const PairRange &bounds, const Scalar) const
Definition: dense_shape.h:199
static DenseShape block(const Index1 &, const Index2 &, const Scalar, const Permutation &)
Definition: dense_shape.h:246
static constexpr bool empty()
Check if the shape is empty (uninitialized)
Definition: dense_shape.h:115
static DenseShape add(const DenseShape &, const Permutation &)
Definition: dense_shape.h:292
static DenseShape add(const DenseShape &)
Definition: dense_shape.h:290
static DenseShape scale(const Scalar)
Definition: dense_shape.h:281
static constexpr bool is_zero(const Index &)
Check that a tile is zero.
Definition: dense_shape.h:88
static DenseShape subt(const Scalar)
Definition: dense_shape.h:333
Range data of a tiled array.
Definition: tiled_range.h:32
static DenseShape mult(const DenseShape &)
Definition: dense_shape.h:342
static constexpr float sparsity()
Sparsity fraction.
Definition: dense_shape.h:100
static DenseShape subt(const Scalar, const Permutation &)
Definition: dense_shape.h:338
static DenseShape mult(const DenseShape &, const Permutation &)
Definition: dense_shape.h:344
static DenseShape update_block(const std::initializer_list< Index1 > &, const std::initializer_list< Index2 > &, const DenseShape &)
Definition: dense_shape.h:130
DenseShape(Real &&, const TiledRange &)
Definition: dense_shape.h:71
static DenseShape add(const DenseShape &, const Scalar)
Definition: dense_shape.h:297
static DenseShape add(const Scalar)
Definition: dense_shape.h:307
DenseShape(DenseShape &&)=default
static DenseShape block(const std::initializer_list< std::initializer_list< Index >> &, const Scalar, const Permutation &)
Definition: dense_shape.h:272
Dense shape of an array.
Definition: dense_shape.h:53
static DenseShape block(const std::initializer_list< Index1 > &, const std::initializer_list< Index2 > &, const Scalar, const Permutation &)
Definition: dense_shape.h:255
TA_1INDEX_TYPE index1_type
Definition: dense_shape.h:55
static DenseShape block(const std::initializer_list< std::initializer_list< Index >> &, const Permutation &)
Definition: dense_shape.h:236
static DenseShape subt(const DenseShape &, const Scalar)
Definition: dense_shape.h:323
DenseShape & operator=(DenseShape &&)=default
static void threshold(const value_type thresh)
Set threshold to thresh.
Definition: dense_shape.h:110
static value_type threshold()
Threshold accessor.
Definition: dense_shape.h:105
constexpr bool is_replicated(World &world, const DenseShape &t)
Definition: dense_shape.h:386
DenseShape mask(const DenseShape &) const
Definition: dense_shape.h:117
static DenseShape gemm(const DenseShape &, const Scalar, const math::GemmHelper &)
Definition: dense_shape.h:359
static DenseShape subt(const DenseShape &)
Definition: dense_shape.h:316
static DenseShape subt(const DenseShape &, const Scalar, const Permutation &)
Definition: dense_shape.h:328
static DenseShape add(const DenseShape &, const Scalar, const Permutation &)
Definition: dense_shape.h:302
static DenseShape block(const Index1 &, const Index2 &, const Scalar)
Definition: dense_shape.h:183
static DenseShape mult(const DenseShape &, const Scalar, const Permutation &)
Definition: dense_shape.h:354
static DenseShape scale(const Scalar, const Permutation &)
Definition: dense_shape.h:286
A (hyperrectangular) interval on , space of integer -indices.
Definition: range.h:46