File: range_fixture.h

package info (click to toggle)
tiledarray 1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 9,568 kB
  • sloc: cpp: 53,449; javascript: 1,599; sh: 393; ansic: 226; python: 223; xml: 195; makefile: 36
file content (118 lines) | stat: -rw-r--r-- 3,567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 *  This file is a part of TiledArray.
 *  Copyright (C) 2013  Virginia Tech
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef TILEDARRAY_RANGE_FIXTURE_H__INCLUDED
#define TILEDARRAY_RANGE_FIXTURE_H__INCLUDED

#include <iostream>
#include "TiledArray/range.h"
#include "TiledArray/tiled_range.h"
#include "TiledArray/tiled_range1.h"
#include "global_fixture.h"

using namespace TiledArray;

struct RangeFixture {
  typedef Range::index_view_type index_view_type;
  typedef Range::index index;
  typedef Range::size_type size_type;

  static const index start;
  static const index finish;
  static const std::vector<std::size_t> size;
  static const std::vector<std::size_t> weight;
  static const size_type volume;
  static const index p0;
  static const index p1;
  static const index p2;
  static const index p3;
  static const index p4;
  static const index p5;
  static const index p6;

  RangeFixture() : r(start, finish) {}

  ~RangeFixture() {}

  template <typename A>
  static std::vector<std::size_t> calc_weight(const A& size, unsigned int n) {
    std::vector<std::size_t> weight(n);
    std::size_t volume = 1ul;
    for (int i = int(n) - 1; i >= 0; --i) {
      weight[i] = volume;
      volume *= size[i];
    }
    return weight;
  }

  Range r;
};

struct Range1Fixture {
  static const size_t ntiles = 5;

  Range1Fixture()
      : a(init_tiling<ntiles + 1>()),
        tiles(0, a.size() - 1),
        elements(a.front(), a.back()),
        tr1(a.begin(), a.end()) {}
  ~Range1Fixture() {}

  template <std::size_t D>
  static std::array<std::size_t, D> init_tiling() {
    std::array<std::size_t, D> result;
    result[0] = 0u;
    for (std::size_t i = 1; i < D; ++i)
      result[i] = result[i - 1] + GlobalFixture::primes[i - 1];
    return result;
  }

  const std::array<std::size_t, ntiles + 1> a;
  const TiledRange1::range_type tiles;
  const TiledRange1::range_type elements;
  TiledRange1 tr1;
  std::array<TiledRange1::range_type, ntiles> tile;
};

struct TiledRangeFixtureBase : public Range1Fixture {
  TiledRangeFixtureBase() : dims(GlobalFixture::dim, tr1) {}
  std::vector<TiledRange1> dims;
};  // struct TiledRangeFixtureBase

struct TiledRangeFixture : public RangeFixture, public TiledRangeFixtureBase {
  typedef TiledRange TRangeN;
  typedef TRangeN::range_type::index tile_index;

  TiledRangeFixture()
      : tiles_range(TiledRangeFixture::index(GlobalFixture::dim, 0),
                    TiledRangeFixture::index(GlobalFixture::dim, 5)),
        elements_range(TiledRangeFixture::tile_index(GlobalFixture::dim, 0),
                       TiledRangeFixture::tile_index(GlobalFixture::dim, a[5])),
        tr(dims.begin(), dims.end()) {}

  ~TiledRangeFixture() {}

  static tile_index fill_tile_index(TRangeN::range_type::index::value_type);

  const TRangeN::range_type tiles_range;
  const TRangeN::range_type elements_range;
  TRangeN tr;
};

#endif  // TILEDARRAY_RANGE_FIXTURE_H__INCLUDED