File: sparse_shape_fixture.h

package info (click to toggle)
tiledarray 0.6.0-5.2
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 5,844 kB
  • sloc: cpp: 31,688; sh: 237; ansic: 227; makefile: 57; python: 12
file content (95 lines) | stat: -rw-r--r-- 3,017 bytes parent folder | download | duplicates (2)
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
/*
 *  This file is a part of TiledArray.
 *  Copyright (C) 2014  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/>.
 *
 *  Justus Calvin
 *  Department of Chemistry, Virginia Tech
 *
 *  sparse_shape_fixture.h
 *  Feb 23, 2014
 *
 */

#ifndef TILEDARRAY_TEST_SPARSE_SHAPE_FIXTURE_H__INCLUDED
#define TILEDARRAY_TEST_SPARSE_SHAPE_FIXTURE_H__INCLUDED

#include "TiledArray/sparse_shape.h"
#include "range_fixture.h"

namespace TiledArray {


  struct SparseShapeFixture : public TiledRangeFixture{
    typedef std::vector<std::size_t> vec_type;

    SparseShapeFixture() :
      sparse_shape(make_shape(tr, 0.5, 42)),
      left(make_shape(tr, 0.1, 23)),
      right(make_shape(tr, 0.1, 82)),
      perm(make_perm()),
      perm_index(tr.tiles_range(), perm),
      tolerance(0.0001)

    {
      SparseShape<float>::threshold(0.001);
    }

    ~SparseShapeFixture() { }


    static Tensor<float> make_norm_tensor(const TiledRange& trange, const float fill_percent, const int seed) {
      GlobalFixture::world->srand(seed);
      Tensor<float> norms(trange.tiles_range());
      for(Tensor<float>::size_type i = 0ul; i < norms.size(); ++i) {
        const Range range = trange.make_tile_range(i);
        norms[i] = (GlobalFixture::world->rand() % 101);
        norms[i] = std::sqrt(norms[i] * norms[i] * range.volume());
      }

      const std::size_t n = float(norms.size()) * (1.0 - fill_percent);
      for(std::size_t i = 0ul; i < n; ++i) {
        norms[GlobalFixture::world->rand() % norms.size()] = SparseShape<float>::threshold() * 0.1;
      }

      return norms;
    }

    static SparseShape<float> make_shape(const TiledRange& trange, const float fill_percent, const int seed) {
      Tensor<float> tile_norms = make_norm_tensor(trange, fill_percent, seed);
      return SparseShape<float>(tile_norms, trange);
    }

    static Permutation make_perm() {
      std::array<unsigned int, GlobalFixture::dim> temp;
      for(std::size_t i = 0; i < temp.size(); ++i)
        temp[i] = i + 1;

      temp.back() = 0;

      return Permutation(temp.begin(), temp.end());
    }

    SparseShape<float> sparse_shape;
    SparseShape<float> left;
    SparseShape<float> right;
    Permutation perm;
    TiledArray::detail::PermIndex perm_index;
    const float tolerance;
  }; // SparseShapeFixture

} // namespace TiledArray

#endif // TILEDARRAY_TEST_SPARSE_SHAPE_FIXTURE_H__INCLUDED