-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathtrange.h
More file actions
78 lines (66 loc) · 2.16 KB
/
Copy pathtrange.h
File metadata and controls
78 lines (66 loc) · 2.16 KB
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
/*
* This file is a part of TiledArray.
* Copyright (C) 2020 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 TA_PYTHON_TRANGE_H
#define TA_PYTHON_TRANGE_H
#include "python.h"
#include <TiledArray/tiled_range.h>
#include <string>
#include <vector>
namespace TiledArray {
namespace python {
namespace trange {
// template<class ... Args>
// inline TiledRange make_trange(Args ... args);
auto list(const TiledRange &trange) {
std::vector<std::vector<int64_t> > v;
for (auto &&tr1 : trange.data()) {
auto it = tr1.begin();
v.push_back({it->first});
for (; it != tr1.end(); ++it) {
v.back().push_back(it->second);
}
}
return v;
}
inline TiledRange make_trange(std::vector<std::vector<int64_t> > trange) {
std::vector<TiledRange1> trange1;
for (auto tr : trange) {
trange1.emplace_back(tr.begin(), tr.end());
}
return TiledRange(trange1.begin(), trange1.end());
}
// template<>
inline TiledRange make_trange(std::vector<int64_t> shape, size_t block) {
std::vector<TiledRange1> trange1;
for (size_t i = 0; i < shape.size(); ++i) {
trange1.emplace_back(TiledRange1::make_uniform(shape[i], block));
}
return TiledRange(trange1.begin(), trange1.end());
}
void __init__(py::module m) {
// py::class_<TiledRange>(m, "TiledRange")
// .def(py::init(&make_trange< std::vector< std::vector<int64_t> > >))
// ;
// py::implicitly_convertible< std::vector< std::vector<int64_t> >,
// TiledRange>();
}
} // namespace trange
} // namespace python
} // namespace TiledArray
#endif // TA_PYTHON_TRANGE_H