mptensor  v0.3.0
Parallel Library for Tensor Network Methods
Loading...
Searching...
No Matches
index.hpp
Go to the documentation of this file.
1/*
2 mptensor - Parallel Library for Tensor Network Methods
3
4 Copyright 2016 Satoshi Morita
5
6 mptensor is free software: you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation, either version 3 of the
9 License, or (at your option) any later version.
10
11 mptensor is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with mptensor. If not, see
18 <https://www.gnu.org/licenses/>.
19*/
20
29#ifndef _INDEX_HPP_
30#define _INDEX_HPP_
31
32#include <iostream>
33#include <vector>
34
35namespace mptensor {
38
39class Index {
40 public:
41 typedef std::vector<size_t> index_t;
42 Index();
43 Index(const index_t& index);
44
45// constructors like as Index(size_t j0,size_t j1,size_t j2);
46#include "index_constructor.hpp"
47
48 const size_t& operator[](size_t i) const;
49 size_t& operator[](size_t i);
50 size_t size() const;
51 void push(size_t i);
52 void resize(size_t n);
53
54 void assign(size_t n, size_t j[]);
55 void sort();
56 Index inverse();
57
58 bool operator==(const Index&) const;
59 Index& operator+=(const Index&);
60
61 private:
62 index_t idx;
63};
64
66std::ostream& operator<<(std::ostream& os, const Index& idx);
67Index operator+(const Index&, const Index&);
69
70/* ---------- constructors ---------- */
71
72inline Index::Index() : idx(){};
73inline Index::Index(const index_t& index) : idx(index){};
74
75/* ---------- inline member functions ---------- */
76
77inline const size_t& Index::operator[](size_t i) const { return idx[i]; };
78inline size_t& Index::operator[](size_t i) { return idx[i]; };
79inline size_t Index::size() const { return idx.size(); };
80inline void Index::push(size_t i) { idx.push_back(i); };
81inline void Index::resize(size_t n) { idx.resize(n); };
82
83/* ---------- non-member functions ---------- */
84Index range(const size_t start, const size_t stop);
85inline Index range(const size_t stop) { return range(0, stop); };
86
88} // namespace mptensor
89
90#endif // _INDEX_HPP_
Definition index.hpp:39
const size_t & operator[](size_t i) const
Definition index.hpp:77
bool operator==(const Index &) const
Definition index.cc:53
void resize(size_t n)
Definition index.hpp:81
std::vector< size_t > index_t
Definition index.hpp:41
void assign(size_t n, size_t j[])
Definition index.cc:37
void push(size_t i)
Definition index.hpp:80
Index inverse()
Definition index.cc:44
Index & operator+=(const Index &)
Definition index.cc:61
void sort()
Definition index.cc:42
size_t size() const
Definition index.hpp:79
Index()
Definition index.hpp:72
std::complex< double > complex
Definition complex.hpp:38
Definition complex.hpp:34
std::ostream & operator<<(std::ostream &os, const Index &idx)
Index range(const size_t start, const size_t stop)
Create an increasing sequence. it is similar to range() in python.
Definition index.cc:91
Index operator+(const Index &, const Index &)